@changke/staticnext-build 0.2.2 → 0.2.3
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/build.mjs +5 -5
- package/lib/config.mjs +44 -0
- package/lib/typedefs.mjs +53 -0
- package/lib/vars.mjs +4 -99
- package/package.json +1 -1
package/build.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {argv} from 'node:process';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import Config from './lib/config.mjs';
|
|
6
6
|
|
|
7
7
|
import clean from './lib/tasks/clean.mjs';
|
|
8
8
|
import copy from './lib/tasks/copy.mjs';
|
|
@@ -16,14 +16,14 @@ import styles from './lib/tasks/styles.mjs';
|
|
|
16
16
|
const taskName = argv[2]?.toLowerCase() || 'dev';
|
|
17
17
|
|
|
18
18
|
// load config data
|
|
19
|
-
const conf = await
|
|
19
|
+
const conf = await Config.loadConfig();
|
|
20
20
|
|
|
21
21
|
const taskEnded = taskName => {
|
|
22
22
|
console.timeEnd(taskName);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const srcPaths =
|
|
26
|
-
const tgtPaths =
|
|
25
|
+
const srcPaths = Config.getSourcePaths(conf.sourcePath, conf.sourceRoot);
|
|
26
|
+
const tgtPaths = Config.getTargetPaths(conf.targetPath, conf.targetRoot, conf.targetAssetsRoot);
|
|
27
27
|
|
|
28
28
|
// Set parameters of each task
|
|
29
29
|
const tasks = {
|
|
@@ -45,7 +45,7 @@ const tasks = {
|
|
|
45
45
|
conf.njkGlobals,
|
|
46
46
|
tgtPaths.prototype
|
|
47
47
|
),
|
|
48
|
-
scripts: () => scripts(
|
|
48
|
+
scripts: () => scripts(Config.getScriptEntries(conf.moduleEntries, conf.mainEntryFile, srcPaths), tgtPaths.assets),
|
|
49
49
|
styles: () => styles([
|
|
50
50
|
`${srcPaths.css}/brands/*.css`,
|
|
51
51
|
`${srcPaths.css}/index.css`,
|
package/lib/config.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {cwd} from 'node:process';
|
|
2
2
|
|
|
3
|
+
import './typedefs.mjs';
|
|
3
4
|
import vars from './vars.mjs';
|
|
4
5
|
|
|
5
6
|
class Config {
|
|
@@ -34,6 +35,49 @@ class Config {
|
|
|
34
35
|
}
|
|
35
36
|
return conf;
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get full source paths
|
|
41
|
+
*
|
|
42
|
+
* @type {GetPathFunc}
|
|
43
|
+
*/
|
|
44
|
+
getSourcePaths = (srcParts, srcRoot) => {
|
|
45
|
+
const sp = Object.assign({}, srcParts);
|
|
46
|
+
for (const [k, v] of Object.entries(sp)) {
|
|
47
|
+
sp[k] = `${srcRoot}${v}`; // extend path
|
|
48
|
+
}
|
|
49
|
+
return sp;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get full target paths
|
|
54
|
+
*
|
|
55
|
+
* @type {GetPathFunc}
|
|
56
|
+
*/
|
|
57
|
+
getTargetPaths = (tgtPaths, tgtRoot, tgtAssetsRoot) => {
|
|
58
|
+
return {
|
|
59
|
+
assets: `${tgtRoot}${tgtAssetsRoot}`,
|
|
60
|
+
css: `${tgtRoot}${tgtAssetsRoot}${tgtPaths.css}`,
|
|
61
|
+
js: `${tgtRoot}${tgtAssetsRoot}${tgtPaths.js}`,
|
|
62
|
+
moduleAssets: `${tgtRoot}${tgtAssetsRoot}${tgtPaths.moduleAssets}`,
|
|
63
|
+
prototype: `${tgtRoot}${tgtPaths.prototype}`,
|
|
64
|
+
markdown: `${tgtRoot}${tgtPaths.markdown}`
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get inputs for esbuild
|
|
70
|
+
*
|
|
71
|
+
* @type {ScriptEntryFunc}
|
|
72
|
+
*/
|
|
73
|
+
getScriptEntries = (modEntries, mainEntry = 'main.ts', srcPaths) => {
|
|
74
|
+
const mainEntryPath = `${srcPaths.js}/${mainEntry}`;
|
|
75
|
+
// For code splitting, as input config for esbuild
|
|
76
|
+
const moduleEntryFiles = modEntries.map(f => {
|
|
77
|
+
return `${srcPaths.modules}/${f}`;
|
|
78
|
+
});
|
|
79
|
+
return [mainEntryPath].concat(moduleEntryFiles);
|
|
80
|
+
};
|
|
37
81
|
}
|
|
38
82
|
|
|
39
83
|
const config = new Config();
|
package/lib/typedefs.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path(suffixes) for various source/target files
|
|
3
|
+
* E.g. CSS source files are located in `${basePath}/css`
|
|
4
|
+
* Built/bundled JS files are stored in `${targetAssetsBase}/js`
|
|
5
|
+
*
|
|
6
|
+
* @typedef {Object} PathPart
|
|
7
|
+
* @property {string} assets Path for general static assets
|
|
8
|
+
* @property {string=} css Path for CSS files
|
|
9
|
+
* @property {string=} js Path for JS files
|
|
10
|
+
* @property {string=} modules Path for module directories / files
|
|
11
|
+
* @property {string=} moduleAssets Path for assets of individual modules
|
|
12
|
+
* @property {string=} prototype Path for prototype (HTML) files
|
|
13
|
+
* @property {string=} test Path for unit-test related files
|
|
14
|
+
* @property {string=} markdown Path for markdown files
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Helper to create an array with input source TS files for esbuild
|
|
19
|
+
*
|
|
20
|
+
* @typedef {Function} ScriptEntryFunc
|
|
21
|
+
* @param {string[]} modEntries Array of module entry TS files
|
|
22
|
+
* @param {string} [mainEntry=main.ts] Main entry TS file, default `main.ts`
|
|
23
|
+
* @param {PathPart} srcPaths
|
|
24
|
+
* @return {string[]}
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Helper to append base path to source/target path-suffixes
|
|
29
|
+
*
|
|
30
|
+
* @typedef {Function} GetPathFunc
|
|
31
|
+
*
|
|
32
|
+
* @param {PathPart} paths Path suffixes of various types e.g. `/css`, `/js`, `/md` (starts with slash)
|
|
33
|
+
* @param {string} root Root path of source/target
|
|
34
|
+
* @param {string=} assetsRoot Only for target: assets root path e.g. `${targetRoot}/assets/_sn_`
|
|
35
|
+
* @return {PathPart}
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {Object} SNConfig
|
|
40
|
+
* @property {string} sourceRoot Root dir of source
|
|
41
|
+
* @property {string} targetRoot Root dir for output (target)
|
|
42
|
+
* @property {PathPart} sourcePath Paths of different types of source files
|
|
43
|
+
* @property {string} targetAssetsRoot
|
|
44
|
+
* @property {PathPart} targetPath Paths for different output files
|
|
45
|
+
* @property {string[]} tenants Theme-names
|
|
46
|
+
* @property {string[]} moduleEntries List of input files of modules e.g. 'mod-foo/foo.ts'
|
|
47
|
+
* @property {string} mainEntryFile The entry point of all JS e.g. main.ts
|
|
48
|
+
* @property {string} assetsUrlPath Path of assets used in URL for resource loading etc.
|
|
49
|
+
* @property {boolean} markdownEnabled Enable markdown feature or not
|
|
50
|
+
* @property {Object} njkGlobals Global variables assigned to Nunjucks compiler
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
export {};
|
package/lib/vars.mjs
CHANGED
|
@@ -1,61 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* Path(suffixes) for various source/target files
|
|
3
|
-
* E.g. CSS source files are located in `${basePath}/css`
|
|
4
|
-
* Built JS in `${targetAssetsBase}/js`
|
|
5
|
-
*
|
|
6
|
-
* @typedef {Object} PathPart
|
|
7
|
-
* @property {string} assets Path for general static assets
|
|
8
|
-
* @property {string=} css Path for CSS files
|
|
9
|
-
* @property {string=} js Path for JS files
|
|
10
|
-
* @property {string=} modules Path for module directories / files
|
|
11
|
-
* @property {string=} moduleAssets Path for assets of individual modules
|
|
12
|
-
* @property {string=} prototype Path for prototype (HTML) files
|
|
13
|
-
* @property {string=} test Path for unit-test related files
|
|
14
|
-
* @property {string=} markdown Path for markdown files
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Helper to create an array with input source TS files for esbuild
|
|
19
|
-
*
|
|
20
|
-
* @typedef {Function} ScriptEntryFunc
|
|
21
|
-
* @param {string[]} modEntries Array of module entry TS files
|
|
22
|
-
* @param {string=} mainEntry Main entry TS file, default `main.ts`
|
|
23
|
-
* @param {PathPart} srcPaths
|
|
24
|
-
* @return {string[]}
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Helper to append base path to source/target path-suffixes
|
|
29
|
-
*
|
|
30
|
-
* @typedef {Function} GetPathFunc
|
|
31
|
-
*
|
|
32
|
-
* @param {PathPart} paths Path suffixes of various types e.g. `/css`, `/js`, `/md` (do with slash)
|
|
33
|
-
* @param {string} root Root path of source/target
|
|
34
|
-
* @param {string=} assetsRoot Only for target: assets root path e.g. `${targetRoot}/assets/_sn_`
|
|
35
|
-
* @return {PathPart}
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @typedef {Object} SNConfig
|
|
40
|
-
* @property {string} sourceRoot Root dir of source
|
|
41
|
-
* @property {string} targetRoot Root dir for output (target)
|
|
42
|
-
* @property {PathPart} sourcePath Paths of different types of source files
|
|
43
|
-
* @property {GetPathFunc} getSourcePaths
|
|
44
|
-
* @property {string} targetAssetsRoot
|
|
45
|
-
* @property {PathPart} targetPath Paths for different output files
|
|
46
|
-
* @property {GetPathFunc} getTargetPaths
|
|
47
|
-
* @property {string[]} tenants Theme-names
|
|
48
|
-
* @property {string[]} moduleEntries List of input files of modules e.g. 'mod-foo/foo.ts'
|
|
49
|
-
* @property {string} mainEntryFile The entry point of all JS e.g. main.ts
|
|
50
|
-
* @property {ScriptEntryFunc} getScriptEntries Inputs of source files for esbuild
|
|
51
|
-
* @property {string} assetsUrlPath Path of assets used in URL for resource loading etc.
|
|
52
|
-
* @property {boolean} markdownEnabled Enable markdown feature or not
|
|
53
|
-
* @property {Record<string, string>} njkGlobals Global variables assigned to Nunjucks compiler
|
|
54
|
-
*/
|
|
1
|
+
import './typedefs.mjs';
|
|
55
2
|
|
|
56
3
|
// default config values
|
|
57
|
-
const moduleEntries = [];
|
|
58
|
-
|
|
59
4
|
const sourceRoot = './src/main/webapp';
|
|
60
5
|
const targetRoot = './tgt/static';
|
|
61
6
|
|
|
@@ -70,21 +15,9 @@ const sourcePath = {
|
|
|
70
15
|
markdown: '/md'
|
|
71
16
|
};
|
|
72
17
|
|
|
73
|
-
/**
|
|
74
|
-
* Extend source paths
|
|
75
|
-
*
|
|
76
|
-
* @type {GetPathFunc}
|
|
77
|
-
*/
|
|
78
|
-
const getSourcePaths = (srcParts, srcRoot) => {
|
|
79
|
-
const sp = Object.assign({}, srcParts);
|
|
80
|
-
for (const [k, v] of Object.entries(sp)) {
|
|
81
|
-
sp[k] = `${srcRoot}${v}`; // extend path
|
|
82
|
-
}
|
|
83
|
-
return sp;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
18
|
const targetAssetsRoot = '/assets/_sn_';
|
|
87
19
|
|
|
20
|
+
/** @type {PathPart} */
|
|
88
21
|
const targetPath = {
|
|
89
22
|
assets: '',
|
|
90
23
|
css: '/css',
|
|
@@ -94,37 +27,12 @@ const targetPath = {
|
|
|
94
27
|
markdown: '/docs'
|
|
95
28
|
};
|
|
96
29
|
|
|
97
|
-
/**
|
|
98
|
-
* Target paths
|
|
99
|
-
*
|
|
100
|
-
* @type {GetPathFunc}
|
|
101
|
-
*/
|
|
102
|
-
const getTargetPaths = (tgtPaths, tgtRoot = targetRoot, tgtAssetsRoot = targetAssetsRoot) => {
|
|
103
|
-
return {
|
|
104
|
-
assets: `${tgtRoot}${tgtAssetsRoot}`,
|
|
105
|
-
css: `${tgtRoot}${tgtAssetsRoot}${tgtPaths.css}`,
|
|
106
|
-
js: `${tgtRoot}${tgtAssetsRoot}${tgtPaths.js}`,
|
|
107
|
-
moduleAssets: `${tgtRoot}${tgtAssetsRoot}${tgtPaths.moduleAssets}`,
|
|
108
|
-
prototype: `${tgtRoot}${tgtPaths.prototype}`,
|
|
109
|
-
markdown: `${tgtRoot}${tgtPaths.markdown}`
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
30
|
// "themes", not in use, replaced with brands directory
|
|
114
31
|
const tenants = ['one', 'two', 'three'];
|
|
115
32
|
|
|
116
|
-
const
|
|
33
|
+
const moduleEntries = [];
|
|
117
34
|
|
|
118
|
-
|
|
119
|
-
/** @type {ScriptEntryFunc} */
|
|
120
|
-
const getScriptEntries = (modEntries, mainEntry = mainEntryFile, srcPaths) => {
|
|
121
|
-
const mainEntryPath = `${srcPaths.js}/${mainEntry}`;
|
|
122
|
-
// For code splitting, as input config for esbuild
|
|
123
|
-
const moduleEntryFiles = modEntries.map(f => {
|
|
124
|
-
return `${srcPaths.modules}/${f}`;
|
|
125
|
-
});
|
|
126
|
-
return [mainEntryPath].concat(moduleEntryFiles);
|
|
127
|
-
};
|
|
35
|
+
const mainEntryFile = 'main.ts';
|
|
128
36
|
|
|
129
37
|
// To get relative path of assets
|
|
130
38
|
const assetsUrlPath = '/assets/_sn_';
|
|
@@ -142,14 +50,11 @@ const config = {
|
|
|
142
50
|
sourceRoot,
|
|
143
51
|
targetRoot,
|
|
144
52
|
sourcePath,
|
|
145
|
-
getSourcePaths,
|
|
146
53
|
targetAssetsRoot,
|
|
147
54
|
targetPath,
|
|
148
|
-
getTargetPaths,
|
|
149
55
|
tenants,
|
|
150
56
|
moduleEntries,
|
|
151
57
|
mainEntryFile,
|
|
152
|
-
getScriptEntries,
|
|
153
58
|
assetsUrlPath,
|
|
154
59
|
markdownEnabled,
|
|
155
60
|
njkGlobals
|