├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── bin
└── index.js
├── lib
├── config.js
├── download.js
├── init.js
├── mirror.js
└── update.js
├── package.json
└── tpl
└── v0.1.0.zip
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | yarn.lock
8 |
9 | # Runtime data
10 | pids
11 | *.pid
12 | *.seed
13 | *.pid.lock
14 |
15 | # Directory for instrumented libs generated by jscoverage/JSCover
16 | lib-cov
17 |
18 | # Coverage directory used by tools like istanbul
19 | coverage
20 |
21 | # nyc test coverage
22 | .nyc_output
23 |
24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25 | .grunt
26 |
27 | # Bower dependency directory (https://bower.io/)
28 | bower_components
29 |
30 | # node-waf configuration
31 | .lock-wscript
32 |
33 | # Compiled binary addons (http://nodejs.org/api/addons.html)
34 | build/Release
35 |
36 | # Dependency directories
37 | node_modules/
38 | jspm_packages/
39 |
40 | # Typescript v1 declaration files
41 | typings/
42 |
43 | # Optional npm cache directory
44 | .npm
45 |
46 | # Optional eslint cache
47 | .eslintcache
48 |
49 | # Optional REPL history
50 | .node_repl_history
51 |
52 | # Output of 'npm pack'
53 | *.tgz
54 |
55 | # Yarn Integrity file
56 | .yarn-integrity
57 |
58 | # dotenv environment variables file
59 | .prettierrc
60 | .git
61 | .vscode
62 | .env
63 | .idea
64 | .DS_Store
65 | dist
66 | es
67 | _site
68 | /coverage
69 |
70 | # useless files
71 | .bak
72 | template/
73 | config.json
74 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | yarn.lock
8 |
9 | # Runtime data
10 | pids
11 | *.pid
12 | *.seed
13 | *.pid.lock
14 |
15 | # Directory for instrumented libs generated by jscoverage/JSCover
16 | lib-cov
17 |
18 | # Coverage directory used by tools like istanbul
19 | coverage
20 |
21 | # nyc test coverage
22 | .nyc_output
23 |
24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25 | .grunt
26 |
27 | # Bower dependency directory (https://bower.io/)
28 | bower_components
29 |
30 | # node-waf configuration
31 | .lock-wscript
32 |
33 | # Compiled binary addons (http://nodejs.org/api/addons.html)
34 | build/Release
35 |
36 | # Dependency directories
37 | node_modules/
38 | jspm_packages/
39 |
40 | # Typescript v1 declaration files
41 | typings/
42 |
43 | # Optional npm cache directory
44 | .npm
45 |
46 | # Optional eslint cache
47 | .eslintcache
48 |
49 | # Optional REPL history
50 | .node_repl_history
51 |
52 | # Output of 'npm pack'
53 | *.tgz
54 |
55 | # Yarn Integrity file
56 | .yarn-integrity
57 |
58 | # dotenv environment variables file
59 | .prettierrc
60 | .git
61 | .vscode
62 | .env
63 | .idea
64 | .DS_Store
65 | dist
66 | es
67 | _site
68 | /coverage
69 |
70 | # useless files
71 | .bak
72 | tpl/
73 | template/
74 | config.json
75 | tpl/
76 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Feng L.H.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
js-plugin-cli
2 |
3 | A lightweight javascript plugin CLI.
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | # Installation
13 | ```
14 | $ npm i js-plugin-cli -g
15 | ```
16 | # Usage
17 | Run the following command line to create the project:
18 | ```
19 | $ js-plugin-cli init myproject
20 | ```
21 |
22 | # Parameter
23 | ## init
24 | Create the JavaScript plugin project:
25 | ```
26 | $ js-plugin-cli init myproject
27 | ```
28 |
29 | ## upgrade
30 | Check the new version is available or not:
31 | ```
32 | $ js-plugin-cli upgrade
33 | ```
34 |
35 | ## template
36 | You can download or upgrade the template from mirror:
37 | ```
38 | $ js-plugin-cli template
39 | ```
40 |
41 | ## mirror
42 | You can also set the template mirror like this:
43 | ```
44 | $ js-plugin-cli mirror https://zpfz.vercel.app/download/files/frontend/tpl/js-plugin-cli/
45 | ```
46 | **NOTE**
47 | You can customize the template mirror link by youself, but the template file name must be `template.zip`, and the mirror link should be `/` ending.
48 | For example, the full link to your custom template mirror is `https://example.com/mirror/template.zip`, the mirror link that js-plugin-cli can recognize should be `https://example.com/mirror/`.
49 |
50 | You can download the js-plugin-cli template from [js-plugin-cli/tpl](https://github.com/zpfz/js-plugin-cli/tree/master/tpl).
51 |
--------------------------------------------------------------------------------
/bin/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | const program = require('commander')
4 |
5 | const updateChk = require('../lib/update')
6 | const setMirror = require('../lib/mirror')
7 | const dlTemplate = require('../lib/download')
8 | const initProject = require('../lib/init')
9 |
10 | // version
11 | program.version(require('../package.json').version, '-v, --version')
12 |
13 | // upgrade
14 | program
15 | .command('upgrade')
16 | .description('Check the js-plugin-cli version.')
17 | .action(() => {
18 | updateChk()
19 | })
20 |
21 | // mirror
22 | program
23 | .command('mirror ')
24 | .description('Set the template mirror.')
25 | .action((tplMirror) => {
26 | setMirror(tplMirror)
27 | })
28 |
29 | // template
30 | program
31 | .command('template')
32 | .description('Download template from mirror.')
33 | .action(() => {
34 | dlTemplate()
35 | })
36 |
37 | // init
38 | program
39 | .name('js-plugin-cli')
40 | .usage(' [options]')
41 | .command('init ')
42 | .description('Create a javascript plugin project.')
43 | .action(project => {
44 | initProject(project)
45 | })
46 |
47 | program.parse(process.argv)
48 |
--------------------------------------------------------------------------------
/lib/config.js:
--------------------------------------------------------------------------------
1 | const fse = require('fs-extra')
2 | const path = require('path')
3 |
4 | const jsonConfig = {
5 | "name": "js-plugin-cli",
6 | "mirror": "https://zpfz.vercel.app/download/files/frontend/tpl/js-plugin-cli/"
7 | }
8 |
9 | const configPath = path.resolve(__dirname,'../config.json')
10 |
11 | async function defConfig() {
12 | try {
13 | await fse.outputJson(configPath, jsonConfig)
14 | } catch (err) {
15 | console.error(err)
16 | process.exit()
17 | }
18 | }
19 |
20 | module.exports = defConfig
21 |
--------------------------------------------------------------------------------
/lib/download.js:
--------------------------------------------------------------------------------
1 | const download = require('download')
2 | const ora = require('ora')
3 | const chalk = require('chalk')
4 | const path = require('path')
5 | const fse = require('fs-extra')
6 |
7 | const defConfig = require('./config')
8 |
9 | const cfgPath = path.resolve(__dirname,'../config.json')
10 | const tplPath = path.resolve(__dirname,'../template')
11 |
12 | async function dlTemplate() {
13 | const exists = await fse.pathExists(cfgPath)
14 | if (exists){
15 | await dlAction()
16 | }else{
17 | await defConfig()
18 | await dlAction()
19 | }
20 | }
21 |
22 | async function dlAction(){
23 | // Remove dir
24 | try {
25 | await fse.remove(tplPath)
26 | } catch (err) {
27 | console.error(err)
28 | process.exit()
29 | }
30 |
31 | const jsonConfig = await fse.readJson(cfgPath)
32 | const dlSpinner = ora(chalk.cyan('Downloading template...'))
33 |
34 | // Download js-plugin-cli template
35 | dlSpinner.start()
36 | try {
37 | await download(jsonConfig.mirror + 'template.zip', path.resolve(__dirname,'../template/'),{extract:true});
38 | } catch (err) {
39 | dlSpinner.text = chalk.red(`Download template failed. ${err}`)
40 | dlSpinner.fail()
41 | process.exit()
42 | }
43 | dlSpinner.text = 'Download template successful.'
44 | dlSpinner.succeed()
45 | }
46 |
47 | module.exports = dlTemplate
48 |
49 |
50 |
--------------------------------------------------------------------------------
/lib/init.js:
--------------------------------------------------------------------------------
1 | const fse = require('fs-extra')
2 | const ora = require('ora')
3 | const chalk = require('chalk')
4 | const symbols = require('log-symbols')
5 | const inquirer = require('inquirer')
6 | const handlebars = require('handlebars')
7 | const path = require('path')
8 |
9 | const dlTemplate = require('./download')
10 |
11 | async function initProject(projectName) {
12 | try {
13 | const exists = await fse.pathExists(projectName)
14 | if (exists) {
15 | console.log(symbols.error, chalk.red('The project already exists.'))
16 | } else {
17 | inquirer
18 | .prompt([
19 | {
20 | type: 'input',
21 | name: 'name',
22 | message: 'Set a global name for javascript plugin?',
23 | default: 'Default',
24 | },
25 | ])
26 | .then(async (answers) => {
27 | const initSpinner = ora(chalk.cyan('Initializing project...'))
28 | initSpinner.start()
29 |
30 | const templatePath = path.resolve(__dirname, '../template/')
31 | const processPath = process.cwd()
32 | const LCProjectName = projectName.toLowerCase()
33 | const targetPath = `${processPath}/${LCProjectName}`
34 |
35 | const exists = await fse.pathExists(templatePath)
36 | if (!exists) {
37 | await dlTemplate()
38 | }
39 |
40 | try {
41 | await fse.copy(templatePath, targetPath)
42 | } catch (err) {
43 | console.log(symbols.error, chalk.red(`Copy template failed. ${err}`))
44 | process.exit()
45 | }
46 |
47 | const multiMeta = {
48 | project_name: LCProjectName,
49 | global_name: answers.name
50 | }
51 | const multiFiles = [
52 | `${targetPath}/package.json`,
53 | `${targetPath}/gulpfile.js`,
54 | `${targetPath}/test/index.html`,
55 | `${targetPath}/src/index.js`
56 | ]
57 |
58 | for (var i = 0;i < multiFiles.length;i++){
59 | try {
60 | const multiFilesContent = await fse.readFile(multiFiles[i], 'utf8')
61 | const multiFilesResult = await handlebars.compile(multiFilesContent)(multiMeta)
62 | await fse.outputFile(multiFiles[i], multiFilesResult)
63 | } catch (err) {
64 | initSpinner.text = chalk.red(`Initialize project failed. ${err}`)
65 | initSpinner.fail()
66 | process.exit()
67 | }
68 | }
69 |
70 | initSpinner.text = 'Initialize project successful.'
71 | initSpinner.succeed()
72 | console.log(`
73 | To get started:
74 |
75 | cd ${chalk.yellow(LCProjectName)}
76 | ${chalk.yellow('npm install')} or ${chalk.yellow('yarn install')}
77 | ${chalk.yellow('npm run dev')} or ${chalk.yellow('yarn run dev')}
78 | `)
79 | })
80 | .catch((error) => {
81 | if (error.isTtyError) {
82 | console.log(symbols.error,chalk.red("Prompt couldn't be rendered in the current environment.")
83 | )
84 | } else {
85 | console.log(symbols.error, chalk.red(error))
86 | }
87 | })
88 | }
89 | } catch (err) {
90 | console.error(err)
91 | process.exit()
92 | }
93 | }
94 |
95 | module.exports = initProject
96 |
--------------------------------------------------------------------------------
/lib/mirror.js:
--------------------------------------------------------------------------------
1 | const symbols = require('log-symbols')
2 | const path = require('path')
3 | const fse = require('fs-extra')
4 | const defConfig = require('./config')
5 |
6 | const cfgPath = path.resolve(__dirname, '../config.json')
7 |
8 |
9 | async function setMirror(link) {
10 | const exists = await fse.pathExists(cfgPath)
11 | if (exists) {
12 | mirrorAction(link)
13 | } else {
14 | await defConfig()
15 | mirrorAction(link)
16 | }
17 | }
18 |
19 | async function mirrorAction(link) {
20 | try {
21 | const jsonConfig = await fse.readJson(cfgPath)
22 | jsonConfig.mirror = link
23 | await fse.writeJson(cfgPath, jsonConfig)
24 | console.log(symbols.success, 'Set the mirror successful.')
25 | } catch (err) {
26 | console.log(symbols.error, chalk.red(`Set the mirror failed. ${err}`))
27 | process.exit()
28 | }
29 | }
30 |
31 | module.exports = setMirror
32 |
33 |
34 |
--------------------------------------------------------------------------------
/lib/update.js:
--------------------------------------------------------------------------------
1 | const updateNotifier = require('update-notifier')
2 | const chalk = require('chalk')
3 | const pkg = require('../package.json')
4 |
5 | const notifier = updateNotifier({
6 | pkg,
7 | updateCheckInterval: 1000,
8 | })
9 |
10 | function updateChk() {
11 | if (notifier.update) {
12 | console.log(`New version available: ${chalk.cyan(notifier.update.latest)}, it's recommended that you update before using.`)
13 | notifier.notify()
14 | } else {
15 | console.log('No new version is available.')
16 | }
17 | }
18 |
19 | module.exports = updateChk
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "js-plugin-cli",
3 | "version": "1.0.0",
4 | "description": "A lightweight javascript plugin CLI.",
5 | "main": "./bin/index.js",
6 | "bin": {
7 | "js-plugin-cli": "./bin/index.js"
8 | },
9 | "scripts": {
10 | "test": "echo \"Error: no test specified\" && exit 1"
11 | },
12 | "repository": "zpfz/js-plugin-cli",
13 | "bugs": "https://github.com/zpfz/js-plugin-cli/issues",
14 | "keywords": [
15 | "js-plugin-cli",
16 | "js",
17 | "plugin",
18 | "js-plugin",
19 | "starter"
20 | ],
21 | "author": "Feng L.H.",
22 | "homepage": "https://github.com/zpfz/js-plugin-cli",
23 | "license": "MIT",
24 | "dependencies": {
25 | "chalk": "^3.0.0",
26 | "co": "^4.6.0",
27 | "commander": "^4.1.1",
28 | "download": "^8.0.0",
29 | "fs-extra": "^9.0.1",
30 | "handlebars": "^4.7.6",
31 | "inquirer": "^7.3.3",
32 | "log-symbols": "^3.0.0",
33 | "ora": "^5.1.0",
34 | "thunkify": "^2.1.2",
35 | "update-notifier": "^4.1.1"
36 | },
37 | "engines": {
38 | "node": ">=8.6"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tpl/v0.1.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zpfz/js-plugin-cli/3acf6a926c1ad9e42bcdad75d03993d55c0f21cd/tpl/v0.1.0.zip
--------------------------------------------------------------------------------