jizy-packer 2.1.0 → 2.1.2
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/Build.js +4 -17
- package/lib/Cli.js +2 -1
- package/lib/Config.js +3 -2
- package/lib/Rollup.js +3 -3
- package/lib/utils.js +9 -4
- package/package.json +1 -1
package/lib/Build.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { rollup } from 'rollup';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
4
5
|
|
|
5
6
|
import LogMe from "./LogMe.js";
|
|
6
7
|
import jPackConfig from "./Config.js";
|
|
@@ -72,24 +73,8 @@ export default async function jPackBuild({
|
|
|
72
73
|
jPackConfig.set('action', action);
|
|
73
74
|
jPackConfig.set('debug', debug);
|
|
74
75
|
|
|
75
|
-
try {
|
|
76
|
-
LogMe.log('Load jPack config');
|
|
77
|
-
|
|
78
|
-
const jpack = path.join(jPackConfig.get('basePath'), 'config', 'jpack.js');
|
|
79
|
-
if (!fs.existsSync(jpack)) {
|
|
80
|
-
throw new Error('Default jPack config not found in ' + jpack);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
require(jpack);
|
|
84
|
-
|
|
85
|
-
jPackConfig.setPackageVersion();
|
|
86
|
-
} catch (error) {
|
|
87
|
-
LogMe.error(error.message);
|
|
88
|
-
process.exit(1);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
76
|
if (config) {
|
|
92
|
-
LogMe.log('
|
|
77
|
+
LogMe.log('Build config');
|
|
93
78
|
try {
|
|
94
79
|
if (config.substr(0, 1) === '{') {
|
|
95
80
|
LogMe.log(' JSON string');
|
|
@@ -104,6 +89,7 @@ export default async function jPackBuild({
|
|
|
104
89
|
}
|
|
105
90
|
}
|
|
106
91
|
|
|
92
|
+
jPackConfig.setPackageVersion();
|
|
107
93
|
jPackConfig.validate();
|
|
108
94
|
|
|
109
95
|
try {
|
|
@@ -115,6 +101,7 @@ export default async function jPackBuild({
|
|
|
115
101
|
process.exit(1);
|
|
116
102
|
}
|
|
117
103
|
|
|
104
|
+
LogMe.log('---');
|
|
118
105
|
LogMe.log('Launch build ...');
|
|
119
106
|
|
|
120
107
|
try {
|
package/lib/Cli.js
CHANGED
|
@@ -3,8 +3,9 @@ import { hideBin } from 'yargs/helpers';
|
|
|
3
3
|
import jPackBuild from "./Build.js";
|
|
4
4
|
import jPackConfig from "./Config.js";
|
|
5
5
|
|
|
6
|
-
const jPackCli = function () {
|
|
6
|
+
const jPackCli = function (jPackData) {
|
|
7
7
|
jPackConfig.set('basePath', process.cwd());
|
|
8
|
+
jPackData();
|
|
8
9
|
|
|
9
10
|
const command = yargs(hideBin(process.argv))
|
|
10
11
|
.usage('Usage: $0 <command> [options]')
|
package/lib/Config.js
CHANGED
|
@@ -86,8 +86,9 @@ const jPackConfig = {
|
|
|
86
86
|
if (typeof newConfig !== 'object' || newConfig === null) {
|
|
87
87
|
throw new Error('Invalid configuration: newConfig must be an object.');
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
|
|
90
|
+
Object.keys(newConfig).forEach(element => {
|
|
91
|
+
config[element] = newConfig[element];
|
|
91
92
|
});
|
|
92
93
|
},
|
|
93
94
|
|
package/lib/Rollup.js
CHANGED
|
@@ -155,11 +155,11 @@ function moveCssFiles() {
|
|
|
155
155
|
LogMe.log('Moving CSS files from js/ to css/ ...');
|
|
156
156
|
const targetPath = jPackConfig.get('targetPath');
|
|
157
157
|
|
|
158
|
-
fs.readdirSync(targetRelativePath + '/js')
|
|
158
|
+
fs.readdirSync(jPackConfig.get('targetRelativePath') + '/js')
|
|
159
159
|
.filter(file => file.endsWith('.css'))
|
|
160
160
|
.forEach(file => {
|
|
161
|
-
const oldPath = path.join(targetRelativePath + '/js', file);
|
|
162
|
-
const newPath = path.join(targetRelativePath + '/css', file);
|
|
161
|
+
const oldPath = path.join(jPackConfig.get('targetRelativePath') + '/js', file);
|
|
162
|
+
const newPath = path.join(jPackConfig.get('targetRelativePath') + '/css', file);
|
|
163
163
|
fs.mkdirSync(path.dirname(newPath), { recursive: true });
|
|
164
164
|
fs.renameSync(oldPath, newPath);
|
|
165
165
|
LogMe.log('- ' + file);
|
package/lib/utils.js
CHANGED
|
@@ -3,8 +3,11 @@ import path from 'path';
|
|
|
3
3
|
|
|
4
4
|
import LogMe from './LogMe.js';
|
|
5
5
|
|
|
6
|
-
export function emptyTargetPath(targetPath) {
|
|
6
|
+
export function emptyTargetPath(targetPath, removeEmpty = false) {
|
|
7
7
|
if (!fs.existsSync(targetPath)) {
|
|
8
|
+
if (removeEmpty) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
8
11
|
fs.mkdirSync(targetPath, { recursive: true });
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -19,7 +22,7 @@ export function emptyTargetPath(targetPath) {
|
|
|
19
22
|
const fullPath = path.join(targetPath, file);
|
|
20
23
|
if (fs.lstatSync(fullPath).isDirectory()) {
|
|
21
24
|
try {
|
|
22
|
-
emptyTargetPath(fullPath);
|
|
25
|
+
emptyTargetPath(fullPath, true);
|
|
23
26
|
} catch (error) {
|
|
24
27
|
LogMe.error('Failed to empty directory: ' + fullPath);
|
|
25
28
|
LogMe.error(error.message);
|
|
@@ -35,8 +38,10 @@ export function emptyTargetPath(targetPath) {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
if (files.length === 0) {
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
if (removeEmpty) {
|
|
42
|
+
LogMe.log(' [RM] ' + targetPath);
|
|
43
|
+
fs.rmdirSync(targetPath);
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
|