Skip to content

Release v5.0.0-rc.1 #224

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 5 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ npm i docsify-cli -g
Use `init` to generate your docs.

```shell
docsify init [path] [--local false] [--theme vue] [--plugins false]
docsify init [path] [--local false] [--rcMode] [--theme vue] [--plugins]

# docsify i [path] [-l false] [-t vue] [--plugins false]
# docsify i [path] [-l false] [--rc] [-t vue] [-p]
```

`[path]` defaults to the current directory. Use relative paths like `./docs` (or `docs`).
Expand All @@ -62,11 +62,16 @@ 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`.
- `--rcMode` option:
- Shorthand: `--rc`
- Type: boolean
- Default: `false`
- Description: Try `docsify` preview release version (`rc` resource).
- `--theme` option:
- Shorthand: `-t`
- Type: string
- Default: `vue`
- Description: Choose a theme, defaults to `vue`, other choices are `buble`, `dark` and `pure`.
- Description: Choose a theme, defaults to `vue`.
- `--plugins` option:
- Shorthand: `-p`
- Type: boolean
Expand Down Expand Up @@ -114,7 +119,7 @@ docsify generate [path] [--sidebar _sidebar.md] [--overwrite]
- Shorthand: `-o`
- Type: boolean
- Default: `false`
- Description: Allow overwrite generated files.
- Description: Allow to overwrite generated files.

## Contributing
Please see the [Contributing Guidelines](./CONTRIBUTING.md)
Expand Down
2 changes: 1 addition & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
module.exports = {
files: ['e2e/**/*.test.js']
}
13 changes: 9 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ npm i docsify-cli -g
Use `init` to generate your docs.

```shell
docsify init [path] [--local false] [--theme vue] [--plugins false]
docsify init [path] [--local false] [--rcMode] [--theme vue] [--plugins]

# docsify i [path] [-l false] [-t vue] [--plugins false]
# docsify i [path] [-l false] [--rc] [-t vue] [-p]
```

`[path]` defaults to the current directory. Use relative paths like `./docs` (or `docs`).
Expand All @@ -47,11 +47,16 @@ 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`.
- `--rcMode` option:
- Shorthand: `--rc`
- Type: boolean
- Default: `false`
- Description: Try `docsify` preview release version (`rc` resource).
- `--theme` option:
- Shorthand: `-t`
- Type: string
- Default: `vue`
- Description: Choose a theme, defaults to `vue`, other choices are `buble`, `dark` and `pure`.
- Description: Choose a theme, defaults to `vue`.
- `--plugins` option:
- Shorthand: `-p`
- Type: boolean
Expand Down Expand Up @@ -99,7 +104,7 @@ docsify generate [path] [--sidebar _sidebar.md] [--overwrite]
- Shorthand: `-o`
- Type: boolean
- Default: `false`
- Description: Allow overwrite generated files.
- Description: Allow to overwrite generated files.

## License

