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