react-native-update-cli 2.18.0 → 2.19.0
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/lib/api.d.ts +1 -1
- package/lib/api.js +140 -134
- package/lib/app.d.ts +2 -2
- package/lib/app.js +60 -107
- package/lib/bin.js +38 -35
- package/lib/bundle-pack.js +57 -77
- package/lib/bundle-runner.js +249 -312
- package/lib/bundle.js +71 -89
- package/lib/diff.js +188 -235
- package/lib/exports.js +14 -37
- package/lib/index.js +16 -17
- package/lib/install.js +24 -37
- package/lib/locales/en.js +3 -11
- package/lib/locales/zh.js +3 -11
- package/lib/package.js +164 -218
- package/lib/provider.js +85 -107
- package/lib/types.js +1 -3
- package/lib/user.d.ts +1 -1
- package/lib/user.js +26 -39
- package/lib/utils/add-gitignore.js +16 -29
- package/lib/utils/app-info-parser/aab.js +133 -157
- package/lib/utils/app-info-parser/apk.js +42 -39
- package/lib/utils/app-info-parser/app.js +5 -11
- package/lib/utils/app-info-parser/index.js +21 -31
- package/lib/utils/app-info-parser/ipa.js +35 -35
- package/lib/utils/app-info-parser/resource-finder.js +84 -71
- package/lib/utils/app-info-parser/utils.js +52 -77
- package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
- package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
- package/lib/utils/app-info-parser/zip.js +43 -51
- package/lib/utils/check-lockfile.js +28 -37
- package/lib/utils/check-plugin.js +16 -32
- package/lib/utils/command-result.js +7 -20
- package/lib/utils/constants.js +23 -63
- package/lib/utils/dep-versions.js +21 -27
- package/lib/utils/git.js +20 -64
- package/lib/utils/hbcTransform.js +133 -246
- package/lib/utils/http-helper.js +33 -44
- package/lib/utils/i18n.js +17 -26
- package/lib/utils/index.js +137 -179
- package/lib/utils/latest-version/index.js +128 -137
- package/lib/utils/options.js +13 -34
- package/lib/utils/plugin-config.js +43 -56
- package/lib/utils/runtime.js +50 -108
- package/lib/utils/zip-entries.js +70 -97
- package/lib/utils/zip-options.js +80 -181
- package/lib/versions.js +231 -265
- package/package.json +19 -21
- package/src/api.ts +44 -3
- package/src/package.ts +1 -1
- package/src/user.ts +1 -1
- package/src/versions.ts +1 -1
package/lib/app.js
CHANGED
|
@@ -1,51 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
get getAppCommands () {
|
|
19
|
-
return getAppCommands;
|
|
20
|
-
},
|
|
21
|
-
get getPlatform () {
|
|
22
|
-
return getPlatform;
|
|
23
|
-
},
|
|
24
|
-
get getSelectedApp () {
|
|
25
|
-
return getSelectedApp;
|
|
26
|
-
},
|
|
27
|
-
get listApp () {
|
|
28
|
-
return listApp;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
32
|
-
const _ttytable = /*#__PURE__*/ _interop_require_default(require("tty-table"));
|
|
33
|
-
const _api = require("./api");
|
|
34
|
-
const _utils = require("./utils");
|
|
35
|
-
const _i18n = require("./utils/i18n");
|
|
36
|
-
function _interop_require_default(obj) {
|
|
37
|
-
return obj && obj.__esModule ? obj : {
|
|
38
|
-
default: obj
|
|
39
|
-
};
|
|
40
|
-
}
|
|
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.getPlatform = getPlatform;
|
|
7
|
+
exports.assertPlatform = assertPlatform;
|
|
8
|
+
exports.getSelectedApp = getSelectedApp;
|
|
9
|
+
exports.listApp = listApp;
|
|
10
|
+
exports.chooseApp = chooseApp;
|
|
11
|
+
exports.getAppCommands = getAppCommands;
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const tty_table_1 = __importDefault(require("tty-table"));
|
|
14
|
+
const api_1 = require("./api");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
const i18n_1 = require("./utils/i18n");
|
|
41
17
|
async function getPlatform(platform) {
|
|
42
|
-
return assertPlatform(platform || await (0,
|
|
18
|
+
return assertPlatform(platform || (await (0, utils_1.question)((0, i18n_1.t)('platformQuestion'))));
|
|
43
19
|
}
|
|
44
20
|
function assertPlatform(platform) {
|
|
45
21
|
if (platform !== 'ios' && platform !== 'android' && platform !== 'harmony') {
|
|
46
|
-
throw new Error((0,
|
|
47
|
-
platform
|
|
48
|
-
}));
|
|
22
|
+
throw new Error((0, i18n_1.t)('unsupportedPlatform', { platform }));
|
|
49
23
|
}
|
|
50
24
|
return platform;
|
|
51
25
|
}
|
|
@@ -53,124 +27,103 @@ async function getSelectedApp(platform, configPath) {
|
|
|
53
27
|
assertPlatform(platform);
|
|
54
28
|
let updateInfo = {};
|
|
55
29
|
try {
|
|
56
|
-
updateInfo = JSON.parse(await
|
|
57
|
-
}
|
|
30
|
+
updateInfo = JSON.parse(await fs_1.default.promises.readFile(configPath || 'update.json', 'utf8'));
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
58
33
|
if (e.code === 'ENOENT') {
|
|
59
|
-
throw new Error((0,
|
|
60
|
-
platform
|
|
61
|
-
}));
|
|
34
|
+
throw new Error((0, i18n_1.t)('appNotSelected', { platform }));
|
|
62
35
|
}
|
|
63
36
|
throw e;
|
|
64
37
|
}
|
|
65
38
|
const info = updateInfo[platform];
|
|
66
39
|
if (!info) {
|
|
67
|
-
throw new Error((0,
|
|
68
|
-
platform
|
|
69
|
-
}));
|
|
40
|
+
throw new Error((0, i18n_1.t)('appNotSelected', { platform }));
|
|
70
41
|
}
|
|
71
42
|
return {
|
|
72
43
|
appId: String(info.appId),
|
|
73
44
|
appKey: info.appKey,
|
|
74
|
-
platform
|
|
45
|
+
platform,
|
|
75
46
|
};
|
|
76
47
|
}
|
|
77
48
|
async function listApp(platform = '') {
|
|
78
|
-
const { data } = await (0,
|
|
49
|
+
const { data } = await (0, api_1.get)('/app/list');
|
|
79
50
|
const allApps = data;
|
|
80
|
-
const list = platform
|
|
51
|
+
const list = platform
|
|
52
|
+
? allApps.filter((app) => app.platform === platform)
|
|
53
|
+
: allApps;
|
|
81
54
|
const header = [
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
value: (0, _i18n.t)('appName')
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
value: (0, _i18n.t)('platform')
|
|
90
|
-
}
|
|
55
|
+
{ value: (0, i18n_1.t)('appId') },
|
|
56
|
+
{ value: (0, i18n_1.t)('appName') },
|
|
57
|
+
{ value: (0, i18n_1.t)('platform') },
|
|
91
58
|
];
|
|
92
59
|
const rows = [];
|
|
93
|
-
for (const app of list){
|
|
94
|
-
rows.push([
|
|
95
|
-
app.id,
|
|
96
|
-
app.name,
|
|
97
|
-
app.platform
|
|
98
|
-
]);
|
|
60
|
+
for (const app of list) {
|
|
61
|
+
rows.push([app.id, app.name, app.platform]);
|
|
99
62
|
}
|
|
100
|
-
console.log((0,
|
|
101
|
-
console.log(`\n${(0,
|
|
102
|
-
count: list.length,
|
|
103
|
-
platform
|
|
104
|
-
})}`);
|
|
63
|
+
console.log((0, tty_table_1.default)(header, rows).render());
|
|
64
|
+
console.log(`\n${(0, i18n_1.t)('totalApps', { count: list.length, platform })}`);
|
|
105
65
|
return list;
|
|
106
66
|
}
|
|
107
67
|
async function chooseApp(platform) {
|
|
108
68
|
const list = await listApp(platform);
|
|
109
|
-
while(true){
|
|
110
|
-
const id = await (0,
|
|
111
|
-
const app = list.find((item)=>item.id === Number(id));
|
|
69
|
+
while (true) {
|
|
70
|
+
const id = await (0, utils_1.question)((0, i18n_1.t)('enterAppIdQuestion'));
|
|
71
|
+
const app = list.find((item) => item.id === Number(id));
|
|
112
72
|
if (app) {
|
|
113
73
|
return app;
|
|
114
74
|
}
|
|
115
75
|
}
|
|
116
76
|
}
|
|
117
|
-
async function selectApp({ args, options }) {
|
|
77
|
+
async function selectApp({ args, options, }) {
|
|
118
78
|
const platform = await getPlatform(options.platform);
|
|
119
|
-
const id = args[0]
|
|
79
|
+
const id = args[0]
|
|
80
|
+
? Number.parseInt(args[0], 10)
|
|
81
|
+
: (await chooseApp(platform)).id;
|
|
120
82
|
const configPath = options.config;
|
|
121
83
|
let updateInfo = {};
|
|
122
84
|
try {
|
|
123
|
-
updateInfo = JSON.parse(await
|
|
124
|
-
}
|
|
85
|
+
updateInfo = JSON.parse(await fs_1.default.promises.readFile(configPath || 'update.json', 'utf8'));
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
125
88
|
if (e.code !== 'ENOENT') {
|
|
126
|
-
console.error((0,
|
|
89
|
+
console.error((0, i18n_1.t)('failedToParseUpdateJson'));
|
|
127
90
|
throw e;
|
|
128
91
|
}
|
|
129
92
|
}
|
|
130
|
-
const { appKey } = await (0,
|
|
93
|
+
const { appKey } = await (0, api_1.get)(`/app/${id}`);
|
|
131
94
|
updateInfo[platform] = {
|
|
132
95
|
appId: id,
|
|
133
|
-
appKey
|
|
96
|
+
appKey,
|
|
134
97
|
};
|
|
135
|
-
await
|
|
98
|
+
await fs_1.default.promises.writeFile(configPath || 'update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
|
136
99
|
}
|
|
137
100
|
function getAppCommands() {
|
|
138
101
|
return {
|
|
139
|
-
createApp: async ({ options })=>{
|
|
140
|
-
const name = options.name || await (0,
|
|
102
|
+
createApp: async ({ options, }) => {
|
|
103
|
+
const name = options.name || (await (0, utils_1.question)((0, i18n_1.t)('appNameQuestion')));
|
|
141
104
|
const { downloadUrl } = options;
|
|
142
105
|
const platform = await getPlatform(options.platform);
|
|
143
|
-
const { id } = await (0,
|
|
144
|
-
|
|
145
|
-
platform,
|
|
146
|
-
downloadUrl
|
|
147
|
-
});
|
|
148
|
-
console.log((0, _i18n.t)('createAppSuccess', {
|
|
149
|
-
id
|
|
150
|
-
}));
|
|
106
|
+
const { id } = await (0, api_1.post)('/app/create', { name, platform, downloadUrl });
|
|
107
|
+
console.log((0, i18n_1.t)('createAppSuccess', { id }));
|
|
151
108
|
await selectApp({
|
|
152
|
-
args: [
|
|
153
|
-
|
|
154
|
-
],
|
|
155
|
-
options: {
|
|
156
|
-
platform
|
|
157
|
-
}
|
|
109
|
+
args: [String(id)],
|
|
110
|
+
options: { platform },
|
|
158
111
|
});
|
|
159
112
|
},
|
|
160
|
-
deleteApp: async ({ args, options })=>{
|
|
113
|
+
deleteApp: async ({ args, options, }) => {
|
|
161
114
|
const { platform } = options;
|
|
162
115
|
const id = args[0] || (await chooseApp(platform)).id;
|
|
163
116
|
if (!id) {
|
|
164
|
-
console.log((0,
|
|
117
|
+
console.log((0, i18n_1.t)('cancelled'));
|
|
165
118
|
return;
|
|
166
119
|
}
|
|
167
|
-
await (0,
|
|
168
|
-
console.log((0,
|
|
120
|
+
await (0, api_1.doDelete)(`/app/${id}`);
|
|
121
|
+
console.log((0, i18n_1.t)('operationSuccess'));
|
|
169
122
|
},
|
|
170
|
-
apps: async ({ options })=>{
|
|
123
|
+
apps: async ({ options }) => {
|
|
171
124
|
const { platform = '' } = options;
|
|
172
125
|
return listApp(platform);
|
|
173
126
|
},
|
|
174
|
-
selectApp
|
|
127
|
+
selectApp,
|
|
175
128
|
};
|
|
176
129
|
}
|
package/lib/bin.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const _i18n = require("./utils/i18n");
|
|
15
|
-
const _versions = require("./versions");
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const app_1 = require("./app");
|
|
6
|
+
const bundle_1 = require("./bundle");
|
|
7
|
+
const diff_1 = require("./diff");
|
|
8
|
+
const install_1 = require("./install");
|
|
9
|
+
const package_1 = require("./package");
|
|
10
|
+
const user_1 = require("./user");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const i18n_1 = require("./utils/i18n");
|
|
13
|
+
const versions_1 = require("./versions");
|
|
16
14
|
function isTruthyEnv(value) {
|
|
17
|
-
return value === '1' ||
|
|
15
|
+
return value === '1' || value?.toLowerCase() === 'true';
|
|
18
16
|
}
|
|
19
17
|
function printUsage(exitCode = 1) {
|
|
20
18
|
console.log('React Native Update CLI');
|
|
21
19
|
console.log('');
|
|
22
20
|
console.log('Commands:');
|
|
23
|
-
for (const name of Object.keys(commandHandlers)){
|
|
21
|
+
for (const name of Object.keys(commandHandlers)) {
|
|
24
22
|
console.log(` ${name}`);
|
|
25
23
|
}
|
|
26
24
|
console.log('');
|
|
@@ -32,40 +30,45 @@ function printUsage(exitCode = 1) {
|
|
|
32
30
|
process.exit(exitCode);
|
|
33
31
|
}
|
|
34
32
|
const commandHandlers = {
|
|
35
|
-
...
|
|
36
|
-
...
|
|
37
|
-
...
|
|
38
|
-
...(0,
|
|
39
|
-
...
|
|
40
|
-
...
|
|
41
|
-
...
|
|
42
|
-
help: printUsage
|
|
33
|
+
...user_1.userCommands,
|
|
34
|
+
...bundle_1.bundleCommands,
|
|
35
|
+
...diff_1.diffCommands,
|
|
36
|
+
...(0, app_1.getAppCommands)(),
|
|
37
|
+
...package_1.packageCommands,
|
|
38
|
+
...versions_1.versionCommands,
|
|
39
|
+
...install_1.installCommands,
|
|
40
|
+
help: printUsage,
|
|
43
41
|
};
|
|
44
42
|
async function run() {
|
|
45
|
-
await (0,
|
|
43
|
+
await (0, utils_1.printVersionCommand)();
|
|
46
44
|
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
|
47
45
|
process.exit();
|
|
48
46
|
}
|
|
49
47
|
const argv = require('cli-arguments').parse(require('../cli.json'));
|
|
50
|
-
global.NO_INTERACTIVE =
|
|
51
|
-
|
|
48
|
+
global.NO_INTERACTIVE =
|
|
49
|
+
Boolean(argv.options['no-interactive']) ||
|
|
50
|
+
isTruthyEnv(process.env.NO_INTERACTIVE);
|
|
51
|
+
global.USE_ACC_OSS =
|
|
52
|
+
Boolean(argv.options.acc) || isTruthyEnv(process.env.USE_ACC_OSS);
|
|
52
53
|
try {
|
|
53
|
-
await (0,
|
|
54
|
+
await (0, api_1.loadSession)();
|
|
54
55
|
if (argv.command === 'help') {
|
|
55
56
|
printUsage(0);
|
|
56
|
-
}
|
|
57
|
+
}
|
|
58
|
+
else if (argv.command === 'list') {
|
|
57
59
|
printUsage(0);
|
|
58
|
-
}
|
|
60
|
+
}
|
|
61
|
+
else if (commandHandlers[argv.command]) {
|
|
59
62
|
const handler = commandHandlers[argv.command];
|
|
60
63
|
await handler(argv);
|
|
61
|
-
} else {
|
|
62
|
-
throw new Error((0, _i18n.t)('unknownCommand', {
|
|
63
|
-
command: argv.command
|
|
64
|
-
}));
|
|
65
64
|
}
|
|
66
|
-
|
|
65
|
+
else {
|
|
66
|
+
throw new Error((0, i18n_1.t)('unknownCommand', { command: argv.command }));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
67
70
|
if (err.status === 401) {
|
|
68
|
-
console.log((0,
|
|
71
|
+
console.log((0, i18n_1.t)('loginFirst'));
|
|
69
72
|
process.exit(1);
|
|
70
73
|
}
|
|
71
74
|
console.error(err.stack);
|
package/lib/bundle-pack.js
CHANGED
|
@@ -1,106 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get: function() {
|
|
8
|
-
return packBundle;
|
|
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]; } };
|
|
9
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;
|
|
10
17
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return obj && obj.__esModule ? obj : {
|
|
18
|
-
default: obj
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
-
if (typeof WeakMap !== "function") return null;
|
|
23
|
-
var cacheBabelInterop = new WeakMap();
|
|
24
|
-
var cacheNodeInterop = new WeakMap();
|
|
25
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
-
})(nodeInterop);
|
|
28
|
-
}
|
|
29
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
30
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
|
-
return obj;
|
|
32
|
-
}
|
|
33
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
34
|
-
return {
|
|
35
|
-
default: obj
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
36
24
|
};
|
|
37
|
-
|
|
38
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
39
|
-
if (cache && cache.has(obj)) {
|
|
40
|
-
return cache.get(obj);
|
|
41
|
-
}
|
|
42
|
-
var newObj = {
|
|
43
|
-
__proto__: null
|
|
25
|
+
return ownKeys(o);
|
|
44
26
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
'txt.map'
|
|
65
|
-
];
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.packBundle = packBundle;
|
|
40
|
+
const fs = __importStar(require("fs-extra"));
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const yazl_1 = require("yazl");
|
|
43
|
+
const i18n_1 = require("./utils/i18n");
|
|
44
|
+
const zip_options_1 = require("./utils/zip-options");
|
|
45
|
+
const ignorePackingExtensions = ['DS_Store', 'txt.map'];
|
|
66
46
|
async function packBundle(dir, output, bundleName) {
|
|
67
47
|
const ignorePackingFileNames = [
|
|
68
48
|
'index.bundlejs.map',
|
|
69
|
-
'bundle.harmony.js.map'
|
|
49
|
+
'bundle.harmony.js.map',
|
|
70
50
|
];
|
|
71
51
|
if (bundleName) {
|
|
72
52
|
ignorePackingFileNames.push(`${bundleName}.map`);
|
|
73
53
|
}
|
|
74
|
-
console.log((0,
|
|
75
|
-
|
|
76
|
-
await new Promise((resolve, reject)=>{
|
|
77
|
-
const zipfile = new
|
|
54
|
+
console.log((0, i18n_1.t)('packing'));
|
|
55
|
+
fs.ensureDirSync(path_1.default.dirname(output));
|
|
56
|
+
await new Promise((resolve, reject) => {
|
|
57
|
+
const zipfile = new yazl_1.ZipFile();
|
|
78
58
|
function addDirectory(root, rel) {
|
|
79
59
|
if (rel) {
|
|
80
60
|
zipfile.addEmptyDirectory(rel);
|
|
81
61
|
}
|
|
82
|
-
const children =
|
|
83
|
-
for (const name of children){
|
|
84
|
-
if (ignorePackingFileNames.includes(name) ||
|
|
62
|
+
const children = fs.readdirSync(root);
|
|
63
|
+
for (const name of children) {
|
|
64
|
+
if (ignorePackingFileNames.includes(name) ||
|
|
65
|
+
ignorePackingExtensions.some((ext) => name.endsWith(`.${ext}`))) {
|
|
85
66
|
continue;
|
|
86
67
|
}
|
|
87
|
-
const fullPath =
|
|
88
|
-
const stat =
|
|
68
|
+
const fullPath = path_1.default.join(root, name);
|
|
69
|
+
const stat = fs.statSync(fullPath);
|
|
89
70
|
if (stat.isFile()) {
|
|
90
|
-
zipfile.addFile(fullPath, rel + name, (0,
|
|
91
|
-
}
|
|
71
|
+
zipfile.addFile(fullPath, rel + name, (0, zip_options_1.zipOptionsForPayloadFile)(fullPath, rel + name));
|
|
72
|
+
}
|
|
73
|
+
else if (stat.isDirectory()) {
|
|
92
74
|
addDirectory(fullPath, `${rel}${name}/`);
|
|
93
75
|
}
|
|
94
76
|
}
|
|
95
77
|
}
|
|
96
78
|
addDirectory(dir, '');
|
|
97
|
-
zipfile.outputStream.on('error', (err)=>reject(err));
|
|
98
|
-
zipfile.outputStream.pipe(
|
|
79
|
+
zipfile.outputStream.on('error', (err) => reject(err));
|
|
80
|
+
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
|
|
99
81
|
resolve();
|
|
100
82
|
});
|
|
101
83
|
zipfile.end();
|
|
102
84
|
});
|
|
103
|
-
console.log((0,
|
|
104
|
-
file: output
|
|
105
|
-
}));
|
|
85
|
+
console.log((0, i18n_1.t)('fileGenerated', { file: output }));
|
|
106
86
|
}
|