mng-cli 1.0.4 → 1.0.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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "mng-cli",
3
3
  "private": false,
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "type": "module",
6
- "files": ["dist", "package.json"],
6
+ "files": ["dist", "package.json", "scripts"],
7
7
  "devDependencies": {
8
8
  "@types/node": "^22.10.6",
9
9
  "@vitest/ui": "^2.1.8",
@@ -32,7 +32,7 @@
32
32
  "scripts": {
33
33
  "dev": "node --loader ts-node/esm src/index.ts",
34
34
  "build": "vite build && cpx \"src/gifsicle-bin/vendor/**/*\" \"dist/vendor\" && node scripts/set-permissions.js dist/vendor",
35
- "postinstall": "node scripts/set-permissions.js src/gifsicle-bin/vendor && node scripts/set-permissions.js dist/vendor",
35
+ "postinstall": "node scripts/set-permissions.js dist/vendor",
36
36
  "test": "vitest",
37
37
  "test:ui": "vitest --ui",
38
38
  "coverage": "vitest --coverage"
@@ -0,0 +1,50 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ // 获取目标目录参数,默认为 src/gifsicle-bin/vendor
9
+ const targetDir = process.argv[2] || path.join(__dirname, 'src/gifsicle-bin/vendor');
10
+ const vendorDir = path.resolve(targetDir);
11
+
12
+ function setExecutable(filePath) {
13
+ try {
14
+ fs.chmodSync(filePath, 0o755);
15
+ console.log(`Set executable permission: ${filePath}`);
16
+ } catch (error) {
17
+ console.warn(`Failed to set permission for ${filePath}:`, error.message);
18
+ }
19
+ }
20
+
21
+ function processDirectory(dir) {
22
+ if (!fs.existsSync(dir)) return;
23
+
24
+ const items = fs.readdirSync(dir, { withFileTypes: true });
25
+ for (const item of items) {
26
+ const fullPath = path.join(dir, item.name);
27
+ if (item.isDirectory()) {
28
+ processDirectory(fullPath);
29
+ } else if (item.isFile()) {
30
+ // 对于非Windows平台的可执行文件设置权限
31
+ if (!item.name.endsWith('.exe')) {
32
+ setExecutable(fullPath);
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ // 只在非Windows平台运行
39
+ if (process.platform !== 'win32') {
40
+ console.log(`Setting executable permissions for gifsicle binaries in: ${vendorDir}`);
41
+ if (!fs.existsSync(vendorDir)) {
42
+ console.warn(`Directory does not exist: ${vendorDir}`);
43
+ console.log('This may be normal if building for the first time.');
44
+ } else {
45
+ processDirectory(vendorDir);
46
+ console.log('Permission setting completed.');
47
+ }
48
+ } else {
49
+ console.log('Windows platform detected, skipping permission setting.');
50
+ }