@vacantthinker/firefox-addon-framework-easy-nodejs 2026.5.2202 → 2026.5.2203
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 +2 -2
- package/src/toolZipFilesOrDirs.js +33 -27
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vacantthinker/firefox-addon-framework-easy-nodejs",
|
|
3
|
-
"version": "2026.5.
|
|
3
|
+
"version": "2026.5.2203",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"git_acp": "git add . && git commit -m '
|
|
10
|
+
"git_acp": "git add . && git commit -m 'update __dirname to process.cwd()' && git push",
|
|
11
11
|
"npm_publish": "npm publish"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import archiver from 'archiver';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
|
|
6
|
-
// Fix for __dirname in ES Modules
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = path.dirname(__filename);
|
|
9
|
-
|
|
10
1
|
/**
|
|
11
2
|
*
|
|
12
3
|
* // zip dist dir => output: current-project-name.zip
|
|
@@ -32,52 +23,67 @@ const __dirname = path.dirname(__filename);
|
|
|
32
23
|
* suffix: [string]
|
|
33
24
|
* }|null}
|
|
34
25
|
*/
|
|
26
|
+
|
|
27
|
+
import {createRequire} from 'module';
|
|
28
|
+
import path from 'path';
|
|
29
|
+
|
|
35
30
|
export function zipFilesOrDirectorys(
|
|
36
31
|
outputAppendName,
|
|
37
32
|
oneDirecoty = null,
|
|
38
33
|
ignoreObj = null) {
|
|
39
34
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
35
|
+
const require = createRequire(import.meta.url);
|
|
36
|
+
const fs = require('fs');
|
|
37
|
+
const archiver = require('archiver');
|
|
38
|
+
|
|
39
|
+
// FIX: Use the execution root directory instead of the package directory
|
|
40
|
+
const projectRootDir = process.cwd();
|
|
41
|
+
const basename = path.basename(projectRootDir);
|
|
42
42
|
|
|
43
|
+
const arrFilename = Array.from([basename]);
|
|
43
44
|
if (outputAppendName) {
|
|
44
|
-
arrFilename.push(outputAppendName)
|
|
45
|
+
arrFilename.push(outputAppendName);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
const
|
|
48
|
+
// Output the zip directly into your project root directory
|
|
49
|
+
const output = fs.createWriteStream(path.join(projectRootDir, `${arrFilename.join('-')}.zip`));
|
|
50
|
+
const archive = archiver('zip');
|
|
49
51
|
|
|
50
52
|
output.on('close', () => {
|
|
51
|
-
console.info(`${outputAppendName} zip finish!`)
|
|
52
|
-
})
|
|
53
|
+
console.info(`${outputAppendName} zip finish!`);
|
|
54
|
+
});
|
|
53
55
|
archive.on('error', (e) => {
|
|
54
56
|
console.info('e=', e);
|
|
55
|
-
})
|
|
57
|
+
});
|
|
56
58
|
|
|
57
|
-
archive.pipe(output)
|
|
59
|
+
archive.pipe(output);
|
|
58
60
|
|
|
59
61
|
if (oneDirecoty) {
|
|
60
|
-
archive.directory(`${oneDirecoty}/`, false)
|
|
62
|
+
archive.directory(`${oneDirecoty}/`, false);
|
|
61
63
|
} else if (ignoreObj) {
|
|
62
|
-
|
|
63
|
-
let
|
|
64
|
+
// Scan the project root directory, not node_modules
|
|
65
|
+
let strings = fs.readdirSync(projectRootDir);
|
|
66
|
+
|
|
67
|
+
let {exclude, suffix} = ignoreObj;
|
|
64
68
|
let arrFilter = strings
|
|
65
69
|
.filter(name => !exclude.includes(name))
|
|
66
|
-
.filter(name => !suffix.some(value => name.endsWith(value)))
|
|
70
|
+
.filter(name => !suffix.some(value => name.endsWith(value)));
|
|
71
|
+
|
|
72
|
+
console.info('arrFilter=', arrFilter);
|
|
67
73
|
|
|
68
74
|
arrFilter.forEach(filename => {
|
|
69
|
-
let pathFile = path.join(
|
|
75
|
+
let pathFile = path.join(projectRootDir, filename);
|
|
70
76
|
let stats = fs.lstatSync(pathFile);
|
|
71
77
|
if (stats.isDirectory()) {
|
|
72
|
-
archive.directory(pathFile, filename)
|
|
78
|
+
archive.directory(pathFile, filename);
|
|
73
79
|
} else if (stats.isFile()) {
|
|
74
|
-
archive.file(pathFile, {name: filename})
|
|
80
|
+
archive.file(pathFile, {name: filename});
|
|
75
81
|
}
|
|
76
|
-
})
|
|
82
|
+
});
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
archive.finalize();
|
|
80
|
-
console.info(`${outputAppendName} zip starting`)
|
|
86
|
+
console.info(`${outputAppendName} zip starting`);
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
|