From ee76d17a56a7c846a9b15e57d67bb1de8fcb3bf6 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Thu, 12 Mar 2020 20:23:39 +0200 Subject: [PATCH 01/29] feat: adding plugins support --- .nojekyll | 0 README.md | 98 ----------------------------------------- docsrr/.nojekyll | 0 docsrr/README.md | 0 docsrr/index.html | 23 ++++++++++ index.html | 21 +++++++++ lib/cli.js | 7 ++- lib/commands/init.js | 12 ++++- lib/template/index.html | 1 + tools/locales/en.json | 1 + 10 files changed, 63 insertions(+), 100 deletions(-) create mode 100644 .nojekyll create mode 100644 docsrr/.nojekyll create mode 100644 docsrr/README.md create mode 100644 docsrr/index.html create mode 100644 index.html diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 8aaa08a..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,98 +0,0 @@ -

- - docsify - -

- -

- 🖌 docsify cli - A magical documentation generator. -

- -

- Backers on Open Collective - Sponsors on Open Collective - Travis Status - npm -gitter -license -npm-total-download -npm-monthly-download - -

- -

Gold Sponsor via Open Collective

- -

- - - -

- -## Screencast - -![Screencast](https://raw.githubusercontent.com/QingWei-Li/docsify-cli/master/media/screencast.gif) - -> Running a server on `localhost` with live-reload. - -## Installation - -Install `docsify-cli` via `npm` or `yarn` globally. - -```shell -npm i docsify-cli -g -# yarn global add docsify-cli -``` - -## Usage - -### `init` command - -Use `init` to generate your docs. - -```shell -docsify init [--local false] [--theme vue] - -# docsify i [--local false] [--theme vue] -``` - -`` defaults to the current directory. Use relative paths like `./docs` (or `docs`). - -- `--local` option: - - Shorthand: `-l` - - Type: boolean - - Default: `false` - - Description: Copy `docsify` files to the docs path, defaults to `false` using `unpkg.com` 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`. - -### `serve` command - -Run a server on `localhost` with livereload. - -```shell -docsify serve [--open false] [--port 3000] - -# docsify s [--open false] [--port 3000] -``` - -- `--open` option: - - Shorthand: `-o` - - Type: boolean - - Default: `false` - - Description: Open the docs in the default browser, defaults to `false`. To explicitly set this option to `false` use `--no-open`. -- `--port` option: - - Shorthand: `-p` - - Type: number - - Default: `3000` - - Description: Choose a listen port, defaults to `3000`. - -## Contributing - -Please see the [Contributing Guidelines](./CONTRIBUTING.md) - -## License - -[MIT](./LICENSE) diff --git a/docsrr/.nojekyll b/docsrr/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docsrr/README.md b/docsrr/README.md new file mode 100644 index 0000000..e69de29 diff --git a/docsrr/index.html b/docsrr/index.html new file mode 100644 index 0000000..22dfd7f --- /dev/null +++ b/docsrr/index.html @@ -0,0 +1,23 @@ + + + + + Document + + + + + + +
+ + + + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..a66b6b1 --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + Document + + + + + + +
+ + + + diff --git a/lib/cli.js b/lib/cli.js index 777a4a3..667274f 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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]', diff --git a/lib/commands/init.js b/lib/commands/init.js index 91a29be..89a22b1 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -10,7 +10,7 @@ const replace = function (file, tpl, replace) { } // eslint-disable-next-line -module.exports = function (path = '', local, theme) { +module.exports = function (path = '', local, theme, plugins) { const msg = '\n' + chalk.green('Initialization succeeded!') + @@ -64,5 +64,15 @@ module.exports = function (path = '', local, theme) { replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) } + if (plugins) { + plugins.forEach(plugin => { + replace(target(filename), '_plugins_', '_plugin_\n _plugin_') + const scriptTemplate = `` + replace(target(filename), '_plugin_', scriptTemplate) + }) + } else { + replace(target(filename), '_plugins_', '') + } + console.log(msg) } diff --git a/lib/template/index.html b/lib/template/index.html index a66b6b1..4562489 100644 --- a/lib/template/index.html +++ b/lib/template/index.html @@ -17,5 +17,6 @@ } + _plugins_ diff --git a/tools/locales/en.json b/tools/locales/en.json index 02f915d..531a324 100644 --- a/tools/locales/en.json +++ b/tools/locales/en.json @@ -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.", From 8b9fccb3385ba4945b786827162a26e30b088fbd Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Thu, 12 Mar 2020 21:30:52 +0200 Subject: [PATCH 02/29] fix: fixing url --- docsrr/index.html | 6 ++++-- lib/commands/init.js | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docsrr/index.html b/docsrr/index.html index 22dfd7f..ff8e88a 100644 --- a/docsrr/index.html +++ b/docsrr/index.html @@ -17,7 +17,9 @@ } - - + + + + diff --git a/lib/commands/init.js b/lib/commands/init.js index 89a22b1..e6f26a3 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -65,10 +65,12 @@ module.exports = function (path = '', local, theme, plugins) { } if (plugins) { + replace(target(filename), '_plugins_', '_plugin\n '.repeat(plugins.length)) plugins.forEach(plugin => { - replace(target(filename), '_plugins_', '_plugin_\n _plugin_') - const scriptTemplate = `` - replace(target(filename), '_plugin_', scriptTemplate) + // Currently only supporting unpkg/docsify/lib/plugins/ + const url = `https://unpkg.com/docsify/lib/${plugin}.min.js` + const scriptTemplate = `` + replace(target(filename), '_plugin', scriptTemplate) }) } else { replace(target(filename), '_plugins_', '') From 21a097f7bb089d9b0fc2fe8947610874230c4caf Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Thu, 12 Mar 2020 21:31:15 +0200 Subject: [PATCH 03/29] fix: removing temp docs --- docsrr/.nojekyll | 0 docsrr/README.md | 0 docsrr/index.html | 25 ------------------------- 3 files changed, 25 deletions(-) delete mode 100644 docsrr/.nojekyll delete mode 100644 docsrr/README.md delete mode 100644 docsrr/index.html diff --git a/docsrr/.nojekyll b/docsrr/.nojekyll deleted file mode 100644 index e69de29..0000000 diff --git a/docsrr/README.md b/docsrr/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/docsrr/index.html b/docsrr/index.html deleted file mode 100644 index ff8e88a..0000000 --- a/docsrr/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - Document - - - - - - -
- - - - - - - - From a078e088766c825833147276d2b72845de1b9338 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Thu, 12 Mar 2020 21:43:20 +0200 Subject: [PATCH 04/29] docs: adding documentation for init --plugins --- docs/README.md | 5 +++++ lib/commands/init.js | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 03159b0..43b684d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -52,6 +52,11 @@ docsify init [--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 `` replace(target(filename), '_plugin', scriptTemplate) }) From b8b89c7ad7fce26091c24f50112e85279c06929d Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Fri, 13 Mar 2020 09:27:33 +0200 Subject: [PATCH 05/29] fix: removing unused files --- README.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 21 -------------- 2 files changed, 84 insertions(+), 21 deletions(-) delete mode 100644 index.html diff --git a/README.md b/README.md index e69de29..43b684d 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,84 @@ +# docsify-cli + +[![Build Status master branch](https://img.shields.io/travis/QingWei-Li/docsify-cli/master.svg?style=flat-square)](https://travis-ci.org/QingWei-Li/docsify-cli) +[![License](https://img.shields.io/github/license/QingWei-Li/docsify-cli.svg?style=flat-square)](https://github.com/QingWei-Li/docsify-cli/blob/master/LICENSE) +[![Github tag](https://img.shields.io/github/tag/QingWei-Li/docsify-cli.svg?style=flat-square)](https://github.com/QingWei-Li/docsify-cli/tags) +[![npm version](https://img.shields.io/npm/v/docsify-cli.svg?style=flat-square)](https://www.npmjs.com/package/docsify-cli) +[![npm total downloads](https://img.shields.io/npm/dt/docsify-cli.svg?style=flat-square)](https://www.npmjs.com/package/docsify-cli) +[![npm total monthly](https://img.shields.io/npm/dm/docsify-cli.svg?style=flat-square)](https://www.npmjs.com/package/docsify-cli) + +> 🖌 docsify cli - A magical documentation generator. + +## Links + +* [docsify](https://github.com/QingWei-Li/docsify) + +## Screencast + +![Screencast](https://raw.githubusercontent.com/QingWei-Li/docsify-cli/master/media/screencast.gif) + +> Running a server on `localhost` with live-reload. + +## Installation + +Install `docsify-cli` via `npm` or `yarn` globally. + +```shell +npm i docsify-cli -g +# yarn global add docsify-cli +``` + +## Usage + +### `init` command + +Use `init` to generate your docs. + +```shell +docsify init [--local false] [--theme vue] + +# docsify i [--local false] [--theme vue] +``` + +`` defaults to the current directory. Use relative paths like `./docs` (or `docs`). + +* `--local` option: + * Shorthand: `-l` + * Type: boolean + * Default: `false` + * Description: Copy `docsify` files to the docs path, defaults to `false` using `unpkg.com` 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`. +* `--plugins` option: + * Shorthand: `-p` + * Type: array + * Default: `[]` + * Description: Provide a list of plugins to insert as ` - - - From 64b32e075abc7cd6b158375e9bb6aae21f78db95 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Fri, 13 Mar 2020 09:28:48 +0200 Subject: [PATCH 06/29] fix: removing .nojekyll top-level --- .nojekyll | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .nojekyll diff --git a/.nojekyll b/.nojekyll deleted file mode 100644 index e69de29..0000000 From f522d07d131541e700078663ebcbf5dc5dce1b9f Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Fri, 13 Mar 2020 10:39:07 +0200 Subject: [PATCH 07/29] chore: adding tests --- e2e/index.js | 11 ++++++-- e2e/index.js.md | 65 ++++++++++++++++++++++++++++++---------------- e2e/index.js.snap | Bin 607 -> 817 bytes 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/e2e/index.js b/e2e/index.js index 5fa8233..ae2a11b 100644 --- a/e2e/index.js +++ b/e2e/index.js @@ -4,7 +4,7 @@ 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}) @@ -12,12 +12,19 @@ test('shows up help message without any args', async t => { }) const matchSnapshot = async (t, arg) => { - const {stdout} = await execa(rootCommand, [arg]) + let args = [arg] + + if ((typeof arg) === 'object') { + args = [arg[0], ...arg.slice(1)] + } + + 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') diff --git a/e2e/index.js.md b/e2e/index.js.md index 2df5842..a9e5a4a 100644 --- a/e2e/index.js.md +++ b/e2e/index.js.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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.0␊ + ` + +## shows version information with -v flag + +> Snapshot 1 + + `␊ + docsify-cli version:␊ + 4.4.0␊ + ` diff --git a/e2e/index.js.sn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j)2ppuUHe)`) zv=$4>fn2If%~oHqj{t23wsdn4L4B4v&45sWm1DI_SBQ`o^7;OSm$}jKgxj7ys%HO0hX-w#c@Sx%Gz}BB^F@0Nmrbp{ud=iS9$*l006#zCI0{b From e532c1e31476f93c7e2d30063fb7cd83f8a96ae0 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Fri, 13 Mar 2020 10:53:56 +0200 Subject: [PATCH 08/29] fix: fixing docs links --- README.md | 97 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 43b684d..22ed33f 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,32 @@ -# docsify-cli - -[![Build Status master branch](https://img.shields.io/travis/QingWei-Li/docsify-cli/master.svg?style=flat-square)](https://travis-ci.org/QingWei-Li/docsify-cli) -[![License](https://img.shields.io/github/license/QingWei-Li/docsify-cli.svg?style=flat-square)](https://github.com/QingWei-Li/docsify-cli/blob/master/LICENSE) -[![Github tag](https://img.shields.io/github/tag/QingWei-Li/docsify-cli.svg?style=flat-square)](https://github.com/QingWei-Li/docsify-cli/tags) -[![npm version](https://img.shields.io/npm/v/docsify-cli.svg?style=flat-square)](https://www.npmjs.com/package/docsify-cli) -[![npm total downloads](https://img.shields.io/npm/dt/docsify-cli.svg?style=flat-square)](https://www.npmjs.com/package/docsify-cli) -[![npm total monthly](https://img.shields.io/npm/dm/docsify-cli.svg?style=flat-square)](https://www.npmjs.com/package/docsify-cli) - -> 🖌 docsify cli - A magical documentation generator. - -## Links - -* [docsify](https://github.com/QingWei-Li/docsify) +

