Skip to content

Commit eff32f5

Browse files
committed
update
1 parent 6985748 commit eff32f5

File tree

8 files changed

+284
-200
lines changed

8 files changed

+284
-200
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Create Vue Library
2+
3+
> CLI for creating reusable, modern Vue libraries using Rollup.
4+
5+
### Quick start
6+
7+
```bash
8+
npx @lokibai/create-vue-library mylib
9+
cd mylib
10+
npm start
11+
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
{
2-
"name": "create-vue-library",
3-
"version": "0.1.0",
4-
"description": "a cli to say hello",
5-
"main": "src/index.js",
6-
"bin": {
7-
"create-vue-library": "bin/create-vue-library"
8-
},
9-
"publishConfig": {
10-
"access": "public"
11-
},
12-
"scripts": {
13-
"test": "echo \"Error: no test specified\" && exit 1"
14-
},
15-
"keywords": [
16-
"cli",
17-
"create-vue-library"
18-
],
19-
"files": [
20-
"bin/",
21-
"src/",
22-
"templates/"
23-
],
24-
"author": "uniquexiaobai",
25-
"license": "MIT",
26-
"dependencies": {
27-
"arg": "^4.1.3",
28-
"chalk": "^3.0.0",
29-
"esm": "^3.2.25",
30-
"execa": "^4.0.0",
31-
"inquirer": "^7.0.5",
32-
"listr": "^0.14.3",
33-
"ncp": "^2.0.0",
34-
"pkg-install": "^1.0.0"
35-
}
2+
"name": "@lokibai/create-vue-library",
3+
"version": "0.1.0",
4+
"description": "CLI for creating reusable, modern Vue libraries using Rollup;",
5+
"author": "uniquexiaobai",
6+
"repository": "https://github.com/uniquexiaobai/create-vue-library",
7+
"bin": {
8+
"create-vue-library": "bin/create-vue-library"
9+
},
10+
"publishConfig": {
11+
"access": "public"
12+
},
13+
"keywords": [
14+
"vue",
15+
"cli",
16+
"create-vue-library"
17+
],
18+
"files": [
19+
"bin/",
20+
"src/",
21+
"templates/"
22+
],
23+
"license": "MIT",
24+
"dependencies": {
25+
"arg": "^4.1.3",
26+
"chalk": "^3.0.0",
27+
"esm": "^3.2.25",
28+
"execa": "^4.0.0",
29+
"inquirer": "^7.0.5",
30+
"listr": "^0.14.3",
31+
"ncp": "^2.0.0",
32+
"pkg-install": "^1.0.0"
33+
}
3634
}

src/cli.js

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -25,108 +25,108 @@ const getHelp = () => chalk`
2525
`;
2626

2727
function parseArgsIntoOptions(rowArgs) {
28-
const projectName = rowArgs[2];
29-
let projectDirectory;
30-
let args;
31-
32-
if (!projectName) {
33-
console.error('Please specify the project directory:');
34-
console.log(
35-
` ${chalk.cyan('create-vue-library')} ${chalk.green(
36-
'<project-directory>'
37-
)}`
38-
);
39-
console.log();
40-
console.log('For example:');
41-
console.log(
42-
` ${chalk.cyan('create-vue-library')} ${chalk.green('my-vue-library')}`
43-
);
44-
console.log();
45-
console.log(
46-
`Run ${chalk.cyan(`${'create-vue-library'} --help`)} to see all options.`
47-
);
48-
process.exit(1);
49-
}
50-
51-
projectDirectory = getAbsolutePath(projectName);
52-
53-
try {
54-
args = arg(
55-
{
56-
'--help': Boolean,
57-
'--version': Boolean,
58-
'--template': String,
59-
60-
'-h': '--help',
61-
'-v': '--version',
62-
'-t': '--template',
63-
},
64-
{
65-
argv: rowArgs.slice(2),
66-
}
67-
);
68-
} catch (err) {
69-
logError(err.message);
70-
process.exit(1);
71-
}
72-
73-
if (args['--version']) {
74-
console.log(pkg.version);
75-
process.exit(0);
76-
}
77-
78-
if (args['--help']) {
79-
console.log(getHelp());
80-
process.exit(0);
81-
}
82-
83-
return {
84-
projectName,
85-
projectDirectory,
86-
template: args['--template'],
87-
};
28+
const projectName = rowArgs[2];
29+
let projectDirectory;
30+
let args;
31+
32+
if (!projectName) {
33+
console.error('Please specify the project directory:');
34+
console.log(
35+
` ${chalk.cyan('create-vue-library')} ${chalk.green(
36+
'<project-directory>'
37+
)}`
38+
);
39+
console.log();
40+
console.log('For example:');
41+
console.log(
42+
` ${chalk.cyan('create-vue-library')} ${chalk.green('my-vue-library')}`
43+
);
44+
console.log();
45+
console.log(
46+
`Run ${chalk.cyan(`${'create-vue-library'} --help`)} to see all options.`
47+
);
48+
process.exit(1);
49+
}
50+
51+
projectDirectory = getAbsolutePath(projectName);
52+
53+
try {
54+
args = arg(
55+
{
56+
'--help': Boolean,
57+
'--version': Boolean,
58+
'--template': String,
59+
60+
'-h': '--help',
61+
'-v': '--version',
62+
'-t': '--template',
63+
},
64+
{
65+
argv: rowArgs.slice(2),
66+
}
67+
);
68+
} catch (err) {
69+
logError(err.message);
70+
process.exit(1);
71+
}
72+
73+
if (args['--version']) {
74+
console.log(pkg.version);
75+
process.exit(0);
76+
}
77+
78+
if (args['--help']) {
79+
console.log(getHelp());
80+
process.exit(0);
81+
}
82+
83+
return {
84+
projectName,
85+
projectDirectory,
86+
template: args['--template'],
87+
};
8888
}
8989

9090
async function checkIsProjectDirectoryValid(options) {
91-
const isExists = await isFileOrDirExists(options.projectDirectory);
92-
93-
if (isExists) {
94-
console.log(
95-
`Uh oh! Looks like there's already a directory called ${chalk.red(
96-
options.projectName
97-
)}.`
98-
);
99-
console.log('Please try a different name or delete that folder.');
100-
process.exit(1);
101-
}
91+
const isExists = await isFileOrDirExists(options.projectDirectory);
92+
93+
if (isExists) {
94+
console.log(
95+
`Uh oh! Looks like there's already a directory called ${chalk.red(
96+
options.projectName
97+
)}.`
98+
);
99+
console.log('Please try a different name or delete that folder.');
100+
process.exit(1);
101+
}
102102
}
103103

104104
async function proptForMissingOptions(options) {
105-
const defaultTemplate = 'basic';
106-
107-
const questions = [];
108-
if (!options.template) {
109-
questions.push({
110-
type: 'list',
111-
name: 'template',
112-
message: 'Please choose which project template to use',
113-
choices: ['basic', 'typescript', 'storybook'],
114-
default: defaultTemplate,
115-
});
116-
}
117-
118-
const answers = await prompt(questions);
119-
return {
120-
...options,
121-
template: options.template || answers.template,
122-
};
105+
const defaultTemplate = 'basic';
106+
107+
const questions = [];
108+
if (!options.template) {
109+
questions.push({
110+
type: 'list',
111+
name: 'template',
112+
message: 'Please choose which project template to use',
113+
choices: ['basic', 'typescript', 'storybook'],
114+
default: defaultTemplate,
115+
});
116+
}
117+
118+
const answers = await prompt(questions);
119+
return {
120+
...options,
121+
template: options.template || answers.template,
122+
};
123123
}
124124

125125
export async function cli(rowArgs) {
126-
let options = parseArgsIntoOptions(rowArgs);
126+
let options = parseArgsIntoOptions(rowArgs);
127127

128-
await checkIsProjectDirectoryValid(options);
128+
await checkIsProjectDirectoryValid(options);
129129

130-
options = await proptForMissingOptions(options);
131-
await createProject(options);
130+
options = await proptForMissingOptions(options);
131+
await createProject(options);
132132
}

0 commit comments

Comments
 (0)