Skip to content

Commit

Permalink
feat: move scope to cli params
Browse files Browse the repository at this point in the history
  • Loading branch information
int64ago committed Sep 24, 2019
1 parent e7701d7 commit f338c4e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<scope-name>
```

- yarn
Expand All @@ -22,6 +28,12 @@ npm init @svrx/plugin
yarn create @svrx/plugin
```

Publish as scoped npm package:

```bash
yarn create @svrx/plugin --scope=<scope-name>
```

#### Test with plugin

> Make sure you've installed [svrx-cli](https://github.com/svrxjs/svrx-cli) globally.
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
const { argv } = require('yargs');

require('../lib/index')(argv._[0]);
require('../lib/index')(argv);
19 changes: 6 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-<name>',
default: 'svrx-plugin-<name>',
filter: (input) => correctFullName(input),
validate(input) {
if (!isSvrxPlugin(input)) {
Expand All @@ -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('@')) {
Expand Down
5 changes: 0 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
Expand Down

0 comments on commit f338c4e

Please sign in to comment.