binhend 2.1.31 → 2.1.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { config } = require('../configuration');
|
|
2
2
|
const { readFileSync } = require('fs');
|
|
3
|
-
const {
|
|
3
|
+
const { parseFileName } = require('./filename-parser');
|
|
4
4
|
const { scanNestedFiles, cloneFileIfNew, printError, makeFullDirPath, writeToFileIfNew } = require('./component.file');
|
|
5
5
|
|
|
6
6
|
const PREFIX_CODE =
|
|
@@ -23,25 +23,25 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
|
|
|
23
23
|
try {
|
|
24
24
|
makeFullDirPath(fileOutputPath);
|
|
25
25
|
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
if (
|
|
26
|
+
var filename = parseFileName(file.name);
|
|
27
|
+
|
|
28
|
+
if (filename.ext === '.css') {
|
|
29
29
|
var cssModuleCode = 'binh.css(module);';
|
|
30
30
|
writeToFileIfNew(fileOutputPath + '.js', cssModuleCode);
|
|
31
31
|
// not return here, but wait for next "if" statement to be copied to build folder, then return there.
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
if (
|
|
34
|
+
if (filename.ext !== '.js' && filename.ext !== '.cjs' && filename.ext !== '.mjs') {
|
|
35
35
|
// any files not JS (.css, .jpg, etc.) will be copied to build folder.
|
|
36
36
|
cloneFileIfNew(fileSourcePath, fileOutputPath);
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
var fileContent = readFileSync(fileSourcePath, { encoding: 'utf8', flag: 'r' });
|
|
41
|
-
var formatCode = mapConfigValues(fileContent.trim()); // for .
|
|
41
|
+
var formatCode = mapConfigValues(fileContent.trim()); // for .c.js files, not build code but still bind config values
|
|
42
42
|
|
|
43
|
-
if (
|
|
44
|
-
// for .js files, build code and bind config values
|
|
43
|
+
if (filename.ext2 !== '.c.js') {
|
|
44
|
+
// except for .c.js files, build code and bind config values for other JS files (.js, .cjs, .mjs)
|
|
45
45
|
formatCode = PREFIX_CODE + formatCode + '\r\n\r\n;binh.final(module);';
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const { parse } = require('path');
|
|
4
|
+
|
|
5
|
+
function parseFileName(filename) {
|
|
6
|
+
const parsed = parse(filename);
|
|
7
|
+
const segments = parsed.base.split('.');
|
|
8
|
+
|
|
9
|
+
var ext2 = parsed.ext;
|
|
10
|
+
|
|
11
|
+
if (segments.length >= 3) {
|
|
12
|
+
// last two segments form the level 2 extension
|
|
13
|
+
ext2 = '.' + segments.slice(-2).join('.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
...parsed,
|
|
18
|
+
ext2,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
parseFileName
|
|
24
|
+
};
|