create-vag 0.1.0 → 0.1.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.
@@ -0,0 +1,281 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/create-vag-cli.ts
4
+ import * as prom from "@clack/prompts";
5
+ import chalk from "chalk";
6
+
7
+ // package.json
8
+ var package_default = {
9
+ name: "create-vag",
10
+ version: "0.1.3",
11
+ description: "The npm-initializer for creating a new vag repo",
12
+ private: false,
13
+ repository: {
14
+ type: "git",
15
+ url: "git+https://github.com/charlyoleg2/create-vag.git"
16
+ },
17
+ homepage: "https://www.npmjs.com/package/create-vag",
18
+ author: "charlyoleg",
19
+ license: "ISC",
20
+ keywords: [
21
+ "git",
22
+ "sub-repo",
23
+ "vcstool",
24
+ "subg",
25
+ "vag"
26
+ ],
27
+ type: "module",
28
+ exports: {
29
+ ".": {
30
+ types: "./dist/create-vag-api.d.ts",
31
+ default: "./dist/create-vag-api.js"
32
+ }
33
+ },
34
+ bin: {
35
+ "create-vag": "dist/create-vag-cli.js"
36
+ },
37
+ files: [
38
+ "dist/create-vag-cli.js",
39
+ "dist/template/",
40
+ "!dist/**/*.map",
41
+ "!dist/**/*.spec.*"
42
+ ],
43
+ tsup: {
44
+ entry: [
45
+ "src/create-vag-api.ts",
46
+ "src/create-vag-ref.ts",
47
+ "src/create-vag-cli.ts"
48
+ ],
49
+ format: "esm",
50
+ splitting: false,
51
+ dts: false,
52
+ sourcemap: false,
53
+ clean: true
54
+ },
55
+ prettier: {
56
+ useTabs: true,
57
+ singleQuote: true,
58
+ trailingComma: "none",
59
+ printWidth: 100,
60
+ plugins: [],
61
+ overrides: []
62
+ },
63
+ scripts: {
64
+ dev: "tsup --watch",
65
+ build: "tsup",
66
+ check: "tsc --noEmit",
67
+ pretty: "prettier --check .",
68
+ format: "prettier --write .",
69
+ lint: "eslint .",
70
+ "test:unit": "vitest",
71
+ "test:unit:once": "vitest --run",
72
+ copy_template: "shx cp -r template dist/",
73
+ cleanCopy_template: "run-s clean:template copy_template",
74
+ ci: "run-s check build pretty lint test:unit:once cleanCopy_template",
75
+ run: "dist/create-vag-cli.js",
76
+ "run:ref": "dist/create-vag-ref.js tmp2",
77
+ "run:diff": "diff -rq tmp tmp2",
78
+ "run:check": "run-s run:ref run:diff",
79
+ cycle: "run-s clean ci run",
80
+ "clean:template": "shx rm -fr dist/template",
81
+ "clean:build": "shx rm -fr dist",
82
+ "clean:output": "shx rm -fr tmp tmp2",
83
+ clean: "run-s clean:build clean:output"
84
+ },
85
+ dependencies: {
86
+ "@clack/prompts": "^0.7.0",
87
+ chalk: "^5.3.0",
88
+ handlebars: "^4.7.8"
89
+ },
90
+ devDependencies: {
91
+ "@eslint/js": "^9.10.0",
92
+ "@types/eslint__js": "^8.42.3",
93
+ "@types/node": "^22.5.5",
94
+ eslint: "^9.10.0",
95
+ "eslint-config-prettier": "^9.1.0",
96
+ "npm-run-all": "^4.1.5",
97
+ prettier: "^3.3.3",
98
+ shx: "^0.3.4",
99
+ tsup: "^8.3.0",
100
+ typescript: "^5.6.2",
101
+ "typescript-eslint": "^8.6.0",
102
+ vitest: "^2.1.1"
103
+ }
104
+ };
105
+
106
+ // src/create-vag-cli.ts
107
+ import { setTimeout as sleep2 } from "node:timers/promises";
108
+
109
+ // src/create-vag-api.ts
110
+ import { setTimeout as sleep } from "node:timers/promises";
111
+ import { readFile, writeFile, access, mkdir } from "node:fs/promises";
112
+ import { Buffer } from "node:buffer";
113
+ import { dirname, extname } from "path";
114
+ import Handlebars from "handlebars";
115
+
116
+ // src/create-vag-common.ts
117
+ function firstLetterCapital(str) {
118
+ const rStr = str.charAt(0).toUpperCase() + str.slice(1);
119
+ return rStr;
120
+ }
121
+ function underline(str) {
122
+ const strLen = str.length;
123
+ const rStr = "=".repeat(strLen);
124
+ return rStr;
125
+ }
126
+ function prefixOutputPath() {
127
+ let rPreDir = ".";
128
+ const scriptDir = new URL("", import.meta.url).toString();
129
+ const regex = new RegExp("/node_modules/");
130
+ if (!regex.test(scriptDir)) {
131
+ rPreDir = "./tmp";
132
+ }
133
+ return rPreDir;
134
+ }
135
+
136
+ // src/create-vag-list.ts
137
+ var template_file_list = [
138
+ ".editorconfig",
139
+ ".gitignore",
140
+ "package.json",
141
+ "README.md",
142
+ "{{projName}}_repos.yml"
143
+ ];
144
+
145
+ // src/create-vag-api.ts
146
+ async function createMissingDir(outPath) {
147
+ const outDir = dirname(outPath);
148
+ try {
149
+ await access(outDir);
150
+ } catch (err) {
151
+ if (err) {
152
+ await mkdir(outDir, { recursive: true });
153
+ }
154
+ }
155
+ }
156
+ function isFileBinary(fpath) {
157
+ const binaryExts = /* @__PURE__ */ new Set([".png"]);
158
+ const infileExt = extname(fpath.toString());
159
+ const rBool = binaryExts.has(infileExt);
160
+ return rBool;
161
+ }
162
+ async function oneFile(onePath, cfg2, preDir2) {
163
+ try {
164
+ const onePathIn = Handlebars.compile(onePath)({ projName: "projAbc", repoName: "projAbc_vag" });
165
+ const onePathOut = Handlebars.compile(onePath)(cfg2);
166
+ const fileIn1 = new URL(`./template/${onePathIn}.handlebars`, import.meta.url);
167
+ const fileIn2 = new URL(`./template/${onePathIn}`, import.meta.url);
168
+ let fileBin = false;
169
+ let fileStr2 = "";
170
+ let fileBuffer2 = Buffer.alloc(0);
171
+ try {
172
+ await access(fileIn1);
173
+ try {
174
+ const fileStr1 = await readFile(fileIn1, { encoding: "utf8" });
175
+ const templateStr = Handlebars.compile(fileStr1);
176
+ fileStr2 = templateStr(cfg2);
177
+ } catch (err) {
178
+ console.log(`err392: error while processing ${fileIn1.toString()}`);
179
+ console.log(err);
180
+ }
181
+ } catch (err) {
182
+ if (err) {
183
+ if (isFileBinary(fileIn2)) {
184
+ fileBin = true;
185
+ fileBuffer2 = await readFile(fileIn2);
186
+ } else {
187
+ fileStr2 = await readFile(fileIn2, { encoding: "utf8" });
188
+ }
189
+ }
190
+ }
191
+ const outPath = `${preDir2}/${cfg2.repoName}/${onePathOut}`;
192
+ await createMissingDir(outPath);
193
+ if (fileBin) {
194
+ await writeFile(outPath, fileBuffer2);
195
+ } else {
196
+ await writeFile(outPath, fileStr2);
197
+ }
198
+ } catch (err) {
199
+ console.log(`err213: error while generating file ${onePath}`);
200
+ console.error(err);
201
+ throw `err214: error with path ${onePath}`;
202
+ }
203
+ }
204
+ async function generate_boirlerplate(cfg12, preDir2) {
205
+ console.log(`Boilerplate with:
206
+ project name : ${cfg12.projName}
207
+ repository name : ${cfg12.repoName}`);
208
+ const cfg2 = {
209
+ projName: cfg12.projName,
210
+ ProjName: firstLetterCapital(cfg12.projName),
211
+ ProjNameUnderline: underline(cfg12.projName),
212
+ repoName: cfg12.repoName,
213
+ RepoName: firstLetterCapital(cfg12.repoName),
214
+ RepoNameUnderline: underline(cfg12.repoName)
215
+ };
216
+ for (const fpath of template_file_list) {
217
+ await oneFile(fpath, cfg2, preDir2);
218
+ }
219
+ console.log(`generate ${template_file_list.length} files in ${preDir2}/${cfg12.repoName}/`);
220
+ await sleep(100);
221
+ const rResp = {
222
+ vim: `vim ${cfg12.projName}_repos.yaml`
223
+ };
224
+ return rResp;
225
+ }
226
+
227
+ // src/create-vag-cli.ts
228
+ var firstMsg = `Create a new ${chalk.italic("vag-top-repo")} with ${chalk.italic(package_default.name)} version ${chalk.italic(package_default.version)}`;
229
+ console.log(firstMsg);
230
+ var projName = process.argv[2] || "blabla";
231
+ var argN = process.argv.length - 2;
232
+ if (argN > 1) {
233
+ console.log(`warn376: ${argN} arguments provided but only one supported!`);
234
+ }
235
+ prom.intro(chalk.inverse(" Your new vag-top-repo "));
236
+ var pCfg = await prom.group(
237
+ {
238
+ projName: () => prom.text({
239
+ message: "Name of the project?",
240
+ initialValue: `${projName}`
241
+ //placeholder: `${projName}`
242
+ }),
243
+ repoName: () => prom.text({
244
+ message: "Name of the top-repository?",
245
+ initialValue: `${projName}_vag`
246
+ //placeholder: `${projName}_vag`
247
+ })
248
+ },
249
+ {
250
+ onCancel: () => {
251
+ prom.cancel("Operation aborted!");
252
+ process.exit(0);
253
+ }
254
+ }
255
+ );
256
+ prom.outro("Your new vag-top-repository will be boilerplated!");
257
+ var cfg1 = {
258
+ projName: pCfg.projName,
259
+ repoName: pCfg.repoName
260
+ };
261
+ var preDir = prefixOutputPath();
262
+ var resp = await generate_boirlerplate(cfg1, preDir);
263
+ await sleep2(100);
264
+ function styl(str) {
265
+ const rStr = chalk.bold.cyan(str);
266
+ return rStr;
267
+ }
268
+ var lastMsg = `
269
+ Next steps:
270
+ 1: ${styl(`cd ${pCfg.repoName}`)}
271
+ 2: ${styl(`npm install`)}
272
+ 3: ${styl('git init && git add -A && git commit -m "Initial commit"')} (optional)
273
+ 4: ${styl(`${resp.vim}`)} (optional)
274
+ 5: ${styl(`npm run`)}
275
+ 6: ${styl(`npm run vag-list`)}
276
+ 7: ${styl(`npm run vag-clone`)}
277
+ 8: ${styl(`npm run vag-pull`)}
278
+ 9: ${styl(`npm run vag-status`)}
279
+ 10: ${styl(`npm run vag-diff`)}
280
+ `;
281
+ console.log(lastMsg);
@@ -0,0 +1,23 @@
1
+ # .editorconfig of vag-root
2
+ # EditorConfig is awesome: https://EditorConfig.org
3
+ # don't forget the vim-plugin for it
4
+
5
+ # top-most EditorConfig file
6
+ root = true
7
+
8
+ # Unix-style newlines with a newline ending every file
9
+ [*]
10
+ indent_style = tab
11
+ indent_size = 4
12
+ end_of_line = lf
13
+ charset = utf-8
14
+ trim_trailing_whitespace = true
15
+ insert_final_newline = true
16
+
17
+ # Tab indentation (no size specified)
18
+ [Makefile]
19
+ indent_style = tab
20
+
21
+ # yaml indentation with spaces
22
+ [*.{yml,yaml}]
23
+ indent_style = space
@@ -0,0 +1,6 @@
1
+ # .gitignore of vag-root
2
+ node_modules
3
+ build
4
+ dist
5
+ tmp
6
+ /repos/
@@ -0,0 +1,30 @@
1
+ {{ProjName}}\_vag
2
+ {{ProjNameUnderline}}====
3
+
4
+
5
+ Presentation
6
+ ------------
7
+
8
+ *{{projName}}\_vag* is the top-repo of the *{{ProjName}}* ecosystem. It just points to other repositories.
9
+
10
+ Using [vag\_tools](https://www.npmjs.com/package/vag_tools), it clones the following repositories:
11
+
12
+ - {{projName}}
13
+ - create-{{projName}}
14
+ - {{projName}}\_vag
15
+
16
+
17
+ Getting started
18
+ ---------------
19
+
20
+ ```bash
21
+ git clone https://github.com/MYNAME/{{projName}}_vag
22
+ cd {{projName}}_vag
23
+ npm i
24
+ npm run
25
+ npm run vag-clone
26
+ npm run vag-pull
27
+ ls -la repos
28
+ npx vag --help
29
+ ```
30
+
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "{{projName}}_vag",
3
+ "version": "0.0.1",
4
+ "description": "top-repo that points to the other {{projName}} repositories",
5
+ "private": true,
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/MYNAME/{{projName}}_vag.git"
9
+ },
10
+ "homepage": "https://github.com/MYNAME/{{projName}}_vag#readme",
11
+ "author": "MYNAME",
12
+ "license": "ISC",
13
+ "keywords": [
14
+ "{{projName}}",
15
+ "vag"
16
+ ],
17
+ "type": "module",
18
+ "main": "index.js",
19
+ "scripts": {
20
+ "vag-list": "vag --importYaml={{projName}}_repos.yml list",
21
+ "vag-clone": "vag --importYaml={{projName}}_repos.yml clone",
22
+ "vag-status": "vag --importYaml={{projName}}_repos.yml --only_configured status",
23
+ "vag-diff": "vag --importYaml={{projName}}_repos.yml --only_configured diff",
24
+ "vag-branch": "vag branch",
25
+ "vag-remote": "vag remote",
26
+ "vag-pull": "vag pull",
27
+ "vag-push": "vag push",
28
+ "vag-verify": "vag verify --importYaml={{projName}}_repos.yml",
29
+ "vag-versions": "vag versions",
30
+ "test": "echo \"Error: no test specified\" && exit 1"
31
+ },
32
+ "devDependencies": {
33
+ "vag_tools": "^0.0.7"
34
+ }
35
+ }
@@ -0,0 +1,13 @@
1
+ # {{projName}}_repos.yml
2
+
3
+ repositories:
4
+ repos/{{projName}}:
5
+ type: git
6
+ url: git@github.com:MYNAME/{{projName}}.git
7
+ version: main
8
+ repos/create-{{projName}}:
9
+ url: git@github.com:MYNAME/create-{{projName}}.git
10
+ version: main
11
+ repos/{{projName}}_vag:
12
+ url: git@github.com:MYNAME/{{projName}}_vag.git
13
+ version: main
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vag",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "The npm-initializer for creating a new vag repo",
5
5
  "private": false,
6
6
  "repository": {