@vlandoss/starter 0.0.14 → 0.0.15-git-06df4ba.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.
Files changed (3) hide show
  1. package/bin.ts +3 -1
  2. package/dist/bin.mjs +194 -0
  3. package/package.json +15 -6
package/bin.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env bun
2
+ import { dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
2
4
  import { main } from "./src/main";
3
5
 
4
6
  main({
5
- binDir: __dirname,
7
+ binDir: dirname(fileURLToPath(import.meta.url)),
6
8
  });
package/dist/bin.mjs ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env node
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { createPkgService, createShellService, cwd, getVersion, palette, run } from "@vlandoss/clibuddy";
5
+ import { Argument, Command, Option, createCommand } from "commander";
6
+ import fs from "node:fs";
7
+ import { createLoggy } from "@vlandoss/loggy";
8
+ import nodePlop from "node-plop";
9
+ //#region src/services/config.ts
10
+ var ConfigService = class {
11
+ #baseDir;
12
+ constructor(baseDir = "") {
13
+ this.#baseDir = baseDir;
14
+ }
15
+ getPluginChoices() {
16
+ const folderPath = this.#getPlopFolderDir("plugins");
17
+ return fs.readdirSync(folderPath).sort();
18
+ }
19
+ getTemplateChoices() {
20
+ const folderPath = this.#getPlopFolderDir("templates");
21
+ return fs.readdirSync(folderPath).filter((folder) => !folder.startsWith("#")).sort();
22
+ }
23
+ #getPlopFolderDir(folder) {
24
+ return join(this.#baseDir, join("plopfiles", folder));
25
+ }
26
+ };
27
+ //#endregion
28
+ //#region src/services/logger.ts
29
+ const logger = createLoggy({ namespace: "vland" });
30
+ //#endregion
31
+ //#region src/services/ctx.ts
32
+ async function createContext(binDir) {
33
+ const debug = logger.subdebug("create-context-value");
34
+ const binPath = fs.realpathSync(binDir);
35
+ debug("bin path %s", binPath);
36
+ const binPkg = await createPkgService(binPath);
37
+ if (!binPkg) throw new Error("Could not find bin package.json");
38
+ debug("bin pkg info %O", binPkg.info());
39
+ return {
40
+ binPkg,
41
+ config: new ConfigService(binDir),
42
+ shell: createShellService({ localBaseBinPath: [binDir] })
43
+ };
44
+ }
45
+ //#endregion
46
+ //#region src/actions/add.ts
47
+ const GENERATOR_ID$1 = "add";
48
+ var AddAction = class {
49
+ #templateService;
50
+ constructor({ templateService }) {
51
+ this.#templateService = templateService;
52
+ }
53
+ async execute(options) {
54
+ logger.subdebug("add-action")("execute options: %O", options);
55
+ const bypassArr = this.#getBypassArr(options);
56
+ await this.#templateService.generate({
57
+ bypassArr,
58
+ generatorId: GENERATOR_ID$1
59
+ });
60
+ logger.success("Added successfully 🎉");
61
+ }
62
+ #getBypassArr(options) {
63
+ const { slugs } = options;
64
+ const bypassArr = [];
65
+ if (slugs.length) bypassArr[0] = slugs.join(",");
66
+ return bypassArr;
67
+ }
68
+ };
69
+ //#endregion
70
+ //#region src/services/template.ts
71
+ var PlopTemplateService = class {
72
+ #plop;
73
+ constructor(plop) {
74
+ this.#plop = plop;
75
+ }
76
+ async generate(options) {
77
+ const { generatorId, bypassArr } = options;
78
+ const debug = logger.subdebug("plop-template-service:generate");
79
+ debug("generate options: %O", options);
80
+ const generator = this.#plop.getGenerator(generatorId);
81
+ const answers = await generator.runPrompts(bypassArr);
82
+ debug("generator answers: %O", answers);
83
+ const results = await generator.runActions(answers);
84
+ debug("generator results: %O", results);
85
+ if (results.failures.length > 0) throw new Error("Can't generate files");
86
+ return { answers };
87
+ }
88
+ };
89
+ const PLOP_CONFIG_PATH = join("plopfiles", "plopfile.ts");
90
+ async function createPlopTemplateService(options) {
91
+ const { force, destBasePath } = options;
92
+ const debug = logger.subdebug("create-plop-template-service");
93
+ debug("options: %O", options);
94
+ const configPath = join(options.basePath, PLOP_CONFIG_PATH);
95
+ debug("plop config path:", configPath);
96
+ return new PlopTemplateService(await nodePlop(configPath, {
97
+ force,
98
+ destBasePath
99
+ }));
100
+ }
101
+ //#endregion
102
+ //#region src/program/commands/add.ts
103
+ function createAddCommand(ctx) {
104
+ return createCommand("add").description("add config files to a project 📁").addArgument(new Argument("[slug...]", "the config slugs to pick").choices(ctx.config.getPluginChoices())).addOption(new Option("-d, --dest <string>", "destination path to create folder (default: cwd)")).addOption(new Option("-f, --force", "override existing files").default(false)).action(async function addAction(slugs, options) {
105
+ try {
106
+ const { dest: destBasePath = cwd, force } = options;
107
+ await new AddAction({ templateService: await createPlopTemplateService({
108
+ force,
109
+ destBasePath,
110
+ basePath: ctx.binPkg.dirPath
111
+ }) }).execute({ slugs });
112
+ } catch (error) {
113
+ logger.error(error);
114
+ process.exit(1);
115
+ }
116
+ }).addHelpText("afterAll", "\nUnder the hood, this command uses Plop.js to generate the project.");
117
+ }
118
+ //#endregion
119
+ //#region src/actions/init.ts
120
+ const GENERATOR_ID = "init";
121
+ var InitAction = class {
122
+ #templateService;
123
+ #shellService;
124
+ constructor({ templateService, shellService }) {
125
+ this.#templateService = templateService;
126
+ this.#shellService = shellService;
127
+ }
128
+ async execute(options) {
129
+ const { destBasePath, git } = options;
130
+ logger.subdebug("init-action")("execute options: %O", options);
131
+ const bypassArr = this.#getBypassArr(options);
132
+ await this.#templateService.generate({
133
+ bypassArr,
134
+ generatorId: GENERATOR_ID
135
+ });
136
+ logger.success("Project generated 🎉");
137
+ const shell = this.#shellService.at(destBasePath).quiet();
138
+ if (git) {
139
+ logger.start("Creating git repository");
140
+ await shell.$`git init`;
141
+ await shell.$`git add . && git commit -m "initial commit"`;
142
+ logger.success("Git repository created");
143
+ }
144
+ }
145
+ #getBypassArr(options) {
146
+ const { template } = options;
147
+ const bypassArr = [];
148
+ if (template) bypassArr[0] = template;
149
+ return bypassArr;
150
+ }
151
+ };
152
+ //#endregion
153
+ //#region src/program/commands/init.ts
154
+ function createInitCommand(ctx) {
155
+ return createCommand("init").description("init a new project 🚀").addArgument(new Argument("[template]", "the template to use").choices(ctx.config.getTemplateChoices())).addOption(new Option("-d, --dest [string]", "destination path to create folder (default: cwd)")).addOption(new Option("--no-git", "skip to create a git repository").default(true)).addOption(new Option("-f, --force", "override existing files").default(false)).action(async function initAction(template, options) {
156
+ try {
157
+ const { dest: destBasePath = cwd, force } = options;
158
+ await new InitAction({
159
+ templateService: await createPlopTemplateService({
160
+ force,
161
+ destBasePath,
162
+ basePath: ctx.binPkg.dirPath
163
+ }),
164
+ shellService: ctx.shell
165
+ }).execute({
166
+ template,
167
+ destBasePath,
168
+ ...options
169
+ });
170
+ } catch (error) {
171
+ logger.error(error);
172
+ process.exit(1);
173
+ }
174
+ }).addHelpText("afterAll", "\nUnder the hood, this command uses Plop.js to generate the project.");
175
+ }
176
+ const BANNER_TEXT = `${`⚡ ${palette.bold("V")} ${palette.bold("L")} ${palette.bold("A")} ${palette.bold("N")} ${palette.bold("D")}`}: The CLI to init a new project in ${`${palette.vland("Variable Land")} 👊`}\n`;
177
+ //#endregion
178
+ //#region src/program/index.ts
179
+ async function createProgram(options) {
180
+ const ctx = await createContext(options.binDir);
181
+ return new Command("vland").version(getVersion(ctx.binPkg), "-v, --version").addHelpText("before", BANNER_TEXT).addCommand(createInitCommand(ctx)).addCommand(createAddCommand(ctx));
182
+ }
183
+ //#endregion
184
+ //#region src/main.ts
185
+ async function main(options) {
186
+ await run(async () => {
187
+ await (await createProgram(options)).parseAsync();
188
+ }, logger);
189
+ }
190
+ //#endregion
191
+ //#region bin.ts
192
+ main({ binDir: dirname(fileURLToPath(import.meta.url)) });
193
+ //#endregion
194
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vlandoss/starter",
3
- "version": "0.0.14",
3
+ "version": "0.0.15-git-06df4ba.0",
4
4
  "description": "The CLI to init a new project in Variable Land",
