Skip to content
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

support docsify init --plugins #99

Merged
merged 32 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ee76d17
feat: adding plugins support
tool3 Mar 12, 2020
8b9fccb
fix: fixing url
tool3 Mar 12, 2020
21a097f
fix: removing temp docs
tool3 Mar 12, 2020
a078e08
docs: adding documentation for init --plugins
tool3 Mar 12, 2020
b8b89c7
fix: removing unused files
tool3 Mar 13, 2020
64b32e0
fix: removing .nojekyll top-level
tool3 Mar 13, 2020
f522d07
chore: adding tests
tool3 Mar 13, 2020
e532c1e
fix: fixing docs links
tool3 Mar 13, 2020
6558cee
refactor: cleaner matchSnapshot
tool3 Mar 13, 2020
5431de3
fix: removing redundant spread
tool3 Mar 20, 2020
1083bec
fix(init): adding jsdelivr and major version to plugins init
tool3 Jun 18, 2020
54dd557
fix: realigning with remote
tool3 Jun 18, 2020
de9bcce
fix(e2e): recreating index snap with latest docsify version
tool3 Jun 18, 2020
3c547f9
Merge branch 'master' into master
tool3 Jun 21, 2020
067bb2a
Update docs/README.md
tool3 Apr 28, 2021
c1f92b4
Update README.md
tool3 Apr 28, 2021
5ec56bb
Update lib/template/index.html
tool3 Apr 28, 2021
0059e7f
Update lib/commands/init.js
tool3 Apr 28, 2021
272e310
chore: Optimize code to ensure equal indentation
sy-records Apr 29, 2021
c83fa11
Merge branch 'master' into tool3/master
sy-records Apr 29, 2021
f3e717c
chore: update snap
sy-records Apr 29, 2021
e48d7a8
chore: update snap
sy-records Apr 29, 2021
f96f6d5
chore: update zh.json
sy-records Apr 29, 2021
2debff8
fix: the exception caused by the plugin name being a number
sy-records Apr 29, 2021
6f26f05
Use MultiSelect
sy-records May 19, 2021
1b7f8f2
Update README
sy-records May 19, 2021
f2943a1
Update lib/commands/init.js
sy-records May 27, 2021
e1118d5
Update msg
sy-records May 27, 2021
63e9d95
Fix missing msg
sy-records May 27, 2021
790e96c
refactor: simplify code with async/await
jamesgeorge007 May 27, 2021
149bd81
chore: handle user interruptions
jamesgeorge007 May 28, 2021
828b672
Update README
sy-records Jun 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ docsify init <path> [--local false] [--theme vue]
- Type: string
- Default: `vue`
- Description: Choose a theme, defaults to `vue`, other choices are `buble`, `dark` and `pure`.
- `--plugins` option:
- Shorthand: `-p`
- Type: array
- Default: `[]`
- Description: Provide a list of plugins to insert as `<script>` tags to `index.html`. If a plugin name is provided the script will have a url of `https://unpkg.com/docsify/lib/plugins/<plugin_name>`, otherwise provide the url to the plugin. Example: `docsify init docs/ -p search gitalk https://unpkg.com/docsify-copy-code@2`
tool3 marked this conversation as resolved.
Show resolved Hide resolved

### `serve` command

Expand All @@ -88,9 +93,7 @@ docsify serve <path> [--open false] [--port 3000]
- Type: number
- Default: `3000`
- Description: Choose a listen port, defaults to `3000`.

## Contributing

Please see the [Contributing Guidelines](./CONTRIBUTING.md)

## Contribution
Expand All @@ -99,4 +102,4 @@ Please see the [Contributing Guidelines](./CONTRIBUTING.md)

## License

[MIT](./LICENSE)
[MIT](./LICENSE)
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ docsify init <path> [--local false] [--theme vue]
* Type: string
* Default: `vue`
* Description: Choose a theme, defaults to `vue`, other choices are `buble`, `dark` and `pure`.
* `--plugins` option:
* Shorthand: `-p`
* Type: array
* Default: `[]`
* Description: Provide a list of plugins to insert as `<script>` tags to `index.html`. If a plugin name is provided the script will have a url of `https://unpkg.com/docsify/lib/plugins/<plugin_name>`, otherwise provide the url to the plugin. Example: `docsify init docs/ -p search gitalk https://unpkg.com/docsify-copy-code@2`
tool3 marked this conversation as resolved.
Show resolved Hide resolved

### `serve` command

Expand Down
6 changes: 4 additions & 2 deletions e2e/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ const path = require('path')
const execa = require('execa')
const test = require('ava')

const rootCommand = path.join(process.cwd(), 'bin/docsify')
let rootCommand = path.join(process.cwd(), 'bin/docsify')

test('shows up help message without any args', async t => {
const {stderr} = await execa(rootCommand, {reject: false})
t.snapshot(stderr)
})

const matchSnapshot = async (t, arg) => {
const {stdout} = await execa(rootCommand, [arg])
const args = (typeof arg) === 'object' ? arg : [arg]
const {stdout} = await execa(rootCommand, args)
t.snapshot(stdout)
}

test('shows help with -h flag', matchSnapshot, '-h')
test('shows help with --help flag', matchSnapshot, '--help')
test('shows help with init --help flag', matchSnapshot, ['init', '--help'])
test('shows version information with -v flag', matchSnapshot, '-v')
test('shows version information with --version flag', matchSnapshot, '--version')