Expand Down
8 changes: 2 additions & 6 deletions e2e/cli.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Generated by [AVA](https://avajs.dev).
Commands:␊
docsify init [path] Creates new docs [aliases: i]␊
docsify serve [path] Run local server to preview site. [aliases: s]␊
docsify start [path] Server for SSR␊
docsify generate [path] Docsify's generators [aliases: g]␊
Global Options␊
Expand All @@ -38,7 +37,6 @@ Generated by [AVA](https://avajs.dev).
Commands:␊
docsify init [path] Creates new docs [aliases: i]␊
docsify serve [path] Run local server to preview site. [aliases: s]␊
docsify start [path] Server for SSR␊
docsify generate [path] Docsify's generators [aliases: g]␊
Global Options␊
Expand All @@ -61,7 +59,6 @@ Generated by [AVA](https://avajs.dev).
Commands:␊
docsify init [path] Creates new docs [aliases: i]␊
docsify serve [path] Run local server to preview site. [aliases: s]␊
docsify start [path] Server for SSR␊
docsify generate [path] Docsify's generators [aliases: g]␊
Global Options␊
Expand All @@ -81,7 +78,7 @@ Generated by [AVA](https://avajs.dev).

`␊
docsify-cli version:␊
4.4.4
5.0.0-rc.1
`

## shows version information with --version flag
Expand All @@ -90,7 +87,7 @@ Generated by [AVA](https://avajs.dev).

`␊
docsify-cli version:␊
4.4.4
5.0.0-rc.1
`

## rejects promise due to error on passing in an unknown command
Expand All @@ -102,7 +99,6 @@ Generated by [AVA](https://avajs.dev).
Commands:␊
docsify init [path] Creates new docs [aliases: i]␊
docsify serve [path] Run local server to preview site. [aliases: s]␊
docsify start [path] Server for SSR␊
docsify generate [path] Docsify's generators [aliases: g]␊
Global Options␊
Expand Down
Binary file modified e2e/cli.test.js.snap
Binary file not shown.
39 changes: 10 additions & 29 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const chalk = require('chalk')
const updateNotifier = require('update-notifier')

const pkg = require('../package.json')
const run = require('../lib')

updateNotifier({pkg: pkg}).notify()

const Locales = require('../tools/locales')
const y18n = new Locales()

Expand Down Expand Up @@ -33,11 +30,19 @@ require('yargs')
requiresArg: false,
type: 'boolean'
},
rcMode: {
alias: 'rc',
default: false,
desc: chalk.gray(y18n.__('init.rc')),
nargs: 0,
requiresArg: false,
type: 'boolean'
},
theme: {
alias: 't',
default: 'vue',
desc: chalk.gray(y18n.__('init.theme')),
choices: ['vue', 'buble', 'dark', 'pure'],
choices: ['vue'],
nargs: 1,
requiresArg: true,
type: 'string'
Expand All @@ -51,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.rcMode, argv.theme, argv.plugins)
})
.command({
command: 'serve [path]',
Expand Down Expand Up @@ -93,30 +98,6 @@ require('yargs')
}),
handler: argv => run.serve(argv.path, argv.open, argv.port, argv.P, argv.i)
})
.command({
command: 'start [path]',
desc: chalk.gray(y18n.__('start')),
builder: yargs =>
yargs.options({
config: {
alias: 'c',
default: false,
desc: chalk.gray(y18n.__('start.config')),
nargs: 1,
requiresArg: false,
type: 'string'
},
port: {
alias: 'p',
default: 4000,
desc: chalk.gray(y18n.__('start.port')),
nargs: 1,
requiresArg: true,
type: 'number'
}
}),
handler: argv => run.start(argv.path, argv.config, argv.port)
})
.command({
command: 'generate [path]',
aliases: 'g',
Expand Down
38 changes: 26 additions & 12 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
const fs = require('fs')
const cp = require('cp-file').sync
const chalk = require('chalk')
const {version} = 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')
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, rcMode, theme, plugins) {
const msg =
'\n' +
chalk.green('Initialization succeeded!') +
Expand Down Expand Up @@ -47,11 +52,11 @@ module.exports = async function (path = '', local, theme, plugins) {
}
}

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

async function createFile(path, local, 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')
Expand All @@ -62,10 +67,11 @@ async function createFile(path, local, theme, plugins) {
const vendor =
exists(cwd('node_modules/docsify')) || pwd('../node_modules/docsify')

cp(resolve(vendor, 'lib/docsify.min.js'), target('vendor/docsify.js'))
cp(resolve(vendor, 'dist/docsify.min.js'), target('vendor/docsify.js'))
cp(resolve(vendor, 'dist/themes/core.css'), target('vendor/themes/core.css'))
cp(
resolve(vendor, `lib/themes/${theme}.css`),
target(`vendor/themes/${theme}.css`)
resolve(vendor, `dist/themes/addons/${theme}.css`),
target(`vendor/themes/addons/${theme}.css`)
)
}

Expand All @@ -75,8 +81,6 @@ async function createFile(path, local, theme, plugins) {
cp(main, target(filename))
cp(pwd('template/.nojekyll'), target('.nojekyll'))

replace(target(filename), 'vue.css', `${theme}.css`)

if (pkg.name) {
replace(
target(filename),
Expand All @@ -97,20 +101,30 @@ async function createFile(path, local, theme, plugins) {
replace(target(filename), 'repo: \'\'', `repo: '${repo}'`)
}

let resourceVersion = 'rc'

if (!rcMode) {
const {major, prerelease = [], version} = semver.parse(cliVersion) || {}
resourceVersion = prerelease.length ? version : String(major)
}

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

// Return early if not opted for plugins
if (!plugins) {
return replace(target(filename), '\n _plugins_', '')
}

const officialPlugins = [
'front-matter',
'search',
'disqus',
'emoji',
'external-script',
'front-matter',
'ga',
'gitalk',
'gtag',
'matomo',
'search',
'zoom-image'
]

Expand Down Expand Up @@ -147,7 +161,7 @@ async function createFile(path, local, theme, plugins) {
replace(target(filename), ' _plugins_', '_plugin'.repeat(answers.length + 1))

answers.forEach(plugin => {
const url = `//cdn.jsdelivr.net/npm/docsify@${version[0]}/lib/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
Loading
Loading