create-yeow 0.1.1 → 0.1.2
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/index.js +36 -32
- package/package.json +9 -4
package/bin/index.js
CHANGED
|
@@ -2,63 +2,69 @@
|
|
|
2
2
|
import { mkdirSync, writeFileSync, readFileSync, existsSync, cpSync } from 'fs';
|
|
3
3
|
import { resolve, dirname } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { createInterface } from 'readline';
|
|
5
6
|
|
|
6
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
8
|
const argv = process.argv.slice(2);
|
|
8
|
-
const
|
|
9
|
-
const
|
|
9
|
+
const flag = (f) => argv.includes(f);
|
|
10
|
+
const val = (f) => argv.find(a => a.startsWith(f))?.split('=').slice(1).join('=');
|
|
10
11
|
|
|
11
|
-
const yes =
|
|
12
|
-
const useTs = _flag('--ts');
|
|
13
|
-
const name = yes ? (_val('--name=') || 'my-yeow-plugin') : (argv[0] || 'my-yeow-plugin');
|
|
14
|
-
const author = yes ? (_val('--author=') || '') : '';
|
|
12
|
+
const yes = flag('-y') || process.env.CI === 'true';
|
|
15
13
|
|
|
16
14
|
const c = { r:'\x1b[0m',b:'\x1b[1m',d:'\x1b[2m',g:'\x1b[32m',y:'\x1b[33m',B:'\x1b[34m',C:'\x1b[36m' };
|
|
17
15
|
const _ = (m) => process.stdout.write(m);
|
|
18
16
|
const ok = (m) => _(` ${c.g}✓${c.r} ${m}\n`);
|
|
19
|
-
const step = (m) => _(` ${c.C}→${c.r} ${m}... `);
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
const
|
|
18
|
+
async function prompt(q, def) {
|
|
19
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
20
|
+
const hint = def ? ` ${c.d}[${def}]${c.r}` : '';
|
|
21
|
+
return new Promise(r => rl.question(` ${c.C}${q}${hint}: `, a => { rl.close(); r(a.trim() || def); }));
|
|
22
|
+
}
|
|
23
23
|
|
|
24
24
|
_(`\n ${c.b}${c.B}Yeow v0${c.r} ${c.d}— plugin scaffolding${c.r}\n\n`);
|
|
25
25
|
if (yes) _(` ${c.d}non-interactive mode${c.r}\n`);
|
|
26
|
-
_(` project ${c.b}${name}${c.r}\n`);
|
|
27
|
-
if (author) _(` author ${author}\n`);
|
|
28
|
-
_(` language ${useTs ? 'TypeScript' : 'JavaScript'}\n\n`);
|
|
29
26
|
|
|
27
|
+
let name, author, desc, useTs;
|
|
28
|
+
if (yes) {
|
|
29
|
+
name = val('--name=') || 'my-yeow-plugin';
|
|
30
|
+
author = val('--author=') || '';
|
|
31
|
+
desc = val('--desc=') || 'A Yeow plugin';
|
|
32
|
+
useTs = flag('--ts') || !flag('--js');
|
|
33
|
+
} else {
|
|
34
|
+
name = await prompt('Project name', 'my-yeow-plugin');
|
|
35
|
+
author = await prompt('Author', '');
|
|
36
|
+
desc = await prompt('Description', 'A Yeow plugin');
|
|
37
|
+
const lang = await prompt('Language (TS/JS)', 'TS');
|
|
38
|
+
useTs = !lang.toLowerCase().startsWith('j');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const tpl = resolve(__dirname, '..', 'templates', 'default');
|
|
42
|
+
const dir = resolve(process.cwd(), name);
|
|
43
|
+
|
|
44
|
+
_('\n');
|
|
30
45
|
if (existsSync(dir)) { console.error(` ${c.y}⚠ ${name} already exists${c.r}\n`); process.exit(1); }
|
|
31
46
|
|
|
47
|
+
const step = (m) => { _(` ${c.C}→${c.r} ${m}... `); };
|
|
32
48
|
step('Creating project'); mkdirSync(dir, { recursive: true }); ok('done');
|
|
33
|
-
|
|
34
49
|
step('Copying template'); cpSync(tpl, dir, { recursive: true }); ok('done');
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
const gitignore = `node_modules/\ndist/\n.yeow/dev/\n*.log\n`;
|
|
38
|
-
writeFileSync(resolve(dir, '.gitignore'), gitignore);
|
|
51
|
+
writeFileSync(resolve(dir, '.gitignore'), 'node_modules/\ndist/\n.yeow/dev/\n*.log\n');
|
|
39
52
|
|
|
40
|
-
// Update package.json
|
|
41
53
|
const pkg = JSON.parse(readFileSync(resolve(dir, 'package.json'), 'utf-8'));
|
|
42
|
-
pkg.name = name.toLowerCase().replace(/[^a-z0-9-]/g,
|
|
54
|
+
pkg.name = name.toLowerCase().replace(/[^a-z0-9-]/g,'-').replace(/-+/g,'-').replace(/^-|-$/g,'');
|
|
43
55
|
if (author) pkg.author = author;
|
|
44
|
-
|
|
56
|
+
pkg.description = desc;
|
|
57
|
+
writeFileSync(resolve(dir, 'package.json'), JSON.stringify(pkg, null, 2)+'\n');
|
|
45
58
|
|
|
46
|
-
// Update yeow.config.json
|
|
47
59
|
const cfg = JSON.parse(readFileSync(resolve(dir, 'yeow.config.json'), 'utf-8'));
|
|
48
|
-
cfg.name = name;
|
|
49
|
-
writeFileSync(resolve(dir, 'yeow.config.json'), JSON.stringify(cfg, null, 4)
|
|
60
|
+
cfg.name = name; cfg.author = author; cfg.description = desc;
|
|
61
|
+
writeFileSync(resolve(dir, 'yeow.config.json'), JSON.stringify(cfg, null, 4)+'\n');
|
|
50
62
|
|
|
51
|
-
// If JS, rename index.ts → index.js and update build.js
|
|
52
63
|
if (!useTs) {
|
|
53
64
|
const tsFile = resolve(dir, 'src', 'index.ts');
|
|
54
65
|
const jsFile = resolve(dir, 'src', 'index.js');
|
|
55
|
-
if (existsSync(tsFile)
|
|
56
|
-
|
|
57
|
-
writeFileSync(jsFile, readFileSync(tsFile, 'utf-8').replace(/(:\s*\w+(\[\])?)\s*(?=,|\)|\n|;)/g, ''));
|
|
58
|
-
}
|
|
59
|
-
// Update build.js to use .js entry
|
|
60
|
-
const buildJs = readFileSync(resolve(dir, '.yeow', 'build.js'), 'utf-8')
|
|
61
|
-
.replace("src/index.ts", "src/index.js");
|
|
66
|
+
if (existsSync(tsFile)) writeFileSync(jsFile, readFileSync(tsFile, 'utf-8'));
|
|
67
|
+
const buildJs = readFileSync(resolve(dir, '.yeow', 'build.js'), 'utf-8').replace("src/index.ts","src/index.js");
|
|
62
68
|
writeFileSync(resolve(dir, '.yeow', 'build.js'), buildJs);
|
|
63
69
|
}
|
|
64
70
|
|
|
@@ -67,5 +73,3 @@ _(` cd ${name}\n`);
|
|
|
67
73
|
_(` npm install\n`);
|
|
68
74
|
_(` npm run dev${c.d} # start dev server${c.r}\n`);
|
|
69
75
|
_(` npm run build${c.d} # build plugin JAR${c.r}\n\n`);
|
|
70
|
-
|
|
71
|
-
function copy(src, dest) { writeFileSync(dest, readFileSync(src)); }
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-yeow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Scaffold a Yeow plugin project",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-yeow": "./bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"templates/"
|
|
12
|
+
],
|
|
8
13
|
"license": "MIT"
|
|
9
|
-
}
|
|
14
|
+
}
|