From e3231a2de9ccfceba6fde8424c3e6eca1ad3d2b9 Mon Sep 17 00:00:00 2001 From: Koy Date: Sat, 5 Jul 2025 12:29:21 +0800 Subject: [PATCH 1/6] update: versioning --- e2e/cli.test.js.snap | Bin 640 -> 0 bytes lib/cli.js | 13 ++++++++++++- lib/commands/init.js | 22 ++++++++++++---------- lib/template/index.html | 8 ++++---- tools/locales/de.json | 1 + tools/locales/en.json | 1 + tools/locales/zh.json | 1 + 7 files changed, 31 insertions(+), 15 deletions(-) delete mode 100644 e2e/cli.test.js.snap diff --git a/e2e/cli.test.js.snap b/e2e/cli.test.js.snap deleted file mode 100644 index c1cde9636ca4a0892ca27f936734f728e9452b5a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 640 zcmV-`0)PEMRzVB7nmMvvJ4KO#NU zKeAvFt{;mC00000000B+mcee*KoEx8AcW)_XD%Zl!38_%flCA&2&n3%L7|aAQ4VW+ zVsC2iT085cmAG($H{jmB0S~|%@KDS;cI&F4PzhB+@*cgj|IF-sSwMz z?EUCX-N7NmIwH9^g%?su`-#x3@D8U^Ns5SCSo&v>03$q_$v!3Jr&Jq4{RB@sye^ zZMH{wDVT8f`Tf`-(C7M@YBlrJ(prrhTE)JsC9-y%_~7pk64{GSG8dM z1yq@bocnDAJx;XDQCZ<4c126AEoj*9*H^QoAYoFd7eI5*gfp4N<&ud)ze{$JW=bw9i zX>f^=d$f$sCBIg2iH>qKMjK# run.init(argv.path, argv.local, argv.theme, argv.plugins) + handler: argv => run.init(argv.path, argv.local, argv.docsifyVersion, argv.theme, argv.plugins) }) .command({ command: 'serve [path]', diff --git a/lib/commands/init.js b/lib/commands/init.js index 8157e8a..bed34d1 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -3,22 +3,24 @@ const fs = require('fs') const cp = require('cp-file').sync const chalk = require('chalk') -const {version} = require('../../package.json') const logger = require('../util/logger') const {prompt, MultiSelect} = require('enquirer') const {cwd, exists, pkg, pwd, read, resolve} = require('../util') const colors = require('ansi-colors') -const semver = require('semver') const replace = function (file, tpl, replace) { fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8') } +const replaceAll = function (file, tpl, replace) { + fs.writeFileSync(file, read(file).replaceAll(tpl, replace), 'utf-8') +} + // eslint-disable-next-line -module.exports = async function (path = '', local, theme, plugins) { +module.exports = async function (path = '', local, docsifyVersion, theme, plugins) { const msg = '\n' + - chalk.green('Initialization succeeded!') + + chalk.green(`Initialization succeeded (${docsifyVersion})!`) + ' Please run ' + chalk.inverse(`docsify serve ${path}`) + '\n' @@ -48,11 +50,11 @@ module.exports = async function (path = '', local, theme, plugins) { } } - await createFile(cwdPath, local, theme, plugins) + await createFile(cwdPath, local, docsifyVersion, theme, plugins) console.log(msg) } -async function createFile(path, local, theme, plugins) { +async function createFile(path, local, docsifyVersion, theme, plugins) { const target = file => resolve(path, file) const readme = exists(cwd('README.md')) || pwd('template/README.md') let main = pwd('template/index.html') @@ -97,6 +99,9 @@ async function createFile(path, local, theme, plugins) { replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) } + const resourceVersion = docsifyVersion + replaceAll(target(filename), '__docsifyVersion__', `${resourceVersion}`) + // Return early if not opted for plugins if (!plugins) { return replace(target(filename), '\n _plugins_', '') @@ -147,11 +152,8 @@ async function createFile(path, local, theme, plugins) { replace(target(filename), ' _plugins_', '_plugin'.repeat(answers.length + 1)) - const {prerelease = [], major} = semver.parse(version) || {} - const pluginVersion = prerelease.length ? prerelease[0] : String(major) - answers.forEach(plugin => { - const url = `//cdn.jsdelivr.net/npm/docsify@${pluginVersion}/dist/plugins/${plugin}.min.js` + const url = `//cdn.jsdelivr.net/npm/docsify@${resourceVersion}/dist/plugins/${plugin}.min.js` replace(target(filename), '_plugin', ` \n`) }) diff --git a/lib/template/index.html b/lib/template/index.html index 5e8192e..602c0c7 100644 --- a/lib/template/index.html +++ b/lib/template/index.html @@ -5,8 +5,8 @@ Document - - + +
@@ -16,8 +16,8 @@ repo: '' } - - + + _plugins_ diff --git a/tools/locales/de.json b/tools/locales/de.json index 8e57683..1aefe0c 100644 --- a/tools/locales/de.json +++ b/tools/locales/de.json @@ -4,6 +4,7 @@ "help": "Zeige Hilfe an", "init": "Erzeuge neue Dokumentation.", "init.local": "Kopiere docsify Dateien in lokale Ordner. Um explizit --local auf false zu setzen, kannst du --no-local verwenden.", + "init.version": "Wählen Sie die docsify-Version aus; standardmäßig wird die neueste Version verwendet.", "init.theme": "Zu verwendende Theme Dateien.", "serve": "Lasse lokalen Server zur Webseitenvorschau laufen.", "serve.open": "Dokumentation im Standardbrowser öffnen. Um explizit --open auf false zu setzen, kannst du --no-open verwenden.", diff --git a/tools/locales/en.json b/tools/locales/en.json index 5a6262f..8be8aec 100644 --- a/tools/locales/en.json +++ b/tools/locales/en.json @@ -4,6 +4,7 @@ "help": "Show help", "init": "Creates new docs", "init.local": "Copy docsify files to local. To explicitly set --local to false you may use --no-local.", + "init.version": "Select docsify version, default is latest.", "init.theme": "Theme file to be used.", "init.plugins": "A list of plugins to be used.", "serve": "Run local server to preview site.", diff --git a/tools/locales/zh.json b/tools/locales/zh.json index b6f839c..b43136b 100644 --- a/tools/locales/zh.json +++ b/tools/locales/zh.json @@ -4,6 +4,7 @@ "help": "帮助", "init": "创建 docs", "init.local": "拷贝 docsify 到本地", + "init.version": "选择 docsify 版本,默认使用最新版本", "init.theme": "选择主题", "init.plugins": "选择插件", "serve": "本地预览", From bacb2f917d5356a2f16f7433b78ffcf90a8e3a50 Mon Sep 17 00:00:00 2001 From: Koy Date: Sat, 5 Jul 2025 12:49:45 +0800 Subject: [PATCH 2/6] fix: test --- e2e/cli.test.js.snap | Bin 0 -> 640 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 e2e/cli.test.js.snap diff --git a/e2e/cli.test.js.snap b/e2e/cli.test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..c1cde9636ca4a0892ca27f936734f728e9452b5a GIT binary patch literal 640 zcmV-`0)PEMRzVB7nmMvvJ4KO#NU zKeAvFt{;mC00000000B+mcee*KoEx8AcW)_XD%Zl!38_%flCA&2&n3%L7|aAQ4VW+ zVsC2iT085cmAG($H{jmB0S~|%@KDS;cI&F4PzhB+@*cgj|IF-sSwMz z?EUCX-N7NmIwH9^g%?su`-#x3@D8U^Ns5SCSo&v>03$q_$v!3Jr&Jq4{RB@sye^ zZMH{wDVT8f`Tf`-(C7M@YBlrJ(prrhTE)JsC9-y%_~7pk64{GSG8dM z1yq@bocnDAJx;XDQCZ<4c126AEoj*9*H^QoAYoFd7eI5*gfp4N<&ud)ze{$JW=bw9i zX>f^=d$f$sCBIg2iH>qKMjK# Date: Sat, 5 Jul 2025 13:16:08 +0800 Subject: [PATCH 3/6] marjor --- lib/commands/init.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index bed34d1..4bd9fc7 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -7,6 +7,7 @@ const logger = require('../util/logger') const {prompt, MultiSelect} = require('enquirer') const {cwd, exists, pkg, pwd, read, resolve} = require('../util') const colors = require('ansi-colors') +const semver = require('semver') const replace = function (file, tpl, replace) { fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8') @@ -99,7 +100,12 @@ async function createFile(path, local, docsifyVersion, theme, plugins) { replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) } - const resourceVersion = docsifyVersion + let resourceVersion = docsifyVersion + // Not rc or rc release, fetch the major version + if (!(/rc/.test(docsifyVersion))) { + resourceVersion = semver.major(docsifyVersion) + } + replaceAll(target(filename), '__docsifyVersion__', `${resourceVersion}`) // Return early if not opted for plugins From d3666020efc234e4bb7a46c5de49c52e917c8e8a Mon Sep 17 00:00:00 2001 From: Koy Date: Sat, 5 Jul 2025 13:35:30 +0800 Subject: [PATCH 4/6] update: rc opt --- lib/cli.js | 19 ++++++++----------- lib/commands/init.js | 18 ++++++++++-------- tools/locales/de.json | 2 +- tools/locales/en.json | 2 +- tools/locales/zh.json | 2 +- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 548226b..349bb4d 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -5,8 +5,6 @@ const run = require('../lib') const Locales = require('../tools/locales') const y18n = new Locales() -// Default use the version same to cli -const docsifyDefaultResourceVersion = pkg.version require('yargonaut') .style('yellow', 'required') @@ -32,14 +30,13 @@ require('yargs') requiresArg: false, type: 'boolean' }, - docsifyVersion: { - alias: 'ver', - default: `${docsifyDefaultResourceVersion}`, - desc: chalk.gray(y18n.__('init.version')), - choices: [`${docsifyDefaultResourceVersion}`, 'rc'], - nargs: 1, - requiresArg: true, - type: 'string' + previewRelease: { + alias: 'rc', + default: false, + desc: chalk.gray(y18n.__('init.rc')), + nargs: 0, + requiresArg: false, + type: 'boolean' }, theme: { alias: 't', @@ -59,7 +56,7 @@ require('yargs') type: 'boolean' } }), - handler: argv => run.init(argv.path, argv.local, argv.docsifyVersion, argv.theme, argv.plugins) + handler: argv => run.init(argv.path, argv.local, argv.previewRelease, argv.theme, argv.plugins) }) .command({ command: 'serve [path]', diff --git a/lib/commands/init.js b/lib/commands/init.js index 4bd9fc7..5eb1d24 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -3,6 +3,7 @@ const fs = require('fs') const cp = require('cp-file').sync const chalk = require('chalk') +const {version: cliVerson} = require('../../package.json') const logger = require('../util/logger') const {prompt, MultiSelect} = require('enquirer') const {cwd, exists, pkg, pwd, read, resolve} = require('../util') @@ -18,10 +19,10 @@ const replaceAll = function (file, tpl, replace) { } // eslint-disable-next-line -module.exports = async function (path = '', local, docsifyVersion, theme, plugins) { +module.exports = async function (path = '', local, previewRelease, theme, plugins) { const msg = '\n' + - chalk.green(`Initialization succeeded (${docsifyVersion})!`) + + chalk.green('Initialization succeeded!') + ' Please run ' + chalk.inverse(`docsify serve ${path}`) + '\n' @@ -51,11 +52,11 @@ module.exports = async function (path = '', local, docsifyVersion, theme, plugin } } - await createFile(cwdPath, local, docsifyVersion, theme, plugins) + await createFile(cwdPath, local, previewRelease, theme, plugins) console.log(msg) } -async function createFile(path, local, docsifyVersion, theme, plugins) { +async function createFile(path, local, previewRelease, theme, plugins) { const target = file => resolve(path, file) const readme = exists(cwd('README.md')) || pwd('template/README.md') let main = pwd('template/index.html') @@ -100,10 +101,11 @@ async function createFile(path, local, docsifyVersion, theme, plugins) { replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) } - let resourceVersion = docsifyVersion - // Not rc or rc release, fetch the major version - if (!(/rc/.test(docsifyVersion))) { - resourceVersion = semver.major(docsifyVersion) + const {major, prerelease = [], version} = semver.parse(cliVerson) || {} + let resourceVersion = prerelease.length ? version : String(major) + + if (previewRelease) { + resourceVersion = 'rc' } replaceAll(target(filename), '__docsifyVersion__', `${resourceVersion}`) diff --git a/tools/locales/de.json b/tools/locales/de.json index 1aefe0c..611c8ec 100644 --- a/tools/locales/de.json +++ b/tools/locales/de.json @@ -4,7 +4,7 @@ "help": "Zeige Hilfe an", "init": "Erzeuge neue Dokumentation.", "init.local": "Kopiere docsify Dateien in lokale Ordner. Um explizit --local auf false zu setzen, kannst du --no-local verwenden.", - "init.version": "Wählen Sie die docsify-Version aus; standardmäßig wird die neueste Version verwendet.", + "init.rc": "Probieren Sie die neueste Vorschauversion von docsify aus.", "init.theme": "Zu verwendende Theme Dateien.", "serve": "Lasse lokalen Server zur Webseitenvorschau laufen.", "serve.open": "Dokumentation im Standardbrowser öffnen. Um explizit --open auf false zu setzen, kannst du --no-open verwenden.", diff --git a/tools/locales/en.json b/tools/locales/en.json index 8be8aec..b821bfb 100644 --- a/tools/locales/en.json +++ b/tools/locales/en.json @@ -4,7 +4,7 @@ "help": "Show help", "init": "Creates new docs", "init.local": "Copy docsify files to local. To explicitly set --local to false you may use --no-local.", - "init.version": "Select docsify version, default is latest.", + "init.rc": "Try docsify preview version, default is marjor.", "init.theme": "Theme file to be used.", "init.plugins": "A list of plugins to be used.", "serve": "Run local server to preview site.", diff --git a/tools/locales/zh.json b/tools/locales/zh.json index b43136b..8d00fa3 100644 --- a/tools/locales/zh.json +++ b/tools/locales/zh.json @@ -4,7 +4,7 @@ "help": "帮助", "init": "创建 docs", "init.local": "拷贝 docsify 到本地", - "init.version": "选择 docsify 版本,默认使用最新版本", + "init.rc": "体验 docsify 预览版本,默认使用最新正式版本", "init.theme": "选择主题", "init.plugins": "选择插件", "serve": "本地预览", From 8875c1f50c25778413bbfaa96a8488d3eb350361 Mon Sep 17 00:00:00 2001 From: Koy Date: Sat, 5 Jul 2025 13:39:13 +0800 Subject: [PATCH 5/6] chore: polish --- README.md | 10 +++++----- tools/locales/en.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80f7cc4..73e2120 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,11 @@ docsify init [path] [--local false] [--theme vue] [--plugins false] - Type: boolean - Default: `false` - Description: Copy `docsify` files to the docs path, defaults to `false` using `cdn.jsdelivr.net` as the content delivery network (CDN). To explicitly set this option to `false` use `--no-local`. -- `--theme` option: - - Shorthand: `-t` - - Type: string - - Default: `vue` - - Description: Choose a theme, defaults to `vue`, other choices are `buble`, `dark` and `pure`. +- `--previewRelease` option: + - Shorthand: `--rc` + - Type: boolean + - Default: `false` + - Description: Try `docsify` preview release version (`rc` resource). - `--plugins` option: - Shorthand: `-p` - Type: boolean diff --git a/tools/locales/en.json b/tools/locales/en.json index b821bfb..cc8da7a 100644 --- a/tools/locales/en.json +++ b/tools/locales/en.json @@ -4,7 +4,7 @@ "help": "Show help", "init": "Creates new docs", "init.local": "Copy docsify files to local. To explicitly set --local to false you may use --no-local.", - "init.rc": "Try docsify preview version, default is marjor.", + "init.rc": "Try docsify preview version, default is major version.", "init.theme": "Theme file to be used.", "init.plugins": "A list of plugins to be used.", "serve": "Run local server to preview site.", From 6356e030aca3bd821b4c47cda5418cdd3677c0ae Mon Sep 17 00:00:00 2001 From: Koy Date: Mon, 7 Jul 2025 18:09:38 +0800 Subject: [PATCH 6/6] update: shorter option name --- README.md | 2 +- lib/cli.js | 4 ++-- lib/commands/init.js | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 73e2120..db9ee0e 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ docsify init [path] [--local false] [--theme vue] [--plugins false] - Type: boolean - Default: `false` - Description: Copy `docsify` files to the docs path, defaults to `false` using `cdn.jsdelivr.net` as the content delivery network (CDN). To explicitly set this option to `false` use `--no-local`. -- `--previewRelease` option: +- `--rcMode` option: - Shorthand: `--rc` - Type: boolean - Default: `false` diff --git a/lib/cli.js b/lib/cli.js index 349bb4d..09d5fd8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -30,7 +30,7 @@ require('yargs') requiresArg: false, type: 'boolean' }, - previewRelease: { + rcMode: { alias: 'rc', default: false, desc: chalk.gray(y18n.__('init.rc')), @@ -56,7 +56,7 @@ require('yargs') type: 'boolean' } }), - handler: argv => run.init(argv.path, argv.local, argv.previewRelease, argv.theme, argv.plugins) + handler: argv => run.init(argv.path, argv.local, argv.rcMode, argv.theme, argv.plugins) }) .command({ command: 'serve [path]', diff --git a/lib/commands/init.js b/lib/commands/init.js index 5eb1d24..051fe62 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -3,7 +3,7 @@ const fs = require('fs') const cp = require('cp-file').sync const chalk = require('chalk') -const {version: cliVerson} = require('../../package.json') +const {version: cliVersion} = require('../../package.json') const logger = require('../util/logger') const {prompt, MultiSelect} = require('enquirer') const {cwd, exists, pkg, pwd, read, resolve} = require('../util') @@ -19,7 +19,7 @@ const replaceAll = function (file, tpl, replace) { } // eslint-disable-next-line -module.exports = async function (path = '', local, previewRelease, theme, plugins) { +module.exports = async function (path = '', local, rcMode, theme, plugins) { const msg = '\n' + chalk.green('Initialization succeeded!') + @@ -52,11 +52,11 @@ module.exports = async function (path = '', local, previewRelease, theme, plugin } } - await createFile(cwdPath, local, previewRelease, theme, plugins) + await createFile(cwdPath, local, rcMode, theme, plugins) console.log(msg) } -async function createFile(path, local, previewRelease, theme, plugins) { +async function createFile(path, local, rcMode, theme, plugins) { const target = file => resolve(path, file) const readme = exists(cwd('README.md')) || pwd('template/README.md') let main = pwd('template/index.html') @@ -101,11 +101,11 @@ async function createFile(path, local, previewRelease, theme, plugins) { replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) } - const {major, prerelease = [], version} = semver.parse(cliVerson) || {} - let resourceVersion = prerelease.length ? version : String(major) + let resourceVersion = 'rc' - if (previewRelease) { - resourceVersion = 'rc' + if (!rcMode) { + const {major, prerelease = [], version} = semver.parse(cliVersion) || {} + resourceVersion = prerelease.length ? version : String(major) } replaceAll(target(filename), '__docsifyVersion__', `${resourceVersion}`)