Skip to content

update: rc preview version support #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option name is too long.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shorter it as rcMode, does it make sense or any idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using --tag and -t, which can be selected as 4, 5, or rc.

Copy link
Member Author

@Koooooo-7 Koooooo-7 Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very beginning I have the same thoughts of it.

choices: [`${docsifyDefaultResourceVersion}`, 'rc'],

But I realized that the cli is designed to match the docsify version resources which is reasonable too.
If we provide the -tag, it means we should support all version resources generation in future, i.e. user can use cli v6 to generate v4 docsify also.
If the template or commands have incompatible change. it is hard to maintain (such as the themes).

So I think we could only provide the rc option specially for all latest rc version (cross version).
the cli of v5 provide the generation of v5 resources.
Ideally, if user wanna use v4, user needs to use v4 cli either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think replacing the version number and adding HTML content separately are the same thing.

Generate different HTML content based on different versions and perform replacements.

--local compatible with scenarios using local docsify.

Copy link
Member Author

@Koooooo-7 Koooooo-7 Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think replacing the version number and adding HTML content separately are the same thing.
for instance now.

If we separated the templates/resources by versions that is feasible.
But the commands are incompatible and hard to handle.
i.e. The theme is only support vue now, If user wanna use v4 docsify, how does he use the --theme for it?

- Shorthand: `--rc`
- Type: boolean
- Default: `false`
- Description: Try `docsify` preview release version (`rc` resource).
- `--plugins` option:
- Shorthand: `-p`
- Type: boolean
Expand Down
10 changes: 9 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ require('yargs')
requiresArg: false,
type: 'boolean'
},
previewRelease: {
alias: 'rc',
default: false,
desc: chalk.gray(y18n.__('init.rc')),
nargs: 0,
requiresArg: false,
type: 'boolean'
},
theme: {
alias: 't',
default: 'vue',
Expand All @@ -48,7 +56,7 @@ require('yargs')
type: 'boolean'
}
}),
handler: argv => run.init(argv.path, argv.local, argv.theme, argv.plugins)
handler: argv => run.init(argv.path, argv.local, argv.previewRelease, argv.theme, argv.plugins)
})
.command({
command: 'serve [path]',
Expand Down
26 changes: 18 additions & 8 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs')
const cp = require('cp-file').sync
const chalk = require('chalk')
const {version} = require('../../package.json')
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')
Expand All @@ -14,8 +14,12 @@ 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, previewRelease, theme, plugins) {
const msg =
'\n' +
chalk.green('Initialization succeeded!') +
Expand Down Expand Up @@ -48,11 +52,11 @@ module.exports = async function (path = '', local, theme, plugins) {
}
}

await createFile(cwdPath, local, theme, plugins)
await createFile(cwdPath, local, previewRelease, theme, plugins)
console.log(msg)
}

async function createFile(path, local, 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')
Expand Down Expand Up @@ -97,6 +101,15 @@ async function createFile(path, local, theme, plugins) {
replace(target(filename), 'repo: \'\'', `repo: '${repo}'`)
}

const {major, prerelease = [], version} = semver.parse(cliVerson) || {}
let resourceVersion = prerelease.length ? version : String(major)

if (previewRelease) {
resourceVersion = 'rc'
}

replaceAll(target(filename), '__docsifyVersion__', `${resourceVersion}`)

// Return early if not opted for plugins
if (!plugins) {
return replace(target(filename), '\n _plugins_', '')
Expand Down Expand Up @@ -147,11 +160,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', ` <script src="${url}"></script>\n`)
})

Expand Down
8 changes: 4 additions & 4 deletions lib/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<title>Document</title>
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@rc/dist/themes/core.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@rc/dist/themes/addons/vue.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@__docsifyVersion__/dist/themes/core.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@__docsifyVersion__/dist/themes/addons/vue.min.css">
</head>
<body>
<div id="app"></div>
Expand All @@ -16,8 +16,8 @@
repo: ''
}
</script>
<!-- Docsify rc -->
<script src="//cdn.jsdelivr.net/npm/docsify@rc"></script>
<!-- Docsify resource -->
<script src="//cdn.jsdelivr.net/npm/docsify@__docsifyVersion__"></script>
_plugins_
</body>
</html>
1 change: 1 addition & 0 deletions tools/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.",
Expand Down
1 change: 1 addition & 0 deletions tools/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.",
Expand Down
1 change: 1 addition & 0 deletions tools/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"help": "帮助",
"init": "创建 docs",
"init.local": "拷贝 docsify 到本地",
"init.rc": "体验 docsify 预览版本,默认使用最新正式版本",
"init.theme": "选择主题",
"init.plugins": "选择插件",
"serve": "本地预览",
Expand Down