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

Draft
wants to merge 6 commits into
base: release/5.0.0-rc.1
Choose a base branch
from
Draft
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
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`.
- `--rcMode` option:
- 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'
},
rcMode: {
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.rcMode, 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: cliVersion} = 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, rcMode, 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, 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 Down Expand Up @@ -97,6 +101,15 @@ 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_', '')
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