Expand Down
65 changes: 42 additions & 23 deletions e2e/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The actual snapshot is saved in `index.js.snap`.

Generated by [AVA](https://ava.li).

## shows help with --help flag
## rejects promise due to error on passing in an unknown command

> Snapshot 1

Expand All @@ -24,9 +24,11 @@ Generated by [AVA](https://ava.li).
https://docsifyjs.github.io/docsify-cli␊
Development:␊
https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md`
https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md␊
Unknown argument: junkcmd`

## shows help with -h flag
## shows help with --help flag

> Snapshot 1

Expand All @@ -48,7 +50,7 @@ Generated by [AVA](https://ava.li).
Development:␊
https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md`

## shows up help message without any args
## shows help with -h flag

> Snapshot 1

Expand All @@ -68,29 +70,28 @@ Generated by [AVA](https://ava.li).
https://docsifyjs.github.io/docsify-cli␊
Development:␊
https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md␊
[ERROR] 0 arguments passed. Please specify a command`

## shows version information with --version flag

> Snapshot 1

`␊
docsify-cli version:␊
4.4.0␊
`
https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md`

## shows version information with -v flag
## shows help with init --help flag

> Snapshot 1

`␊
docsify-cli version:␊
4.4.0␊
`
`docsify init [path]␊
Creates new docs␊
Global Options␊
--help, -h Show help [boolean]␊
--version, -v Show version number [boolean]␊
Options:␊
--local, -l Copy docsify files to local. To explicitly set --local to false␊
you may use --no-local. [boolean] [default: false]␊
--theme, -t Theme file to be used.␊
[string] [choices: "vue", "buble", "dark", "pure"] [default: "vue"]␊
--plugins, -p A list of plugins to be used. [array]`

## rejects promise due to error on passing in an unknown command
## shows up help message without any args

> Snapshot 1

Expand All @@ -112,4 +113,22 @@ Generated by [AVA](https://ava.li).
Development:␊
https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md␊
Unknown argument: junkcmd`
[ERROR] 0 arguments passed. Please specify a command`

## shows version information with --version flag

> Snapshot 1

`␊
docsify-cli version:␊
4.4.1␊
`

## shows version information with -v flag

> Snapshot 1

`␊
docsify-cli version:␊
4.4.1␊
`
Binary file modified e2e/index.js.snap
Binary file not shown.
7 changes: 6 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ require('yargs')
nargs: 1,
requiresArg: true,
type: 'string'
},
plugins: {
alias: 'p',
desc: chalk.gray(y18n.__('init.plugins')),
type: 'array'
}
}),
handler: argv => run.init(argv.path, argv.local, argv.theme)
handler: argv => run.init(argv.path, argv.local, argv.theme, argv.plugins)
})
.command({
command: 'serve [path]',
Expand Down
15 changes: 14 additions & 1 deletion lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
const fs = require('fs')
const cp = require('cp-file').sync
const chalk = require('chalk')
const {version} = require('../../package.json')
const {cwd, exists, pkg, pwd, read, resolve} = require('../util')

const replace = function (file, tpl, replace) {
fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8')
}

// eslint-disable-next-line
module.exports = function (path = '', local, theme) {
module.exports = function (path = '', local, theme, plugins) {
const msg =
'\n' +
chalk.green('Initialization succeeded!') +
Expand Down Expand Up @@ -64,5 +65,17 @@ module.exports = function (path = '', local, theme) {
replace(target(filename), 'repo: \'\'', `repo: '${repo}'`)
}

if (plugins) {
replace(target(filename), '_plugins_', '_plugin\n '.repeat(plugins.length))
plugins.forEach(plugin => {
const major = version[0]
const url = plugin.includes('//') ? plugin : `https://cdn.jsdelivr.net/npm/docsify@${major}/lib/plugins/${plugin}.min.js`
Copy link
Member

Choose a reason for hiding this comment

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

if use ./bin/docsify init docs2 -p 1, An exception will be thrown here

image

Copy link
Member

Choose a reason for hiding this comment

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

I added the enquirer in #117, you can use this here as well.

see https://github.com/enquirer/enquirer#multiselect-prompt

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we should support specifying a list of plugins as an argument to --plugins such that the prompt shows up on not supplying any or passing in an unsupported plugin.

docsify init [path] --plugins, -p [...plugins]

tool3 marked this conversation as resolved.
Show resolved Hide resolved
const scriptTemplate = `<script src="${url}"></script>`
replace(target(filename), '_plugin', scriptTemplate)
})
} else {
replace(target(filename), '_plugins_', '')
}

console.log(msg)
}
1 change: 1 addition & 0 deletions lib/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
</script>
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
_plugins_
tool3 marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>
1 change: 1 addition & 0 deletions tools/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "Server for SSR",
"init.local": "Copy docsify files to local. To explicitly set --local to false you may use --no-local.",
"init.theme": "Theme file to be used.",
"init.plugins": "A list of plugins to be used.",
"serve": "Run local server to preview site.",
"serve.open": "Open docs in default browser. To explicitly set --open to false you may use --no-open.",
"serve.port": "Listen port.",
Expand Down