@vlandoss/starter 0.0.1 → 0.0.2-git-9f81e60.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/package.json +1 -1
- package/plopfiles/plopfile.ts +17 -8
- package/plopfiles/plugins/tsconfig/tsconfig.json.hbs +3 -0
- package/plopfiles/prompts/tsconfig.ts +31 -0
- package/plopfiles/templates/basic/package.json.hbs +1 -1
- package/plopfiles/templates/monorepo/package.json.hbs +1 -1
- package/src/actions/add.ts +5 -1
package/package.json
CHANGED
package/plopfiles/plopfile.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import type { NodePlopAPI } from "node-plop";
|
|
3
3
|
import { ConfigService } from "~/services/config";
|
|
4
|
+
import { tsconfigPrompts } from "./prompts/tsconfig";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const configService = new ConfigService(baseDir);
|
|
8
|
-
|
|
9
|
-
function atLeastOne(answer: string[]) {
|
|
6
|
+
const validators = {
|
|
7
|
+
atLeastOne: (answer: string[]) => {
|
|
10
8
|
if (answer.length === 0) {
|
|
11
9
|
return "At least one option must be selected";
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
return true;
|
|
15
|
-
}
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default function configPlop(plop: NodePlopAPI) {
|
|
17
|
+
const baseDir = path.dirname(plop.getPlopfilePath());
|
|
18
|
+
const configService = new ConfigService(baseDir);
|
|
19
|
+
|
|
20
|
+
plop.setHelper("ternary", (condition, trueValue, falseValue) => {
|
|
21
|
+
return condition ? trueValue : falseValue;
|
|
22
|
+
});
|
|
16
23
|
|
|
17
24
|
plop.setGenerator("init", {
|
|
18
25
|
description: "Initialize a project based on a predefined template",
|
|
@@ -22,7 +29,7 @@ export default function configPlop(plop: NodePlopAPI) {
|
|
|
22
29
|
name: "template",
|
|
23
30
|
message: "Template:",
|
|
24
31
|
choices: configService.getTemplateChoices(),
|
|
25
|
-
validate: atLeastOne,
|
|
32
|
+
validate: validators.atLeastOne,
|
|
26
33
|
},
|
|
27
34
|
{
|
|
28
35
|
type: "input",
|
|
@@ -65,8 +72,10 @@ export default function configPlop(plop: NodePlopAPI) {
|
|
|
65
72
|
name: "slugs",
|
|
66
73
|
message: "Select configs:",
|
|
67
74
|
choices: configService.getPluginChoices(),
|
|
68
|
-
validate: atLeastOne,
|
|
75
|
+
validate: validators.atLeastOne,
|
|
69
76
|
},
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
...tsconfigPrompts,
|
|
70
79
|
],
|
|
71
80
|
actions: (answers: unknown) => {
|
|
72
81
|
// @ts-expect-error
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function whenAddTsconfig(answers: { slugs: string[] }) {
|
|
2
|
+
return answers.slugs.includes("tsconfig");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const tsconfigPrompts = [
|
|
6
|
+
{
|
|
7
|
+
type: "confirm",
|
|
8
|
+
name: "useTSC",
|
|
9
|
+
message: "Are you using TSC to turn your .ts files into .js files?",
|
|
10
|
+
default: false,
|
|
11
|
+
when: whenAddTsconfig,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
type: "confirm",
|
|
15
|
+
name: "useDOM",
|
|
16
|
+
message: "Is your code running in a DOM environment?",
|
|
17
|
+
default: false,
|
|
18
|
+
when: whenAddTsconfig,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "list",
|
|
22
|
+
name: "tsProjectType",
|
|
23
|
+
message: "What type of TS project are you creating?",
|
|
24
|
+
choices: [
|
|
25
|
+
{ name: "App", value: "app" },
|
|
26
|
+
{ name: "Library", value: "library" },
|
|
27
|
+
{ name: "Monorepo library", value: "library-monorepo" },
|
|
28
|
+
],
|
|
29
|
+
when: whenAddTsconfig,
|
|
30
|
+
},
|
|
31
|
+
];
|
package/src/actions/add.ts
CHANGED
|
@@ -10,6 +10,10 @@ type ExecuteOptions = {
|
|
|
10
10
|
slugs: string[];
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
type GeneratorAnswers = {
|
|
14
|
+
slugs: string[];
|
|
15
|
+
};
|
|
16
|
+
|
|
13
17
|
const GENERATOR_ID = "add";
|
|
14
18
|
|
|
15
19
|
export class AddAction implements AnyAction<ExecuteOptions> {
|
|
@@ -26,7 +30,7 @@ export class AddAction implements AnyAction<ExecuteOptions> {
|
|
|
26
30
|
|
|
27
31
|
const bypassArr = this.#getBypassArr(options);
|
|
28
32
|
|
|
29
|
-
await this.#templateService.generate({
|
|
33
|
+
await this.#templateService.generate<GeneratorAnswers>({
|
|
30
34
|
bypassArr,
|
|
31
35
|
generatorId: GENERATOR_ID,
|
|
32
36
|
});
|