xhs-mp-compiler-cli 1.1.3 → 1.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/dist/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +40 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +59 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/compiler.d.ts +76 -0
- package/dist/compiler.js +361 -0
- package/dist/compilerCP.d.ts +1 -0
- package/dist/compilerCP.js +175 -0
- package/dist/config/constant.config.d.ts +27 -0
- package/dist/config/constant.config.js +30 -0
- package/dist/config/dir.config.d.ts +3 -0
- package/dist/config/dir.config.js +16 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +454 -0
- package/dist/packs/index.d.ts +14 -0
- package/dist/packs/index.js +31 -0
- package/dist/packs/mp-pack/index.d.ts +3 -0
- package/dist/packs/mp-pack/index.js +32 -0
- package/dist/packs/webpack/dev-server/index.d.ts +3 -0
- package/dist/packs/webpack/dev-server/index.js +64 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +32 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +23 -0
- package/dist/packs/webpack/dev-server/lib/openChrome.applescript +78 -0
- package/dist/packs/webpack/index.d.ts +3 -0
- package/dist/packs/webpack/index.js +92 -0
- package/dist/packs/webpack/webpack.d.ts +21 -0
- package/dist/packs/webpack/webpack.js +79 -0
- package/dist/presets/babel.d.ts +8 -0
- package/dist/presets/babel.js +59 -0
- package/dist/presets/common.d.ts +4 -0
- package/dist/presets/common.js +48 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
- package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
- package/dist/presets/configs/minigame/assets/index.js +65 -0
- package/dist/presets/configs/minigame/service/index.d.ts +3 -0
- package/dist/presets/configs/minigame/service/index.js +34 -0
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
- package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
- package/dist/presets/configs/miniprogram/assets/index.js +47 -0
- package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/component.js +47 -0
- package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/render/index.js +71 -0
- package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/render.js +49 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +55 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +163 -0
- package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/service/index.js +72 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +66 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.js +95 -0
- package/dist/presets/loaders/mg-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mg-entry-loader.js +27 -0
- package/dist/presets/loaders/mini-style-loader.d.ts +1 -0
- package/dist/presets/loaders/mini-style-loader.js +72 -0
- package/dist/presets/loaders/mp-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mp-entry-loader.js +196 -0
- package/dist/presets/loaders/sjs-loader/index.d.ts +12 -0
- package/dist/presets/loaders/sjs-loader/index.js +605 -0
- package/dist/presets/loaders/sjs-loader/scope.d.ts +36 -0
- package/dist/presets/loaders/sjs-loader/scope.js +122 -0
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +2 -0
- package/dist/presets/loaders/sjs-loader/tranform.js +31 -0
- package/dist/presets/loaders/wxss-loader.d.ts +1 -0
- package/dist/presets/loaders/wxss-loader.js +77 -0
- package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
- package/dist/presets/plugins/InjectorPlugin.js +14 -0
- package/dist/presets/prod.d.ts +4 -0
- package/dist/presets/prod.js +80 -0
- package/dist/types/index.d.ts +118 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/common.d.ts +8 -0
- package/dist/utils/common.js +36 -0
- package/dist/utils/const.d.ts +27 -0
- package/dist/utils/const.js +47 -0
- package/dist/utils/css.d.ts +2 -0
- package/dist/utils/css.js +41 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/file.d.ts +2 -0
- package/dist/utils/file.js +67 -0
- package/dist/utils/getSuffixName.d.ts +3 -0
- package/dist/utils/getSuffixName.js +18 -0
- package/dist/utils/loader-utils.d.ts +15 -0
- package/dist/utils/loader-utils.js +59 -0
- package/dist/utils/postcssRpx2Vw.d.ts +12 -0
- package/dist/utils/postcssRpx2Vw.js +35 -0
- package/dist/utils/project.d.ts +27 -0
- package/dist/utils/project.js +164 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/tagTransformMap.d.ts +35 -0
- package/dist/utils/tagTransformMap.js +38 -0
- package/dist/utils/utils.d.ts +7 -0
- package/dist/utils/utils.js +50 -0
- package/dist/utils/zip.d.ts +28 -0
- package/dist/utils/zip.js +287 -0
- package/package.json +6 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tagTransformMap = {
|
|
4
|
+
view: 'xhs-vue-view',
|
|
5
|
+
text: 'xhs-vue-text',
|
|
6
|
+
// block: 'span',
|
|
7
|
+
image: 'xhs-vue-image',
|
|
8
|
+
input: 'xhs-vue-input',
|
|
9
|
+
icon: 'xhs-vue-icon',
|
|
10
|
+
label: 'xhs-vue-label',
|
|
11
|
+
radio: 'xhs-vue-radio',
|
|
12
|
+
'radio-group': 'xhs-vue-radio-group',
|
|
13
|
+
checkbox: 'xhs-vue-checkbox',
|
|
14
|
+
'checkbox-group': 'xhs-vue-checkbox-group',
|
|
15
|
+
switch: 'xhs-vue-switch',
|
|
16
|
+
textarea: 'xhs-vue-textarea',
|
|
17
|
+
button: 'xhs-vue-button',
|
|
18
|
+
swiper: 'xhs-vue-swiper',
|
|
19
|
+
'swiper-item': 'xhs-vue-swiper-item',
|
|
20
|
+
navigator: 'xhs-vue-navigator',
|
|
21
|
+
slider: 'xhs-vue-slider',
|
|
22
|
+
progress: 'xhs-vue-progress',
|
|
23
|
+
'rich-text': 'xhs-vue-rich-text',
|
|
24
|
+
'mf-page': 'div',
|
|
25
|
+
'scroll-view': 'xhs-vue-scroll-view',
|
|
26
|
+
picker: 'xhs-vue-picker',
|
|
27
|
+
'picker-view': 'xhs-vue-picker-view',
|
|
28
|
+
'picker-view-column': 'xhs-vue-picker-view-column',
|
|
29
|
+
form: 'xhs-vue-form',
|
|
30
|
+
'web-view': 'xhs-vue-web-view',
|
|
31
|
+
video: 'xhs-vue-video',
|
|
32
|
+
map: 'xhs-vue-map',
|
|
33
|
+
editor: 'xhs-vue-editor',
|
|
34
|
+
'movable-area': 'xhs-vue-movable-area',
|
|
35
|
+
'movable-view': 'xhs-vue-movable-view',
|
|
36
|
+
canvas: 'xhs-vue-canvas'
|
|
37
|
+
};
|
|
38
|
+
exports.default = tagTransformMap;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizePath = exports.getMd5 = void 0;
|
|
7
|
+
// @ts-nocheck
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const crypto = require('crypto');
|
|
11
|
+
function getMd5(str) {
|
|
12
|
+
const hash = crypto.createHash('md5');
|
|
13
|
+
hash.update(str);
|
|
14
|
+
const md5 = hash.digest('hex');
|
|
15
|
+
return md5;
|
|
16
|
+
}
|
|
17
|
+
exports.getMd5 = getMd5;
|
|
18
|
+
function normalizePath(str) {
|
|
19
|
+
return str.replace(/\\/g, '/');
|
|
20
|
+
}
|
|
21
|
+
exports.normalizePath = normalizePath;
|
|
22
|
+
const hasFile = filepath => {
|
|
23
|
+
try {
|
|
24
|
+
const stat = fs_1.default.statSync(filepath);
|
|
25
|
+
return stat.isFile();
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const getTsconfigPath = config => {
|
|
32
|
+
let res = '';
|
|
33
|
+
// 查询距离最近的 tsconfig.json
|
|
34
|
+
if (config.projectPath) {
|
|
35
|
+
res = path_1.default.resolve(process.cwd(), config.projectPath, 'tsconfig.json');
|
|
36
|
+
if (hasFile(res)) {
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// 查询 root 的 tsconfig.json
|
|
41
|
+
res = path_1.default.resolve(process.cwd(), 'tsconfig.json');
|
|
42
|
+
if (hasFile(res)) {
|
|
43
|
+
return res;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
exports.default = {
|
|
48
|
+
hasFile,
|
|
49
|
+
getTsconfigPath,
|
|
50
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Archiver } from 'archiver';
|
|
2
|
+
import * as fse from 'fs-extra';
|
|
3
|
+
interface IOptions {
|
|
4
|
+
outputDir: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class Zip {
|
|
7
|
+
options: IOptions;
|
|
8
|
+
archive: Archiver;
|
|
9
|
+
output: fse.WriteStream;
|
|
10
|
+
constructor(options: IOptions);
|
|
11
|
+
initOutput(): void;
|
|
12
|
+
finalize(): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 解压 zip 文件 yauzl
|
|
16
|
+
* @param zipPath string
|
|
17
|
+
* @param outputDir string
|
|
18
|
+
* @param options unzipOptions
|
|
19
|
+
*/
|
|
20
|
+
export declare function unzip(zipPath: string, outputDir: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* 解压 zip 文件
|
|
23
|
+
* @param zipPath string
|
|
24
|
+
* @param outputDir string
|
|
25
|
+
*/
|
|
26
|
+
export declare function unzipMac(zipPath: string, outputDir: string): Promise<unknown>;
|
|
27
|
+
export declare const genZip: (input: string, output: string, appId?: string) => Promise<void>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.genZip = exports.unzipMac = exports.unzip = exports.Zip = void 0;
|
|
36
|
+
const child_process_1 = require("child_process");
|
|
37
|
+
const fs_1 = require("fs");
|
|
38
|
+
const fse = __importStar(require("fs-extra"));
|
|
39
|
+
const debug = require('debug')('zip');
|
|
40
|
+
const path = require('path');
|
|
41
|
+
const { promisify } = require('util');
|
|
42
|
+
const stream = require('stream');
|
|
43
|
+
const archiver = require('archiver');
|
|
44
|
+
const yauzl = require('yauzl');
|
|
45
|
+
const openZip = promisify(yauzl.open);
|
|
46
|
+
const pipeline = promisify(stream.pipeline);
|
|
47
|
+
class Extractor {
|
|
48
|
+
constructor(zipPath, opts) {
|
|
49
|
+
this.zipPath = '';
|
|
50
|
+
this.opts = null;
|
|
51
|
+
this.zipfile = null;
|
|
52
|
+
this.canceled = false;
|
|
53
|
+
this.zipPath = zipPath;
|
|
54
|
+
this.opts = opts;
|
|
55
|
+
}
|
|
56
|
+
extract() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
debug('opening', this.zipPath, 'with opts', this.opts);
|
|
59
|
+
this.zipfile = yield openZip(this.zipPath, { lazyEntries: true });
|
|
60
|
+
this.canceled = false;
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
this.zipfile.on('error', err => {
|
|
63
|
+
this.canceled = true;
|
|
64
|
+
reject(err);
|
|
65
|
+
});
|
|
66
|
+
this.zipfile.readEntry();
|
|
67
|
+
this.zipfile.on('close', () => {
|
|
68
|
+
if (!this.canceled) {
|
|
69
|
+
debug('zip extraction complete');
|
|
70
|
+
resolve();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
this.zipfile.on('entry', (entry) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
/* istanbul ignore if */
|
|
75
|
+
if (this.canceled) {
|
|
76
|
+
debug('skipping entry', entry.fileName, { cancelled: this.canceled });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
debug('zipfile entry', entry.fileName);
|
|
80
|
+
if (entry.fileName.startsWith('__MACOSX/')) {
|
|
81
|
+
this.zipfile.readEntry();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const destDir = path.dirname(path.join(this.opts.dir, entry.fileName));
|
|
85
|
+
try {
|
|
86
|
+
yield fs_1.promises.mkdir(destDir, { recursive: true });
|
|
87
|
+
let canonicalDestDir = '';
|
|
88
|
+
try {
|
|
89
|
+
canonicalDestDir = yield fs_1.promises.realpath(destDir);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
canonicalDestDir = path.resolve(destDir);
|
|
93
|
+
}
|
|
94
|
+
const relativeDestDir = path.relative(this.opts.dir, canonicalDestDir);
|
|
95
|
+
if (relativeDestDir.split(path.sep).includes('..')) {
|
|
96
|
+
throw new Error(`Out of bound path "${canonicalDestDir}" found while processing file ${entry.fileName}`);
|
|
97
|
+
}
|
|
98
|
+
yield this.extractEntry(entry);
|
|
99
|
+
debug('finished processing', entry.fileName);
|
|
100
|
+
this.zipfile.readEntry();
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
this.canceled = true;
|
|
104
|
+
this.zipfile.close();
|
|
105
|
+
reject(err);
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
extractEntry(entry) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
/* istanbul ignore if */
|
|
114
|
+
if (this.canceled) {
|
|
115
|
+
debug('skipping entry extraction', entry.fileName, {
|
|
116
|
+
cancelled: this.canceled
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (this.opts.onEntry) {
|
|
121
|
+
this.opts.onEntry(entry, this.zipfile);
|
|
122
|
+
}
|
|
123
|
+
const dest = path.join(this.opts.dir, entry.fileName);
|
|
124
|
+
// convert external file attr int into a fs stat mode int
|
|
125
|
+
const mode = (entry.externalFileAttributes >> 16) & 0xffff;
|
|
126
|
+
// check if it's a symlink or dir (using stat mode constants)
|
|
127
|
+
const IFMT = 61440;
|
|
128
|
+
const IFDIR = 16384;
|
|
129
|
+
const IFLNK = 40960;
|
|
130
|
+
const symlink = (mode & IFMT) === IFLNK;
|
|
131
|
+
let isDir = (mode & IFMT) === IFDIR;
|
|
132
|
+
// Failsafe, borrowed from jsZip
|
|
133
|
+
if (!isDir && entry.fileName.endsWith('/')) {
|
|
134
|
+
isDir = true;
|
|
135
|
+
}
|
|
136
|
+
// check for windows weird way of specifying a directory
|
|
137
|
+
// https://github.com/maxogden/extract-zip/issues/13#issuecomment-154494566
|
|
138
|
+
const madeBy = entry.versionMadeBy >> 8;
|
|
139
|
+
if (!isDir)
|
|
140
|
+
isDir = madeBy === 0 && entry.externalFileAttributes === 16;
|
|
141
|
+
debug('extracting entry', {
|
|
142
|
+
filename: entry.fileName,
|
|
143
|
+
isDir,
|
|
144
|
+
isSymlink: symlink
|
|
145
|
+
});
|
|
146
|
+
const procMode = this.getExtractedMode(mode, isDir) & 0o777;
|
|
147
|
+
// always ensure folders are created
|
|
148
|
+
const destDir = isDir ? dest : path.dirname(dest);
|
|
149
|
+
const mkdirOptions = { recursive: true };
|
|
150
|
+
if (isDir) {
|
|
151
|
+
mkdirOptions.mode = procMode;
|
|
152
|
+
}
|
|
153
|
+
debug('mkdir', Object.assign({ dir: destDir }, mkdirOptions));
|
|
154
|
+
yield fs_1.promises.mkdir(destDir, mkdirOptions);
|
|
155
|
+
if (isDir)
|
|
156
|
+
return;
|
|
157
|
+
debug('opening read stream', dest);
|
|
158
|
+
const readStream = yield promisify(this.zipfile.openReadStream.bind(this.zipfile))(entry);
|
|
159
|
+
if (symlink) {
|
|
160
|
+
// const link = await getStream(readStream)
|
|
161
|
+
// debug('creating symlink', link, dest)
|
|
162
|
+
// await fs.symlink(link, dest)
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
yield pipeline(readStream, (0, fs_1.createWriteStream)(dest, { mode: procMode }));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
getExtractedMode(entryMode, isDir) {
|
|
170
|
+
let mode = entryMode;
|
|
171
|
+
// Set defaults, if necessary
|
|
172
|
+
if (mode === 0) {
|
|
173
|
+
if (isDir) {
|
|
174
|
+
if (this.opts.defaultDirMode) {
|
|
175
|
+
mode = parseInt(this.opts.defaultDirMode, 10);
|
|
176
|
+
}
|
|
177
|
+
if (!mode) {
|
|
178
|
+
mode = 0o755;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (this.opts.defaultFileMode) {
|
|
183
|
+
mode = parseInt(this.opts.defaultFileMode, 10);
|
|
184
|
+
}
|
|
185
|
+
if (!mode) {
|
|
186
|
+
mode = 0o644;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return mode;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
class Zip {
|
|
194
|
+
constructor(options) {
|
|
195
|
+
this.options = options;
|
|
196
|
+
this.archive = archiver('zip', {
|
|
197
|
+
zlib: { level: 9 } // Sets the compression level.
|
|
198
|
+
});
|
|
199
|
+
this.initOutput();
|
|
200
|
+
}
|
|
201
|
+
initOutput() {
|
|
202
|
+
const { outputDir } = this.options;
|
|
203
|
+
this.output = fse.createWriteStream(outputDir);
|
|
204
|
+
this.archive.pipe(this.output);
|
|
205
|
+
}
|
|
206
|
+
finalize() {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
return this.archive.finalize();
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.Zip = Zip;
|
|
213
|
+
/**
|
|
214
|
+
* 解压 zip 文件 yauzl
|
|
215
|
+
* @param zipPath string
|
|
216
|
+
* @param outputDir string
|
|
217
|
+
* @param options unzipOptions
|
|
218
|
+
*/
|
|
219
|
+
function unzip(zipPath, outputDir) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
debug('creating target directory', outputDir);
|
|
222
|
+
if (!path.isAbsolute(outputDir)) {
|
|
223
|
+
throw new Error('Target directory is expected to be absolute');
|
|
224
|
+
}
|
|
225
|
+
yield fs_1.promises.mkdir(outputDir, { recursive: true });
|
|
226
|
+
const _outputDir = yield fs_1.promises.realpath(outputDir);
|
|
227
|
+
return new Extractor(zipPath, {
|
|
228
|
+
dir: _outputDir
|
|
229
|
+
}).extract();
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
exports.unzip = unzip;
|
|
233
|
+
/**
|
|
234
|
+
* 解压 zip 文件
|
|
235
|
+
* @param zipPath string
|
|
236
|
+
* @param outputDir string
|
|
237
|
+
*/
|
|
238
|
+
function unzipMac(zipPath, outputDir) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
return new Promise((resolve, reject) => {
|
|
241
|
+
const proc = (0, child_process_1.spawn)('/usr/bin/unzip', [zipPath, '-d', outputDir]);
|
|
242
|
+
const output = '';
|
|
243
|
+
proc.on('error', err => {
|
|
244
|
+
reject(err);
|
|
245
|
+
});
|
|
246
|
+
proc.on('exit', (code) => {
|
|
247
|
+
if (code > 0) {
|
|
248
|
+
reject(new Error(`Exited with code ${code}`));
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
resolve(output);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
proc.stderr.on('data', chunk => {
|
|
255
|
+
console.error(chunk.toString());
|
|
256
|
+
});
|
|
257
|
+
proc.stdout.on('data', chunk => {
|
|
258
|
+
// console.log(chunk.toString());
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
exports.unzipMac = unzipMac;
|
|
264
|
+
const genZip = (input, output, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
return new Promise((resolve, reject) => {
|
|
266
|
+
const outputStream = (0, fs_1.createWriteStream)(output);
|
|
267
|
+
const archive = archiver('zip', {
|
|
268
|
+
zlib: { level: 9 } // Sets the compression level.
|
|
269
|
+
});
|
|
270
|
+
outputStream.on('close', () => {
|
|
271
|
+
resolve();
|
|
272
|
+
});
|
|
273
|
+
archive.on('error', error => {
|
|
274
|
+
console.error('archive error:', error);
|
|
275
|
+
reject(error);
|
|
276
|
+
});
|
|
277
|
+
archive.pipe(outputStream);
|
|
278
|
+
if (appId) {
|
|
279
|
+
archive.directory(input, appId);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
archive.directory(input, './');
|
|
283
|
+
}
|
|
284
|
+
archive.finalize();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
exports.genZip = genZip;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-compiler-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "xhs mp command tool.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"category": "esm",
|
|
@@ -82,11 +82,11 @@
|
|
|
82
82
|
"webpack-bundle-analyzer": "^4.4.0",
|
|
83
83
|
"webpack-chain": "^6.5.1",
|
|
84
84
|
"webpack-sources": "^3.2.2",
|
|
85
|
-
"xhs-mp-compiler-ml-loader": "1.1.
|
|
86
|
-
"xhs-mp-compiler-utils": "1.1.
|
|
87
|
-
"xhs-mp-pack": "^1.1.
|
|
88
|
-
"xhs-mp-project": "^1.1.
|
|
89
|
-
"xhs-mp-utils": "^1.1.
|
|
85
|
+
"xhs-mp-compiler-ml-loader": "1.1.3",
|
|
86
|
+
"xhs-mp-compiler-utils": "1.1.2",
|
|
87
|
+
"xhs-mp-pack": "^1.1.2",
|
|
88
|
+
"xhs-mp-project": "^1.1.2",
|
|
89
|
+
"xhs-mp-utils": "^1.1.2"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@types/babel__generator": "7.6.3",
|