weapp-ide-cli 0.0.1
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/README.md +44 -0
- package/bin/weapp.js +2 -0
- package/dist/cli.js +114 -0
- package/dist/index.js +16 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/defaults.d.ts +4 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/types.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/utils-b22f3285.js +69 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# weapp-ide-cli
|
|
2
|
+
|
|
3
|
+
微信开发者工具的命令行(v2) 的一个二次封装的包裹实现,来让开发者更加方便的使用微信开发者工具。
|
|
4
|
+
|
|
5
|
+
> 要使用命令行,注意首先需要在开发者工具的设置 -> 安全设置中开启服务端口。
|
|
6
|
+
## 快速使用
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i -g weapp-ide-cli
|
|
10
|
+
# or
|
|
11
|
+
yarn global add weapp-ide-cli
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### 执行命令
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
weapp open
|
|
18
|
+
# 等价
|
|
19
|
+
weapp-ide-cli open
|
|
20
|
+
|
|
21
|
+
# 在当前命令行所在位置,打开微信开发者工具
|
|
22
|
+
weapp open -p
|
|
23
|
+
# 等价
|
|
24
|
+
weapp open --project
|
|
25
|
+
# 官方 cli 项目选项中 `--project` 等价于 `-h`
|
|
26
|
+
|
|
27
|
+
# 在相对的路径,打开微信开发者工具
|
|
28
|
+
# 比如 uni-app 就可以在项目目录执行
|
|
29
|
+
weapp open -p dist/dev/mp-weixin
|
|
30
|
+
# 工具会把它转化为绝对路径,然后打开
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 自定义配置
|
|
34
|
+
|
|
35
|
+
`weapp config` 可以对微信开发者工具的 `cli` 目录进行配置,而配置文件就存放在用户的 `${homedir}/.weapp-ide-cli/config.json` 中,您可以随时进行更改。
|
|
36
|
+
|
|
37
|
+
> 比如 windows 存放位置就在 `C:\Users\${你的用户名}\.weapp-ide-cli/config.json`
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### 更多命令
|
|
41
|
+
|
|
42
|
+
这个工具本质是一个 `cli` 二次处理工具,所以绝大部分命令都是透传的。
|
|
43
|
+
|
|
44
|
+
全部的命令请查看 https://developers.weixin.qq.com/miniprogram/dev/devtools/cli.html
|
package/bin/weapp.js
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils-b22f3285.js');
|
|
4
|
+
var execa = require('execa');
|
|
5
|
+
var fs = require('fs/promises');
|
|
6
|
+
var readline = require('readline');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
require('os');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
13
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
14
|
+
var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
|
|
15
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
16
|
+
|
|
17
|
+
const rl = readline__default["default"].createInterface({
|
|
18
|
+
input: process.stdin,
|
|
19
|
+
output: process.stdout
|
|
20
|
+
});
|
|
21
|
+
const isSupported = Boolean(utils.defaultPath);
|
|
22
|
+
const argv = process.argv.slice(2);
|
|
23
|
+
function createCustomConfig(params) {
|
|
24
|
+
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const isExisted = yield utils.exist(utils.defaultCustomConfigDirPath);
|
|
26
|
+
if (!isExisted) {
|
|
27
|
+
yield fs__default["default"].mkdir(utils.defaultCustomConfigDirPath, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
yield fs__default["default"].writeFile(utils.defaultCustomConfigFilePath, JSON.stringify({
|
|
30
|
+
cliPath: params.cliPath
|
|
31
|
+
}, null, 2), {
|
|
32
|
+
encoding: 'utf8'
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function getConfig() {
|
|
37
|
+
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const isExisted = yield utils.exist(utils.defaultCustomConfigFilePath);
|
|
39
|
+
if (isExisted) {
|
|
40
|
+
const content = yield fs__default["default"].readFile(utils.defaultCustomConfigFilePath, {
|
|
41
|
+
encoding: 'utf8'
|
|
42
|
+
});
|
|
43
|
+
const config = JSON.parse(content);
|
|
44
|
+
console.log('自定义Cli路径:', config.cliPath);
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return {
|
|
49
|
+
cliPath: utils.defaultPath
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function rlSetConfig() {
|
|
55
|
+
console.log('请设置微信web开发者工具 cli 的路径:');
|
|
56
|
+
console.log('提示:命令行工具默认所在位置:');
|
|
57
|
+
console.log('macOS: <安装路径>/Contents/MacOS/cli');
|
|
58
|
+
console.log('Windows: <安装路径>/cli.bat');
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
rl.question('请输入微信web开发者工具 cli 的路径:', (cliPath) => utils.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield createCustomConfig({
|
|
62
|
+
cliPath
|
|
63
|
+
});
|
|
64
|
+
console.log(`全局配置存储位置:${utils.defaultCustomConfigFilePath}`);
|
|
65
|
+
resolve(cliPath);
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function main() {
|
|
70
|
+
var _a;
|
|
71
|
+
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
if (isSupported) {
|
|
73
|
+
const { cliPath } = yield getConfig();
|
|
74
|
+
const isExisted = yield utils.exist(cliPath);
|
|
75
|
+
if (isExisted) {
|
|
76
|
+
if (argv[0] === 'config') {
|
|
77
|
+
yield rlSetConfig();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let projectOptionIdx = argv.indexOf('-p');
|
|
81
|
+
if (projectOptionIdx > -1) {
|
|
82
|
+
argv[projectOptionIdx] = '--project';
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
projectOptionIdx = argv.indexOf('--project');
|
|
86
|
+
}
|
|
87
|
+
if (projectOptionIdx > -1) {
|
|
88
|
+
const projectPathIdx = projectOptionIdx + 1;
|
|
89
|
+
const projectPath = argv[projectPathIdx];
|
|
90
|
+
if (projectPath) {
|
|
91
|
+
if (!path__default["default"].isAbsolute(projectPath)) {
|
|
92
|
+
argv[projectPathIdx] = path__default["default"].resolve(process.cwd(), projectPath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
argv.splice(projectPathIdx, 0, process.cwd());
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const task = execa__default["default"](cliPath, argv);
|
|
100
|
+
(_a = task === null || task === void 0 ? void 0 : task.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
101
|
+
yield task;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
yield rlSetConfig();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log(`微信web开发者工具不支持当前平台:${utils.operatingSystemName} !`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
main().finally(() => {
|
|
113
|
+
process.exit();
|
|
114
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils = require('./utils-b22f3285.js');
|
|
6
|
+
require('path');
|
|
7
|
+
require('os');
|
|
8
|
+
require('fs/promises');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.defaultCustomConfigDirPath = utils.defaultCustomConfigDirPath;
|
|
13
|
+
exports.defaultCustomConfigFilePath = utils.defaultCustomConfigFilePath;
|
|
14
|
+
exports.defaultPath = utils.defaultPath;
|
|
15
|
+
exports.exist = utils.exist;
|
|
16
|
+
exports.operatingSystemName = utils.operatingSystemName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function exist(filepath: string, mode?: number): Promise<boolean>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var os = require('os');
|
|
5
|
+
var fs = require('fs/promises');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
10
|
+
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
12
|
+
|
|
13
|
+
const homedir = os__default["default"].homedir();
|
|
14
|
+
const SupportedPlatformsMap = {
|
|
15
|
+
Windows_NT: 'Windows_NT',
|
|
16
|
+
Darwin: 'Darwin'
|
|
17
|
+
};
|
|
18
|
+
const defaultPathMap = {
|
|
19
|
+
[SupportedPlatformsMap.Windows_NT]: 'C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat',
|
|
20
|
+
[SupportedPlatformsMap.Darwin]: '/Applications/wechatwebdevtools.app/Contents/MacOS/cli'
|
|
21
|
+
};
|
|
22
|
+
const operatingSystemName = os__default["default"].type();
|
|
23
|
+
const defaultCustomConfigDirPath = path__default["default"].join(homedir, '.weapp-ide-cli');
|
|
24
|
+
const defaultCustomConfigFilePath = path__default["default"].join(defaultCustomConfigDirPath, 'config.json');
|
|
25
|
+
const defaultPath = defaultPathMap[operatingSystemName];
|
|
26
|
+
|
|
27
|
+
/******************************************************************************
|
|
28
|
+
Copyright (c) Microsoft Corporation.
|
|
29
|
+
|
|
30
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
31
|
+
purpose with or without fee is hereby granted.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
34
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
35
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
36
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
37
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
38
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
39
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
40
|
+
***************************************************************************** */
|
|
41
|
+
|
|
42
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
43
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
44
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
45
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
46
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
47
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
48
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function exist(filepath, mode) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
try {
|
|
55
|
+
yield fs__default["default"].access(filepath, mode);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.__awaiter = __awaiter;
|
|
65
|
+
exports.defaultCustomConfigDirPath = defaultCustomConfigDirPath;
|
|
66
|
+
exports.defaultCustomConfigFilePath = defaultCustomConfigFilePath;
|
|
67
|
+
exports.defaultPath = defaultPath;
|
|
68
|
+
exports.exist = exist;
|
|
69
|
+
exports.operatingSystemName = operatingSystemName;
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "weapp-ide-cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "让微信开发者工具,用起来更加方便吧!",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"bin"
|
|
11
|
+
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"weapp": "bin/weapp.js",
|
|
14
|
+
"weapp-ide-cli": "bin/weapp.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "cross-env NODE_ENV=development rollup -cw",
|
|
18
|
+
"build": "cross-env NODE_ENV=production rollup -c",
|
|
19
|
+
"weapp": "ts-node src/cli.ts",
|
|
20
|
+
"debug": "ts-node src/cli.ts config",
|
|
21
|
+
"raw": "node bin/weapp.js"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"weapp",
|
|
29
|
+
"cli",
|
|
30
|
+
"uni-app",
|
|
31
|
+
"taro",
|
|
32
|
+
"ide",
|
|
33
|
+
"weapp-ide",
|
|
34
|
+
"mini",
|
|
35
|
+
"miniprogram"
|
|
36
|
+
],
|
|
37
|
+
"author": "SonOfMagic <qq1324318532@gmail.com>",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@icebreakers/rollup": "*",
|
|
41
|
+
"@icebreakers/tsconfig": "*"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"execa": "5.1.1"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/sonofmagic/utils.git"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/sonofmagic/utils/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/sonofmagic/utils/tree/main/packages/weapp-ide-cli#readme"
|
|
54
|
+
}
|