@vidavidorra/create-project 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +64 -0
- package/dist/content/package.d.ts +10 -0
- package/dist/content/package.js +4 -0
- package/dist/create-project.d.ts +3 -0
- package/dist/create-project.js +12 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -61
- package/dist/options.d.ts +2 -1
- package/dist/scripts/postinstall.d.ts +13 -0
- package/dist/scripts/postinstall.js +27 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Interactively create a project.
|
|
|
9
9
|
|
|
10
10
|
[](https://www.npmjs.com/package/@vidavidorra/create-project)
|
|
11
11
|
[](https://www.npmjs.com/package/@vidavidorra/create-project)
|
|
12
|
-
[](https://nodejs.org/en/about/releases/)
|
|
13
13
|
[](https://renovatebot.com)
|
|
14
14
|
[](https://github.com/semantic-release/semantic-release)
|
|
15
15
|
[](https://codecov.io/gh/vidavidorra/create-project)
|
|
@@ -32,7 +32,13 @@ npm install --global @vidavidorra/create-project
|
|
|
32
32
|
Start the interactive CLI to create a project.
|
|
33
33
|
|
|
34
34
|
```shell
|
|
35
|
-
|
|
35
|
+
create-project
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or run the interactive CLI directly via `npx`.
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
npx @vidavidorra/create-project
|
|
36
42
|
```
|
|
37
43
|
|
|
38
44
|
## Contributing
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { input, confirm } from '@inquirer/prompts';
|
|
3
|
+
import { createProject, options as schema } from './index.js';
|
|
4
|
+
function validate(value, option) {
|
|
5
|
+
const validation = schema.shape[option].safeParse(value);
|
|
6
|
+
return validation.success
|
|
7
|
+
? true
|
|
8
|
+
: validation.error.errors.map(({ message }) => message).join('\n> ');
|
|
9
|
+
}
|
|
10
|
+
const project = await input({
|
|
11
|
+
message: 'Project name:',
|
|
12
|
+
validate: (value) => validate(value, 'project'),
|
|
13
|
+
});
|
|
14
|
+
const name = project.replaceAll(' ', '-').toLowerCase();
|
|
15
|
+
const defaultPackage = validate(name, 'package') === true ? name : undefined;
|
|
16
|
+
const options = {
|
|
17
|
+
project,
|
|
18
|
+
package: await input({
|
|
19
|
+
message: 'Package name:',
|
|
20
|
+
validate: (value) => validate(value, 'package'),
|
|
21
|
+
default: defaultPackage,
|
|
22
|
+
}),
|
|
23
|
+
public: await confirm({
|
|
24
|
+
message: 'Make package public?',
|
|
25
|
+
default: schema.shape.public._def.defaultValue(),
|
|
26
|
+
}),
|
|
27
|
+
description: await input({
|
|
28
|
+
message: 'Description:',
|
|
29
|
+
validate: (value) => validate(value, 'description'),
|
|
30
|
+
}),
|
|
31
|
+
author: await input({
|
|
32
|
+
message: 'Author:',
|
|
33
|
+
validate: (value) => validate(value, 'author'),
|
|
34
|
+
}),
|
|
35
|
+
githubOwner: await input({
|
|
36
|
+
message: 'GitHub owner:',
|
|
37
|
+
validate: (value) => validate(value, 'githubOwner'),
|
|
38
|
+
}),
|
|
39
|
+
githubRepository: await input({
|
|
40
|
+
message: 'GitHub repository:',
|
|
41
|
+
validate: (value) => validate(value, 'githubRepository'),
|
|
42
|
+
default: validate(defaultPackage, 'githubRepository') === true
|
|
43
|
+
? defaultPackage
|
|
44
|
+
: undefined,
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
options.typescript = await confirm({ message: 'Add typescript?' });
|
|
48
|
+
if (options.typescript) {
|
|
49
|
+
options.testing = await confirm({ message: 'Add AVA testing framework?' });
|
|
50
|
+
}
|
|
51
|
+
if (options.testing) {
|
|
52
|
+
options.reportCodeCoverage = await confirm({
|
|
53
|
+
message: 'Report code coverate to Codecov?',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
options.path = await input({ message: 'Output folder:' });
|
|
57
|
+
options.dryRun = await confirm({ message: 'Dry run?' });
|
|
58
|
+
const files = await createProject(schema.parse(options));
|
|
59
|
+
if (options.dryRun) {
|
|
60
|
+
for (const path of files) {
|
|
61
|
+
console.log(`Create file ${path}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -28,6 +28,7 @@ declare const schema: z.ZodObject<{
|
|
|
28
28
|
author: z.ZodString;
|
|
29
29
|
type: z.ZodLiteral<"module">;
|
|
30
30
|
exports: z.ZodOptional<z.ZodString>;
|
|
31
|
+
bin: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
31
32
|
files: z.ZodOptional<z.ZodTuple<[z.ZodLiteral<"./dist/**/!(*.test).{js,d.ts,cjs}">], z.ZodString>>;
|
|
32
33
|
scripts: z.ZodObject<{
|
|
33
34
|
build: z.ZodString;
|
|
@@ -35,6 +36,7 @@ declare const schema: z.ZodObject<{
|
|
|
35
36
|
'format:check': z.ZodString;
|
|
36
37
|
lint: z.ZodLiteral<"npm run format:check && xo">;
|
|
37
38
|
'lint:fix': z.ZodLiteral<"npm run format && xo --fix">;
|
|
39
|
+
postinstall: z.ZodOptional<z.ZodString>;
|
|
38
40
|
prepare: z.ZodLiteral<"husky install .github/husky">;
|
|
39
41
|
test: z.ZodString;
|
|
40
42
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -45,6 +47,7 @@ declare const schema: z.ZodObject<{
|
|
|
45
47
|
'format:check': string;
|
|
46
48
|
'lint:fix': "npm run format && xo --fix";
|
|
47
49
|
prepare: "husky install .github/husky";
|
|
50
|
+
postinstall?: string | undefined;
|
|
48
51
|
}, {
|
|
49
52
|
format: string;
|
|
50
53
|
lint: "npm run format:check && xo";
|
|
@@ -53,6 +56,7 @@ declare const schema: z.ZodObject<{
|
|
|
53
56
|
'format:check': string;
|
|
54
57
|
'lint:fix': "npm run format && xo --fix";
|
|
55
58
|
prepare: "husky install .github/husky";
|
|
59
|
+
postinstall?: string | undefined;
|
|
56
60
|
}>;
|
|
57
61
|
commitlint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
58
62
|
xo: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
@@ -101,6 +105,7 @@ declare const schema: z.ZodObject<{
|
|
|
101
105
|
'format:check': string;
|
|
102
106
|
'lint:fix': "npm run format && xo --fix";
|
|
103
107
|
prepare: "husky install .github/husky";
|
|
108
|
+
postinstall?: string | undefined;
|
|
104
109
|
};
|
|
105
110
|
commitlint: Record<string, unknown>;
|
|
106
111
|
xo: Record<string, unknown>;
|
|
@@ -110,6 +115,7 @@ declare const schema: z.ZodObject<{
|
|
|
110
115
|
};
|
|
111
116
|
private?: boolean | undefined;
|
|
112
117
|
exports?: string | undefined;
|
|
118
|
+
bin?: Record<string, unknown> | undefined;
|
|
113
119
|
files?: ["./dist/**/!(*.test).{js,d.ts,cjs}", ...string[]] | undefined;
|
|
114
120
|
ava?: Record<string, unknown> | undefined;
|
|
115
121
|
c8?: Record<string, unknown> | undefined;
|
|
@@ -142,6 +148,7 @@ declare const schema: z.ZodObject<{
|
|
|
142
148
|
'format:check': string;
|
|
143
149
|
'lint:fix': "npm run format && xo --fix";
|
|
144
150
|
prepare: "husky install .github/husky";
|
|
151
|
+
postinstall?: string | undefined;
|
|
145
152
|
};
|
|
146
153
|
commitlint: Record<string, unknown>;
|
|
147
154
|
xo: Record<string, unknown>;
|
|
@@ -151,6 +158,7 @@ declare const schema: z.ZodObject<{
|
|
|
151
158
|
};
|
|
152
159
|
private?: boolean | undefined;
|
|
153
160
|
exports?: string | undefined;
|
|
161
|
+
bin?: Record<string, unknown> | undefined;
|
|
154
162
|
files?: ["./dist/**/!(*.test).{js,d.ts,cjs}", ...string[]] | undefined;
|
|
155
163
|
ava?: Record<string, unknown> | undefined;
|
|
156
164
|
c8?: Record<string, unknown> | undefined;
|
|
@@ -189,6 +197,7 @@ declare class Package extends File {
|
|
|
189
197
|
'format:check': string;
|
|
190
198
|
'lint:fix': "npm run format && xo --fix";
|
|
191
199
|
prepare: "husky install .github/husky";
|
|
200
|
+
postinstall?: string | undefined;
|
|
192
201
|
};
|
|
193
202
|
commitlint: Record<string, unknown>;
|
|
194
203
|
xo: Record<string, unknown>;
|
|
@@ -198,6 +207,7 @@ declare class Package extends File {
|
|
|
198
207
|
};
|
|
199
208
|
private?: boolean | undefined;
|
|
200
209
|
exports?: string | undefined;
|
|
210
|
+
bin?: Record<string, unknown> | undefined;
|
|
201
211
|
files?: ["./dist/**/!(*.test).{js,d.ts,cjs}", ...string[]] | undefined;
|
|
202
212
|
ava?: Record<string, unknown> | undefined;
|
|
203
213
|
c8?: Record<string, unknown> | undefined;
|
package/dist/content/package.js
CHANGED
|
@@ -23,6 +23,7 @@ const schema = z
|
|
|
23
23
|
author: z.string().min(1),
|
|
24
24
|
type: z.literal('module'),
|
|
25
25
|
exports: z.string().min(1).optional(),
|
|
26
|
+
bin: z.record(z.unknown()).optional(),
|
|
26
27
|
files: z
|
|
27
28
|
.tuple([z.literal('./dist/**/!(*.test).{js,d.ts,cjs}')])
|
|
28
29
|
.rest(z.string().min(1))
|
|
@@ -36,6 +37,7 @@ const schema = z
|
|
|
36
37
|
lint: z.literal('npm run format:check && xo'),
|
|
37
38
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
38
39
|
'lint:fix': z.literal('npm run format && xo --fix'),
|
|
40
|
+
postinstall: z.string().optional(),
|
|
39
41
|
prepare: z.literal('husky install .github/husky'),
|
|
40
42
|
test: z.string().min(1),
|
|
41
43
|
})
|
|
@@ -75,7 +77,9 @@ class Package extends File {
|
|
|
75
77
|
...this._package.devDependencies,
|
|
76
78
|
...this._package.dependencies,
|
|
77
79
|
};
|
|
80
|
+
delete this._package.bin;
|
|
78
81
|
delete this._package.dependencies;
|
|
82
|
+
delete this._package.scripts.postinstall;
|
|
79
83
|
if (this._options.public) {
|
|
80
84
|
delete this._package.private;
|
|
81
85
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { schema } from './options.js';
|
|
2
|
+
import { files } from './content/index.js';
|
|
3
|
+
async function createProject(options) {
|
|
4
|
+
const paths = [];
|
|
5
|
+
for await (const file of files(schema.parse(options))) {
|
|
6
|
+
await file.write();
|
|
7
|
+
paths.push(file.path);
|
|
8
|
+
}
|
|
9
|
+
return paths;
|
|
10
|
+
}
|
|
11
|
+
export { createProject };
|
|
12
|
+
//# sourceMappingURL=create-project.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { type OptionsInput as Options, options } from './options.js';
|
|
2
|
+
export { createProject } from './create-project.js';
|
package/dist/index.js
CHANGED
|
@@ -1,62 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { files } from './content/index.js';
|
|
4
|
-
function validate(value, option) {
|
|
5
|
-
const validation = schema.shape[option].safeParse(value);
|
|
6
|
-
return validation.success
|
|
7
|
-
? true
|
|
8
|
-
: validation.error.errors.map(({ message }) => message).join('\n> ');
|
|
9
|
-
}
|
|
10
|
-
const project = await input({
|
|
11
|
-
message: 'Project name:',
|
|
12
|
-
validate: (value) => validate(value, 'project'),
|
|
13
|
-
});
|
|
14
|
-
const name = project.replaceAll(' ', '-').toLowerCase();
|
|
15
|
-
const defaultPackage = validate(name, 'package') === true ? name : undefined;
|
|
16
|
-
const options = {
|
|
17
|
-
project,
|
|
18
|
-
package: await input({
|
|
19
|
-
message: 'Package name:',
|
|
20
|
-
validate: (value) => validate(value, 'package'),
|
|
21
|
-
default: defaultPackage,
|
|
22
|
-
}),
|
|
23
|
-
public: await confirm({
|
|
24
|
-
message: 'Make package public?',
|
|
25
|
-
default: schema.shape.public._def.defaultValue(),
|
|
26
|
-
}),
|
|
27
|
-
description: await input({
|
|
28
|
-
message: 'Description:',
|
|
29
|
-
validate: (value) => validate(value, 'description'),
|
|
30
|
-
}),
|
|
31
|
-
author: await input({
|
|
32
|
-
message: 'Author:',
|
|
33
|
-
validate: (value) => validate(value, 'author'),
|
|
34
|
-
}),
|
|
35
|
-
githubOwner: await input({
|
|
36
|
-
message: 'GitHub owner:',
|
|
37
|
-
validate: (value) => validate(value, 'githubOwner'),
|
|
38
|
-
}),
|
|
39
|
-
githubRepository: await input({
|
|
40
|
-
message: 'GitHub repository:',
|
|
41
|
-
validate: (value) => validate(value, 'githubRepository'),
|
|
42
|
-
default: validate(defaultPackage, 'githubRepository') === true
|
|
43
|
-
? defaultPackage
|
|
44
|
-
: undefined,
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
options.typescript = await confirm({ message: 'Add typescript?' });
|
|
48
|
-
if (options.typescript) {
|
|
49
|
-
options.testing = await confirm({ message: 'Add AVA testing framework?' });
|
|
50
|
-
}
|
|
51
|
-
if (options.testing) {
|
|
52
|
-
options.reportCodeCoverage = await confirm({
|
|
53
|
-
message: 'Report code coverate to Codecov?',
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
options.path = await input({ message: 'Output folder:' });
|
|
57
|
-
options.dryRun = await confirm({ message: 'Dry run?' });
|
|
58
|
-
for await (const file of files(schema.parse(options))) {
|
|
59
|
-
console.log(`Create file ${file.path}`);
|
|
60
|
-
await file.write();
|
|
61
|
-
}
|
|
1
|
+
export { options } from './options.js';
|
|
2
|
+
export { createProject } from './create-project.js';
|
|
62
3
|
//# sourceMappingURL=index.js.map
|
package/dist/options.d.ts
CHANGED
|
@@ -39,5 +39,6 @@ declare const schema: z.ZodObject<{
|
|
|
39
39
|
reportCodeCoverage?: boolean | undefined;
|
|
40
40
|
dryRun?: boolean | undefined;
|
|
41
41
|
}>;
|
|
42
|
+
type OptionsInput = z.input<typeof schema>;
|
|
42
43
|
type Options = z.infer<typeof schema>;
|
|
43
|
-
export { schema, schema as options, type Options };
|
|
44
|
+
export { schema, schema as options, type Options, type OptionsInput };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const gitIgnore: string;
|
|
2
|
+
declare const npmIgnore: string;
|
|
3
|
+
/**
|
|
4
|
+
* Workaround for [Rename `.gitignore` to `.npmignore` in package if no
|
|
5
|
+
* `.npmignore` found](https://github.com/npm/npm/issues/1862) and ['npm pack'/
|
|
6
|
+
* `publish` option to not rename or keep a copy of `.gitignore` files](
|
|
7
|
+
* https://github.com/npm/npm/issues/7252) issues. With npm v9 or newer, the
|
|
8
|
+
* `npm pack` includes the `.gitignore` in the tarball and `npm install` renames
|
|
9
|
+
* the file to `.npmignore`. This script simply reverts that rename if it has
|
|
10
|
+
* occurred.
|
|
11
|
+
*/
|
|
12
|
+
declare function postinstall(): void;
|
|
13
|
+
export { gitIgnore, npmIgnore, postinstall };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { argv } from 'node:process';
|
|
5
|
+
import rootPath from '../root-path.js';
|
|
6
|
+
const gitIgnore = join(rootPath, '.gitignore');
|
|
7
|
+
const npmIgnore = join(rootPath, '.npmignore');
|
|
8
|
+
/**
|
|
9
|
+
* Workaround for [Rename `.gitignore` to `.npmignore` in package if no
|
|
10
|
+
* `.npmignore` found](https://github.com/npm/npm/issues/1862) and ['npm pack'/
|
|
11
|
+
* `publish` option to not rename or keep a copy of `.gitignore` files](
|
|
12
|
+
* https://github.com/npm/npm/issues/7252) issues. With npm v9 or newer, the
|
|
13
|
+
* `npm pack` includes the `.gitignore` in the tarball and `npm install` renames
|
|
14
|
+
* the file to `.npmignore`. This script simply reverts that rename if it has
|
|
15
|
+
* occurred.
|
|
16
|
+
*/
|
|
17
|
+
function postinstall() {
|
|
18
|
+
if (fs.existsSync(npmIgnore) && !fs.existsSync(gitIgnore)) {
|
|
19
|
+
fs.renameSync(npmIgnore, gitIgnore);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (import.meta.url.startsWith('file:') &&
|
|
23
|
+
fileURLToPath(import.meta.url) === argv.at(1)) {
|
|
24
|
+
postinstall();
|
|
25
|
+
}
|
|
26
|
+
export { gitIgnore, npmIgnore, postinstall };
|
|
27
|
+
//# sourceMappingURL=postinstall.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vidavidorra/create-project",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Interactively create a GitHub project.",
|
|
6
6
|
"homepage": "https://github.com/vidavidorra/create-project#readme",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"author": "Jeroen de Bruijn",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"exports": "./dist/index.js",
|
|
18
|
+
"bin": {
|
|
19
|
+
"create-project": "./dist/cli.js"
|
|
20
|
+
},
|
|
18
21
|
"files": [
|
|
19
22
|
"./dist/**/!(*.test).{js,d.ts,cjs}",
|
|
20
23
|
"./.github/",
|
|
@@ -28,6 +31,7 @@
|
|
|
28
31
|
"build": "tsc",
|
|
29
32
|
"format": "prettier --ignore-path .gitignore --write \"**/*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}\" --log-level warn",
|
|
30
33
|
"format:check": "prettier --ignore-path .gitignore --check \"**/*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}\" --log-level warn",
|
|
34
|
+
"postinstall": "node ./dist/scripts/postinstall.js",
|
|
31
35
|
"lint": "npm run format:check && xo",
|
|
32
36
|
"lint:fix": "npm run format && xo --fix",
|
|
33
37
|
"prepare": "husky install .github/husky",
|
|
@@ -179,6 +183,7 @@
|
|
|
179
183
|
}
|
|
180
184
|
},
|
|
181
185
|
"c8": {
|
|
186
|
+
"all": true,
|
|
182
187
|
"include": [
|
|
183
188
|
"dist/**/*.js"
|
|
184
189
|
],
|