From f338c4e8307d7471a7af664d306dbdfffbac2019 Mon Sep 17 00:00:00 2001 From: Cody Chan Date: Tue, 24 Sep 2019 22:51:05 +0800 Subject: [PATCH] feat: move scope to cli params --- README.md | 12 ++++++++++++ bin/index.js | 2 +- lib/index.js | 19 ++++++------------- lib/utils.js | 5 ----- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7ce035a..fa1dbca 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ Initialize a svrx plugin by running one command. ```bash npm init @svrx/plugin +``` + +Publish as scoped npm package: + +```bash +npm init @svrx/plugin --scope= ``` - yarn @@ -22,6 +28,12 @@ npm init @svrx/plugin yarn create @svrx/plugin ``` +Publish as scoped npm package: + +```bash +yarn create @svrx/plugin --scope= +``` + #### Test with plugin > Make sure you've installed [svrx-cli](https://github.com/svrxjs/svrx-cli) globally. diff --git a/bin/index.js b/bin/index.js index 220689a..aa56e1e 100644 --- a/bin/index.js +++ b/bin/index.js @@ -1,4 +1,4 @@ #!/usr/bin/env node const { argv } = require('yargs'); -require('../lib/index')(argv._[0]); +require('../lib/index')(argv); diff --git a/lib/index.js b/lib/index.js index 8d225c8..188c38f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,20 +4,19 @@ const { existsSync } = require('fs-extra'); const Generator = require('./Generator'); const { isSvrxPlugin, - correctName, correctFullName, getAuthor, } = require('./utils'); -module.exports = (name) => { - const fullname = correctName(name); +module.exports = (argv) => { + const { scope } = argv; const questions = [ { type: 'input', name: 'projectName', message: 'The project name:', - default: fullname || 'svrx-plugin-', + default: 'svrx-plugin-', filter: (input) => correctFullName(input), validate(input) { if (!isSvrxPlugin(input)) { @@ -36,19 +35,13 @@ module.exports = (name) => { return `The svrx plugin for ${projectName.substr(12)}`; }, }, - { - type: 'confirm', - name: 'withScope', - message: 'Publish npm package with scope?', - default: false, - }, { type: 'input', name: 'scopeName', message: 'The npm scope:', - default: '@svrx', - when({ withScope }) { - return withScope; + default: scope.startsWith('@') ? scope : `@${scope}`, + when() { + return !!scope; }, validate(input) { if (!input || !input.startsWith('@')) { diff --git a/lib/utils.js b/lib/utils.js index 098b95f..0110cfb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -12,11 +12,6 @@ exports.getPluginName = (name, scope) => { return pluginName; }; -exports.correctName = (name) => { - if (name && !isSvrxPlugin(name)) return `svrx-plugin-${paramCase(name)}`; - return name; -}; - exports.correctFullName = (name) => { if (isSvrxPlugin(name)) return paramCase(name); return `svrx-plugin-${paramCase(name)}`;