@ryziz/cli 0.0.44 → 0.0.46
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/package.json +1 -1
- package/src/build.js +17 -16
package/package.json
CHANGED
package/src/build.js
CHANGED
|
@@ -7,20 +7,23 @@ import { task } from '@ryziz/flow';
|
|
|
7
7
|
export default (isDev) => task('Building', {
|
|
8
8
|
'Preparing': (c) => {
|
|
9
9
|
c.root = process.cwd(); c.dist = 'dist'; c.public = join(c.root, 'public');
|
|
10
|
+
c.src = resolve(c.root, 'src');
|
|
11
|
+
c.routerPkg = dirname(createRequire(import.meta.url).resolve('@ryziz/router/package.json'));
|
|
12
|
+
c.functionsPkg = dirname(createRequire(import.meta.url).resolve('@ryziz/functions/package.json'));
|
|
10
13
|
if (existsSync(c.dist)) rmSync(c.dist, { recursive: true, force: true });
|
|
11
14
|
mkdirSync(c.dist, { recursive: true });
|
|
12
15
|
mkdirSync(join(c.dist, 'functions'), { recursive: true });
|
|
13
16
|
},
|
|
14
17
|
'Hosting': async (c) => {
|
|
15
18
|
const getRoutes = () => {
|
|
16
|
-
const
|
|
19
|
+
const files = existsSync(c.src) ? readdirSync(c.src).filter((f) => /^pages\..+\.jsx$/.test(f)) : [];
|
|
17
20
|
const imports = files.map((file, index) => `import R${index} from './src/${file}';`).join('\n');
|
|
18
21
|
const exports = files.map((file, index) => `{path:'${('/' + file.slice(6, -4)).replace(/^\/index$/, '/').replace(/\./g, '/').replace(/\$/g, ':')}',element:<R${index}/>}`).join(',');
|
|
19
|
-
return { contents: `import React from 'react';\n${imports}\nexport default [${exports}];`, loader: 'jsx', resolveDir: c.root, watchDirs: [src] };
|
|
22
|
+
return { contents: `import React from 'react';\n${imports}\nexport default [${exports}];`, loader: 'jsx', resolveDir: c.root, watchDirs: [c.src] };
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
c.hostingBuilder = await context({
|
|
23
|
-
entryPoints: { index: join(
|
|
26
|
+
entryPoints: { index: join(c.routerPkg, 'entry.jsx') },
|
|
24
27
|
bundle: true, splitting: true, format: 'esm', outdir: join(c.dist, 'assets'), loader: { '.js': 'jsx' }, jsx: 'automatic', nodePaths: [join(c.root, 'node_modules')],
|
|
25
28
|
plugins: [
|
|
26
29
|
{ name: 'log', setup: (b) => b.onEnd(() => { c.onHostingBuilt?.(); }) },
|
|
@@ -38,30 +41,28 @@ export default (isDev) => task('Building', {
|
|
|
38
41
|
if (!isDev) await c.hostingBuilder.dispose();
|
|
39
42
|
},
|
|
40
43
|
'Functions': async (c) => {
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
return { contents: `${imports}\nmodule.exports = [${routes.map((r) => r.entry).join(',')}];`, loader: 'js', resolveDir: c.root, watchDirs: [src], routes };
|
|
44
|
+
const scanApiRoutes = () => {
|
|
45
|
+
const files = existsSync(c.src) ? readdirSync(c.src).filter((f) => /^api\..+\.js$/.test(f)) : [];
|
|
46
|
+
return files.map((file) => ({
|
|
47
|
+
file,
|
|
48
|
+
path: ('/' + file.slice(4, -3)).replace(/^\/index$/, '/').replace(/\./g, '/').replace(/\$/g, ':'),
|
|
49
|
+
functionName: file.slice(0, -3).replace(/\./g, '-').replace(/\$/g, ''),
|
|
50
|
+
}));
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
c.functionsBuilder = await context({
|
|
53
|
-
entryPoints: { index: join(
|
|
54
|
+
entryPoints: { index: join(c.functionsPkg, 'entry.js') },
|
|
54
55
|
bundle: true, format: 'cjs', platform: 'node', outfile: join(c.dist, 'functions', 'index.js'), minify: !isDev,
|
|
55
56
|
external: ['firebase-admin', 'firebase-functions', 'express'],
|
|
56
57
|
plugins: [
|
|
57
58
|
{ name: 'log', setup: (b) => b.onEnd(() => { c.onFunctionsBuilt?.(); }) },
|
|
58
|
-
{ name: 'var', setup: (b) => { b.onResolve({ filter: /^virtual:api-routes$/ }, (a) => ({ path: a.path, namespace: 'var' })); b.onLoad({ filter: /.*/, namespace: 'var' },
|
|
59
|
-
{ name: 'fb', setup: (b) => b.onEnd(() => { const cfg = JSON.parse(readFileSync(join(
|
|
59
|
+
{ name: 'var', setup: (b) => { b.onResolve({ filter: /^virtual:api-routes$/ }, (a) => ({ path: a.path, namespace: 'var' })); b.onLoad({ filter: /.*/, namespace: 'var' }, () => { const routes = scanApiRoutes(); const requires = routes.map((r, i) => `const handler${i} = require('./src/${r.file}');`).join('\n'); const entries = routes.map((r, i) => `{path:'${r.path}',handler:handler${i}.default || handler${i},functionName:'${r.functionName}'}`).join(','); return { contents: `${requires}\nmodule.exports = [${entries}];`, loader: 'js', resolveDir: c.root, watchDirs: [c.src] }; }); } },
|
|
60
|
+
{ name: 'fb', setup: (b) => b.onEnd(() => { const routes = scanApiRoutes(); const cfg = JSON.parse(readFileSync(join(c.functionsPkg, 'firebase.json'))); writeFileSync(join(c.dist, 'firebase.json'), JSON.stringify({ ...cfg, hosting: { ...cfg.hosting, rewrites: [...routes.map((r) => ({ source: r.path, function: r.functionName })), { source: '**', destination: '/index.html' }] } }, null, 2)); }) },
|
|
60
61
|
],
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
await c.functionsBuilder.rebuild();
|
|
64
|
-
cpSync(
|
|
65
|
+
cpSync(join(c.functionsPkg, 'package.json'), join(c.dist, 'functions', 'package.json'));
|
|
65
66
|
if (!isDev) await c.functionsBuilder.dispose();
|
|
66
67
|
},
|
|
67
68
|
'Watching': async (c) => {
|