@polylith/builder 0.0.31 → 0.0.32
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 +5 -3
- package/ConfigApp.js +1 -1
- package/Files.js +13 -9
- package/package.json +1 -1
- package/plugin-copy-resources.js +7 -2
package/App.js
CHANGED
|
@@ -11,6 +11,7 @@ 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";
|
|
14
15
|
|
|
15
16
|
import ConfigFeature from './ConfigFeature.js';
|
|
16
17
|
import Files from './Files.js';
|
|
@@ -52,7 +53,7 @@ export default class App {
|
|
|
52
53
|
this.root = root;
|
|
53
54
|
|
|
54
55
|
var filename = path.posix.join(root, index);
|
|
55
|
-
this.sourcePath = path.posix.
|
|
56
|
+
this.sourcePath = path.posix.dirname(filename);
|
|
56
57
|
this.destPath = path.posix.join(root, dest);
|
|
57
58
|
|
|
58
59
|
this.name = name;
|
|
@@ -65,7 +66,7 @@ export default class App {
|
|
|
65
66
|
this.configs = {};
|
|
66
67
|
this.manualChunkType = 'function';
|
|
67
68
|
this.manualChunks = [];
|
|
68
|
-
this.files = new Files(sourcePath, destPath)
|
|
69
|
+
this.files = new Files(this.sourcePath, this.destPath)
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
static fileToPath(filename) {
|
|
@@ -373,7 +374,8 @@ export default class App {
|
|
|
373
374
|
source: this.htmlTemplate.source,
|
|
374
375
|
destination: this.htmlTemplate.destination,
|
|
375
376
|
replaceVars: {},
|
|
376
|
-
})
|
|
377
|
+
}),
|
|
378
|
+
resources(this.name, this.files)
|
|
377
379
|
],
|
|
378
380
|
},
|
|
379
381
|
output : {
|
package/ConfigApp.js
CHANGED
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 = {};
|
|
@@ -73,9 +75,10 @@ export default class Files {
|
|
|
73
75
|
// Since file paths here are absolute tthis will always be based on the
|
|
74
76
|
// string length.
|
|
75
77
|
files.forEach(function(file) {
|
|
78
|
+
file = App.fixPath(file);
|
|
76
79
|
// reconcile conflicts
|
|
77
80
|
if (this.files[file]) {
|
|
78
|
-
copyInfo = this.files[file];
|
|
81
|
+
var copyInfo = this.files[file];
|
|
79
82
|
if (copyInfo.searchRoot.length > searchRoot.length) return;
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -107,7 +110,7 @@ export default class Files {
|
|
|
107
110
|
unique: true,
|
|
108
111
|
dot: true,
|
|
109
112
|
}
|
|
110
|
-
let fullGlob = path.join(
|
|
113
|
+
let fullGlob = path.join(searchRoot, spec.glob);
|
|
111
114
|
let files = await fg(fullGlob, options);
|
|
112
115
|
|
|
113
116
|
this.addFiles(searchRoot, files, spec);
|
|
@@ -123,13 +126,15 @@ export default class Files {
|
|
|
123
126
|
async copyFiles() {
|
|
124
127
|
await this.findAllFiles();
|
|
125
128
|
|
|
126
|
-
var filenames = Object.keys(this.files);
|
|
127
129
|
|
|
130
|
+
var filenames = Object.keys(this.files);
|
|
128
131
|
// using a for loop because we are making async calls
|
|
129
132
|
for (let idx = 0 ; idx < filenames.length; idx++) {
|
|
130
133
|
let srcFilename = filenames[idx];
|
|
131
134
|
let spec = this.files[srcFilename].spec;
|
|
132
|
-
let
|
|
135
|
+
let searchRoot = this.files[srcFilename].searchRoot;
|
|
136
|
+
let fullPath = searchRoot;
|
|
137
|
+
let relativePath = srcFilename.slice(fullPath.length + 1);
|
|
133
138
|
let destFilename = '';
|
|
134
139
|
|
|
135
140
|
if (spec.keepNest) {
|
|
@@ -138,14 +143,13 @@ export default class Files {
|
|
|
138
143
|
destFilename = path.join(this.dest, spec.dest, path.basename(srcFilename));
|
|
139
144
|
}
|
|
140
145
|
|
|
146
|
+
var destFilePath = path.dirname(destFilename);
|
|
141
147
|
// we will override existing destination files. This could have
|
|
142
148
|
// unintended consequences
|
|
143
149
|
try {
|
|
144
150
|
console.log(`copying ${srcFilename} to ${destFilename}`);
|
|
145
|
-
|
|
146
|
-
await
|
|
147
|
-
await fs.copyFiles(srcFilename, destFilename);
|
|
148
|
-
*/
|
|
151
|
+
await ensureDir(destFilePath);
|
|
152
|
+
await copyFile(srcFilename, destFilename);
|
|
149
153
|
} catch (e) {
|
|
150
154
|
console.error(`Error copying file ${srcFilename} to ${destFilename}`);
|
|
151
155
|
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
|
}
|