weapp-ide-cli 0.0.2 → 1.0.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/README.md +2 -2
- package/dist/cli.js +27 -38
- package/dist/index.js +6 -1
- package/dist/types/compose.d.ts +1 -0
- package/dist/types/config.d.ts +3 -0
- package/dist/types/types.d.ts +4 -0
- package/dist/types/utils.d.ts +5 -0
- package/dist/{utils-b22f3285.js → utils-a2548256.js} +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,12 +22,12 @@ weapp-ide-cli open
|
|
|
22
22
|
weapp open -p
|
|
23
23
|
# 等价
|
|
24
24
|
weapp open --project
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
|
|
27
27
|
# 在相对的路径,打开微信开发者工具
|
|
28
28
|
# 比如 uni-app 就可以在项目目录执行
|
|
29
29
|
weapp open -p dist/dev/mp-weixin
|
|
30
|
-
#
|
|
30
|
+
# 工具会把相对路径转化为绝对路径,然后打开(绝对路径不转化)
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
## 常用命令
|
package/dist/cli.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var utils = require('./utils-
|
|
4
|
-
var execa = require('execa');
|
|
5
|
-
var fs = require('fs/promises');
|
|
3
|
+
var utils = require('./utils-a2548256.js');
|
|
6
4
|
var readline = require('readline');
|
|
7
|
-
var
|
|
5
|
+
var fs = require('fs/promises');
|
|
6
|
+
require('path');
|
|
8
7
|
require('os');
|
|
8
|
+
require('execa');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
11
|
|
|
12
|
-
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
13
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
14
12
|
var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
|
|
15
|
-
var
|
|
13
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
16
14
|
|
|
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
15
|
function createCustomConfig(params) {
|
|
24
16
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
25
17
|
const isExisted = yield utils.exist(utils.defaultCustomConfigDirPath);
|
|
@@ -41,7 +33,7 @@ function getConfig() {
|
|
|
41
33
|
encoding: 'utf8'
|
|
42
34
|
});
|
|
43
35
|
const config = JSON.parse(content);
|
|
44
|
-
console.log('自定义cli路径:', config.cliPath);
|
|
36
|
+
console.log('> 自定义cli路径:', config.cliPath);
|
|
45
37
|
return config;
|
|
46
38
|
}
|
|
47
39
|
else {
|
|
@@ -50,7 +42,24 @@ function getConfig() {
|
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
44
|
});
|
|
53
|
-
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function compose(...funcs) {
|
|
48
|
+
if (funcs.length === 0) {
|
|
49
|
+
return (arg) => arg;
|
|
50
|
+
}
|
|
51
|
+
if (funcs.length === 1) {
|
|
52
|
+
return funcs[0];
|
|
53
|
+
}
|
|
54
|
+
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const rl = readline__default["default"].createInterface({
|
|
58
|
+
input: process.stdin,
|
|
59
|
+
output: process.stdout
|
|
60
|
+
});
|
|
61
|
+
const isSupported = Boolean(utils.defaultPath);
|
|
62
|
+
const argv = process.argv.slice(2);
|
|
54
63
|
function rlSetConfig() {
|
|
55
64
|
console.log('请设置微信web开发者工具 cli 的路径');
|
|
56
65
|
console.log('> 提示:命令行工具默认所在位置:');
|
|
@@ -66,8 +75,8 @@ function rlSetConfig() {
|
|
|
66
75
|
}));
|
|
67
76
|
});
|
|
68
77
|
}
|
|
78
|
+
const parseArgv = compose(utils.createAlias({ find: '-p', replacement: '--project' }), utils.createPathCompat('--result-output'), utils.createPathCompat('-r'), utils.createPathCompat('--qr-output'), utils.createPathCompat('-o'), utils.createPathCompat('--info-output'), utils.createPathCompat('-i'));
|
|
69
79
|
function main() {
|
|
70
|
-
var _a;
|
|
71
80
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
72
81
|
if (isSupported) {
|
|
73
82
|
const { cliPath } = yield getConfig();
|
|
@@ -77,28 +86,8 @@ function main() {
|
|
|
77
86
|
yield rlSetConfig();
|
|
78
87
|
return;
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
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;
|
|
89
|
+
const formattedArgv = parseArgv(argv);
|
|
90
|
+
yield utils.execute(cliPath, formattedArgv);
|
|
102
91
|
}
|
|
103
92
|
else {
|
|
104
93
|
console.log('在当前自定义路径中,未找到微信web开发者命令行工具,请重新指定路径');
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var utils = require('./utils-
|
|
5
|
+
var utils = require('./utils-a2548256.js');
|
|
6
6
|
require('path');
|
|
7
7
|
require('os');
|
|
8
|
+
require('execa');
|
|
8
9
|
require('fs/promises');
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
exports.createAlias = utils.createAlias;
|
|
14
|
+
exports.createPathCompat = utils.createPathCompat;
|
|
12
15
|
exports.defaultCustomConfigDirPath = utils.defaultCustomConfigDirPath;
|
|
13
16
|
exports.defaultCustomConfigFilePath = utils.defaultCustomConfigFilePath;
|
|
14
17
|
exports.defaultPath = utils.defaultPath;
|
|
18
|
+
exports.execute = utils.execute;
|
|
15
19
|
exports.exist = utils.exist;
|
|
16
20
|
exports.operatingSystemName = utils.operatingSystemName;
|
|
21
|
+
exports.resolvePath = utils.resolvePath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compose<TArgs extends any[]>(...funcs: TArgs): any;
|
package/dist/types/types.d.ts
CHANGED
package/dist/types/utils.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
+
import type { IAliasEntry } from './types';
|
|
1
2
|
export declare function exist(filepath: string, mode?: number): Promise<boolean>;
|
|
3
|
+
export declare function execute(cliPath: string, argv: string[]): Promise<void>;
|
|
4
|
+
export declare function resolvePath(filePath: string): string;
|
|
5
|
+
export declare function createAlias(entry: IAliasEntry): (argv: string[]) => string[];
|
|
6
|
+
export declare function createPathCompat(option: string): (argv: string[]) => string[];
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
4
|
var os = require('os');
|
|
5
|
+
var execa = require('execa');
|
|
5
6
|
var fs = require('fs/promises');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
9
|
|
|
9
10
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
10
11
|
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
12
|
+
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
11
13
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
12
14
|
|
|
13
15
|
const homedir = os__default["default"].homedir();
|
|
@@ -59,11 +61,75 @@ function exist(filepath, mode) {
|
|
|
59
61
|
return false;
|
|
60
62
|
}
|
|
61
63
|
});
|
|
64
|
+
}
|
|
65
|
+
function execute(cliPath, argv) {
|
|
66
|
+
var _a;
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const task = execa__default["default"](cliPath, argv);
|
|
69
|
+
(_a = task === null || task === void 0 ? void 0 : task.stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout);
|
|
70
|
+
yield task;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function resolvePath(filePath) {
|
|
74
|
+
if (path__default["default"].isAbsolute(filePath)) {
|
|
75
|
+
return filePath;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return path__default["default"].resolve(process.cwd(), filePath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function alias(argv, entry) {
|
|
82
|
+
let findIdx = argv.indexOf(entry.find);
|
|
83
|
+
if (findIdx > -1) {
|
|
84
|
+
argv[findIdx] = entry.replacement;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
findIdx = argv.indexOf(entry.replacement);
|
|
88
|
+
}
|
|
89
|
+
if (findIdx > -1) {
|
|
90
|
+
const paramIdx = findIdx + 1;
|
|
91
|
+
const param = argv[paramIdx];
|
|
92
|
+
if (param && param[0] !== '-') {
|
|
93
|
+
argv[paramIdx] = resolvePath(param);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
argv.splice(paramIdx, 0, process.cwd());
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return argv;
|
|
100
|
+
}
|
|
101
|
+
function pathCompat(argv, option) {
|
|
102
|
+
const findIdx = argv.indexOf(option);
|
|
103
|
+
if (findIdx > -1) {
|
|
104
|
+
const paramIdx = findIdx + 1;
|
|
105
|
+
const param = argv[paramIdx];
|
|
106
|
+
if (param && param[0] !== '-') {
|
|
107
|
+
argv[paramIdx] = resolvePath(param);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
argv.splice(paramIdx, 0, process.cwd());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return argv;
|
|
114
|
+
}
|
|
115
|
+
function createAlias(entry) {
|
|
116
|
+
return function (argv) {
|
|
117
|
+
return alias(argv, entry);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function createPathCompat(option) {
|
|
121
|
+
return function (argv) {
|
|
122
|
+
return pathCompat(argv, option);
|
|
123
|
+
};
|
|
62
124
|
}
|
|
63
125
|
|
|
64
126
|
exports.__awaiter = __awaiter;
|
|
127
|
+
exports.createAlias = createAlias;
|
|
128
|
+
exports.createPathCompat = createPathCompat;
|
|
65
129
|
exports.defaultCustomConfigDirPath = defaultCustomConfigDirPath;
|
|
66
130
|
exports.defaultCustomConfigFilePath = defaultCustomConfigFilePath;
|
|
67
131
|
exports.defaultPath = defaultPath;
|
|
132
|
+
exports.execute = execute;
|
|
68
133
|
exports.exist = exist;
|
|
69
134
|
exports.operatingSystemName = operatingSystemName;
|
|
135
|
+
exports.resolvePath = resolvePath;
|