nexfpack 0.1.2 → 0.1.4
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/README-CN.md +1 -0
- package/README.md +1 -0
- package/cli.mjs +49 -0
- package/index.d.mts +1 -0
- package/index.mjs +45 -37
- package/package.json +1 -1
package/README-CN.md
CHANGED
|
@@ -81,6 +81,7 @@ nexfpack(config);
|
|
|
81
81
|
| name | string | 应用名称 | `nexfpack-app` |
|
|
82
82
|
| root | string | 根目录 | 若使用配置文件,则为文件所在目录,否则为 `process.cwd()` |
|
|
83
83
|
| relativeRoot | boolean | `root` 是否为相对路径 | `false` |
|
|
84
|
+
| log | boolean | 是否打印日志 | `true` |
|
|
84
85
|
| entry | string | 入口文件路径 | `index.js` |
|
|
85
86
|
| output | string | 输出目录 | `dist` |
|
|
86
87
|
| tempdir | string | 打包过程中的临时目录 | `.nexfpack-temp` |
|
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ nexfpack(config);
|
|
|
81
81
|
| name | string | Application name | `nexfpack-app` |
|
|
82
82
|
| root | string | Root directory | The directory of the config file if specified, otherwise `process.cwd()` |
|
|
83
83
|
| relativeRoot | boolean | Whether `root` is a relative path | `false` |
|
|
84
|
+
| log | boolean | Whether to print logs | `true` |
|
|
84
85
|
| entry | string | Entry file path | `index.js` |
|
|
85
86
|
| output | string | Output directory | `dist` |
|
|
86
87
|
| tempdir | string | Temporary directory for the build process | `.nexfpack-temp` |
|
package/cli.mjs
CHANGED
|
@@ -4,10 +4,59 @@ import nexfpack from "./index.mjs";
|
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
5
|
if(args.length === 0) {
|
|
6
6
|
console.log("Usage: nexfpack <config-file-path>");
|
|
7
|
+
console.log("Use nexfpack --help for more info.")
|
|
7
8
|
process.exit(1);
|
|
8
9
|
}
|
|
9
10
|
const configFilePath = args[0];
|
|
10
11
|
|
|
12
|
+
if(configFilePath === "--help" || configFilePath === "-h") {
|
|
13
|
+
console.log(
|
|
14
|
+
`
|
|
15
|
+
__ _ __ _
|
|
16
|
+
/ \\ / /\\_____\\ \\ / /
|
|
17
|
+
/ /\\ \\ / / / ____/\\ \\/ /
|
|
18
|
+
/ / /\\ \\/ / / /____\\/\\ /_____
|
|
19
|
+
/_/ / \\__/ / ____/\\ / \\ ___\\
|
|
20
|
+
\\_\\/ \\_\\/ /____\\/ / /\\ \\ \\__/
|
|
21
|
+
/_____/\\ /_/ \\_\\ __\\
|
|
22
|
+
\\_____\\/ \\ \\ \\_/
|
|
23
|
+
\\ \\_\\
|
|
24
|
+
_______ _____ \\/_/__
|
|
25
|
+
| ___ | /\\ | ___| | | / /
|
|
26
|
+
| |___| | / \\ | | | |/ /
|
|
27
|
+
| _____| / /\\ \\ | | | |
|
|
28
|
+
| | / ____ \\ | |___ | |\\ \\
|
|
29
|
+
|_| /_/ \\_\\ |_____| |_| \\_\\
|
|
30
|
+
|
|
31
|
+
`)
|
|
32
|
+
console.log("Nexfpack - A tool for building single executable files from Node.js scripts or modules.");
|
|
33
|
+
|
|
34
|
+
const helpText = `
|
|
35
|
+
Usage: nexfpack <config-file-path>
|
|
36
|
+
|
|
37
|
+
Arguments:
|
|
38
|
+
configFile Path to JSON config file (default: ./nexfpack.config.json)
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
--help Show this help message
|
|
42
|
+
|
|
43
|
+
Examples:
|
|
44
|
+
nexfpack ./my-config.json # Use custom config file
|
|
45
|
+
|
|
46
|
+
Config file example (nexfpack.config.json):
|
|
47
|
+
{
|
|
48
|
+
"name": "my-app",
|
|
49
|
+
"entry": "index.js",
|
|
50
|
+
"output": "dist",
|
|
51
|
+
"ignore": [".gitignore", "README.md"],
|
|
52
|
+
"autoRun": true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
For more details, visit: https://github.com/nexfteam/Nexfpack`
|
|
56
|
+
console.log(helpText);
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
|
|
11
60
|
nexfpack({
|
|
12
61
|
configFile: configFilePath,
|
|
13
62
|
});
|
package/index.d.mts
CHANGED
package/index.mjs
CHANGED
|
@@ -42,6 +42,7 @@ async function fillOptions(options) {
|
|
|
42
42
|
return {
|
|
43
43
|
name: options.name ?? 'nexfpack-app',
|
|
44
44
|
root: cwd,
|
|
45
|
+
log: options.log ?? true,
|
|
45
46
|
entry: path.resolve(cwd, options.entry ?? 'index.js'),
|
|
46
47
|
output: path.resolve(cwd, options.output ?? 'dist'),
|
|
47
48
|
tempdir: path.resolve(cwd, options.tempdir ?? '.nexfpack-temp'),
|
|
@@ -67,35 +68,19 @@ function listAllFiles(dir) {
|
|
|
67
68
|
return result;
|
|
68
69
|
}
|
|
69
70
|
async function nexfpack(options) {
|
|
71
|
+
let config;
|
|
72
|
+
if (options.configFile) {
|
|
73
|
+
config = JSON.parse(fs.readFileSync(options.configFile, 'utf8'));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
config = options;
|
|
77
|
+
}
|
|
78
|
+
const filledConfig = await fillOptions(config);
|
|
70
79
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/ /\\ \\ / / / ____/\\ \\/ /
|
|
75
|
-
/ / /\\ \\/ / / /____\\/\\ /_____
|
|
76
|
-
/_/ / \\__/ / ____/\\ / \\ ___\\
|
|
77
|
-
\\_\\/ \\_\\/ /____\\/ / /\\ \\ \\__/
|
|
78
|
-
/_____/\\ /_/ \\_\\ __\\
|
|
79
|
-
\\_____\\/ \\ \\ \\_/
|
|
80
|
-
\\ \\_\\
|
|
81
|
-
_______ _____ \\/_/__
|
|
82
|
-
| ___ | /\\ | ___| | | / /
|
|
83
|
-
| |___| | / \\ | | | |/ /
|
|
84
|
-
| _____| / /\\ \\ | | | |
|
|
85
|
-
| | / ____ \\ | |___ | |\\ \\
|
|
86
|
-
|_| /_/ \\_\\ |_____| |_| \\_\\
|
|
87
|
-
|
|
88
|
-
`);
|
|
89
|
-
console.log('▶️ Start packing...');
|
|
90
|
-
console.log('🧪 Tips: Nexfpack is very experimental. It may have some errors.');
|
|
91
|
-
let config;
|
|
92
|
-
if (options.configFile) {
|
|
93
|
-
config = JSON.parse(fs.readFileSync(options.configFile, 'utf8'));
|
|
80
|
+
if (filledConfig.log) {
|
|
81
|
+
console.log('▶ Start packing...');
|
|
82
|
+
console.log('🧪 Tips: Nexfpack is very experimental. It may have some errors.');
|
|
94
83
|
}
|
|
95
|
-
else {
|
|
96
|
-
config = options;
|
|
97
|
-
}
|
|
98
|
-
const filledConfig = await fillOptions(config);
|
|
99
84
|
if (!fs.existsSync(filledConfig.tempdir)) {
|
|
100
85
|
fs.mkdirSync(filledConfig.tempdir, { recursive: true });
|
|
101
86
|
}
|
|
@@ -103,14 +88,18 @@ async function nexfpack(options) {
|
|
|
103
88
|
fs.rmSync(filledConfig.tempdir, { recursive: true, force: true });
|
|
104
89
|
fs.mkdirSync(filledConfig.tempdir, { recursive: true });
|
|
105
90
|
}
|
|
106
|
-
|
|
91
|
+
if (filledConfig.log) {
|
|
92
|
+
console.log('📄 Copying files...');
|
|
93
|
+
}
|
|
107
94
|
if (!fs.existsSync(path.join(filledConfig.tempdir, 'source-copy'))) {
|
|
108
95
|
fs.mkdirSync(path.join(filledConfig.tempdir, 'source-copy'), { recursive: true });
|
|
109
96
|
}
|
|
110
97
|
await new Promise((resolve, reject) => {
|
|
111
98
|
copyfiles([filledConfig.root, path.join(filledConfig.tempdir, 'source-copy')], { up: 1, exclude: filledConfig.ignore }, (err) => {
|
|
112
99
|
if (err) {
|
|
113
|
-
|
|
100
|
+
if (filledConfig.log) {
|
|
101
|
+
console.error('❌ Failed to copy files:', err);
|
|
102
|
+
}
|
|
114
103
|
reject(err);
|
|
115
104
|
}
|
|
116
105
|
else {
|
|
@@ -118,11 +107,15 @@ async function nexfpack(options) {
|
|
|
118
107
|
}
|
|
119
108
|
});
|
|
120
109
|
});
|
|
121
|
-
|
|
110
|
+
if (filledConfig.log) {
|
|
111
|
+
console.log('📜 Packing source...');
|
|
112
|
+
}
|
|
122
113
|
const tarStream = packTar(path.join(filledConfig.tempdir, 'source-copy'));
|
|
123
114
|
const writeStream = fs.createWriteStream(path.join(filledConfig.tempdir, 'source.tar'));
|
|
124
115
|
await pipeline(tarStream, writeStream);
|
|
125
|
-
|
|
116
|
+
if (filledConfig.log) {
|
|
117
|
+
console.log('📦 Packing executable...');
|
|
118
|
+
}
|
|
126
119
|
fs.writeFileSync(path.join(filledConfig.tempdir, 'package.json'), JSON.stringify({
|
|
127
120
|
name: filledConfig.name,
|
|
128
121
|
version: '1.0.0',
|
|
@@ -134,7 +127,10 @@ async function nexfpack(options) {
|
|
|
134
127
|
}, null, 2));
|
|
135
128
|
const installSpawnResult = child_process.spawnSync('npm install --omit=dev', { stdio: 'inherit', cwd: filledConfig.tempdir, shell: true });
|
|
136
129
|
if (installSpawnResult.status !== 0) {
|
|
137
|
-
|
|
130
|
+
if (filledConfig.log) {
|
|
131
|
+
console.error('❌ Failed to install dependencies');
|
|
132
|
+
}
|
|
133
|
+
throw new Error('Failed to install dependencies');
|
|
138
134
|
}
|
|
139
135
|
const allNodeModulesFiles = listAllFiles(path.join(filledConfig.tempdir, 'node_modules'));
|
|
140
136
|
const seaConfigContent = {
|
|
@@ -209,7 +205,10 @@ async function nexfpack(options) {
|
|
|
209
205
|
fs.writeFileSync(path.join(filledConfig.tempdir, 'launcher.cjs'), launcherContent);
|
|
210
206
|
const blobSpawnResult = child_process.spawnSync('node --experimental-sea-config sea-config.json', { stdio: 'inherit', cwd: filledConfig.tempdir, shell: true });
|
|
211
207
|
if (blobSpawnResult.status !== 0) {
|
|
212
|
-
|
|
208
|
+
if (filledConfig.log) {
|
|
209
|
+
console.error('❌ Failed to generate blob');
|
|
210
|
+
}
|
|
211
|
+
throw new Error('Failed to generate blob');
|
|
213
212
|
}
|
|
214
213
|
const NODE_SEA_FUSE = 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2';
|
|
215
214
|
const blobData = fs.readFileSync(path.join(filledConfig.tempdir, 'sea-prep.blob'));
|
|
@@ -230,17 +229,26 @@ async function nexfpack(options) {
|
|
|
230
229
|
console.log("⚠️ Sorry, we can't sign your executable file. Please sign it by yourself.");
|
|
231
230
|
}
|
|
232
231
|
if (filledConfig.autoDeleteTempFiles) {
|
|
233
|
-
|
|
232
|
+
if (filledConfig.log) {
|
|
233
|
+
console.log('♻️ Deleting temp files...');
|
|
234
|
+
}
|
|
234
235
|
fs.rmSync(filledConfig.tempdir, { recursive: true, force: true });
|
|
235
236
|
}
|
|
236
|
-
|
|
237
|
+
if (filledConfig.log) {
|
|
238
|
+
console.log('✅ Done!');
|
|
239
|
+
}
|
|
237
240
|
if (filledConfig.autoRun) {
|
|
238
|
-
|
|
241
|
+
if (filledConfig.log) {
|
|
242
|
+
console.log('🚀 Auto-run executable...');
|
|
243
|
+
}
|
|
239
244
|
child_process.spawnSync(exePath, { stdio: 'inherit', cwd: filledConfig.output, shell: true });
|
|
240
245
|
}
|
|
241
246
|
}
|
|
242
247
|
catch (err) {
|
|
243
|
-
|
|
248
|
+
if (filledConfig.log) {
|
|
249
|
+
console.error('❌ Nexfpack Failed:', err);
|
|
250
|
+
}
|
|
251
|
+
throw err;
|
|
244
252
|
}
|
|
245
253
|
}
|
|
246
254
|
export default nexfpack;
|
package/package.json
CHANGED