|
3 | 3 | const fs = require('fs') |
4 | 4 | const cp = require('cp-file').sync |
5 | 5 | const chalk = require('chalk') |
6 | | -const {version} = require('../../package.json') |
7 | 6 | const logger = require('../util/logger') |
8 | 7 | const {prompt, MultiSelect} = require('enquirer') |
9 | 8 | const {cwd, exists, pkg, pwd, read, resolve} = require('../util') |
10 | 9 | const colors = require('ansi-colors') |
11 | | -const semver = require('semver') |
12 | 10 |
|
13 | 11 | const replace = function (file, tpl, replace) { |
14 | 12 | fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8') |
15 | 13 | } |
16 | 14 |
|
| 15 | +const replaceAll = function (file, tpl, replace) { |
| 16 | + fs.writeFileSync(file, read(file).replaceAll(tpl, replace), 'utf-8') |
| 17 | +} |
| 18 | + |
17 | 19 | // eslint-disable-next-line |
18 | | -module.exports = async function (path = '', local, theme, plugins) { |
| 20 | +module.exports = async function (path = '', local, docsifyVersion, theme, plugins) { |
19 | 21 | const msg = |
20 | 22 | '\n' + |
21 | | - chalk.green('Initialization succeeded!') + |
| 23 | + chalk.green(`Initialization succeeded (${docsifyVersion})!`) + |
22 | 24 | ' Please run ' + |
23 | 25 | chalk.inverse(`docsify serve ${path}`) + |
24 | 26 | '\n' |
@@ -48,11 +50,11 @@ module.exports = async function (path = '', local, theme, plugins) { |
48 | 50 | } |
49 | 51 | } |
50 | 52 |
|
51 | | - await createFile(cwdPath, local, theme, plugins) |
| 53 | + await createFile(cwdPath, local, docsifyVersion, theme, plugins) |
52 | 54 | console.log(msg) |
53 | 55 | } |
54 | 56 |
|
55 | | -async function createFile(path, local, theme, plugins) { |
| 57 | +async function createFile(path, local, docsifyVersion, theme, plugins) { |
56 | 58 | const target = file => resolve(path, file) |
57 | 59 | const readme = exists(cwd('README.md')) || pwd('template/README.md') |
58 | 60 | let main = pwd('template/index.html') |
@@ -97,6 +99,9 @@ async function createFile(path, local, theme, plugins) { |
97 | 99 | replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) |
98 | 100 | } |
99 | 101 |
|
| 102 | + const resourceVersion = docsifyVersion |
| 103 | + replaceAll(target(filename), '__docsifyVersion__', `${resourceVersion}`) |
| 104 | + |
100 | 105 | // Return early if not opted for plugins |
101 | 106 | if (!plugins) { |
102 | 107 | return replace(target(filename), '\n _plugins_', '') |
@@ -147,11 +152,8 @@ async function createFile(path, local, theme, plugins) { |
147 | 152 |
|
148 | 153 | replace(target(filename), ' _plugins_', '_plugin'.repeat(answers.length + 1)) |
149 | 154 |
|
150 | | - const {prerelease = [], major} = semver.parse(version) || {} |
151 | | - const pluginVersion = prerelease.length ? prerelease[0] : String(major) |
152 | | - |
153 | 155 | answers.forEach(plugin => { |
154 | | - const url = `//cdn.jsdelivr.net/npm/docsify@${pluginVersion}/dist/plugins/${plugin}.min.js` |
| 156 | + const url = `//cdn.jsdelivr.net/npm/docsify@${resourceVersion}/dist/plugins/${plugin}.min.js` |
155 | 157 | replace(target(filename), '_plugin', ` <script src="${url}"></script>\n`) |
156 | 158 | }) |
157 | 159 |
|
|
0 commit comments