Skip to content

Commit

Permalink
feat: standing on the shoulders of giants (#5)
Browse files Browse the repository at this point in the history
* feat: standing on the shoulders of giants

* chore: update docs

* chore: update docs
  • Loading branch information
Wxh16144 authored Feb 19, 2024
1 parent f7e59ee commit d7931e2
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .backuprc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; 默认情况下仅 vscode 调试生效
; 如果要在终端调试请建立软链接, ln -s $PWD/.backuprc $HOME/.backuprc
[storage]
directory = mackup
directory = tmp_backup

[applications_to_ignore]
backup
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
dist
backup

tmp_*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "mackup"]
path = mackup
url = [email protected]:lra/mackup.git
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"program": "${workspaceFolder}/dev.ts",
"args": [
// "-d", // debug
// "-l", // app list
"--config", // show config
"-l", // app list
// "--config", // show config
],
"cwd": "${workspaceFolder}",
"env": {
Expand Down
8 changes: 7 additions & 1 deletion README.en_US.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @wuxh/backup-cli

> Backup your configuration files and directories
> Backup your configuration files and directories [Why?](https://github.com/lra/mackup/issues/1849#issuecomment-1369963734), [lra/mackup#1969](https://github.com/lra/mackup/discussions/1969).
[![npm](https://img.shields.io/npm/v/@wuxh/backup-cli.svg?style=for-the-badge)](https://www.npmjs.com/package/@wuxh/backup-cli)
[![npm](https://img.shields.io/npm/dt/@wuxh/backup-cli.svg?style=for-the-badge)](https://www.npmjs.com/package/@wuxh/backup-cli)
Expand All @@ -27,6 +27,12 @@ backup-cli
backup-cli -r
```

### Support Apps

```bash
backup-cli -l
```

### View Configuration

```bash
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @wuxh/backup-cli

> 备份你的配置文件和目录
> 备份你的配置文件和目录 [为什么重复创造轮子?](https://github.com/lra/mackup/issues/1849#issuecomment-1369963734)[lra/mackup#1969](https://github.com/lra/mackup/discussions/1969)
[![npm](https://img.shields.io/npm/v/@wuxh/backup-cli.svg?style=for-the-badge)](https://www.npmjs.com/package/@wuxh/backup-cli)
[![npm](https://img.shields.io/npm/dt/@wuxh/backup-cli.svg?style=for-the-badge)](https://www.npmjs.com/package/@wuxh/backup-cli)
Expand All @@ -27,6 +27,12 @@ backup-cli
backup-cli -r
```

### 支持的应用程序

```bash
backup-cli -l
```

### 查看配置

```bash
Expand Down
12 changes: 0 additions & 12 deletions applications/bash.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions applications/git.cfg

This file was deleted.

10 changes: 0 additions & 10 deletions applications/iterm2.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions applications/ni.cfg

This file was deleted.

7 changes: 7 additions & 0 deletions applications/reanme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 内置的应用程序 (builtInApps)

在保持 `.backup` 优先级不变的情况下,2.x 开始, 优先使用了 [mackup/mackup/applications](https://github.com/lra/mackup/tree/master/mackup/applications)

所以可以理解成, mackup 不支持的应用程序才会走到当前 applications 中

优先级:customApp > mackup > backup(当前CLI)
6 changes: 0 additions & 6 deletions applications/rust.cfg

This file was deleted.

13 changes: 0 additions & 13 deletions applications/vscode.cfg

This file was deleted.

9 changes: 0 additions & 9 deletions applications/zsh.cfg

This file was deleted.

1 change: 1 addition & 0 deletions mackup
Submodule mackup added at ca38f2
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
},
"files": [
"applications",
"mackup/mackup/applications",
"index.js",
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub",
"start": "esno dev.ts -d",
"prepublishOnly": "npm run build",
"prepublishOnly": "git submodule update --remote && npm run build",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
21 changes: 13 additions & 8 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ import type { AppConfig, Config } from './type'
import type { LoggerType } from './logger'

export async function getAppConfigs() {
// https://github.com/lra/mackup/blob/master/LICENSE
const _defaultAppDir = resolveProjectRoot('mackup/mackup/applications');
const _defaultCustomAppDirPath = resolveHome(CUSTOM_APP_CONFIG_DIR);

const defaultApps = await glob.sync(`*${CONFIG_FILE_EXT}`, {
cwd: resolveProjectRoot('applications'),
cwd: [process.env.BACKUP_DEFAULT_APP_DIR || _defaultAppDir].find(fs.existsSync) || _defaultAppDir,
deep: 1,
absolute: true,
});

const customAppDir = process.env.BACKUP_CUSTOM_APP_DIR
const defaultAppDirPath = resolveHome(CUSTOM_APP_CONFIG_DIR);

const customApps = await glob.sync(`*${CONFIG_FILE_EXT}`, {
cwd: customAppDir && fs.existsSync(customAppDir)
? customAppDir
: defaultAppDirPath,
cwd: [process.env.BACKUP_CUSTOM_APP_DIR || _defaultCustomAppDirPath].find(fs.existsSync) || _defaultCustomAppDirPath,
deep: 1,
absolute: true,
});

const builtInApps = await glob.sync(`*${CONFIG_FILE_EXT}`, {
cwd: resolveProjectRoot('applications'),
deep: 1,
absolute: true,
});

return [...defaultApps, ...customApps]
return [...builtInApps, ...defaultApps, ...customApps]
}

export async function getApps(apps: string[], config: Config = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Obj = Record<string, unknown>;
export type Obj = Record<PropertyKey, any>

export interface Argv {
branch?: string;
Expand Down

0 comments on commit d7931e2

Please sign in to comment.