@ryziz/cli 0.0.37 → 0.0.38
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/index.js +78 -0
- package/package.json +5 -2
package/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { readFileSync, readdirSync, mkdirSync, existsSync, cpSync, watch as fsWatch } from 'node:fs';
|
|
4
|
+
import { join, resolve, dirname } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { build } from 'esbuild';
|
|
8
|
+
import { task } from '@ryziz/flow';
|
|
9
|
+
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf-8'));
|
|
13
|
+
|
|
14
|
+
const program = new Command();
|
|
15
|
+
program.name('ryziz').version(pkg.version);
|
|
16
|
+
|
|
17
|
+
program.command('dev').action(() => runBuild(true));
|
|
18
|
+
program.command('build').action(() => runBuild(false));
|
|
19
|
+
|
|
20
|
+
program.parse();
|
|
21
|
+
|
|
22
|
+
function runBuild(watch) {
|
|
23
|
+
task(watch ? 'Serving' : 'Bundling', {
|
|
24
|
+
'Configuring': (c) => {
|
|
25
|
+
c.root = process.cwd();
|
|
26
|
+
c.out = 'dist';
|
|
27
|
+
c.pub = join(c.root, 'public');
|
|
28
|
+
c.pkg = require.resolve('@ryziz/router/package.json');
|
|
29
|
+
if (!existsSync(c.out)) mkdirSync(c.out, { recursive: true });
|
|
30
|
+
},
|
|
31
|
+
'Scanning': (c) => {
|
|
32
|
+
const src = resolve(c.root, 'src');
|
|
33
|
+
if (existsSync(src)) {
|
|
34
|
+
const files = readdirSync(src).filter((f) => f.startsWith('pages.') && f.endsWith('.jsx'));
|
|
35
|
+
const maps = files.map((f, i) => ({
|
|
36
|
+
n: `R${i}`,
|
|
37
|
+
p: join(src, f).replace(/\\/g, '/'),
|
|
38
|
+
r: ('/' + f.slice(6, -4)).replace(/^\/index$/, '/').replace(/\./g, '/').replace(/\$/g, ':'),
|
|
39
|
+
}));
|
|
40
|
+
c.imp = maps.map((m) => `import ${m.n} from '${m.p}';`).join('\n');
|
|
41
|
+
c.rts = `[${maps.map((m) => `{path:'${m.r}',element:<${m.n}/>}`).join(',')}]`;
|
|
42
|
+
} else {
|
|
43
|
+
c.imp = ''; c.rts = '[]';
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
'Building': async (c) => {
|
|
47
|
+
const cp = () => existsSync(c.pub) && cpSync(c.pub, c.out, { recursive: true });
|
|
48
|
+
|
|
49
|
+
await build({
|
|
50
|
+
entryPoints: [join(dirname(c.pkg), 'entry.jsx')],
|
|
51
|
+
bundle: true,
|
|
52
|
+
outfile: join(c.out, 'assets/index.js'),
|
|
53
|
+
plugins: [{
|
|
54
|
+
name: 'vr',
|
|
55
|
+
setup(b) {
|
|
56
|
+
b.onResolve({ filter: /^virtual:routes$/ }, (a) => ({ path: a.path, namespace: 'vr' }));
|
|
57
|
+
b.onLoad({ filter: /.*/, namespace: 'vr' }, () => ({
|
|
58
|
+
contents: `import React from 'react';\n${c.imp}\nexport default ${c.rts};`,
|
|
59
|
+
loader: 'jsx',
|
|
60
|
+
resolveDir: c.root,
|
|
61
|
+
}));
|
|
62
|
+
},
|
|
63
|
+
}],
|
|
64
|
+
loader: { '.js': 'jsx', '.jsx': 'jsx' },
|
|
65
|
+
jsx: 'automatic',
|
|
66
|
+
watch: watch && {
|
|
67
|
+
onRebuild(e) { !e && (console.log('Reloaded'), cp()); },
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
cp();
|
|
72
|
+
if (watch) {
|
|
73
|
+
if (existsSync(c.pub)) fsWatch(c.pub, { recursive: true }, cp);
|
|
74
|
+
await new Promise(() => { });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryziz/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
+
"ryziz": "./index.js",
|
|
6
7
|
"create-react": "./create.js"
|
|
7
8
|
},
|
|
8
9
|
"dependencies": {
|
|
9
|
-
"@ryziz/flow": "^0.0.24"
|
|
10
|
+
"@ryziz/flow": "^0.0.24",
|
|
11
|
+
"commander": "^14.0.2",
|
|
12
|
+
"esbuild": "^0.27.2"
|
|
10
13
|
}
|
|
11
14
|
}
|