5
5
  "homepage": "https://github.com/variableland/dx/tree/main/packages/starter#readme",
6
6
  "bugs": {
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/variableland/dx.git"
11
+ "url": "git+https://github.com/variableland/dx.git",
12
+ "directory": "packages/starter"
12
13
  },
13
14
  "license": "MIT",
14
15
  "author": "rcrd <rcrd@variable.land>",
@@ -18,27 +19,35 @@
18
19
  },
19
20
  "module": "src/main.ts",
20
21
  "bin": {
21
- "vland": "./bin.ts"
22
+ "vland": "./dist/bin.mjs"
22
23
  },
23
24
  "files": [
24
- "bin",
25
+ "bin.ts",
26
+ "dist",
25
27
  "src",
28
+ "!src/**/__tests__",
29
+ "!src/**/*.test.*",
26
30
  "plopfiles",
27
31
  "tsconfig.json"
28
32
  ],
29
33
  "dependencies": {
30
34
  "commander": "14.0.3",
31
35
  "node-plop": "0.32.3",
32
- "@vlandoss/clibuddy": "0.0.10",
33
- "@vlandoss/loggy": "0.0.7"
36
+ "@vlandoss/clibuddy": "0.0.11-git-06df4ba.0",
37
+ "@vlandoss/loggy": "0.0.8-git-06df4ba.0"
34
38
  },
35
39
  "publishConfig": {
36
40
  "access": "public"
37
41
  },
38
42
  "engines": {
43
+ "node": ">=20.0.0",
39
44
  "bun": ">=1.0.0"
40
45
  },
46
+ "devDependencies": {
47
+ "@vlandoss/tsdown-config": "^0.0.2-git-06df4ba.0"
48
+ },
41
49
  "scripts": {
50
+ "build": "tsdown",
42
51
  "test:types": "rr tsc"
43
52
  }
44
53
  }