Skip to content

Commit 0fd9b1a

Browse files
trousevsy-records
andauthored
feat: add --overwrite flag to generator (#182)
Co-authored-by: Lu Fei <[email protected]>
1 parent 6cb8efc commit 0fd9b1a

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ docsify serve [path] [--open false] [--port 3000]
9999
Docsify's generators.
100100

101101
```shell
102-
docsify generate [path] [--sidebar _sidebar.md]
102+
docsify generate [path] [--sidebar _sidebar.md] [--overwrite]
103103

104-
# docsify g [path] [-s _sidebar.md]
104+
# docsify g [path] [-s _sidebar.md] [-o]
105105
```
106106

107107
- `--sidebar` option:
@@ -110,6 +110,12 @@ docsify generate [path] [--sidebar _sidebar.md]
110110
- Default: `_sidebar.md`
111111
- Description: Generate sidebar file, defaults to `_sidebar.md`.
112112

113+
- `--overwrite` option:
114+
- Shorthand: `-o`
115+
- Type: boolean
116+
- Default: `false`
117+
- Description: Allow overwrite generated files.
118+
113119
## Contributing
114120
Please see the [Contributing Guidelines](./CONTRIBUTING.md)
115121

docs/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ docsify serve [path] [--open false] [--port 3000]
8484
Docsify's generators.
8585

8686
```shell
87-
docsify generate [path] [--sidebar _sidebar.md]
87+
docsify generate [path] [--sidebar _sidebar.md] [--overwrite]
8888

89-
# docsify g [path] [-s _sidebar.md]
89+
# docsify g [path] [-s _sidebar.md] [-o]
9090
```
9191

9292
- `--sidebar` option:
@@ -95,6 +95,12 @@ docsify generate [path] [--sidebar _sidebar.md]
9595
- Default: `_sidebar.md`
9696
- Description: Generate sidebar file, defaults to `_sidebar.md`.
9797

98+
- `--overwrite` option:
99+
- Shorthand: `-o`
100+
- Type: boolean
101+
- Default: `false`
102+
- Description: Allow overwrite generated files.
103+
98104
## License
99105

100106
MIT

lib/cli.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,23 @@ require('yargs')
123123
desc: chalk.gray(y18n.__('generate')),
124124
builder: yargs =>
125125
yargs.options({
126+
overwrite: {
127+
alias: 'o',
128+
default: false,
129+
desc: chalk.gray(y18n.__('generate.overwrite')),
130+
nargs: 0,
131+
type: 'boolean'
132+
},
126133
sidebar: {
127134
alias: 's',
128135
default: '_sidebar.md',
129-
desc: chalk.gray(y18n.__('gen.sidebar')),
136+
desc: chalk.gray(y18n.__('generate.sidebar')),
130137
nargs: 1,
131138
requiresArg: true,
132139
type: 'string'
133140
}
134141
}),
135-
handler: argv => run.generate(argv.path, argv.sidebar)
142+
handler: argv => run.generate(argv.path, argv.sidebar, {overwrite: argv.overwrite})
136143
})
137144
.help()
138145
.option('help', {

lib/commands/generate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ const path = require('path')
77
const logger = require('../util/logger')
88
const ignoreFiles = ['_navbar', '_coverpage', '_sidebar']
99

10-
module.exports = function (path, sidebar) {
10+
module.exports = function (path, sidebar, options) {
1111
const cwdPath = cwd(path || '.')
1212

1313
if (exists(cwdPath)) {
1414
if (sidebar) {
1515
const sidebarPath = cwdPath + '/' + sidebar || '_sidebar.md'
1616

17-
if (!exists(sidebarPath)) {
17+
if (!exists(sidebarPath) || options.overwrite) {
1818
genSidebar(cwdPath, sidebarPath)
1919
logger.success(`Successfully generated the sidebar file '${sidebar}'.`)
2020
return true

tools/locales/en.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"serve.indexname": "Custom filename instead of index.html to serve by default",
1414
"generate": "Docsify's generators",
1515
"generate.sidebar": "Generate sidebar file",
16+
"generate.overwrite": "Allow overwrite generated files",
1617
"livereload.port": "livereload Listen port.",
1718
"usage": "Usage",
18-
"version": "Show version number",
19-
"gen.sidebar": "Generate sidebar"
19+
"version": "Show version number"
2020
}

tools/locales/zh.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"serve.indexname": "自定义入口文件名,代替默认的 index.html",
1414
"generate": "docsify 的生成器",
1515
"generate.sidebar": "生成侧边栏文件",
16+
"generate.overwrite": "允许覆盖生成的文件",
1617
"livereload.port": "设置 livereload 端口",
1718
"usage": "例子",
18-
"version": "当前版本号",
19-
"gen.sidebar": "生成侧边栏"
19+
"version": "当前版本号"
2020
}

0 commit comments

Comments
 (0)