jizy-packer 2.1.4 → 2.1.6
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 +0 -4
- package/lib/index.js +4 -1
- package/lib/utils.js +40 -1
- package/package.json +1 -1
package/lib/Build.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,11 +3,14 @@ import jPackCli from './Cli.js';
|
|
|
3
3
|
import jPackConfig from './Config.js';
|
|
4
4
|
import LogMe from './LogMe.js';
|
|
5
5
|
import jPackRollup from './Rollup.js';
|
|
6
|
+
import { generateLessVariablesFromConfig, deleteLessVariablesFile } from './utils.js';
|
|
6
7
|
|
|
7
8
|
export {
|
|
8
9
|
jPackBuild,
|
|
9
10
|
jPackCli,
|
|
11
|
+
jPackRollup,
|
|
10
12
|
jPackConfig,
|
|
11
13
|
LogMe,
|
|
12
|
-
|
|
14
|
+
generateLessVariablesFromConfig,
|
|
15
|
+
deleteLessVariablesFile
|
|
13
16
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
|
|
4
3
|
import LogMe from './LogMe.js';
|
|
5
4
|
|
|
6
5
|
export function emptyTargetPath(targetPath, removeEmpty = false) {
|
|
@@ -75,6 +74,26 @@ export function loadJsonConfigs(...configs) {
|
|
|
75
74
|
return mergedConfig;
|
|
76
75
|
};
|
|
77
76
|
|
|
77
|
+
export function generateLessVariablesFromConfig(variablesPath, targetVariablesPath, variables) {
|
|
78
|
+
const _variables = parseLessVariablesToObject(variablesPath);
|
|
79
|
+
variables = { ..._variables, ...variables };
|
|
80
|
+
|
|
81
|
+
const less = '';
|
|
82
|
+
Object.keys(variables).forEach(key => {
|
|
83
|
+
// replace camelcase to kebab-case for less variable names
|
|
84
|
+
const variableName = key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
85
|
+
less += `@${variableName}: ${variables[key]};` + "\n";
|
|
86
|
+
});
|
|
87
|
+
fs.writeFileSync(targetVariablesPath, less, { encoding: 'utf8' });
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function deleteLessVariablesFile(variablesPath) {
|
|
91
|
+
if (fs.existsSync(variablesPath)) {
|
|
92
|
+
LogMe.log('Delete lib/less/_variables.less');
|
|
93
|
+
fs.unlinkSync(variablesPath);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
78
97
|
function isObject(item) {
|
|
79
98
|
return (item && typeof item === 'object' && !Array.isArray(item));
|
|
80
99
|
}
|
|
@@ -90,3 +109,23 @@ function deepMerge(target, source) {
|
|
|
90
109
|
}
|
|
91
110
|
return target;
|
|
92
111
|
}
|
|
112
|
+
|
|
113
|
+
function parseLessVariablesToObject(variablesPath) {
|
|
114
|
+
const variables = {};
|
|
115
|
+
|
|
116
|
+
if (!fs.existsSync(variablesPath)) {
|
|
117
|
+
return variables;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const data = fs.readFileSync(variablesPath, 'utf8');
|
|
121
|
+
const lines = data.split('\n');
|
|
122
|
+
|
|
123
|
+
lines.forEach(line => {
|
|
124
|
+
const match = line.match(/@([a-zA-Z0-9-_]+):\s*(.+);/);
|
|
125
|
+
if (match) {
|
|
126
|
+
variables[match[1]] = match[2];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return variables;
|
|
131
|
+
}
|