jizy-packer 2.1.11 → 2.1.13
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/lib/Rollup.js +33 -34
- package/lib/utils.js +22 -0
- package/package.json +1 -1
package/lib/Rollup.js
CHANGED
|
@@ -9,7 +9,7 @@ import terser from '@rollup/plugin-terser';
|
|
|
9
9
|
|
|
10
10
|
import jPackConfig from "./Config.js";
|
|
11
11
|
import LogMe from "./LogMe.js";
|
|
12
|
-
import { emptyTargetPath } from './utils.js';
|
|
12
|
+
import { emptyTargetPath, moveFolderFiles } from './utils.js';
|
|
13
13
|
|
|
14
14
|
export default async function jPackRollup(config) {
|
|
15
15
|
return [
|
|
@@ -81,7 +81,7 @@ export default async function jPackRollup(config) {
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
function generateBuildJs() {
|
|
84
|
-
LogMe.log('Generate
|
|
84
|
+
LogMe.log('Generate build.js');
|
|
85
85
|
|
|
86
86
|
// Read the build template
|
|
87
87
|
let code = fs.readFileSync(jPackConfig.get('buildTemplatePath'), 'utf8');
|
|
@@ -89,7 +89,7 @@ function generateBuildJs() {
|
|
|
89
89
|
// append config callback
|
|
90
90
|
const onGenerateBuildJs = jPackConfig.get('onGenerateBuildJs');
|
|
91
91
|
if (typeof onGenerateBuildJs === 'function') {
|
|
92
|
-
LogMe.log('
|
|
92
|
+
LogMe.log('**onGenerateBuildJs');
|
|
93
93
|
code = onGenerateBuildJs(code);
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -99,15 +99,15 @@ function generateBuildJs() {
|
|
|
99
99
|
fs.writeFileSync(jPackConfig.get('buildJsFilePath'), code, 'utf8');
|
|
100
100
|
|
|
101
101
|
if (fs.existsSync(jPackConfig.get('buildJsFilePath'))) {
|
|
102
|
-
LogMe.log('
|
|
102
|
+
LogMe.log('Build generated in "' + jPackConfig.get('buildJsFilePath') + '"');
|
|
103
103
|
} else {
|
|
104
|
-
console.error('Error:
|
|
104
|
+
console.error('Error: build.js file not found');
|
|
105
105
|
process.exit(1);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
function generateWrappedJs(code) {
|
|
110
|
-
LogMe.log('Generate
|
|
110
|
+
LogMe.log('Generate wrapper.js');
|
|
111
111
|
|
|
112
112
|
const date = new Date();
|
|
113
113
|
const wrapper = fs.readFileSync(jPackConfig.get('wrapperPath'), 'utf8');
|
|
@@ -134,6 +134,7 @@ function generateWrappedJs(code) {
|
|
|
134
134
|
|
|
135
135
|
const onGenerateWrappedJs = jPackConfig.get('onGenerateWrappedJs');
|
|
136
136
|
if (typeof onGenerateWrappedJs === 'function') {
|
|
137
|
+
LogMe.log('**onGenerateWrappedJs');
|
|
137
138
|
wrapped = onGenerateWrappedJs(wrapped);
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -141,32 +142,9 @@ function generateWrappedJs(code) {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
function onPacked() {
|
|
144
|
-
LogMe.log('
|
|
145
|
+
LogMe.log('*onPacked');
|
|
145
146
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const onPacked = jPackConfig.get('onPacked');
|
|
149
|
-
if (typeof onPacked === 'function') {
|
|
150
|
-
onPacked();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Cleanup the build folder
|
|
154
|
-
cleanupBuild();
|
|
155
|
-
|
|
156
|
-
LogMe.log('Build process completed.');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function onComplete() {
|
|
160
|
-
LogMe.log('All done.');
|
|
161
|
-
|
|
162
|
-
const onComplete = jPackConfig.get('onComplete');
|
|
163
|
-
if (typeof onComplete === 'function') {
|
|
164
|
-
onComplete();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function moveCssFiles() {
|
|
169
|
-
LogMe.log('Moving CSS files from js/ to css/ ...');
|
|
147
|
+
LogMe.log('Move CSS files from js/ to css/');
|
|
170
148
|
const targetPath = jPackConfig.get('targetPath');
|
|
171
149
|
|
|
172
150
|
fs.readdirSync(jPackConfig.get('targetRelativePath') + '/js')
|
|
@@ -178,10 +156,14 @@ function moveCssFiles() {
|
|
|
178
156
|
fs.renameSync(oldPath, newPath);
|
|
179
157
|
LogMe.log('- ' + file);
|
|
180
158
|
});
|
|
181
|
-
}
|
|
182
159
|
|
|
183
|
-
|
|
184
|
-
|
|
160
|
+
const onPacked = jPackConfig.get('onPacked');
|
|
161
|
+
if (typeof onPacked === 'function') {
|
|
162
|
+
LogMe.log('**onPacked');
|
|
163
|
+
onPacked();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
LogMe.log('Clean up');
|
|
185
167
|
|
|
186
168
|
// Remove the generated build.js file
|
|
187
169
|
if (fs.existsSync(jPackConfig.get('buildJsFilePath'))) {
|
|
@@ -199,3 +181,20 @@ function cleanupBuild() {
|
|
|
199
181
|
}
|
|
200
182
|
});
|
|
201
183
|
}
|
|
184
|
+
|
|
185
|
+
function onComplete() {
|
|
186
|
+
LogMe.log('*onComplete');
|
|
187
|
+
|
|
188
|
+
if (jPackConfig.get('buildName') === 'example') {
|
|
189
|
+
LogMe.log('Move example files to root example folder');
|
|
190
|
+
const src = path.join(jPackConfig.get('basePath'), 'build/example');
|
|
191
|
+
const dest = path.join(jPackConfig.get('basePath'), 'example');
|
|
192
|
+
moveFolderFiles(src, dest);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const onComplete = jPackConfig.get('onComplete');
|
|
196
|
+
if (typeof onComplete === 'function') {
|
|
197
|
+
LogMe.log('**onComplete');
|
|
198
|
+
onComplete();
|
|
199
|
+
}
|
|
200
|
+
}
|
package/lib/utils.js
CHANGED
|
@@ -94,6 +94,28 @@ export function deleteLessVariablesFile(variablesPath) {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
export function moveFolderFiles(src, dest) {
|
|
98
|
+
if (!fs.existsSync(src)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
103
|
+
|
|
104
|
+
fs.readdirSync(src).forEach(file => {
|
|
105
|
+
const srcPath = path.join(src, file);
|
|
106
|
+
const destPath = path.join(dest, file);
|
|
107
|
+
if (fs.lstatSync(srcPath).isDirectory()) {
|
|
108
|
+
moveFolderFiles(srcPath, destPath);
|
|
109
|
+
} else {
|
|
110
|
+
fs.copyFileSync(srcPath, destPath);
|
|
111
|
+
}
|
|
112
|
+
fs.unlinkSync(srcPath);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
fs.rmdirSync(src);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
|
|
97
119
|
function isObject(item) {
|
|
98
120
|
return (item && typeof item === 'object' && !Array.isArray(item));
|
|
99
121
|
}
|