1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const fs = require("fs-extra");
|
12 | const path = require("path");
|
13 | const chalk_1 = require("chalk");
|
14 | const helper_1 = require("./mini/helper");
|
15 | const mini_1 = require("./mini");
|
16 | const PLUGIN_JSON = 'plugin.json';
|
17 | const PLUGIN_MOCK_JSON = 'plugin-mock.json';
|
18 | function build(appPath, { watch, platform }, builder) {
|
19 | return __awaiter(this, void 0, void 0, function* () {
|
20 | switch (platform) {
|
21 | case "weapp" :
|
22 | yield buildWxPlugin(appPath, { watch, type: "weapp" }, builder);
|
23 | break;
|
24 | case "alipay" :
|
25 | yield buildAlipayPlugin(appPath, { watch, type: "alipay" }, builder);
|
26 | break;
|
27 | default:
|
28 | console.log(chalk_1.default.red('输入插件类型错误,目前只支持 weapp/alipay 插件类型'));
|
29 | break;
|
30 | }
|
31 | });
|
32 | }
|
33 | exports.build = build;
|
34 | function buildWxPlugin(appPath, { watch, type }, builder) {
|
35 | return __awaiter(this, void 0, void 0, function* () {
|
36 | yield mini_1.build(appPath, { watch, type: "plugin" }, null, builder);
|
37 | const { outputDirName } = helper_1.getBuildData();
|
38 | yield mini_1.build(appPath, { watch, type }, {
|
39 | outputDirName: `${outputDirName}/miniprogram`
|
40 | }, builder);
|
41 | });
|
42 | }
|
43 | function buildAlipayPlugin(appPath, { watch, type }, builder) {
|
44 | return __awaiter(this, void 0, void 0, function* () {
|
45 | yield mini_1.build(appPath, { watch, type }, null, builder);
|
46 | const { sourceDir, outputDir } = helper_1.getBuildData();
|
47 | const pluginJson = path.join(sourceDir, PLUGIN_JSON);
|
48 | const pluginMockJson = path.join(sourceDir, PLUGIN_MOCK_JSON);
|
49 | if (fs.existsSync(pluginJson)) {
|
50 | fs.copyFileSync(pluginJson, path.join(outputDir, PLUGIN_JSON));
|
51 | }
|
52 | if (fs.existsSync(pluginMockJson)) {
|
53 | fs.copyFileSync(pluginMockJson, path.join(outputDir, PLUGIN_MOCK_JSON));
|
54 | }
|
55 | });
|
56 | }
|