+ + docsify + +

+ +

+ 🖌 docsify cli - A magical documentation generator. +

+ +

+ Backers on Open Collective + Sponsors on Open Collective + Travis Status + npm +gitter +license +npm-total-download +npm-monthly-download + +

+ +

Gold Sponsor via Open Collective

+ +

+ + + +

## Screencast @@ -42,21 +57,21 @@ docsify init [--local false] [--theme vue] `` defaults to the current directory. Use relative paths like `./docs` (or `docs`). -* `--local` option: - * Shorthand: `-l` - * Type: boolean - * Default: `false` - * Description: Copy `docsify` files to the docs path, defaults to `false` using `unpkg.com` 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`. -* `--plugins` option: - * Shorthand: `-p` - * Type: array - * Default: `[]` - * Description: Provide a list of plugins to insert as `` replace(target(filename), '_plugin', scriptTemplate) }) From de9bcceda0f372442021308258b99a926596f812 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Thu, 18 Jun 2020 13:41:32 +0300 Subject: [PATCH 12/29] fix(e2e): recreating index snap with latest docsify version --- e2e/index.js.md | 4 ++-- e2e/index.js.snap | Bin 817 -> 818 bytes 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/index.js.md b/e2e/index.js.md index a9e5a4a..d66c9dd 100644 --- a/e2e/index.js.md +++ b/e2e/index.js.md @@ -121,7 +121,7 @@ Generated by [AVA](https://ava.li). `␊ docsify-cli version:␊ - 4.4.0␊ + 4.4.1␊ ` ## shows version information with -v flag @@ -130,5 +130,5 @@ Generated by [AVA](https://ava.li). `␊ docsify-cli version:␊ - 4.4.0␊ + 4.4.1␊ ` diff --git a/e2e/index.js.snap b/e2e/index.js.snap index 223cd554780b06b63d51ad6dd9d5dab517fab343..7ea960c5c312c3a70013b3301408ed5856e326f5 100644 GIT binary patch literal 818 zcmV-21I_$FRzVE#eAN5fKr~Z%(4gMxhr&ThLZYL0d`ELrJU7ZYIgLvpeg~Y+_XG!Hc&Z z6!Fl5qJq+M3(`tK@g()6C>|A|Ck0PERB>jqt*KVAy$KmucK7lA`~S~>3^T83+IDSX zk7ca{w_85kxc~49Jv^sta>d1Cete8xewn?$t1^{Yn0Ym+D|E6+)0%_W%Xjk!A0$ZE z;=TRLFLZ^@iRZ!l);n*fMh;Y77r#DzbM2O{(4}pfHrzY+ZTiAW`@+8G&F$xJ4(STr zyIs>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r4^^_w vi)e4kC)fnQ&;?slRT;VBB{mOgr}*Vbrs}bqoLi3!#IH From 067bb2a3d229605603dba9509a6c9a6f5520fa84 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Wed, 28 Apr 2021 13:47:22 +0300 Subject: [PATCH 13/29] Update docs/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 沈唁 <52o@qq52o.cn> --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 43b684d..f8da67a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -56,7 +56,7 @@ docsify init [--local false] [--theme vue] * Shorthand: `-p` * Type: array * Default: `[]` - * Description: Provide a list of plugins to insert as ` - _plugins_ + _plugins_ From 0059e7ff741fe0fd3a619a964e56fc28a3fdcb75 Mon Sep 17 00:00:00 2001 From: Tal Hayut Date: Wed, 28 Apr 2021 13:47:44 +0300 Subject: [PATCH 16/29] Update lib/commands/init.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 沈唁 <52o@qq52o.cn> --- lib/commands/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index d1a9445..a3dfd6d 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -69,7 +69,7 @@ module.exports = function (path = '', local, theme, 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` + const url = plugin.includes('//') ? plugin : `//cdn.jsdelivr.net/npm/docsify@${major}/lib/plugins/${plugin}.min.js` const scriptTemplate = `` replace(target(filename), '_plugin', scriptTemplate) }) From 272e310cd59163ff1056a9dbbe7de952e5616002 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Thu, 29 Apr 2021 10:36:36 +0800 Subject: [PATCH 17/29] chore: Optimize code to ensure equal indentation --- lib/commands/init.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index a3dfd6d..a180ec5 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -66,15 +66,15 @@ module.exports = function (path = '', local, theme, plugins) { } if (plugins) { - replace(target(filename), '_plugins_', '_plugin\n '.repeat(plugins.length)) + replace(target(filename), ' _plugins_', '_plugin'.repeat(plugins.length + 1)) + let url = '' plugins.forEach(plugin => { - const major = version[0] - const url = plugin.includes('//') ? plugin : `//cdn.jsdelivr.net/npm/docsify@${major}/lib/plugins/${plugin}.min.js` - const scriptTemplate = `` - replace(target(filename), '_plugin', scriptTemplate) + url = plugin.includes('//') ? plugin : `//cdn.jsdelivr.net/npm/docsify@${version[0]}/lib/plugins/${plugin}.min.js` + replace(target(filename), '_plugin', ` \n`) }) + replace(target(filename), '\n_plugin', '') } else { - replace(target(filename), '_plugins_', '') + replace(target(filename), '\n _plugins_', '') } console.log(msg) From f3e717cbe47255b7dfc1936272dafaa1a4252b31 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Thu, 29 Apr 2021 10:56:39 +0800 Subject: [PATCH 18/29] chore: update snap --- e2e/cli.test.js.md | 84 ++++++------------------------------------- e2e/cli.test.js.snap | Bin 657 -> 610 bytes 2 files changed, 10 insertions(+), 74 deletions(-) diff --git a/e2e/cli.test.js.md b/e2e/cli.test.js.md index b3818fb..42a1d7e 100644 --- a/e2e/cli.test.js.md +++ b/e2e/cli.test.js.md @@ -11,35 +11,9 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs [aliases: i]␊ - docsify serve [path] Run local server to preview site. [aliases: s]␊ - docsify start Server for SSR␊ - docsify generate Docsify's generators [aliases: g]␊ - ␊ - Global Options␊ - --help, -h Show help [boolean]␊ - --version, -v Show version number [boolean]␊ - ␊ - Documentation:␊ - https://docsifyjs.github.io/docsify␊ - https://docsifyjs.github.io/docsify-cli␊ - ␊ - Development:␊ - https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md␊ - ␊ - Unknown argument: junkcmd` - -## rejects promise due to error on passing in an unknown command - -> Snapshot 1 - - `Usage: docsify ␊ - ␊ - Commands:␊ - docsify init [path] Creates new docs [aliases: i]␊ - docsify serve [path] Run local server to preview site. [aliases: s]␊ - docsify start Server for SSR␊ - docsify generate Docsify's generators [aliases: g]␊ + docsify init [path] Creates new docs␊ + docsify serve [path] Run local server to preview site.␊ + docsify start Server for SSR␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ @@ -61,10 +35,9 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs [aliases: i]␊ - docsify serve [path] Run local server to preview site. [aliases: s]␊ - docsify start Server for SSR␊ - docsify generate Docsify's generators [aliases: g]␊ + docsify init [path] Creates new docs␊ + docsify serve [path] Run local server to preview site.␊ + docsify start Server for SSR␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ @@ -84,10 +57,9 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs [aliases: i]␊ - docsify serve [path] Run local server to preview site. [aliases: s]␊ - docsify start Server for SSR␊ - docsify generate Docsify's generators [aliases: g]␊ + docsify init [path] Creates new docs␊ + docsify serve [path] Run local server to preview site.␊ + docsify start Server for SSR␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ @@ -98,42 +70,7 @@ Generated by [AVA](https://avajs.dev). https://docsifyjs.github.io/docsify-cli␊ ␊ Development:␊ -<<<<<<< HEAD:e2e/index.js.md https://github.com/docsifyjs/docsify-cli/blob/master/CONTRIBUTING.md` -======= - 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.3␊ - ` ->>>>>>> master:e2e/cli.test.js.md - -## shows help with init --help flag - -> Snapshot 1 - -<<<<<<< HEAD:e2e/index.js.md - `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]` ## shows up help message without any args @@ -165,14 +102,13 @@ Generated by [AVA](https://avajs.dev). `␊ docsify-cli version:␊ - 4.4.1␊ + 4.4.3␊ ` ## shows version information with -v flag > Snapshot 1 - `␊ docsify-cli version:␊ 4.4.3␊ diff --git a/e2e/cli.test.js.snap b/e2e/cli.test.js.snap index f36cbfeffd4654e4e590a6af63b69a91ff557e49..4cf0956c48da3bbff2475e952c3967c6dd9d7794 100644 GIT binary patch literal 610 zcmV-o0-gOqRzV(AmAo?Iyc3%g)>#{y_^H zI|W57u22&}No|@KQixU1N>MDevQe-~5y6?g%Xv1zq~3vTKEC&RZ{B_|&k#cW$oTdW zZ~t6hIo51hTd&^V(~vq&3Zd06gO5M8E}w3GsQudfc5(fBN?NRL_9K*z&TfBxeP%V|PriFPwDVSr)$j7VeZsbPqep#T@2)(*!Om@Hv3ha< zA+odn!n&Sbc=BU(ZLl?YM~l_UQAtAs@ibZ=I-V+~N*vcn4yw%I-r_Zw@TezlauPMj z6ikFzxKp~GXF-5zmFINm8kG;q%1{A-d_=Gy94KkVjviyo>N?Fj1)n+CZ|e~V24O@R zo-E{^AVzPcz>(+-0bsTLi!1`mGIf2{XST!?Lg6v08fG#s@xxKbxS)>ZvL+}64syyi zV?M#O5(8yJF6oll=m0wk(0X9YX$}I^XP8qD2o+dOtaj-N5%OF%+qv)(H)@`6>$c&s zJ?;No8OQe|pEQWiLe-*|-f=rD_>1T*%-V93*#L7vqHMk}Uo_{YOU1eQStF?GdikPh z7R(Bq2OQPn@i~N;b5b?nlDrrvz(eAw|AoP62j!oL4JQ#xBDPP&lCUIUIaFA*VZEnn wZxgE1m@#Ht&=2cPjVB>YLb&gvSfb06HEH)r%)wHfE;~W>50~99CjSWl00klzicE5do`?A~N|liitRXYLMv(89*f zLJ^BAG>KqHW#KhZQixSFm7-W`VW(grDI#Qc?k5*aKc>SII+dh~5zsjo47TT|%bL8%7zt7^0qIGp&JC~|C*EUGYzyVF0gOjjE zM$k}zg);(Sj`=>O6`qBtON@A^6cNfutz1a3ARJLrS0uFCDq+vXobW7i%RPe1vsclm zQsglUd#$4o35J4@)Ld!6T|xBU1^G5XfkV;mLGcPLnQ0cHLc!=^+Jur&7T+b0whm77 z&JhcD?q|!|E<-rxF;kYC4}{Aomj>yyL%d)BrJYs*4y&UG*>yHMdYFuP1kve<(cs7%1k7kDJwkw>fsk^L${TVB5d9Kta zHR7=#vglQBvn}RtN%Vf0G36vPKIVdinOuHi(ilHqoE)DR)BOsBr3;3UH_GTN!lA9o z=P1COlZuWm%EmZBJRnwdvlv;e>~2f_vpDr}>i1Ua Date: Thu, 29 Apr 2021 11:09:15 +0800 Subject: [PATCH 19/29] chore: update snap --- e2e/cli.test.js.md | 28 ++++++++++++++++------------ e2e/cli.test.js.snap | Bin 610 -> 657 bytes e2e/index.js.snap | Bin 818 -> 0 bytes 3 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 e2e/index.js.snap diff --git a/e2e/cli.test.js.md b/e2e/cli.test.js.md index 42a1d7e..53395ac 100644 --- a/e2e/cli.test.js.md +++ b/e2e/cli.test.js.md @@ -11,9 +11,10 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs␊ - docsify serve [path] Run local server to preview site.␊ - docsify start Server for SSR␊ + docsify init [path] Creates new docs [aliases: i]␊ + docsify serve [path] Run local server to preview site. [aliases: s]␊ + docsify start Server for SSR␊ + docsify generate Docsify's generators [aliases: g]␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ @@ -35,9 +36,10 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs␊ - docsify serve [path] Run local server to preview site.␊ - docsify start Server for SSR␊ + docsify init [path] Creates new docs [aliases: i]␊ + docsify serve [path] Run local server to preview site. [aliases: s]␊ + docsify start Server for SSR␊ + docsify generate Docsify's generators [aliases: g]␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ @@ -57,9 +59,10 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs␊ - docsify serve [path] Run local server to preview site.␊ - docsify start Server for SSR␊ + docsify init [path] Creates new docs [aliases: i]␊ + docsify serve [path] Run local server to preview site. [aliases: s]␊ + docsify start Server for SSR␊ + docsify generate Docsify's generators [aliases: g]␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ @@ -79,9 +82,10 @@ Generated by [AVA](https://avajs.dev). `Usage: docsify ␊ ␊ Commands:␊ - docsify init [path] Creates new docs␊ - docsify serve [path] Run local server to preview site.␊ - docsify start Server for SSR␊ + docsify init [path] Creates new docs [aliases: i]␊ + docsify serve [path] Run local server to preview site. [aliases: s]␊ + docsify start Server for SSR␊ + docsify generate Docsify's generators [aliases: g]␊ ␊ Global Options␊ --help, -h Show help [boolean]␊ diff --git a/e2e/cli.test.js.snap b/e2e/cli.test.js.snap index 4cf0956c48da3bbff2475e952c3967c6dd9d7794..f36cbfeffd4654e4e590a6af63b69a91ff557e49 100644 GIT binary patch literal 657 zcmV;C0&e|5RzVzicE5do`?A~N|liitRXYLMv(89*f zLJ^BAG>KqHW#KhZQixSFm7-W`VW(grDI#Qc?k5*aKc>SII+dh~5zsjo47TT|%bL8%7zt7^0qIGp&JC~|C*EUGYzyVF0gOjjE zM$k}zg);(Sj`=>O6`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A|Ck0PERB>jqt*KVAy$KmucK7lA`~S~>3^T83+IDSX zk7ca{w_85kxc~49Jv^sta>d1Cete8xewn?$t1^{Yn0Ym+D|E6+)0%_W%Xjk!A0$ZE z;=TRLFLZ^@iRZ!l);n*fMh;Y77r#DzbM2O{(4}pfHrzY+ZTiAW`@+8G&F$xJ4(STr zyIs>pmSU%8CcZCzI(O*VqFFtnEA-+HO~cExk205=hwpxlPq$8WUDp-*WT&V=R4$j^ zqV3k(j6AiOQ>Z3v;y@V(%%NV&0O&9~%wtA9w<+5+#845ZAPRv_$8-2qhJ!NhhE5;x zQnz9BP}fCXo=K5aqU1qN5=H@_C%}kf1|F^`MjcUUtufP~2ZY*))bIc}1wX)LM+7p5 zW3xVzqku<60Aylt8XbiB>=&u$h&!C?yzq zqe?K^JfT^R1S15z(6vN0n-Mg6sU5o5BLH0!E$96c8PUox9l2bs0VdJ-~RT_ee zst}4(KaucgBGTHpG|1&~0fmI8YI?Qic?r8%RLCVaD}PjJGOLB9a^75@ILCP4cts&+ zm#AZ7mV#J0#IZQUtk5FrBaeb{`S!yA$LbR+W-YN#!lL6bky^~|1Q3UDpaqEF`uu;} wcN7GuI=aqV#~TOHpUl}fh}0!&$Q$=)#ap{VrC==d#%(wM1I0>Y%ykR^0B2c@^8f$< From f96f6d5f64b24fe494a17177e32caf4ffeecc6e3 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Thu, 29 Apr 2021 11:27:37 +0800 Subject: [PATCH 20/29] chore: update zh.json --- tools/locales/zh.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/locales/zh.json b/tools/locales/zh.json index 6244da8..162179e 100644 --- a/tools/locales/zh.json +++ b/tools/locales/zh.json @@ -6,13 +6,14 @@ "init": "创建 docs", "init.local": "拷贝 docsify 到本地", "init.theme": "选择主题", + "init.plugins": "选择插件", "serve": "本地预览", "serve.open": "自动打开浏览器", "serve.port": "设置端口", - "serve.indexname": "Custom filename instead of index.html to serve by default", - "generate": "Docsify的生成器", + "serve.indexname": "自定义入口文件名,代替默认的 index.html", + "generate": "docsify 的生成器", "generate.sidebar": "生成侧边栏文件", - "livereload.port": "设置livereload端口", + "livereload.port": "设置 livereload 端口", "usage": "例子", "version": "当前版本号" } From 2debff85df5108b135468a58bbc7c3fad9f8c580 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Thu, 29 Apr 2021 11:38:57 +0800 Subject: [PATCH 21/29] fix: the exception caused by the plugin name being a number https://github.com/docsifyjs/docsify-cli/pull/99#discussion_r621952975 --- lib/commands/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index 87bdcd7..ad90767 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -101,7 +101,7 @@ function createFile(path, local, theme, plugins) { replace(target(filename), ' _plugins_', '_plugin'.repeat(plugins.length + 1)) let url = '' plugins.forEach(plugin => { - url = plugin.includes('//') ? plugin : `//cdn.jsdelivr.net/npm/docsify@${version[0]}/lib/plugins/${plugin}.min.js` + url = String(plugin).includes('//') ? plugin : `//cdn.jsdelivr.net/npm/docsify@${version[0]}/lib/plugins/${plugin}.min.js` replace(target(filename), '_plugin', ` \n`) }) replace(target(filename), '\n_plugin', '') From 6f26f05cf004a7be5b79b6240cc8b60776823999 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Wed, 19 May 2021 14:55:15 +0800 Subject: [PATCH 22/29] Use MultiSelect --- lib/cli.js | 5 ++++- lib/commands/init.js | 44 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 2a79a8b..11de63d 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -44,8 +44,11 @@ require('yargs') }, plugins: { alias: 'p', + default: false, desc: chalk.gray(y18n.__('init.plugins')), - type: 'array' + nargs: 0, + requiresArg: false, + type: 'boolean' } }), handler: argv => run.init(argv.path, argv.local, argv.theme, argv.plugins) diff --git a/lib/commands/init.js b/lib/commands/init.js index ad90767..08cf304 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -5,8 +5,9 @@ const cp = require('cp-file').sync const chalk = require('chalk') const {version} = require('../../package.json') const logger = require('../util/logger') -const {prompt} = require('enquirer') +const {prompt, MultiSelect} = require('enquirer') const {cwd, exists, pkg, pwd, read, resolve} = require('../util') +const colors = require('ansi-colors') const replace = function (file, tpl, replace) { fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8') @@ -98,13 +99,42 @@ function createFile(path, local, theme, plugins) { } if (plugins) { - replace(target(filename), ' _plugins_', '_plugin'.repeat(plugins.length + 1)) - let url = '' - plugins.forEach(plugin => { - url = String(plugin).includes('//') ? plugin : `//cdn.jsdelivr.net/npm/docsify@${version[0]}/lib/plugins/${plugin}.min.js` - replace(target(filename), '_plugin', ` \n`) + const prompt = new MultiSelect({ + name: 'plugins', + message: 'Select plugins to be used', + hint: '(Use to select, to submit)', + default: '', + choices: [ + {name: 'front-matter', value: 'front-matter'}, + {name: 'search', value: 'search'}, + {name: 'disqus', value: 'disqus'}, + {name: 'emoji', value: 'emoji'}, + {name: 'external-script', value: 'external-script'}, + {name: 'ga', value: 'ga'}, + {name: 'gitalk', value: 'gitalk'}, + {name: 'matomo', value: 'matomo'}, + {name: 'zoom-image', value: 'zoom-image'} + ], + indicator(state, choice) { + if (choice.enabled) { + return colors.cyan(state.symbols.radio.on) + } + + return colors.gray(state.symbols.radio.off) + } }) - replace(target(filename), '\n_plugin', '') + prompt.on('cancel', () => replace(target(filename), '\n _plugins_', '')) + prompt.run() + .then(answers => { + replace(target(filename), ' _plugins_', '_plugin'.repeat(answers.length + 1)) + let url = '' + answers.forEach(plugin => { + url = `//cdn.jsdelivr.net/npm/docsify@${version[0]}/lib/plugins/${plugin}.min.js` + replace(target(filename), '_plugin', ` \n`) + }) + replace(target(filename), '\n_plugin', '') + }) + .catch(console.error) } else { replace(target(filename), '\n _plugins_', '') } From 1b7f8f2a750ddca332e74a087589971bbfd1cf57 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Wed, 19 May 2021 15:01:30 +0800 Subject: [PATCH 23/29] Update README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a791b94..ed9826f 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,9 @@ docsify init [--local false] [--theme 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 `\n`) - }) - replace(target(filename), '\n_plugin', '') - }) - .catch(console.error) - } else { - replace(target(filename), '\n _plugins_', '') - console.log(msg) + + return colors.gray(state.symbols.radio.off) + } + }) + + prompt.on('cancel', () => replace(target(filename), '\n _plugins_', '')) + + let answers = [] + try { + answers = await prompt.run() + } catch (err) { + logger.error(err) + process.exit(1) } + + 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` + replace(target(filename), '_plugin', ` \n`) + }) + + replace(target(filename), '\n_plugin', '') } From 149bd8117b10b96cca9e2527b8f8ad9a70047825 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 28 May 2021 11:38:39 +0530 Subject: [PATCH 28/29] chore: handle user interruptions --- lib/commands/init.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/commands/init.js b/lib/commands/init.js index 8d38c74..401ca2c 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -27,16 +27,22 @@ module.exports = async function (path = '', local, theme, plugins) { if (exists(cwdPath)) { logger.error(`${path || '.'} already exists.`) - const {rewrite} = await prompt({ - type: 'confirm', - name: 'rewrite', - symbols: { - separator: '' - }, - message: 'Are you sure you want to rewrite it?' - }) - - if (!rewrite) { + let answer = {} + try { + answer = await prompt({ + type: 'confirm', + name: 'rewrite', + symbols: { + separator: '' + }, + message: 'Are you sure you want to rewrite it?' + }) + } catch (err) { + err && logger.error(err) + process.exit(1) + } + + if (!answer.rewrite) { return } } @@ -130,8 +136,12 @@ async function createFile(path, local, theme, plugins) { try { answers = await prompt.run() } catch (err) { - logger.error(err) - process.exit(1) + if (err) { + logger.error(err) + process.exitCode = 1 + } + + return } replace(target(filename), ' _plugins_', '_plugin'.repeat(answers.length + 1)) From 828b672ec189149fb1b5c50281c7509a4a627b26 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Fri, 11 Jun 2021 12:07:49 +0800 Subject: [PATCH 29/29] Update README --- README.md | 4 ++-- docs/README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ed9826f..577100d 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,9 @@ npm i docsify-cli -g Use `init` to generate your docs. ```shell -docsify init [--local false] [--theme vue] +docsify init [--local false] [--theme vue] [--plugins false] -# docsify i [-l false] [-t vue] +# docsify i [-l false] [-t vue] [--plugins false] ``` `` defaults to the current directory. Use relative paths like `./docs` (or `docs`). diff --git a/docs/README.md b/docs/README.md index 310e159..599a815 100644 --- a/docs/README.md +++ b/docs/README.md @@ -35,9 +35,9 @@ npm i docsify-cli -g Use `init` to generate your docs. ```shell -docsify init [--local false] [--theme vue] +docsify init [--local false] [--theme vue] [--plugins false] -# docsify i [--local false] [--theme vue] +# docsify i [--local false] [--theme vue] [--plugins false] ``` `` defaults to the current directory. Use relative paths like `./docs` (or `docs`). @@ -56,7 +56,7 @@ docsify init [--local false] [--theme vue] * Shorthand: `-p` * Type: array * Default: `[]` - * Description: Provide a list of plugins to insert as `