@vidavidorra/create-project 1.0.0
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/.editorconfig +12 -0
- package/.github/husky/commit-msg +4 -0
- package/.github/husky/pre-commit +4 -0
- package/.github/lint-staged.js +6 -0
- package/.github/renovate.json +4 -0
- package/.github/workflows/ci-cd.yml +36 -0
- package/.gitignore +355 -0
- package/.npmrc +1 -0
- package/LICENSE.md +619 -0
- package/README.md +76 -0
- package/dist/content/ci-cd.d.ts +246 -0
- package/dist/content/ci-cd.js +112 -0
- package/dist/content/file.d.ts +36 -0
- package/dist/content/file.js +52 -0
- package/dist/content/files.d.ts +4 -0
- package/dist/content/files.js +23 -0
- package/dist/content/index.d.ts +1 -0
- package/dist/content/index.js +2 -0
- package/dist/content/lint-staged.d.ts +12 -0
- package/dist/content/lint-staged.js +40 -0
- package/dist/content/package.d.ts +211 -0
- package/dist/content/package.js +122 -0
- package/dist/content/readme/badge.d.ts +15 -0
- package/dist/content/readme/badge.js +75 -0
- package/dist/content/readme/index.d.ts +1 -0
- package/dist/content/readme/index.js +2 -0
- package/dist/content/readme/readme.d.ts +17 -0
- package/dist/content/readme/readme.js +129 -0
- package/dist/content/readme/readme.js.map +1 -0
- package/dist/content/readme/readme.test.d.ts +1 -0
- package/dist/content/readme/readme.test.js +35 -0
- package/dist/content/readme/readme.test.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +62 -0
- package/dist/options.d.ts +43 -0
- package/dist/options.js +52 -0
- package/dist/root-path.d.ts +2 -0
- package/dist/root-path.js +5 -0
- package/package.json +226 -0
- package/tsconfig.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Create project <!-- omit in toc -->
|
|
2
|
+
|
|
3
|
+
Interactively create a project.
|
|
4
|
+
|
|
5
|
+
- Standardised project and repository setup.
|
|
6
|
+
- Add TypeScript, a testing framework and code coverage as desired.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
[](https://www.npmjs.com/package/@vidavidorra/create-project)
|
|
11
|
+
[](https://www.npmjs.com/package/@vidavidorra/create-project)
|
|
12
|
+
[](https://nodejs.org/en/about/releases/)
|
|
13
|
+
[](https://renovatebot.com)
|
|
14
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
15
|
+
[](https://codecov.io/gh/vidavidorra/create-project)
|
|
16
|
+
[](LICENSE.md)
|
|
17
|
+
|
|
18
|
+
- [Install](#install)
|
|
19
|
+
- [Usage](#usage)
|
|
20
|
+
- [Contributing](#contributing)
|
|
21
|
+
- [Security policy](#security-policy)
|
|
22
|
+
- [License](#license)
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
npm install --global @vidavidorra/create-project
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
Start the interactive CLI to create a project.
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
@vidavidorra/create-project
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Contributing
|
|
39
|
+
|
|
40
|
+
Please [create an issue](https://github.com/vidavidorra/create-project/issues/new/choose) if you have a bug report or feature proposal, or [create a discussion](https://github.com/vidavidorra/create-project/discussions) if you have a question. If you like this project, please consider giving it a star ⭐
|
|
41
|
+
|
|
42
|
+
Refer to the [contributing guide](https://github.com/vidavidorra/.github/blob/main/CONTRIBUTING.md) detailed information about other contributions, like pull requests.
|
|
43
|
+
|
|
44
|
+
[](https://conventionalcommits.org)
|
|
45
|
+
[](https://github.com/xojs/xo)
|
|
46
|
+
[](https://github.com/prettier/prettier)
|
|
47
|
+
|
|
48
|
+
## Security policy
|
|
49
|
+
|
|
50
|
+
Please refer to the [Security Policy on GitHub](https://github.com/vidavidorra/create-project/security/) for the security policy.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
This project is licensed under the [GPLv3 license](https://www.gnu.org/licenses/gpl.html).
|
|
55
|
+
|
|
56
|
+
Copyright © 2023 Jeroen de Bruijn
|
|
57
|
+
|
|
58
|
+
<details><summary>License notice</summary>
|
|
59
|
+
<p>
|
|
60
|
+
|
|
61
|
+
This program is free software: you can redistribute it and/or modify
|
|
62
|
+
it under the terms of the GNU General Public License as published by
|
|
63
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
64
|
+
(at your option) any later version.
|
|
65
|
+
|
|
66
|
+
This program is distributed in the hope that it will be useful,
|
|
67
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
68
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
69
|
+
GNU General Public License for more details.
|
|
70
|
+
|
|
71
|
+
You should have received a copy of the GNU General Public License
|
|
72
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
73
|
+
|
|
74
|
+
The full text of the license is available in the [LICENSE](LICENSE.md) file in this repository and [online](https://www.gnu.org/licenses/gpl.html).
|
|
75
|
+
|
|
76
|
+
</details>
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Options } from '../options.js';
|
|
3
|
+
import { File } from './file.js';
|
|
4
|
+
declare const schema: z.ZodObject<{
|
|
5
|
+
name: z.ZodLiteral<"CI/CD">;
|
|
6
|
+
on: z.ZodObject<{
|
|
7
|
+
push: z.ZodObject<{
|
|
8
|
+
branches: z.ZodTuple<[z.ZodLiteral<"main">, z.ZodLiteral<"beta">, z.ZodLiteral<"renovate/**">], null>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
branches: ["main", "beta", "renovate/**"];
|
|
11
|
+
}, {
|
|
12
|
+
branches: ["main", "beta", "renovate/**"];
|
|
13
|
+
}>;
|
|
14
|
+
pull_request: z.ZodNull;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
push: {
|
|
17
|
+
branches: ["main", "beta", "renovate/**"];
|
|
18
|
+
};
|
|
19
|
+
pull_request: null;
|
|
20
|
+
}, {
|
|
21
|
+
push: {
|
|
22
|
+
branches: ["main", "beta", "renovate/**"];
|
|
23
|
+
};
|
|
24
|
+
pull_request: null;
|
|
25
|
+
}>;
|
|
26
|
+
jobs: z.ZodObject<{
|
|
27
|
+
'lint-commit-messages': z.ZodObject<{
|
|
28
|
+
uses: z.ZodString;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
uses: string;
|
|
31
|
+
}, {
|
|
32
|
+
uses: string;
|
|
33
|
+
}>;
|
|
34
|
+
lint: z.ZodObject<{
|
|
35
|
+
uses: z.ZodString;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
uses: string;
|
|
38
|
+
}, {
|
|
39
|
+
uses: string;
|
|
40
|
+
}>;
|
|
41
|
+
build: z.ZodObject<{
|
|
42
|
+
uses: z.ZodString;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
uses: string;
|
|
45
|
+
}, {
|
|
46
|
+
uses: string;
|
|
47
|
+
}>;
|
|
48
|
+
test: z.ZodObject<{
|
|
49
|
+
uses: z.ZodString;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
uses: string;
|
|
52
|
+
}, {
|
|
53
|
+
uses: string;
|
|
54
|
+
}>;
|
|
55
|
+
'code-coverage': z.ZodObject<{
|
|
56
|
+
uses: z.ZodString;
|
|
57
|
+
needs: z.ZodTuple<[z.ZodLiteral<"lint">, z.ZodLiteral<"build">, z.ZodLiteral<"test">], null>;
|
|
58
|
+
secrets: z.ZodObject<{
|
|
59
|
+
codecovToken: z.ZodString;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
codecovToken: string;
|
|
62
|
+
}, {
|
|
63
|
+
codecovToken: string;
|
|
64
|
+
}>;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
uses: string;
|
|
67
|
+
needs: ["lint", "build", "test"];
|
|
68
|
+
secrets: {
|
|
69
|
+
codecovToken: string;
|
|
70
|
+
};
|
|
71
|
+
}, {
|
|
72
|
+
uses: string;
|
|
73
|
+
needs: ["lint", "build", "test"];
|
|
74
|
+
secrets: {
|
|
75
|
+
codecovToken: string;
|
|
76
|
+
};
|
|
77
|
+
}>;
|
|
78
|
+
release: z.ZodObject<{
|
|
79
|
+
uses: z.ZodString;
|
|
80
|
+
needs: z.ZodArray<z.ZodUnion<[z.ZodLiteral<"lint-commit-messages">, z.ZodLiteral<"lint">, z.ZodLiteral<"build">, z.ZodLiteral<"test">, z.ZodLiteral<"code-coverage">]>, "many">;
|
|
81
|
+
secrets: z.ZodObject<{
|
|
82
|
+
privateKey: z.ZodString;
|
|
83
|
+
npmToken: z.ZodString;
|
|
84
|
+
}, "strip", z.ZodTypeAny, {
|
|
85
|
+
privateKey: string;
|
|
86
|
+
npmToken: string;
|
|
87
|
+
}, {
|
|
88
|
+
privateKey: string;
|
|
89
|
+
npmToken: string;
|
|
90
|
+
}>;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
uses: string;
|
|
93
|
+
needs: ("lint-commit-messages" | "lint" | "build" | "test" | "code-coverage")[];
|
|
94
|
+
secrets: {
|
|
95
|
+
privateKey: string;
|
|
96
|
+
npmToken: string;
|
|
97
|
+
};
|
|
98
|
+
}, {
|
|
99
|
+
uses: string;
|
|
100
|
+
needs: ("lint-commit-messages" | "lint" | "build" | "test" | "code-coverage")[];
|
|
101
|
+
secrets: {
|
|
102
|
+
privateKey: string;
|
|
103
|
+
npmToken: string;
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
}, "strict", z.ZodTypeAny, {
|
|
107
|
+
'lint-commit-messages': {
|
|
108
|
+
uses: string;
|
|
109
|
+
};
|
|
110
|
+
lint: {
|
|
111
|
+
uses: string;
|
|
112
|
+
};
|
|
113
|
+
build: {
|
|
114
|
+
uses: string;
|
|
115
|
+
};
|
|
116
|
+
test: {
|
|
117
|
+
uses: string;
|
|
118
|
+
};
|
|
119
|
+
'code-coverage': {
|
|
120
|
+
uses: string;
|
|
121
|
+
needs: ["lint", "build", "test"];
|
|
122
|
+
secrets: {
|
|
123
|
+
codecovToken: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
release: {
|
|
127
|
+
uses: string;
|
|
128
|
+
needs: ("lint-commit-messages" | "lint" | "build" | "test" | "code-coverage")[];
|
|
129
|
+
secrets: {
|
|
130
|
+
privateKey: string;
|
|
131
|
+
npmToken: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}, {
|
|
135
|
+
'lint-commit-messages': {
|
|
136
|
+
uses: string;
|
|
137
|
+
};
|
|
138
|
+
lint: {
|
|
139
|
+
uses: string;
|
|
140
|
+
};
|
|
141
|
+
build: {
|
|
142
|
+
uses: string;
|
|
143
|
+
};
|
|
144
|
+
test: {
|
|
145
|
+
uses: string;
|
|
146
|
+
};
|
|
147
|
+
'code-coverage': {
|
|
148
|
+
uses: string;
|
|
149
|
+
needs: ["lint", "build", "test"];
|
|
150
|
+
secrets: {
|
|
151
|
+
codecovToken: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
release: {
|
|
155
|
+
uses: string;
|
|
156
|
+
needs: ("lint-commit-messages" | "lint" | "build" | "test" | "code-coverage")[];
|
|
157
|
+
secrets: {
|
|
158
|
+
privateKey: string;
|
|
159
|
+
npmToken: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}>;
|
|
163
|
+
}, "strict", z.ZodTypeAny, {
|
|
164
|
+
name: "CI/CD";
|
|
165
|
+
on: {
|
|
166
|
+
push: {
|
|
167
|
+
branches: ["main", "beta", "renovate/**"];
|
|
168
|
+
};
|
|
169
|
+
pull_request: null;
|
|
170
|
+
};
|
|
171
|
+
jobs: {
|
|
172
|
+
'lint-commit-messages': {
|
|
173
|
+
uses: string;
|
|
174
|
+
};
|
|
175
|
+
lint: {
|
|
176
|
+
uses: string;
|
|
177
|
+
};
|
|
178
|
+
build: {
|
|
179
|
+
uses: string;
|
|
180
|
+
};
|
|
181
|
+
test: {
|
|
182
|
+
uses: string;
|
|
183
|
+
};
|
|
184
|
+
'code-coverage': {
|
|
185
|
+
uses: string;
|
|
186
|
+
needs: ["lint", "build", "test"];
|
|
187
|
+
secrets: {
|
|
188
|
+
codecovToken: string;
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
release: {
|
|
192
|
+
uses: string;
|
|
193
|
+
needs: ("lint-commit-messages" | "lint" | "build" | "test" | "code-coverage")[];
|
|
194
|
+
secrets: {
|
|
195
|
+
privateKey: string;
|
|
196
|
+
npmToken: string;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
}, {
|
|
201
|
+
name: "CI/CD";
|
|
202
|
+
on: {
|
|
203
|
+
push: {
|
|
204
|
+
branches: ["main", "beta", "renovate/**"];
|
|
205
|
+
};
|
|
206
|
+
pull_request: null;
|
|
207
|
+
};
|
|
208
|
+
jobs: {
|
|
209
|
+
'lint-commit-messages': {
|
|
210
|
+
uses: string;
|
|
211
|
+
};
|
|
212
|
+
lint: {
|
|
213
|
+
uses: string;
|
|
214
|
+
};
|
|
215
|
+
build: {
|
|
216
|
+
uses: string;
|
|
217
|
+
};
|
|
218
|
+
test: {
|
|
219
|
+
uses: string;
|
|
220
|
+
};
|
|
221
|
+
'code-coverage': {
|
|
222
|
+
uses: string;
|
|
223
|
+
needs: ["lint", "build", "test"];
|
|
224
|
+
secrets: {
|
|
225
|
+
codecovToken: string;
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
release: {
|
|
229
|
+
uses: string;
|
|
230
|
+
needs: ("lint-commit-messages" | "lint" | "build" | "test" | "code-coverage")[];
|
|
231
|
+
secrets: {
|
|
232
|
+
privateKey: string;
|
|
233
|
+
npmToken: string;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
}>;
|
|
238
|
+
type Yaml = z.infer<typeof schema>;
|
|
239
|
+
declare class CiCd extends File {
|
|
240
|
+
protected readonly _yaml: Yaml;
|
|
241
|
+
constructor(path: string, options: Options);
|
|
242
|
+
process(): this;
|
|
243
|
+
protected get sha(): string;
|
|
244
|
+
protected get version(): string;
|
|
245
|
+
}
|
|
246
|
+
export { CiCd };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { parse, stringify } from 'yaml';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { File } from './file.js';
|
|
4
|
+
const job = (action) => z.object({
|
|
5
|
+
uses: z
|
|
6
|
+
.string()
|
|
7
|
+
.startsWith(`vidavidorra/.github/.github/workflows/${action}@`)
|
|
8
|
+
.regex(/.*?@[\da-f]{6,64}$/),
|
|
9
|
+
});
|
|
10
|
+
const schema = z
|
|
11
|
+
.object({
|
|
12
|
+
name: z.literal('CI/CD'),
|
|
13
|
+
on: z.object({
|
|
14
|
+
push: z.object({
|
|
15
|
+
branches: z.tuple([
|
|
16
|
+
z.literal('main'),
|
|
17
|
+
z.literal('beta'),
|
|
18
|
+
z.literal('renovate/**'),
|
|
19
|
+
]),
|
|
20
|
+
}),
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
+
pull_request: z.null(),
|
|
23
|
+
}),
|
|
24
|
+
jobs: z
|
|
25
|
+
.object({
|
|
26
|
+
'lint-commit-messages': job('lint-commit-messages.yml'),
|
|
27
|
+
lint: job('node-lint.yml'),
|
|
28
|
+
build: job('node-build.yml'),
|
|
29
|
+
test: job('node-test.yml'),
|
|
30
|
+
'code-coverage': job('node-test-coverage.yml').extend({
|
|
31
|
+
needs: z.tuple([
|
|
32
|
+
z.literal('lint'),
|
|
33
|
+
z.literal('build'),
|
|
34
|
+
z.literal('test'),
|
|
35
|
+
]),
|
|
36
|
+
secrets: z.object({ codecovToken: z.string() }),
|
|
37
|
+
}),
|
|
38
|
+
release: job('release.yml').extend({
|
|
39
|
+
needs: z
|
|
40
|
+
.array(z.union([
|
|
41
|
+
z.literal('lint-commit-messages'),
|
|
42
|
+
z.literal('lint'),
|
|
43
|
+
z.literal('build'),
|
|
44
|
+
z.literal('test'),
|
|
45
|
+
z.literal('code-coverage'),
|
|
46
|
+
]))
|
|
47
|
+
.length(5),
|
|
48
|
+
secrets: z.object({
|
|
49
|
+
privateKey: z.string(),
|
|
50
|
+
npmToken: z.string(),
|
|
51
|
+
}),
|
|
52
|
+
}),
|
|
53
|
+
})
|
|
54
|
+
.strict(),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
class CiCd extends File {
|
|
58
|
+
_yaml;
|
|
59
|
+
constructor(path, options) {
|
|
60
|
+
super(path, { ...options, format: true });
|
|
61
|
+
this._yaml = schema.parse(parse(this._content));
|
|
62
|
+
}
|
|
63
|
+
process() {
|
|
64
|
+
const data = schema.deepPartial().parse(this._yaml);
|
|
65
|
+
const removeFromRelease = [];
|
|
66
|
+
if (!this._options.typescript) {
|
|
67
|
+
delete data.jobs?.build;
|
|
68
|
+
removeFromRelease.push('build');
|
|
69
|
+
}
|
|
70
|
+
if (!this._options.typescript || !this._options.testing) {
|
|
71
|
+
delete data.jobs?.test;
|
|
72
|
+
removeFromRelease.push('test');
|
|
73
|
+
}
|
|
74
|
+
if (!this._options.typescript ||
|
|
75
|
+
!this._options.testing ||
|
|
76
|
+
!this._options.reportCodeCoverage) {
|
|
77
|
+
delete data.jobs?.['code-coverage'];
|
|
78
|
+
removeFromRelease.push('code-coverage');
|
|
79
|
+
}
|
|
80
|
+
if (data.jobs?.release?.needs !== undefined) {
|
|
81
|
+
data.jobs.release.needs = data.jobs.release.needs.filter((action) => !removeFromRelease.includes(action));
|
|
82
|
+
}
|
|
83
|
+
if (!this._options.public) {
|
|
84
|
+
delete data.jobs?.release?.secrets?.npmToken;
|
|
85
|
+
}
|
|
86
|
+
const { sha, version } = this;
|
|
87
|
+
this._content = stringify(data).replaceAll(sha, `${sha}${version}`);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
get sha() {
|
|
91
|
+
const sha = this._yaml.jobs.lint.uses.split('@').at(1);
|
|
92
|
+
if (sha === undefined) {
|
|
93
|
+
throw new Error('SHA is required in YAML');
|
|
94
|
+
}
|
|
95
|
+
return sha;
|
|
96
|
+
}
|
|
97
|
+
get version() {
|
|
98
|
+
const job = 'lint';
|
|
99
|
+
const value = this._yaml.jobs[job].uses;
|
|
100
|
+
const line = this._content.split('\n').find((line) => line.includes(value));
|
|
101
|
+
if (line === undefined) {
|
|
102
|
+
throw new Error(`"${job}" job not found in content`);
|
|
103
|
+
}
|
|
104
|
+
const version = line.replace(new RegExp(`^.*${value}`), '');
|
|
105
|
+
if (!/ +# v\d+\.\d+\.\d+$/.test(version)) {
|
|
106
|
+
throw new Error(`Version is not in a valid format (version: "${version}")`);
|
|
107
|
+
}
|
|
108
|
+
return version;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export { CiCd };
|
|
112
|
+
//# sourceMappingURL=ci-cd.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Options } from '../options.js';
|
|
2
|
+
type FileOptions = {
|
|
3
|
+
mode: number;
|
|
4
|
+
format: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare class File {
|
|
7
|
+
readonly path: string;
|
|
8
|
+
protected _content: string;
|
|
9
|
+
protected readonly _options: Options & FileOptions;
|
|
10
|
+
private readonly _directory;
|
|
11
|
+
constructor(path: string, options: Options & Partial<FileOptions>);
|
|
12
|
+
get options(): {
|
|
13
|
+
project: string;
|
|
14
|
+
package: string;
|
|
15
|
+
path: string;
|
|
16
|
+
public: boolean;
|
|
17
|
+
description: string;
|
|
18
|
+
author: string;
|
|
19
|
+
typescript: boolean;
|
|
20
|
+
testing: boolean;
|
|
21
|
+
reportCodeCoverage: boolean;
|
|
22
|
+
githubOwner: string;
|
|
23
|
+
githubRepository: string;
|
|
24
|
+
dryRun: boolean;
|
|
25
|
+
} & FileOptions;
|
|
26
|
+
get content(): string;
|
|
27
|
+
write(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Process file contents.
|
|
30
|
+
*
|
|
31
|
+
* @note This function is called automatically from `write`.
|
|
32
|
+
*/
|
|
33
|
+
process(): this;
|
|
34
|
+
private format;
|
|
35
|
+
}
|
|
36
|
+
export { File };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { join, dirname } from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import prettier from 'prettier';
|
|
4
|
+
import rootPath from '../root-path.js';
|
|
5
|
+
class File {
|
|
6
|
+
path;
|
|
7
|
+
_content;
|
|
8
|
+
_options;
|
|
9
|
+
_directory;
|
|
10
|
+
constructor(path, options) {
|
|
11
|
+
this.path = path;
|
|
12
|
+
this._directory = dirname(path);
|
|
13
|
+
this._options = { mode: 0o644, format: false, ...options };
|
|
14
|
+
this._content = fs.readFileSync(join(rootPath, path), 'utf8');
|
|
15
|
+
}
|
|
16
|
+
get options() {
|
|
17
|
+
return structuredClone(this._options);
|
|
18
|
+
}
|
|
19
|
+
get content() {
|
|
20
|
+
return this._content;
|
|
21
|
+
}
|
|
22
|
+
async write() {
|
|
23
|
+
this.process();
|
|
24
|
+
const path = join(this.options.path, this.path);
|
|
25
|
+
if (!this._options.dryRun) {
|
|
26
|
+
const directory = join(this.options.path, this._directory);
|
|
27
|
+
if (!fs.existsSync(directory)) {
|
|
28
|
+
await fs.promises.mkdir(directory, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
await fs.promises.writeFile(path, await this.format(), {
|
|
31
|
+
mode: this._options.mode,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Process file contents.
|
|
37
|
+
*
|
|
38
|
+
* @note This function is called automatically from `write`.
|
|
39
|
+
*/
|
|
40
|
+
process() {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
async format() {
|
|
44
|
+
if (this._options.format) {
|
|
45
|
+
const config = await prettier.resolveConfig(join(rootPath, 'package.json'));
|
|
46
|
+
return prettier.format(this._content, { ...config, filepath: this.path });
|
|
47
|
+
}
|
|
48
|
+
return this._content;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export { File };
|
|
52
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CiCd } from './ci-cd.js';
|
|
2
|
+
import { File } from './file.js';
|
|
3
|
+
import { LintStaged } from './lint-staged.js';
|
|
4
|
+
import { Package } from './package.js';
|
|
5
|
+
import { Readme } from './readme/index.js';
|
|
6
|
+
function files(options) {
|
|
7
|
+
return [
|
|
8
|
+
new File('.github/husky/commit-msg', { ...options, mode: 0o755 }),
|
|
9
|
+
new File('.github/husky/pre-commit', { ...options, mode: 0o755 }),
|
|
10
|
+
new CiCd('.github/workflows/ci-cd.yml', options),
|
|
11
|
+
new LintStaged('.github/lint-staged.js', options),
|
|
12
|
+
new File('.github/renovate.json', options),
|
|
13
|
+
new File('.editorconfig', options),
|
|
14
|
+
new File('.gitignore', options),
|
|
15
|
+
new File('.npmrc', options),
|
|
16
|
+
new File('LICENSE.md', options),
|
|
17
|
+
new Package('package.json', options),
|
|
18
|
+
new Readme('README.md', options),
|
|
19
|
+
new File('tsconfig.json', options),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
export { files };
|
|
23
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { files } from './files.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Options } from '../options.js';
|
|
2
|
+
import { File } from './file.js';
|
|
3
|
+
declare class LintStaged extends File {
|
|
4
|
+
constructor(path: string, options: Options);
|
|
5
|
+
process(): this;
|
|
6
|
+
private xo;
|
|
7
|
+
private ava;
|
|
8
|
+
private prettier;
|
|
9
|
+
private config;
|
|
10
|
+
private sourceFile;
|
|
11
|
+
}
|
|
12
|
+
export { LintStaged };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { File } from './file.js';
|
|
3
|
+
class LintStaged extends File {
|
|
4
|
+
constructor(path, options) {
|
|
5
|
+
super(path, { ...options, format: true });
|
|
6
|
+
}
|
|
7
|
+
process() {
|
|
8
|
+
this._content = ts.createPrinter().printFile(this.sourceFile());
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
xo() {
|
|
12
|
+
return ts.factory.createStringLiteral('xo --fix');
|
|
13
|
+
}
|
|
14
|
+
ava() {
|
|
15
|
+
return ts.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, ts.factory.createStringLiteral('ava'));
|
|
16
|
+
}
|
|
17
|
+
prettier() {
|
|
18
|
+
return ts.factory.createStringLiteral('prettier --write');
|
|
19
|
+
}
|
|
20
|
+
config() {
|
|
21
|
+
return ts.factory.createObjectLiteralExpression([
|
|
22
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral('*.{ts,tsx,js,jsx}'), ts.factory.createArrayLiteralExpression([
|
|
23
|
+
this.xo(),
|
|
24
|
+
...(this._options.testing ? [this.ava()] : []),
|
|
25
|
+
])),
|
|
26
|
+
ts.factory.createPropertyAssignment(ts.factory.createStringLiteral('*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}'), this.prettier()),
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
sourceFile() {
|
|
30
|
+
const statements = [
|
|
31
|
+
ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
|
|
32
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier('config'), undefined, undefined, this.config()),
|
|
33
|
+
], ts.NodeFlags.Const)),
|
|
34
|
+
ts.factory.createExportAssignment(undefined, undefined, ts.factory.createIdentifier('config')),
|
|
35
|
+
];
|
|
36
|
+
return ts.factory.createSourceFile(statements, ts.factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export { LintStaged };
|
|
40
|
+
//# sourceMappingURL=lint-staged.js.map
|