xhs-mp-compiler-cli 1.0.2-beta.0 → 1.0.2
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 +81 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.js +22 -0
- package/dist/dev-server/index.d.ts +3 -0
- package/dist/dev-server/index.js +62 -0
- package/dist/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/dev-server/lib/ensurePort.js +32 -0
- package/dist/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/dev-server/lib/openBrowser.js +23 -0
- package/dist/dev-server/lib/openChrome.applescript +78 -0
- package/dist/globalData/SjsModule.d.ts +32 -0
- package/dist/globalData/SjsModule.js +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +114 -0
- package/dist/types/index.d.ts +106 -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/combineExtJson.d.ts +3 -0
- package/dist/utils/combineExtJson.js +74 -0
- package/dist/utils/common.d.ts +7 -0
- package/dist/utils/common.js +35 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/getCssSuffixName.d.ts +1 -0
- package/dist/utils/getCssSuffixName.js +9 -0
- package/dist/utils/getMlSuffixName.d.ts +1 -0
- package/dist/utils/getMlSuffixName.js +6 -0
- package/dist/utils/getPrefixName.d.ts +1 -0
- package/dist/utils/getPrefixName.js +6 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/transformAppJson.d.ts +16 -0
- package/dist/utils/transformAppJson.js +199 -0
- package/dist/utils/validateAppJson.d.ts +4 -0
- package/dist/utils/validateAppJson.js +111 -0
- package/dist/webpack-config/index.d.ts +4 -0
- package/dist/webpack-config/index.js +41 -0
- package/dist/webpack-config/lib/const.d.ts +13 -0
- package/dist/webpack-config/lib/const.js +15 -0
- package/dist/webpack-config/lib/css.d.ts +2 -0
- package/dist/webpack-config/lib/css.js +41 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +12 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.js +35 -0
- package/dist/webpack-config/lib/tagTransformMap.d.ts +35 -0
- package/dist/webpack-config/lib/tagTransformMap.js +38 -0
- package/dist/webpack-config/lib/utils.d.ts +5 -0
- package/dist/webpack-config/lib/utils.js +37 -0
- package/dist/webpack-config/loaders/component-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-loader.js +31 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +24 -0
- package/dist/webpack-config/loaders/mini-style-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/mini-style-loader.js +69 -0
- package/dist/webpack-config/loaders/render-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/render-entry-loader.js +50 -0
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/service-entry-loader.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +12 -0
- package/dist/webpack-config/loaders/sjs-loader/index.js +609 -0
- package/dist/webpack-config/loaders/sjs-loader/scope.d.ts +36 -0
- package/dist/webpack-config/loaders/sjs-loader/scope.js +122 -0
- package/dist/webpack-config/loaders/sjs-loader/tranform.d.ts +2 -0
- package/dist/webpack-config/loaders/sjs-loader/tranform.js +31 -0
- package/dist/webpack-config/loaders/utils.d.ts +13 -0
- package/dist/webpack-config/loaders/utils.js +41 -0
- package/dist/webpack-config/loaders/wxss-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/wxss-loader.js +76 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +19 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +205 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +8 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +40 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +36 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +71 -0
- package/dist/webpack-config/presets/babel.d.ts +8 -0
- package/dist/webpack-config/presets/babel.js +57 -0
- package/dist/webpack-config/presets/common.d.ts +4 -0
- package/dist/webpack-config/presets/common.js +40 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +23 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +87 -0
- package/dist/webpack-config/presets/mp/index.d.ts +4 -0
- package/dist/webpack-config/presets/mp/index.js +48 -0
- package/dist/webpack-config/presets/prod.d.ts +4 -0
- package/dist/webpack-config/presets/prod.js +83 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +18 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +77 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +50 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +14 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +42 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +31 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.js +160 -0
- package/dist/webpack-config/presets/render/index.d.ts +4 -0
- package/dist/webpack-config/presets/render/index.js +62 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +36 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +6 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +46 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.js +65 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +27 -0
- package/dist/webpack-config/presets/service/index.d.ts +4 -0
- package/dist/webpack-config/presets/service/index.js +39 -0
- package/package.json +2 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const index_1 = require("../index");
|
|
10
|
+
const commander = new commander_1.Command();
|
|
11
|
+
commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
|
|
12
|
+
commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
|
|
13
|
+
commander.usage('[options]').option('-l, --lite <string>', '轻量编译器');
|
|
14
|
+
commander.usage('[options]').option('-c, --compressJs <boolean>', 'compressJs');
|
|
15
|
+
commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
|
|
16
|
+
commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
|
|
17
|
+
commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
|
|
18
|
+
commander.parse(process.argv);
|
|
19
|
+
const mpDir = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
|
|
20
|
+
const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
|
|
21
|
+
const enableV1 = commander.opts().enableV1 === "true";
|
|
22
|
+
const enableV2 = commander.opts().enableV2 === "true";
|
|
23
|
+
const enableVDom = commander.opts().enableVDom === "true";
|
|
24
|
+
const compressJs = commander.opts().compressJs === "true";
|
|
25
|
+
const multiCompiler = (0, index_1.nodeStart)({
|
|
26
|
+
mpDir,
|
|
27
|
+
action: 'build',
|
|
28
|
+
platform,
|
|
29
|
+
compressJs,
|
|
30
|
+
enableSourcemap: false,
|
|
31
|
+
enableV1,
|
|
32
|
+
enableV2,
|
|
33
|
+
enableVDom,
|
|
34
|
+
});
|
|
35
|
+
multiCompiler.run((err, stats) => {
|
|
36
|
+
console.log(stats.toString({ warnings: true, errors: true, all: false }));
|
|
37
|
+
multiCompiler.close(() => {
|
|
38
|
+
// noop
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const commander_1 = require("commander");
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const index_1 = __importStar(require("../index"));
|
|
33
|
+
const commander = new commander_1.Command();
|
|
34
|
+
commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
|
|
35
|
+
commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
|
|
36
|
+
commander.usage('[options]').option('-P, --port <string>', 'set dev server port [default: 1388]');
|
|
37
|
+
commander.usage('[options]').option('-l, --lite <string>', 'lite compiler');
|
|
38
|
+
commander.usage('[options]').option('-o, --out <string>', '是否输出内容');
|
|
39
|
+
commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
|
|
40
|
+
commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
|
|
41
|
+
commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
|
|
42
|
+
commander.parse(process.argv);
|
|
43
|
+
const mpDir = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
|
|
44
|
+
const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
|
|
45
|
+
const port = commander.opts().port ? commander.opts().port : 1388;
|
|
46
|
+
const out = commander.opts().out === "true";
|
|
47
|
+
const enableV1 = commander.opts().enableV1 === "true";
|
|
48
|
+
const enableV2 = commander.opts().enableV2 === "true";
|
|
49
|
+
const enableVDom = commander.opts().enableVDom === "true";
|
|
50
|
+
process.env.PRETTIER_XHSML = "true";
|
|
51
|
+
if (out) {
|
|
52
|
+
const multiCompiler = (0, index_1.nodeStart)({
|
|
53
|
+
mpDir,
|
|
54
|
+
action: 'dev',
|
|
55
|
+
platform,
|
|
56
|
+
compressJs: false,
|
|
57
|
+
enableSourcemap: false,
|
|
58
|
+
enableV1,
|
|
59
|
+
enableV2,
|
|
60
|
+
enableVDom,
|
|
61
|
+
});
|
|
62
|
+
multiCompiler.run((err, stats) => {
|
|
63
|
+
console.log(stats.toString({ warnings: true, errors: true, all: false }));
|
|
64
|
+
multiCompiler.close(() => {
|
|
65
|
+
// noop
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
(0, index_1.default)({
|
|
71
|
+
mpDir,
|
|
72
|
+
action: 'dev',
|
|
73
|
+
platform,
|
|
74
|
+
compressJs: false,
|
|
75
|
+
port,
|
|
76
|
+
enableSourcemap: true,
|
|
77
|
+
enableV1,
|
|
78
|
+
enableV2,
|
|
79
|
+
enableVDom,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
10
|
+
const commander = new commander_1.Command();
|
|
11
|
+
commander
|
|
12
|
+
.version(package_json_1.default.version)
|
|
13
|
+
.usage('<command> [options]')
|
|
14
|
+
.command('dev', '启动开发服务')
|
|
15
|
+
.command('build', '打包小程序')
|
|
16
|
+
.parse(process.argv);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const webpack_config_1 = __importDefault(require("../webpack-config"));
|
|
16
|
+
const asyncWebpack_1 = __importDefault(require("../utils/asyncWebpack"));
|
|
17
|
+
const build = (config, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
// 构建 render
|
|
19
|
+
const webpackConfig = (0, webpack_config_1.default)(config);
|
|
20
|
+
return (0, asyncWebpack_1.default)(webpackConfig, callback);
|
|
21
|
+
});
|
|
22
|
+
exports.default = build;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
17
|
+
const ensurePort_1 = __importDefault(require("./lib/ensurePort"));
|
|
18
|
+
const openBrowser_1 = __importDefault(require("./lib/openBrowser"));
|
|
19
|
+
const webpack_config_1 = __importDefault(require("../webpack-config"));
|
|
20
|
+
const devServer = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const webpackConfig = (0, webpack_config_1.default)(config);
|
|
22
|
+
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
23
|
+
const host = 'localhost';
|
|
24
|
+
const devServerConfig = {
|
|
25
|
+
open: false,
|
|
26
|
+
historyApiFallback: true,
|
|
27
|
+
port: (config === null || config === void 0 ? void 0 : config.port) || 1388,
|
|
28
|
+
hot: false,
|
|
29
|
+
static: [
|
|
30
|
+
// emulator entry 地址
|
|
31
|
+
path_1.default.resolve('node_modules/@xhs/mp-simulator/dist'),
|
|
32
|
+
path_1.default.resolve('node_modules/@xhs/mp-js-core/dist'),
|
|
33
|
+
...JSON.parse(process.env.XHS_MP_LIB || '[]'), // 自定义地址
|
|
34
|
+
config.distDir,
|
|
35
|
+
],
|
|
36
|
+
client: {
|
|
37
|
+
logging: 'error',
|
|
38
|
+
overlay: false,
|
|
39
|
+
progress: false,
|
|
40
|
+
},
|
|
41
|
+
// firewall: false,
|
|
42
|
+
headers: {
|
|
43
|
+
'Access-Control-Allow-Origin': '*',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
// 检查端口是否被占用,若占用会修改 devServerConfig.port
|
|
47
|
+
yield (0, ensurePort_1.default)(devServerConfig);
|
|
48
|
+
const Server = require('webpack-dev-server');
|
|
49
|
+
const server = new Server(compiler, Object.assign(Object.assign({}, devServerConfig), { open: false }));
|
|
50
|
+
server.listen(devServerConfig.port, host, () => { });
|
|
51
|
+
let isBrowserOpened = false;
|
|
52
|
+
compiler.hooks.done.tap('xhs-mp-cli', stats => {
|
|
53
|
+
if (stats.hasErrors()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (devServerConfig.open && !isBrowserOpened) {
|
|
57
|
+
isBrowserOpened = true;
|
|
58
|
+
(0, openBrowser_1.default)(host, devServerConfig.port);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
exports.default = devServer;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
7
|
+
const net_1 = __importDefault(require("net"));
|
|
8
|
+
const ensurePort = (devServerConfig) => new Promise(res => {
|
|
9
|
+
const checkPort = () => {
|
|
10
|
+
const server = net_1.default.createServer().listen(devServerConfig.port, devServerConfig.client.host);
|
|
11
|
+
server.on('listening', () => {
|
|
12
|
+
server.close();
|
|
13
|
+
res(1);
|
|
14
|
+
});
|
|
15
|
+
server.on('error', err => {
|
|
16
|
+
if (err.code === 'EADDRINUSE') {
|
|
17
|
+
devServerConfig.port += 1;
|
|
18
|
+
checkPort(devServerConfig);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
checkPort();
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (err.code === 'EADDRINUSE') {
|
|
27
|
+
devServerConfig.port += 1;
|
|
28
|
+
checkPort(devServerConfig);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.default = ensurePort;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const open_1 = __importDefault(require("open"));
|
|
8
|
+
// eslint-disable-next-line consistent-return
|
|
9
|
+
const openBrowser = (host, port) => {
|
|
10
|
+
const url = `http://${host}:${port}`;
|
|
11
|
+
try {
|
|
12
|
+
(0, child_process_1.execSync)(`osascript ${__dirname}/openChrome.applescript ${encodeURI(url)}`, {
|
|
13
|
+
stdio: 'ignore',
|
|
14
|
+
});
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// Ignore errors.
|
|
19
|
+
}
|
|
20
|
+
// fallback to normal open
|
|
21
|
+
(0, open_1.default)(url);
|
|
22
|
+
};
|
|
23
|
+
exports.default = openBrowser;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
property targetTab: null
|
|
2
|
+
property targetTabIndex: -1
|
|
3
|
+
property targetWindow: null
|
|
4
|
+
|
|
5
|
+
on run argv
|
|
6
|
+
set theURL to item 1 of argv
|
|
7
|
+
|
|
8
|
+
with timeout of 2 seconds
|
|
9
|
+
tell application "Chrome"
|
|
10
|
+
|
|
11
|
+
if (count every window) = 0 then
|
|
12
|
+
make new window
|
|
13
|
+
end if
|
|
14
|
+
|
|
15
|
+
-- 1: Looking for tab running debugger
|
|
16
|
+
-- then, Reload debugging tab if found
|
|
17
|
+
-- then return
|
|
18
|
+
set found to my lookupTabWithUrl(theURL)
|
|
19
|
+
if found then
|
|
20
|
+
set targetWindow's active tab index to targetTabIndex
|
|
21
|
+
tell targetTab to reload
|
|
22
|
+
tell targetWindow to activate
|
|
23
|
+
set index of targetWindow to 1
|
|
24
|
+
return
|
|
25
|
+
end if
|
|
26
|
+
|
|
27
|
+
-- 2: Looking for Empty tab
|
|
28
|
+
-- In case debugging tab was not found
|
|
29
|
+
-- We try to find an empty tab instead
|
|
30
|
+
set found to my lookupTabWithUrl("chrome://newtab/")
|
|
31
|
+
if found then
|
|
32
|
+
set targetWindow's active tab index to targetTabIndex
|
|
33
|
+
set URL of targetTab to theURL
|
|
34
|
+
tell targetWindow to activate
|
|
35
|
+
return
|
|
36
|
+
end if
|
|
37
|
+
|
|
38
|
+
-- 3: Create new tab
|
|
39
|
+
-- both debugging and empty tab were not found
|
|
40
|
+
-- make a new tab with url
|
|
41
|
+
tell window 1
|
|
42
|
+
activate
|
|
43
|
+
make new tab with properties {URL:theURL}
|
|
44
|
+
end tell
|
|
45
|
+
end tell
|
|
46
|
+
end timeout
|
|
47
|
+
end run
|
|
48
|
+
|
|
49
|
+
-- Function:
|
|
50
|
+
-- Lookup tab with given url
|
|
51
|
+
-- if found, store tab, index, and window in properties
|
|
52
|
+
-- (properties were declared on top of file)
|
|
53
|
+
on lookupTabWithUrl(lookupUrl)
|
|
54
|
+
tell application "Chrome"
|
|
55
|
+
-- Find a tab with the given url
|
|
56
|
+
set found to false
|
|
57
|
+
set theTabIndex to -1
|
|
58
|
+
repeat with theWindow in every window
|
|
59
|
+
set theTabIndex to 0
|
|
60
|
+
repeat with theTab in every tab of theWindow
|
|
61
|
+
set theTabIndex to theTabIndex + 1
|
|
62
|
+
if (theTab's URL as string) contains lookupUrl then
|
|
63
|
+
-- assign tab, tab index, and window to properties
|
|
64
|
+
set targetTab to theTab
|
|
65
|
+
set targetTabIndex to theTabIndex
|
|
66
|
+
set targetWindow to theWindow
|
|
67
|
+
set found to true
|
|
68
|
+
exit repeat
|
|
69
|
+
end if
|
|
70
|
+
end repeat
|
|
71
|
+
|
|
72
|
+
if found then
|
|
73
|
+
exit repeat
|
|
74
|
+
end if
|
|
75
|
+
end repeat
|
|
76
|
+
end tell
|
|
77
|
+
return found
|
|
78
|
+
end lookupTabWithUrl
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type ModuleMap = {
|
|
2
|
+
[key: string]: {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
};
|
|
5
|
+
};
|
|
6
|
+
declare class SjsModule {
|
|
7
|
+
/**
|
|
8
|
+
* @NOTE
|
|
9
|
+
* 管理 file 与 sjs module 的关系
|
|
10
|
+
*/
|
|
11
|
+
moduleMap: ModuleMap;
|
|
12
|
+
/**
|
|
13
|
+
* @NOTE
|
|
14
|
+
* 收集 sjs 的相对路径
|
|
15
|
+
*/
|
|
16
|
+
sjsAbsoulatePaths: Set<string>;
|
|
17
|
+
templateHashToModuleName: Map<string, string[]>;
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* key:
|
|
21
|
+
* template path hash
|
|
22
|
+
* value:
|
|
23
|
+
* sjsScopeNames
|
|
24
|
+
*
|
|
25
|
+
* { 'Cc9103733ab20cb5ce2c008224782e53f': ['a1', 'b1', 'c1' ] }
|
|
26
|
+
*/
|
|
27
|
+
addTemplateHash(hash: string, sjsScopeNames: string[]): void;
|
|
28
|
+
add(issuer: any, moduleName: any, target: any): void;
|
|
29
|
+
addPath(path: string): void;
|
|
30
|
+
}
|
|
31
|
+
declare const _default: SjsModule;
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class SjsModule {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.moduleMap = {};
|
|
6
|
+
this.templateHashToModuleName = new Map();
|
|
7
|
+
this.sjsAbsoulatePaths = new Set();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* key:
|
|
11
|
+
* template path hash
|
|
12
|
+
* value:
|
|
13
|
+
* sjsScopeNames
|
|
14
|
+
*
|
|
15
|
+
* { 'Cc9103733ab20cb5ce2c008224782e53f': ['a1', 'b1', 'c1' ] }
|
|
16
|
+
*/
|
|
17
|
+
addTemplateHash(hash, sjsScopeNames) {
|
|
18
|
+
this.templateHashToModuleName.set(hash, sjsScopeNames);
|
|
19
|
+
}
|
|
20
|
+
add(issuer, moduleName, target) {
|
|
21
|
+
if (this.moduleMap[issuer]) {
|
|
22
|
+
this.moduleMap[issuer][moduleName] = target;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.moduleMap[issuer] = {
|
|
26
|
+
[moduleName]: target
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
addPath(path) {
|
|
31
|
+
this.sjsAbsoulatePaths.add(path);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = new SjsModule();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
import { IStart } from './types';
|
|
3
|
+
declare const start: (startConfig: IStart) => Promise<unknown>;
|
|
4
|
+
export default start;
|
|
5
|
+
export declare function nodeStart(startConfig: IStart): webpack.MultiCompiler;
|
|
6
|
+
export declare const utils: {
|
|
7
|
+
transformAppJson: (mpDir: string, miniprogramDir: string, extJsonPath?: string | undefined, compilation?: webpack.Compilation | undefined) => {
|
|
8
|
+
legacyAppJSON: any;
|
|
9
|
+
appJSON: import("./types").AppJSON;
|
|
10
|
+
};
|
|
11
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.utils = exports.nodeStart = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
18
|
+
const fs_extra_1 = require("fs-extra");
|
|
19
|
+
const dev_server_1 = __importDefault(require("./dev-server"));
|
|
20
|
+
const build_1 = __importDefault(require("./build"));
|
|
21
|
+
const webpack_config_1 = __importDefault(require("./webpack-config"));
|
|
22
|
+
const common_1 = require("./utils/common");
|
|
23
|
+
const types_1 = require("./types");
|
|
24
|
+
const projectConfig_1 = require("./utils/projectConfig");
|
|
25
|
+
const transformAppJson_1 = __importDefault(require("./utils/transformAppJson"));
|
|
26
|
+
// 防御编程
|
|
27
|
+
const handleVersion = (startConfig) => {
|
|
28
|
+
let { action, enableV1 = true, enableV2 = false, enableVDom = false } = startConfig;
|
|
29
|
+
// 正式环境必须有v1 并且不允许并行编译
|
|
30
|
+
if (action === 'build') {
|
|
31
|
+
enableV1 = true;
|
|
32
|
+
}
|
|
33
|
+
if (!enableV1 && !enableV2) {
|
|
34
|
+
enableV1 = true;
|
|
35
|
+
enableV2 = false;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
enableV1,
|
|
39
|
+
enableV2,
|
|
40
|
+
enableVDom,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const start = (startConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const { mpDir, action, callback, platform, extJsonPath, port } = startConfig;
|
|
45
|
+
process.env.__platform = platform;
|
|
46
|
+
const { enableV1, enableV2, enableVDom } = handleVersion(startConfig);
|
|
47
|
+
const projectJson = (0, projectConfig_1.getProjectConfig)(mpDir);
|
|
48
|
+
let miniprogramDir = path_1.default.join(mpDir, projectJson.miniprogramRoot || '');
|
|
49
|
+
miniprogramDir = miniprogramDir.endsWith('/') ? miniprogramDir.slice(0, -1) : miniprogramDir;
|
|
50
|
+
const config = {
|
|
51
|
+
mpDir: (0, common_1.toUnixPath)(mpDir),
|
|
52
|
+
miniprogramDir: (0, common_1.toUnixPath)(miniprogramDir).replace(/\/+$/, ""),
|
|
53
|
+
extJsonPath,
|
|
54
|
+
distDir: startConfig.distDir || path_1.default.join(process.cwd(), 'dist'),
|
|
55
|
+
env: action === 'dev' ? types_1.ENV.development : types_1.ENV.production,
|
|
56
|
+
watch: action === 'dev' || startConfig.watch,
|
|
57
|
+
tsConfigPath: (0, common_1.getTsConfigPath)(mpDir),
|
|
58
|
+
compressJs: false,
|
|
59
|
+
enableSourcemap: true,
|
|
60
|
+
port,
|
|
61
|
+
enableV1,
|
|
62
|
+
enableV2,
|
|
63
|
+
enableVDom,
|
|
64
|
+
};
|
|
65
|
+
if (action === 'dev') {
|
|
66
|
+
return (0, dev_server_1.default)(config);
|
|
67
|
+
}
|
|
68
|
+
return (0, build_1.default)(config, callback);
|
|
69
|
+
});
|
|
70
|
+
exports.default = start;
|
|
71
|
+
function nodeStart(startConfig) {
|
|
72
|
+
const { mpDir, action, tsConfigPath, platform, extJsonPath, compressJs = false, enableSourcemap = false, } = startConfig;
|
|
73
|
+
process.env.__platform = platform;
|
|
74
|
+
const { enableV1, enableV2, enableVDom } = handleVersion(startConfig);
|
|
75
|
+
const distDir = startConfig.distDir || path_1.default.join(process.cwd(), 'dist');
|
|
76
|
+
try {
|
|
77
|
+
if ((0, fs_extra_1.existsSync)(distDir)) { // eslint-disable-line
|
|
78
|
+
(0, fs_extra_1.rmSync)(distDir, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// noop
|
|
83
|
+
}
|
|
84
|
+
const projectJson = (0, projectConfig_1.getProjectConfig)(mpDir);
|
|
85
|
+
let miniprogramDir = path_1.default.join(mpDir, projectJson.miniprogramRoot || '');
|
|
86
|
+
miniprogramDir = miniprogramDir.endsWith('/') ? miniprogramDir.slice(0, -1) : miniprogramDir;
|
|
87
|
+
const config = {
|
|
88
|
+
mpDir: (0, common_1.toUnixPath)(mpDir),
|
|
89
|
+
miniprogramDir: (0, common_1.toUnixPath)(miniprogramDir).replace(/\/+$/, ""),
|
|
90
|
+
extJsonPath,
|
|
91
|
+
distDir,
|
|
92
|
+
env: action === 'dev' ? types_1.ENV.development : types_1.ENV.production,
|
|
93
|
+
tsConfigPath: tsConfigPath || (0, common_1.getTsConfigPath)(mpDir),
|
|
94
|
+
cacheDirectory: startConfig.cacheDirectory,
|
|
95
|
+
compressJs,
|
|
96
|
+
enableSourcemap,
|
|
97
|
+
enableV1,
|
|
98
|
+
enableV2,
|
|
99
|
+
enableVDom,
|
|
100
|
+
};
|
|
101
|
+
const webpackConfig = (0, webpack_config_1.default)(config);
|
|
102
|
+
webpackConfig.forEach(config => {
|
|
103
|
+
var _a, _b, _c, _d;
|
|
104
|
+
/* 修改在ide里的node_modules的路径 */
|
|
105
|
+
(_b = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../'));
|
|
106
|
+
// cli的node_modules路径
|
|
107
|
+
(_d = (_c = config.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../'));
|
|
108
|
+
});
|
|
109
|
+
return (0, webpack_1.default)(webpackConfig);
|
|
110
|
+
}
|
|
111
|
+
exports.nodeStart = nodeStart;
|
|
112
|
+
exports.utils = {
|
|
113
|
+
transformAppJson: transformAppJson_1.default,
|
|
114
|
+
};
|