@ryziz/cli 0.0.37 → 0.0.39
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 +14 -0
- package/package.json +5 -2
- package/src/build.js +47 -0
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import runBuild from './src/build.js';
|
|
5
|
+
|
|
6
|
+
const pkg = createRequire(import.meta.url)('./package.json');
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program.name('ryziz').version(pkg.version);
|
|
10
|
+
|
|
11
|
+
program.command('dev').action(() => runBuild(true));
|
|
12
|
+
program.command('build').action(() => runBuild(false));
|
|
13
|
+
|
|
14
|
+
program.parse();
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryziz/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
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
|
}
|
package/src/build.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { context } from 'esbuild';
|
|
2
|
+
import { existsSync, readdirSync, mkdirSync, cpSync, watch, rmSync } from 'node:fs';
|
|
3
|
+
import { join, resolve, dirname } from 'node:path';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { task } from '@ryziz/flow';
|
|
6
|
+
|
|
7
|
+
export default (isDev) => task('Building', {
|
|
8
|
+
'Preparing': (c) => {
|
|
9
|
+
c.root = process.cwd(); c.dist = 'dist'; c.public = join(c.root, 'public');
|
|
10
|
+
if (existsSync(c.dist)) rmSync(c.dist, { recursive: true, force: true });
|
|
11
|
+
mkdirSync(c.dist, { recursive: true });
|
|
12
|
+
},
|
|
13
|
+
'Setup': async (c) => {
|
|
14
|
+
const getRoutes = () => {
|
|
15
|
+
const src = resolve(c.root, 'src'), files = existsSync(src) ? readdirSync(src).filter((f) => /^pages\..+\.jsx$/.test(f)) : [];
|
|
16
|
+
const imports = files.map((file, index) => `import R${index} from './src/${file}';`).join('\n');
|
|
17
|
+
const exports = files.map((file, index) => `{path:'${('/' + file.slice(6, -4)).replace(/^\/index$/, '/').replace(/\./g, '/').replace(/\$/g, ':')}',element:<R${index}/>}`).join(',');
|
|
18
|
+
return { contents: `import React from 'react';\n${imports}\nexport default [${exports}];`, loader: 'jsx', resolveDir: c.root, watchDirs: [src] };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
c.builder = await context({
|
|
22
|
+
entryPoints: { index: join(dirname(createRequire(import.meta.url).resolve('@ryziz/router/package.json')), 'entry.jsx') },
|
|
23
|
+
bundle: true, splitting: true, format: 'esm', outdir: join(c.dist, 'assets'), loader: { '.js': 'jsx' }, jsx: 'automatic', nodePaths: [join(c.root, 'node_modules')],
|
|
24
|
+
plugins: [
|
|
25
|
+
{ name: 'log', setup: (b) => b.onEnd(() => { c.onBuilt?.(); }) },
|
|
26
|
+
{ name: 'vr', setup: (b) => { b.onResolve({ filter: /^virtual:routes$/ }, (a) => ({ path: a.path, namespace: 'vr' })); b.onLoad({ filter: /.*/, namespace: 'vr' }, getRoutes); } },
|
|
27
|
+
],
|
|
28
|
+
alias: {
|
|
29
|
+
'react': join(c.root, 'node_modules/react'),
|
|
30
|
+
'react-dom': join(c.root, 'node_modules/react-dom'),
|
|
31
|
+
'react-router': join(c.root, 'node_modules/react-router'),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
'Building': async (c) => {
|
|
36
|
+
await c.builder.rebuild();
|
|
37
|
+
if (existsSync(c.public)) cpSync(c.public, c.dist, { recursive: true });
|
|
38
|
+
if (!isDev) await c.builder.dispose();
|
|
39
|
+
},
|
|
40
|
+
'Watching': async (c) => {
|
|
41
|
+
if (!isDev) c.skip();
|
|
42
|
+
let isFirst = true; c.onBuilt = () => isFirst ? (isFirst = false) : console.log('Client build updated');
|
|
43
|
+
if (existsSync(c.public)) watch(c.public, { recursive: true }, () => { console.log('Public assets updated'); cpSync(c.public, c.dist, { recursive: true }); });
|
|
44
|
+
await c.builder.watch();
|
|
45
|
+
await new Promise(() => { });
|
|
46
|
+
},
|
|
47
|
+
});
|