nexfpack 0.1.2 → 0.1.3

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 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
@@ -1,13 +1,65 @@
1
1
  #!/usr/bin/env node
2
2
  import nexfpack from "./index.mjs";
3
+ import fs from "fs";
3
4
 
4
5
  const args = process.argv.slice(2);
5
6
  if(args.length === 0) {
6
7
  console.log("Usage: nexfpack <config-file-path>");
8
+ console.log("Use nexfpack --help for more info.")
7
9
  process.exit(1);
8
10
  }
9
11
  const configFilePath = args[0];
10
12
 
13
+ if(configFilePath === "--help" || configFilePath === "-h") {
14
+ console.log(
15
+ `
16
+ __ _ __ _
17
+ / \\ / /\\_____\\ \\ / /
18
+ / /\\ \\ / / / ____/\\ \\/ /
19
+ / / /\\ \\/ / / /____\\/\\ /_____
20
+ /_/ / \\__/ / ____/\\ / \\ ___\\
21
+ \\_\\/ \\_\\/ /____\\/ / /\\ \\ \\__/
22
+ /_____/\\ /_/ \\_\\ __\\
23
+ \\_____\\/ \\ \\ \\_/
24
+ \\ \\_\\
25
+ _______ _____ \\/_/__
26
+ | ___ | /\\ | ___| | | / /
27
+ | |___| | / \\ | | | |/ /
28
+ | _____| / /\\ \\ | | | |
29
+ | | / ____ \\ | |___ | |\\ \\
30
+ |_| /_/ \\_\\ |_____| |_| \\_\\
31
+
32
+ `)
33
+ console.log("Nexfpack - A tool for building single executable files from Node.js scripts or modules.");
34
+
35
+ console.log("Version: " + JSON.parse(fs.readFileSync("./package.json", "utf8")).version);
36
+
37
+ const helpText = `
38
+ Usage: nexfpack <config-file-path>
39
+
40
+ Arguments:
41
+ configFile Path to JSON config file (default: ./nexfpack.config.json)
42
+
43
+ Options:
44
+ --help Show this help message
45
+
46
+ Examples:
47
+ nexfpack ./my-config.json # Use custom config file
48
+
49
+ Config file example (nexfpack.config.json):
50
+ {
51
+ "name": "my-app",
52
+ "entry": "index.js",
53
+ "output": "dist",
54
+ "ignore": [".gitignore", "README.md"],
55
+ "autoRun": true
56
+ }
57
+
58
+ For more details, visit: https://github.com/nexfteam/Nexfpack`
59
+ console.log(helpText);
60
+ process.exit(0);
61
+ }
62
+
11
63
  nexfpack({
12
64
  configFile: configFilePath,
13
65
  });
package/index.d.mts CHANGED
@@ -2,6 +2,7 @@ interface NexfpackOptions {
2
2
  name?: string;
3
3
  root?: string;
4
4
  relativeRoot?: boolean;
5
+ log?: boolean;
5
6
  entry?: string;
6
7
  output?: string;
7
8
  tempdir?: string;
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
- console.log(`
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
- console.log('📄 Copying files...');
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
- console.error('❌ Failed to copy files:', err);
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
- console.log('📜 Packing source...');
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
- console.log('📦 Packing executable...');
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
- throw new Error('❌ Failed to install dependencies');
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
- throw new Error('❌ Failed to generate blob');
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
- console.log('♻️ Deleting temp files...');
232
+ if (filledConfig.log) {
233
+ console.log('♻️ Deleting temp files...');
234
+ }
234
235
  fs.rmSync(filledConfig.tempdir, { recursive: true, force: true });
235
236
  }
236
- console.log('✅ Done!');
237
+ if (filledConfig.log) {
238
+ console.log('✅ Done!');
239
+ }
237
240
  if (filledConfig.autoRun) {
238
- console.log('🚀 Auto-run executable...');
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
- console.error('❌ Nexfpack Failed:', err);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexfpack",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A tool for building single executable files from Node.js scripts or modules.",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/nexfteam/Nexfpack",