@ryziz/cli 0.0.39 → 0.0.41
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 +37 -9
package/package.json
CHANGED
package/src/build.js
CHANGED
|
@@ -9,8 +9,9 @@ export default (isDev) => task('Building', {
|
|
|
9
9
|
c.root = process.cwd(); c.dist = 'dist'; c.public = join(c.root, 'public');
|
|
10
10
|
if (existsSync(c.dist)) rmSync(c.dist, { recursive: true, force: true });
|
|
11
11
|
mkdirSync(c.dist, { recursive: true });
|
|
12
|
+
mkdirSync(join(c.dist, 'functions'), { recursive: true });
|
|
12
13
|
},
|
|
13
|
-
'
|
|
14
|
+
'Hosting': async (c) => {
|
|
14
15
|
const getRoutes = () => {
|
|
15
16
|
const src = resolve(c.root, 'src'), files = existsSync(src) ? readdirSync(src).filter((f) => /^pages\..+\.jsx$/.test(f)) : [];
|
|
16
17
|
const imports = files.map((file, index) => `import R${index} from './src/${file}';`).join('\n');
|
|
@@ -18,11 +19,11 @@ export default (isDev) => task('Building', {
|
|
|
18
19
|
return { contents: `import React from 'react';\n${imports}\nexport default [${exports}];`, loader: 'jsx', resolveDir: c.root, watchDirs: [src] };
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
c.
|
|
22
|
+
c.hostingBuilder = await context({
|
|
22
23
|
entryPoints: { index: join(dirname(createRequire(import.meta.url).resolve('@ryziz/router/package.json')), 'entry.jsx') },
|
|
23
24
|
bundle: true, splitting: true, format: 'esm', outdir: join(c.dist, 'assets'), loader: { '.js': 'jsx' }, jsx: 'automatic', nodePaths: [join(c.root, 'node_modules')],
|
|
24
25
|
plugins: [
|
|
25
|
-
{ name: 'log', setup: (b) => b.onEnd(() => { c.
|
|
26
|
+
{ name: 'log', setup: (b) => b.onEnd(() => { c.onHostingBuilt?.(); }) },
|
|
26
27
|
{ name: 'vr', setup: (b) => { b.onResolve({ filter: /^virtual:routes$/ }, (a) => ({ path: a.path, namespace: 'vr' })); b.onLoad({ filter: /.*/, namespace: 'vr' }, getRoutes); } },
|
|
27
28
|
],
|
|
28
29
|
alias: {
|
|
@@ -31,17 +32,44 @@ export default (isDev) => task('Building', {
|
|
|
31
32
|
'react-router': join(c.root, 'node_modules/react-router'),
|
|
32
33
|
},
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await c.builder.rebuild();
|
|
35
|
+
|
|
36
|
+
await c.hostingBuilder.rebuild();
|
|
37
37
|
if (existsSync(c.public)) cpSync(c.public, c.dist, { recursive: true });
|
|
38
|
-
if (!isDev) await c.
|
|
38
|
+
if (!isDev) await c.hostingBuilder.dispose();
|
|
39
|
+
},
|
|
40
|
+
'Functions': async (c) => {
|
|
41
|
+
const getApiRoutes = () => {
|
|
42
|
+
const src = resolve(c.root, 'src'), files = existsSync(src) ? readdirSync(src).filter((f) => /^api\..+\.js$/.test(f)) : [];
|
|
43
|
+
const imports = files.map((file, index) => `import handler${index} from './src/${file}';`).join('\n');
|
|
44
|
+
const routes = files.map((file, index) => {
|
|
45
|
+
const path = ('/' + file.slice(4, -3)).replace(/^\/index$/, '/').replace(/\./g, '/').replace(/\$/g, ':');
|
|
46
|
+
const functionName = file.slice(0, -3).replace(/\./g, '-').replace(/\$/g, '');
|
|
47
|
+
return `{path:'${path}',handler:handler${index},functionName:'${functionName}'}`;
|
|
48
|
+
}).join(',');
|
|
49
|
+
return { contents: `${imports}\nexport default [${routes}];`, loader: 'js', resolveDir: c.root, watchDirs: [src] };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
c.functionsBuilder = await context({
|
|
53
|
+
entryPoints: { index: join(dirname(createRequire(import.meta.url).resolve('@ryziz/functions/package.json')), 'entry.js') },
|
|
54
|
+
bundle: true, format: 'cjs', platform: 'node', outfile: join(c.dist, 'functions', 'index.js'), minify: !isDev,
|
|
55
|
+
external: ['firebase-admin', 'firebase-functions', 'express'],
|
|
56
|
+
plugins: [
|
|
57
|
+
{ 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' }, getApiRoutes); } },
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await c.functionsBuilder.rebuild();
|
|
63
|
+
if (!isDev) await c.functionsBuilder.dispose();
|
|
39
64
|
},
|
|
40
65
|
'Watching': async (c) => {
|
|
41
66
|
if (!isDev) c.skip();
|
|
42
|
-
let
|
|
67
|
+
let isFirstHosting = true, isFirstFunctions = true;
|
|
68
|
+
c.onHostingBuilt = () => isFirstHosting ? (isFirstHosting = false) : console.log('Hosting build updated');
|
|
69
|
+
c.onFunctionsBuilt = () => isFirstFunctions ? (isFirstFunctions = false) : console.log('Functions build updated');
|
|
43
70
|
if (existsSync(c.public)) watch(c.public, { recursive: true }, () => { console.log('Public assets updated'); cpSync(c.public, c.dist, { recursive: true }); });
|
|
44
|
-
await c.
|
|
71
|
+
await c.hostingBuilder.watch();
|
|
72
|
+
await c.functionsBuilder.watch();
|
|
45
73
|
await new Promise(() => { });
|
|
46
74
|
},
|
|
47
75
|
});
|