@polylith/builder 0.0.31 → 0.0.33
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/App.js +23 -6
- package/ConfigApp.js +2 -2
- package/ConfigFeature.js +3 -2
- package/Files.js +56 -32
- package/loaderTemplate.js +12 -0
- package/package.json +1 -1
- package/plugin-copy-resources.js +7 -2
- package/plugin-features.js +3 -1
- package/plugin-jsconfig.js +147 -0
- package/plugin-loader.js +40 -17
package/App.js
CHANGED
|
@@ -11,6 +11,8 @@ import loader from './plugin-loader.js';
|
|
|
11
11
|
import mainHTML from './plugin-main-html.js';
|
|
12
12
|
import features from './plugin-features.js';
|
|
13
13
|
import styles from "rollup-plugin-styles";
|
|
14
|
+
import resources from "./plugin-copy-resources.js";
|
|
15
|
+
import jsconfig from "./plugin-jsconfig.js";
|
|
14
16
|
|
|
15
17
|
import ConfigFeature from './ConfigFeature.js';
|
|
16
18
|
import Files from './Files.js';
|
|
@@ -52,7 +54,7 @@ export default class App {
|
|
|
52
54
|
this.root = root;
|
|
53
55
|
|
|
54
56
|
var filename = path.posix.join(root, index);
|
|
55
|
-
this.sourcePath = path.posix.
|
|
57
|
+
this.sourcePath = path.posix.dirname(filename);
|
|
56
58
|
this.destPath = path.posix.join(root, dest);
|
|
57
59
|
|
|
58
60
|
this.name = name;
|
|
@@ -65,7 +67,7 @@ export default class App {
|
|
|
65
67
|
this.configs = {};
|
|
66
68
|
this.manualChunkType = 'function';
|
|
67
69
|
this.manualChunks = [];
|
|
68
|
-
this.files = new Files(sourcePath, destPath)
|
|
70
|
+
this.files = new Files(this.sourcePath, this.destPath)
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
static fileToPath(filename) {
|
|
@@ -158,7 +160,7 @@ export default class App {
|
|
|
158
160
|
* the application source folder.
|
|
159
161
|
*/
|
|
160
162
|
addFeatureIndex(index) {
|
|
161
|
-
this.featureIndexes.push(index);
|
|
163
|
+
this.featureIndexes.push(path.join(this.sourcePath, index));
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
/**
|
|
@@ -325,7 +327,20 @@ export default class App {
|
|
|
325
327
|
* ready methods will be called on all services starting with this
|
|
326
328
|
* prefix.
|
|
327
329
|
*/
|
|
328
|
-
addLoadable(name, main, prefix) {
|
|
330
|
+
async addLoadable(name, main, prefix, css) {
|
|
331
|
+
// expand css specs
|
|
332
|
+
var files = new Files(this.sourcePath, this.destPath)
|
|
333
|
+
resourceSpecs.forEach(function(spec) {
|
|
334
|
+
files.addCopySpec(root, spec);
|
|
335
|
+
}, this)
|
|
336
|
+
var cssUris = [];
|
|
337
|
+
var expanded = await files.findAllFiles();
|
|
338
|
+
var keys = Object.keys(expanded);
|
|
339
|
+
keys.forEach(function(key){
|
|
340
|
+
var file = expanded[key];
|
|
341
|
+
cssUris.push(file.uri)
|
|
342
|
+
}, this)
|
|
343
|
+
|
|
329
344
|
var dest = path.posix.join(this.sourcePath, main);
|
|
330
345
|
this.loadables.push({name, path: dest, prefix});
|
|
331
346
|
}
|
|
@@ -364,6 +379,7 @@ export default class App {
|
|
|
364
379
|
}),
|
|
365
380
|
loader(this.loadables),
|
|
366
381
|
features(this.featureIndexes),
|
|
382
|
+
jsconfig(this.root),
|
|
367
383
|
html({
|
|
368
384
|
include: path.join(this.sourcePath, "**/*.html"),
|
|
369
385
|
}),
|
|
@@ -373,7 +389,8 @@ export default class App {
|
|
|
373
389
|
source: this.htmlTemplate.source,
|
|
374
390
|
destination: this.htmlTemplate.destination,
|
|
375
391
|
replaceVars: {},
|
|
376
|
-
})
|
|
392
|
+
}),
|
|
393
|
+
resources(this.name, this.files)
|
|
377
394
|
],
|
|
378
395
|
},
|
|
379
396
|
output : {
|
|
@@ -425,7 +442,7 @@ export default class App {
|
|
|
425
442
|
watch() {
|
|
426
443
|
var watchConfig = {
|
|
427
444
|
...this.config.input,
|
|
428
|
-
|
|
445
|
+
output: [this.config.output.output],
|
|
429
446
|
...this.config.watch,
|
|
430
447
|
}
|
|
431
448
|
|
package/ConfigApp.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import App from './App';
|
|
1
|
+
import App from './App.js';
|
|
2
2
|
import path from 'node:path/posix';
|
|
3
3
|
|
|
4
4
|
export default class ConfigApp extends App {
|
|
5
5
|
constructor (config, root) {
|
|
6
|
-
App.fixPath(root);
|
|
6
|
+
root = App.fixPath(root);
|
|
7
7
|
var name = config.name || 'unnamed';
|
|
8
8
|
var index = config.index || path.join(root, 'src', 'index.js');
|
|
9
9
|
var dest = config.dest || path.join(root, 'dist');
|
package/ConfigFeature.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Feature from './Feature.js';
|
|
2
|
+
import path from 'node:path/posix';
|
|
2
3
|
|
|
3
4
|
export default class ConfigFeature extends Feature {
|
|
4
5
|
/**
|
|
@@ -22,12 +23,12 @@ export default class ConfigFeature extends Feature {
|
|
|
22
23
|
if (config.loadables && Array.isArray(config.loadables)) {
|
|
23
24
|
config.loadables.forEach(function(loadable) {
|
|
24
25
|
if (loadable.name && loadable.index) {
|
|
25
|
-
app.addLoadable(loadable.name, loadable.index, loadable.prefix);
|
|
26
|
+
app.addLoadable(loadable.name, path.join(this.root, loadable.index), loadable.prefix, loadable.css);
|
|
26
27
|
}
|
|
27
28
|
}, this);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
if (config.index) app.addFeatureIndex(config.index);
|
|
31
|
+
if (config.index) app.addFeatureIndex(path.join(this.root, config.index));
|
|
31
32
|
if (config.config) app.addConfig(config.config, this.root);
|
|
32
33
|
if (config.resources && Array.isArray(config.resources)) app.addResources(config.resources, this.root);
|
|
33
34
|
}
|
package/Files.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fg from 'fast-glob';
|
|
2
2
|
import path from 'node:path/posix'
|
|
3
3
|
import {ensureDir} from 'fs-extra';
|
|
4
|
+
import { copyFile } from 'node:fs/promises';
|
|
5
|
+
import App from './App.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @typedef {Object} CopySpec
|
|
@@ -35,7 +37,7 @@ export default class Files {
|
|
|
35
37
|
* @param {String} src the abolute path to the applications source
|
|
36
38
|
* directory
|
|
37
39
|
*/
|
|
38
|
-
constructor(
|
|
40
|
+
constructor(src, dest) {
|
|
39
41
|
this.dest = dest;
|
|
40
42
|
this.src = src;
|
|
41
43
|
this.files = {};
|
|
@@ -57,6 +59,28 @@ export default class Files {
|
|
|
57
59
|
this.specs.push(spec);
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
/**
|
|
63
|
+
* call this methid to generate the destination filename from the spec and
|
|
64
|
+
* the source filename
|
|
65
|
+
*
|
|
66
|
+
* @param {CopySpec} spec the spec that generate the filename
|
|
67
|
+
* @param {String} srcFilename the source filename
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
makeDestination(searchRoot, spec, srcFilename) {
|
|
71
|
+
var fullPath = searchRoot;
|
|
72
|
+
var relativePath = srcFilename.slice(fullPath.length + 1);
|
|
73
|
+
var destFilename = '';
|
|
74
|
+
|
|
75
|
+
if (spec.keepNest) {
|
|
76
|
+
destFilename = path.join(this.dest, spec.dest, relativePath);
|
|
77
|
+
} else {
|
|
78
|
+
destFilename = path.join(this.dest, spec.dest, path.basename(srcFilename));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return destFilename;
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
/**
|
|
61
85
|
* Call this method once per spec to add a list of files to the complete
|
|
62
86
|
* list of all the files to be copied. If multiple files are found through
|
|
@@ -73,20 +97,43 @@ export default class Files {
|
|
|
73
97
|
// Since file paths here are absolute tthis will always be based on the
|
|
74
98
|
// string length.
|
|
75
99
|
files.forEach(function(file) {
|
|
100
|
+
file = App.fixPath(file);
|
|
76
101
|
// reconcile conflicts
|
|
77
102
|
if (this.files[file]) {
|
|
78
|
-
copyInfo = this.files[file];
|
|
103
|
+
var copyInfo = this.files[file];
|
|
79
104
|
if (copyInfo.searchRoot.length > searchRoot.length) return;
|
|
80
105
|
}
|
|
106
|
+
var destination = this.makeDestination(searchRoot, spec, file);
|
|
107
|
+
var uri = destination.slice(this.dest.length + 1);
|
|
81
108
|
|
|
82
109
|
this.files[file] = {
|
|
83
110
|
name: file,
|
|
111
|
+
destFilename: destination,
|
|
112
|
+
uri: uri,
|
|
84
113
|
searchRoot: searchRoot,
|
|
85
114
|
spec: spec,
|
|
86
115
|
}
|
|
87
116
|
}, this)
|
|
88
117
|
}
|
|
89
118
|
|
|
119
|
+
async findFiles(spec) {
|
|
120
|
+
var searchRoot = path.join(this.src, spec.root, spec.cwd);
|
|
121
|
+
var options = {
|
|
122
|
+
cwd: searchRoot,
|
|
123
|
+
ignore: ['**/node_modules'],
|
|
124
|
+
absolute: true,
|
|
125
|
+
onlyFiles: true,
|
|
126
|
+
unique: true,
|
|
127
|
+
dot: true,
|
|
128
|
+
}
|
|
129
|
+
var fullGlob = path.join(searchRoot, spec.glob);
|
|
130
|
+
var files = await fg(fullGlob, options);
|
|
131
|
+
|
|
132
|
+
this.addFiles(searchRoot, files, spec);
|
|
133
|
+
|
|
134
|
+
return this.files;
|
|
135
|
+
}
|
|
136
|
+
|
|
90
137
|
/**
|
|
91
138
|
* Call this method to locate all the files to be found from all the copy
|
|
92
139
|
* specs that have been added
|
|
@@ -98,22 +145,10 @@ export default class Files {
|
|
|
98
145
|
// using a for loop here because we are making async calls
|
|
99
146
|
for (let idx = 0; idx < this.specs.length; idx++) {
|
|
100
147
|
let spec = this.specs[idx];
|
|
101
|
-
|
|
102
|
-
let options = {
|
|
103
|
-
cwd: searchRoot,
|
|
104
|
-
ignore: ['**/node_modules'],
|
|
105
|
-
absolute: true,
|
|
106
|
-
onlyFiles: true,
|
|
107
|
-
unique: true,
|
|
108
|
-
dot: true,
|
|
109
|
-
}
|
|
110
|
-
let fullGlob = path.join(searchPath, spec.glob);
|
|
111
|
-
let files = await fg(fullGlob, options);
|
|
112
|
-
|
|
113
|
-
this.addFiles(searchRoot, files, spec);
|
|
148
|
+
await this.findFiles(spec);
|
|
114
149
|
}
|
|
115
150
|
|
|
116
|
-
return this.files
|
|
151
|
+
return this.files;
|
|
117
152
|
}
|
|
118
153
|
|
|
119
154
|
/**
|
|
@@ -124,28 +159,17 @@ export default class Files {
|
|
|
124
159
|
await this.findAllFiles();
|
|
125
160
|
|
|
126
161
|
var filenames = Object.keys(this.files);
|
|
127
|
-
|
|
128
162
|
// using a for loop because we are making async calls
|
|
129
163
|
for (let idx = 0 ; idx < filenames.length; idx++) {
|
|
130
164
|
let srcFilename = filenames[idx];
|
|
131
|
-
let
|
|
132
|
-
|
|
133
|
-
let destFilename = '';
|
|
134
|
-
|
|
135
|
-
if (spec.keepNest) {
|
|
136
|
-
destFilename = path.join(this.dest, spec.dest, relativePath);
|
|
137
|
-
} else {
|
|
138
|
-
destFilename = path.join(this.dest, spec.dest, path.basename(srcFilename));
|
|
139
|
-
}
|
|
140
|
-
|
|
165
|
+
let destFilename = this.files[srcFilename].destFilename;
|
|
166
|
+
var destFilePath = path.dirname(destFilename);
|
|
141
167
|
// we will override existing destination files. This could have
|
|
142
168
|
// unintended consequences
|
|
143
169
|
try {
|
|
144
|
-
console.log(`copying ${srcFilename} to ${destFilename}`);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
await fs.copyFiles(srcFilename, destFilename);
|
|
148
|
-
*/
|
|
170
|
+
// console.log(`copying ${srcFilename} to ${destFilename}`);
|
|
171
|
+
await ensureDir(destFilePath);
|
|
172
|
+
await copyFile(srcFilename, destFilename);
|
|
149
173
|
} catch (e) {
|
|
150
174
|
console.error(`Error copying file ${srcFilename} to ${destFilename}`);
|
|
151
175
|
throw e;
|
package/package.json
CHANGED
package/plugin-copy-resources.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
var copied= {}
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
*
|
|
3
5
|
* @param {Files} files the files object that specifies the resource files to
|
|
4
6
|
* copy
|
|
5
7
|
* @returns {Object} the plugin
|
|
6
8
|
*/
|
|
7
|
-
export default function(files) {
|
|
9
|
+
export default function(name, files) {
|
|
8
10
|
return {
|
|
9
|
-
name: "main-html-
|
|
11
|
+
name: "main-html-resources",
|
|
10
12
|
|
|
11
13
|
async generateBundle(outputOptions, bundleInfo) {
|
|
14
|
+
// assets are not watched, never copy more than once
|
|
15
|
+
if (copied[name]) return;
|
|
12
16
|
return new Promise(async function (resolve, reject) {
|
|
13
17
|
try {
|
|
14
18
|
await files.copyFiles();
|
|
15
19
|
resolve(true)
|
|
20
|
+
copied[name] = true;
|
|
16
21
|
} catch (e) {
|
|
17
22
|
reject(e)
|
|
18
23
|
}
|
package/plugin-features.js
CHANGED
|
@@ -2,11 +2,13 @@ function makeSource(features) {
|
|
|
2
2
|
|
|
3
3
|
var importStatements = '';
|
|
4
4
|
features.forEach(function(feature) {
|
|
5
|
-
importStatements += `import
|
|
5
|
+
importStatements += `import ${JSON.stringify(feature)}\n`;
|
|
6
6
|
})
|
|
7
7
|
|
|
8
8
|
var source = `${importStatements}`
|
|
9
9
|
|
|
10
|
+
console.log('@polylith/features');
|
|
11
|
+
console.log(source);
|
|
10
12
|
return source;
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import path from 'node:path/posix';
|
|
2
|
+
import {readFile, writeFile, stat} from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
async function fileExists(path) {
|
|
5
|
+
try {
|
|
6
|
+
await stat(path)
|
|
7
|
+
return true;
|
|
8
|
+
} catch (e) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function fixPath(src) {
|
|
14
|
+
src = src.replace('file:', '');
|
|
15
|
+
src = src.replace('///', '');
|
|
16
|
+
src = src.replace(/.:/, '');
|
|
17
|
+
src = src.replace(/\\/g, '/');
|
|
18
|
+
|
|
19
|
+
return src;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Matches pattern with a single star against search.
|
|
26
|
+
* Star must match at least one character to be considered a match.
|
|
27
|
+
*
|
|
28
|
+
* @param patttern for example "foo*"
|
|
29
|
+
* @param search for example "fooawesomebar"
|
|
30
|
+
* @returns the part of search that * matches, or undefined if no match.
|
|
31
|
+
*/
|
|
32
|
+
function matchStar(pattern, search) {
|
|
33
|
+
if (search.length < pattern.length) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (pattern === "*") {
|
|
37
|
+
return search;
|
|
38
|
+
}
|
|
39
|
+
const star = pattern.indexOf("*");
|
|
40
|
+
|
|
41
|
+
if (star === -1) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const part1 = pattern.substring(0, star);
|
|
46
|
+
const part2 = pattern.substring(star + 1);
|
|
47
|
+
|
|
48
|
+
if (search.substr(0, star) !== part1) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (search.substr(search.length - part2.length) !== part2) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return search.substr(star, search.length - part2.length);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function findPathMatch(base, source, paths) {
|
|
60
|
+
var patterns = Object.keys(paths);
|
|
61
|
+
var source = fixPath(source);
|
|
62
|
+
|
|
63
|
+
if (source.indexOf(base) === 0) return
|
|
64
|
+
// source = source.slice(base.length);
|
|
65
|
+
|
|
66
|
+
console.log('>>>', source)
|
|
67
|
+
for(let patternIdx = 0; patternIdx < patterns.length; patternIdx++) {
|
|
68
|
+
let pattern = patterns[patternIdx];
|
|
69
|
+
let searches = paths[pattern];
|
|
70
|
+
let capture = matchStar(pattern, source);
|
|
71
|
+
if (!capture) continue;
|
|
72
|
+
|
|
73
|
+
if (!Array.isArray(searches)) continue;
|
|
74
|
+
for (let searchIdx = 0; searchIdx < searches.length; searchIdx++) {
|
|
75
|
+
var tryName = path.join(base, searches[searchIdx].replace('*', capture));
|
|
76
|
+
console.log('\t..', searches[searchIdx], tryName);
|
|
77
|
+
|
|
78
|
+
if (await fileExists(tryName)) {
|
|
79
|
+
return tryName;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export default function features(root) {
|
|
87
|
+
var jsConfig;
|
|
88
|
+
var basePath;
|
|
89
|
+
var paths;
|
|
90
|
+
var previouslyMatched = {};
|
|
91
|
+
|
|
92
|
+
console.log('====root', root);
|
|
93
|
+
async function readJsConfig() {
|
|
94
|
+
var jsConfigPath = path.join(root, 'jsconfig.json');
|
|
95
|
+
var exists = await fileExists(jsConfigPath);
|
|
96
|
+
if (!exists) {
|
|
97
|
+
jsConfig === false;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
let content = JSON.parse(await readFile(jsConfigPath));
|
|
103
|
+
basePath = content.compilerOptions.baseUrl;
|
|
104
|
+
paths = content.compilerOptions.paths;
|
|
105
|
+
jsConfig = content;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.err(e)
|
|
108
|
+
jsConfig = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
name: 'features',
|
|
115
|
+
|
|
116
|
+
async resolveId (source, importer, options) {
|
|
117
|
+
source = fixPath(source);
|
|
118
|
+
|
|
119
|
+
// console.log('---', source);
|
|
120
|
+
if (previouslyMatched[source] !== undefined) return previouslyMatched[source];
|
|
121
|
+
previouslyMatched[source] === null;
|
|
122
|
+
|
|
123
|
+
if (jsConfig === undefined) await readJsConfig();
|
|
124
|
+
if (!jsConfig) return null;
|
|
125
|
+
|
|
126
|
+
if (basePath) {
|
|
127
|
+
var tryName = path.join(root, basePath, source);
|
|
128
|
+
if (await fileExists(tryName)) {
|
|
129
|
+
previouslyMatched[source] = tryName;
|
|
130
|
+
return tryName;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (paths) {
|
|
134
|
+
if (source.indexOf(root) === 0) return null;
|
|
135
|
+
|
|
136
|
+
var matchedPath = await findPathMatch(path.join(root, basePath), source, paths);
|
|
137
|
+
|
|
138
|
+
if (matchedPath) {
|
|
139
|
+
previouslyMatched[source] = matchedPath;
|
|
140
|
+
return matchedPath;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
package/plugin-loader.js
CHANGED
|
@@ -1,15 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'node:path/posix';
|
|
2
|
+
import {readFile, writeFile, stat} from 'node:fs/promises';
|
|
3
|
+
var templateSource;
|
|
4
|
+
|
|
5
|
+
async function fileExists(path) {
|
|
6
|
+
try {
|
|
7
|
+
await stat(path)
|
|
8
|
+
return true;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
2
13
|
|
|
14
|
+
function makeSource(loadables) {
|
|
3
15
|
var loadableSwitches = '';
|
|
4
16
|
|
|
17
|
+
function makeCss() {
|
|
18
|
+
if (!loadable.css) return '';
|
|
19
|
+
var jsonCss = JSON.stringify(loadable.css);
|
|
20
|
+
return (
|
|
21
|
+
` App.loadCss(${jsonCss});`
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function makeServices() {
|
|
27
|
+
if (!loadable.prefix) return '';
|
|
28
|
+
return (
|
|
29
|
+
` await registry.start('${loadable.prefix}');`
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
5
33
|
loadables.forEach(function(loadable) {
|
|
6
34
|
var prefixStr = ';';
|
|
35
|
+
var cssStr = makeCss();
|
|
36
|
+
var serviceStr = makeServices();
|
|
7
37
|
|
|
8
|
-
if (loadable.prefix) {
|
|
38
|
+
if (loadable.prefix || loadable.css) {
|
|
9
39
|
prefixStr = `
|
|
10
40
|
.then(async function(result) {
|
|
11
|
-
|
|
12
|
-
|
|
41
|
+
${cssStr}
|
|
42
|
+
${serviceStr}
|
|
13
43
|
});
|
|
14
44
|
`
|
|
15
45
|
}
|
|
@@ -22,19 +52,9 @@ function makeSource(loadables) {
|
|
|
22
52
|
loadableSwitches += switchStr;
|
|
23
53
|
})
|
|
24
54
|
|
|
25
|
-
var source =
|
|
26
|
-
|
|
27
|
-
import {registry} from '@polylith/core';
|
|
28
|
-
|
|
29
|
-
export async function load(name) {
|
|
30
|
-
var promise;
|
|
55
|
+
var source = templateSource;
|
|
56
|
+
var source = source.replace('{{SWITCHES}}', loadableSwitches);
|
|
31
57
|
|
|
32
|
-
switch (name) {
|
|
33
|
-
${loadableSwitches}
|
|
34
|
-
}
|
|
35
|
-
return promise;
|
|
36
|
-
}
|
|
37
|
-
`
|
|
38
58
|
return source;
|
|
39
59
|
}
|
|
40
60
|
|
|
@@ -49,7 +69,10 @@ export default function loader(loadables) {
|
|
|
49
69
|
return null;
|
|
50
70
|
},
|
|
51
71
|
|
|
52
|
-
load (id) {
|
|
72
|
+
async load (id) {
|
|
73
|
+
if (templateSource) {
|
|
74
|
+
templateSource = await readFile('./loaderTemplate.js');
|
|
75
|
+
}
|
|
53
76
|
if (id === '@polylith/loader') {
|
|
54
77
|
return makeSource(loadables);
|
|
55
78
|
}
|