tt-minigame-ide-cli 1.0.2 → 2.0.0-alpha.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.
Files changed (67) hide show
  1. package/README.md +5 -98
  2. package/bin/tmg.js +4 -161
  3. package/dist/cli.js +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/miniprogram-utils/src/constants/error.d.ts +41 -0
  6. package/dist/miniprogram-utils/src/constants/index.d.ts +217 -0
  7. package/dist/miniprogram-utils/src/constants/project.d.ts +3 -0
  8. package/dist/miniprogram-utils/src/constants/slardar-events/update-events.d.ts +24 -0
  9. package/dist/miniprogram-utils/src/data/app.d.ts +30 -0
  10. package/dist/miniprogram-utils/src/data/ext.d.ts +6 -0
  11. package/dist/miniprogram-utils/src/data/jsons.d.ts +23 -0
  12. package/dist/miniprogram-utils/src/data/project.d.ts +124 -0
  13. package/dist/miniprogram-utils/src/electron-monitor/common/tea-sdk.d.ts +17 -0
  14. package/dist/miniprogram-utils/src/formation.d.ts +17 -0
  15. package/dist/miniprogram-utils/src/network/axios.d.ts +28 -0
  16. package/dist/tt-ide-cli/src/features/audit.d.ts +9 -0
  17. package/dist/tt-ide-cli/src/features/cli-login.d.ts +1 -0
  18. package/dist/tt-ide-cli/src/features/config.d.ts +3 -0
  19. package/dist/tt-ide-cli/src/features/create.d.ts +7 -0
  20. package/dist/tt-ide-cli/src/features/login.d.ts +18 -0
  21. package/dist/tt-ide-cli/src/features/meta.d.ts +23 -0
  22. package/dist/tt-ide-cli/src/features/microgame/cloud-compile.d.ts +75 -0
  23. package/dist/tt-ide-cli/src/features/microgame/index.d.ts +3 -0
  24. package/dist/tt-ide-cli/src/features/microgame/meta.d.ts +1 -0
  25. package/dist/tt-ide-cli/src/features/microgame/utils/file-system.d.ts +13 -0
  26. package/dist/tt-ide-cli/src/features/microgame/utils/package.d.ts +22 -0
  27. package/dist/tt-ide-cli/src/features/microgame/utils/settings.d.ts +48 -0
  28. package/dist/tt-ide-cli/src/features/microgame/utils/source.type.d.ts +35 -0
  29. package/dist/tt-ide-cli/src/features/npm.d.ts +10 -0
  30. package/dist/tt-ide-cli/src/features/open.d.ts +3 -0
  31. package/dist/tt-ide-cli/src/features/packages.d.ts +53 -0
  32. package/dist/tt-ide-cli/src/features/preview.d.ts +80 -0
  33. package/dist/tt-ide-cli/src/features/third-party.d.ts +9 -0
  34. package/dist/tt-ide-cli/src/index.d.ts +22 -0
  35. package/dist/tt-ide-cli/src/monitor/cli-monitor.d.ts +15 -0
  36. package/dist/tt-ide-cli/src/monitor/constants.d.ts +7 -0
  37. package/dist/tt-ide-cli/src/monitor/index.d.ts +2 -0
  38. package/dist/tt-ide-cli/src/types.d.ts +44 -0
  39. package/dist/tt-ide-cli/src/utils/constants.d.ts +3 -0
  40. package/dist/tt-ide-cli/src/utils/cookie.d.ts +6 -0
  41. package/dist/tt-ide-cli/src/utils/logger.d.ts +19 -0
  42. package/dist/tt-ide-cli/src/utils/metrics.d.ts +67 -0
  43. package/dist/tt-ide-cli/src/utils/qrcode.d.ts +64 -0
  44. package/dist/tt-ide-cli/src/utils/util.d.ts +56 -0
  45. package/dist/tt-minigame-ide-cli/src/cli.d.ts +1 -0
  46. package/dist/tt-minigame-ide-cli/src/index.d.ts +1 -0
  47. package/dist/tt-minigame-ide-cli/src/types.d.ts +43 -0
  48. package/package.json +49 -26
  49. package/.yarnrc +0 -1
  50. package/LICENSE +0 -21
  51. package/README.en.md +0 -104
  52. package/lib/auth.js +0 -145
  53. package/lib/build-npm.js +0 -22
  54. package/lib/create.js +0 -106
  55. package/lib/index.d.ts +0 -23
  56. package/lib/index.js +0 -79
  57. package/lib/preview.js +0 -92
  58. package/lib/upload.js +0 -133
  59. package/lib/util/check.js +0 -84
  60. package/lib/util/config.js +0 -41
  61. package/lib/util/cookie.js +0 -36
  62. package/lib/util/helper.js +0 -245
  63. package/lib/util/logger.js +0 -54
  64. package/lib/util/qrcode.js +0 -34
  65. package/lib/util/request.js +0 -396
  66. package/lib/util/version.js +0 -27
  67. package/lib/version.js +0 -44
@@ -0,0 +1,56 @@
1
+ /// <reference types="node" />
2
+ import { ProjectConfig } from '@byted/miniprogram-utils/dist/data/project';
3
+ import archiver from 'archiver';
4
+ import { Transform } from 'stream';
5
+ export declare const HIGH_WATER_MARK: number;
6
+ export declare function isMac(): boolean;
7
+ export declare function isCli(): boolean;
8
+ export declare function isMiniGameCli(): boolean;
9
+ export declare function isIDE(): boolean;
10
+ export declare const maxConcurrency: () => number;
11
+ export declare function cleanArgs(cmd: any): any;
12
+ export declare function createProjectConfigFile(projectName: string, projectDir: string, useTypeScript?: boolean): Promise<void>;
13
+ export declare function getPackageRoot(): string;
14
+ /**
15
+ * Will throw {@link Error} if invalid
16
+ * @param number
17
+ */
18
+ export declare function validatePhoneNumber(number: string): void;
19
+ /**
20
+ * Will throw {@link Error} if invalid
21
+ * @param code
22
+ */
23
+ export declare function validateVerificationCode(code: string): void;
24
+ /**
25
+ * Will throw {@link Error} if invalid
26
+ * @param email
27
+ */
28
+ export declare function validateEmail(email: string): void;
29
+ /**
30
+ * Will throw {@link Error} if invalid
31
+ * @param id
32
+ */
33
+ export declare function validateAppId(id: string): void;
34
+ /**
35
+ * 简单 encode 字符串
36
+ * @param data
37
+ * @returns encoded string
38
+ */
39
+ export declare function mixEncode(data: string): string;
40
+ export declare function clearConsole(title?: string): void;
41
+ /**
42
+ * The folder **`$HOME/.tma-cli`**
43
+ */
44
+ export declare function getCliDefaultStoragePath(): string;
45
+ export declare function getAppid(projectConfig: ProjectConfig): string;
46
+ export declare function getProjectConfig(projectPath: string): Promise<ProjectConfig>;
47
+ export declare function getAppJson(projectConfig: ProjectConfig, projectPath: string, isGame: boolean): Promise<any>;
48
+ /**
49
+ * Duplicate a stream with md5 hash of its content
50
+ * @param source old source stream
51
+ * @returns a stream with md5
52
+ */
53
+ export declare function getMD5Stream(source: archiver.Archiver): Promise<Transform & {
54
+ __md5: string;
55
+ }>;
56
+ export declare const getNextVersion: (version: string) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { loginByEmail, loginByPhone, checkSession, buildNpm, setConfig, preview, upload, } from 'tt-ide-cli';
@@ -0,0 +1,43 @@
1
+ export interface ProjectInfo {
2
+ path: string;
3
+ }
4
+ export interface TMACliConfig {
5
+ proxy: string | null;
6
+ tempFilePath: string | null;
7
+ storagePath: string;
8
+ url: {
9
+ makeSchema: string;
10
+ compileProgress: string;
11
+ preview: string;
12
+ upload: string;
13
+ emailLogin: string;
14
+ mobileLogin: string;
15
+ sendLoginCode: string;
16
+ getUserInfo: string;
17
+ };
18
+ interactGameUrl: {
19
+ makeSchema: string;
20
+ compileProgress: string;
21
+ preview: string;
22
+ upload: string;
23
+ };
24
+ microgameUrl: {
25
+ makeSchema: string;
26
+ compileProgress: string;
27
+ preview: string;
28
+ upload: string;
29
+ versionInfo: string;
30
+ };
31
+ env: {
32
+ type: 'online' | 'ppe' | 'boe';
33
+ channel: string;
34
+ };
35
+ }
36
+ export interface QrcodeInfo {
37
+ format: 'imageFile' | 'terminal' | 'imageSVG' | 'plain' | null;
38
+ output?: string;
39
+ options?: {
40
+ small?: boolean;
41
+ };
42
+ }
43
+ export {};
package/package.json CHANGED
@@ -1,41 +1,64 @@
1
1
  {
2
2
  "name": "tt-minigame-ide-cli",
3
- "version": "1.0.2",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "Command line interface for micro app development",
5
- "main": "lib/index.js",
5
+ "license": "ISC",
6
+ "main": "dist/index.js",
6
7
  "bin": {
7
8
  "tmg": "bin/tmg.js"
8
9
  },
10
+ "files": [
11
+ "bin",
12
+ "templates",
13
+ "dist"
14
+ ],
9
15
  "scripts": {
10
- "doctoc": "doctoc README.md README.en.md"
16
+ "build": "yarn build:cli",
17
+ "build:cli": "cross-env NODE_ENV=production BUILD_ENV=CLI NODE_OPTIONS=--max-old-space-size=4096 webpack --config webpack.cli.js --progress",
18
+ "dev": "yarn dev:cli",
19
+ "dev:cli": "cross-env NODE_ENV=development webpack --config webpack.cli.js --progress --watch",
20
+ "prepublishOnly": "yarn build:cli",
21
+ "test": "npx patch-package && jest"
11
22
  },
12
- "author": "liubowen.howard@bytedance.com",
13
- "license": "ISC",
14
23
  "dependencies": {
15
- "@tt-miniprogram/ext-pack": "1.0.20",
16
- "address": "^1.1.2",
17
- "archiver": "^3.1.1",
18
- "axios": "^0.19.2",
19
- "chalk": "^3.0.0",
24
+ "@tt-miniprogram/ext-pack": "^1.0.33",
25
+ "archiver": "^5.3.0",
26
+ "chalk": "^4.1.2",
20
27
  "clipboardy": "^2.2.0",
21
- "commander": "^4.1.1",
22
- "compare-versions": "^4.1.3",
23
- "execa": "^4.0.0",
24
- "folder-hash": "^3.3.0",
25
- "form-data": "^3.0.0",
26
- "fs-extra": "^8.1.0",
27
- "glob": "^7.2.0",
28
- "inquirer": "^7.0.4",
29
- "minimist": "^1.2.0",
30
- "qrcode": "^1.5.0",
31
- "semver": "^7.3.5",
32
- "tunnel": "^0.0.6",
28
+ "commander": "5.1.0",
29
+ "deep-clone": "^3.0.3",
30
+ "easy-table": "^1.2.0",
31
+ "fast-glob": "^3.2.11",
32
+ "folder-hash": "^4.0.1",
33
+ "form-data": "^4.0.0",
34
+ "fs-extra": "^10.0.0",
35
+ "inquirer": "^8.2.0",
36
+ "ora": "^5.4.1",
37
+ "qrcode": "^1.4.4",
38
+ "qrcode-terminal": "^0.12.0",
39
+ "semver-compare": "^1.0.0",
33
40
  "unzipper": "^0.10.11"
34
41
  },
35
- "engines": {
36
- "node": ">=8.9"
37
- },
38
42
  "devDependencies": {
39
- "doctoc": "^2.2.0"
43
+ "@types/archiver": "^5.1.1",
44
+ "@types/chalk": "^2.2.0",
45
+ "@types/folder-hash": "^4.0.1",
46
+ "@types/fs-extra": "^9.0.13",
47
+ "@types/inquirer": "^8.1.3",
48
+ "@types/jest": "^29.2.3",
49
+ "@types/qrcode": "^1.4.2",
50
+ "@types/qrcode-terminal": "^0.12.0",
51
+ "@types/unzipper": "^0.10.4",
52
+ "@types/webpack-merge": "4.1.5",
53
+ "clean-webpack-plugin": "3.0.0",
54
+ "cross-env": "^7.0.3",
55
+ "jest": "^26.6.3",
56
+ "patch-package": "^6.4.7",
57
+ "ts-jest": "^26.5.6",
58
+ "ts-loader": "8.0.5",
59
+ "webpack-merge": "4.2.2"
60
+ },
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org"
40
63
  }
41
64
  }
package/.yarnrc DELETED
@@ -1 +0,0 @@
1
- registry "https://registry.npmjs.org"
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Bytedance Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.en.md DELETED
@@ -1,104 +0,0 @@
1
- # tmg-cli
2
-
3
- > `tmg` cli is the official tool for bytedance minigame development.
4
-
5
- [中文](./README.md)
6
-
7
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
-
10
- - [Installation](#installation)
11
- - [Usage](#usage)
12
- - [Login](#login)
13
- - [Login by email](#login-by-email)
14
- - [Preview project](#preview-project)
15
- - [Upload project](#upload-project)
16
- - [Get project version](#get-project-version)
17
-
18
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
19
-
20
- ## Installation
21
-
22
- It's recommended to install `tmg` globally.
23
-
24
- ```
25
- npm install -g tt-minigame-ide-cli
26
- ```
27
-
28
- ## Usage
29
-
30
- ### Login
31
-
32
- Login to the developer Platform. Proxy is supported.
33
-
34
- ```
35
- Usage: tmg login [options]
36
-
37
- Login to the developer platform
38
-
39
- Options:
40
- -m, --mobile Login by mobile
41
- -e, --email Login by email
42
- -p, --proxy <proxy> Login with proxy
43
- -h, --help output usage information
44
- ```
45
-
46
- ### Login by email
47
-
48
- ```
49
- Usage: login-e [email] [password]
50
-
51
- Login to the developer platform by E-mail
52
-
53
- Options:
54
- -p, --proxy <proxy> Login with proxy
55
- -h, --help Output usage information
56
- ```
57
-
58
- ### Preview project
59
-
60
- Upload project to remote and preview the result by scanning the output QR code.
61
-
62
- ```
63
- Usage: tmg preview [options] [entry]
64
-
65
- preview project by remote
66
-
67
- Options:
68
- -f, --force Preview project without local cache(deprecated)
69
- --disable-cache Preview project without local cache
70
- -s, --small Use small QR Code, but it does not take effect in some environments
71
- -u, --copy Copy remote url to clipboard
72
- -p, --proxy <proxy> Preview with proxy
73
- -h, --help output usage information
74
- -o, --output <path> QRCode image output path
75
- ```
76
-
77
- ### Upload project
78
-
79
- Upload project to the developer platform
80
-
81
- ```
82
- Usage: tmg upload [options] [entry]
83
-
84
- upload project to the developer platform
85
-
86
- Options:
87
- -v, --app-version <version> App version (eg: [major].[minor].[patch])
88
- -c, --app-changelog <log> Changelog for this version
89
- -p, --proxy <proxy> Update request proxy
90
- -u, --copy Copy remote url to clipboard
91
- -h, --help output usage information
92
- -o, --output <path> QRCode image output path
93
- ```
94
-
95
- ### Get project version
96
-
97
- Get latest released version of project.
98
-
99
- ```
100
- Usage: tmg version [entry]
101
-
102
- Get latest released version of project
103
- ```
104
-
package/lib/auth.js DELETED
@@ -1,145 +0,0 @@
1
- // login
2
- const inquirer = require('inquirer');
3
- const chalk = require('chalk');
4
- const { isValidPhoneNumber, isValidVerificationCode, isValidEmail } = require('./util/check');
5
- const { clearConsole, outputResult } = require('./util/logger');
6
- const { getMobileVerificationCode, userLogin, getUserData } = require('./util/request');
7
- const { saveUserCookies } = require('./util/cookie');
8
- const { mixEncode } = require('./util/helper');
9
-
10
- async function auth(options) {
11
- // Choose login type
12
- const loginType = await checkLoginType(options);
13
- let requestParams = {};
14
- clearConsole(chalk.bold.green(`${loginType === 'mobile' ? '📱': ' 📧'} Sign in with ${loginType}`));
15
- const { inputRet } = await inquirer.prompt([
16
- {
17
- name: 'inputRet',
18
- type: 'input',
19
- message: `Your ${loginType === 'mobile' ? 'mobile number': 'email'}:`
20
- }
21
- ]);
22
- if (loginType === 'mobile') {
23
- if (isValidPhoneNumber(inputRet)) {
24
- const result = await getMobileVerificationCode(inputRet, options.proxy);
25
- result.success ? console.log(chalk.green('Send verification code success')): console.log(chalk.red(result.msg));
26
- if (!result.success) return;
27
- const { code } = await inquirer.prompt([
28
- {
29
- name: 'code',
30
- type: 'input',
31
- message: `Your verification code:`
32
- }
33
- ]);
34
- if (isValidVerificationCode(code)) {
35
- requestParams = { mobile: inputRet, code };
36
- } else {
37
- console.log(chalk.red(`[CLI LOGIN ERROR]: Verification code ${chalk.cyan(code)} is not correct`));
38
- return;
39
- }
40
- } else {
41
- console.log(chalk.red(`[CLI LOGIN ERROR]: Mobile number ${chalk.cyan(inputRet)} is not correct`));
42
- return;
43
- }
44
- } else {
45
- if (isValidEmail(inputRet)) {
46
- const { pwd } = await inquirer.prompt([
47
- {
48
- name: 'pwd',
49
- type: 'password',
50
- message: `Your password:`
51
- }
52
- ]);
53
- requestParams = {
54
- mix_mode: 1,
55
- email: mixEncode(inputRet),
56
- password: mixEncode(pwd)
57
- }
58
- } else {
59
- console.log(chalk.red(`[CLI LOGIN ERROR]: Email ${chalk.cyan(inputRet)} is not correct`));
60
- return;
61
- }
62
- }
63
- // Start login
64
- const { success: loginSuccess, msg: loginMsg, cookies } = await userLogin(loginType, requestParams, options.proxy);
65
- if (!loginSuccess) {
66
- console.log(chalk.red(`[CLI LOGIN ERROR]: ${loginMsg}`));
67
- return;
68
- }
69
- await saveUserCookies(cookies);
70
- const { success: checkSuccess, msg: checkMsg } = await getUserData(options.proxy);
71
- if (!checkSuccess) {
72
- console.log(chalk.red(`[CLI LOGIN ERROR]: ${checkMsg}`));
73
- return;
74
- }
75
- outputResult('success', loginType, ` 🎉 Login success`);
76
- }
77
-
78
- async function loginDirect(options) {
79
- const proxy = options.proxy || options.cmd.proxy;
80
- if (!isValidEmail(options.email)) {
81
- console.log(chalk.red(`[CLI LOGIN ERROR]: Email ${chalk.cyan(options.email)} is not correct`));
82
- return;
83
- }
84
- const loginType = 'email';
85
- const requestParams = {
86
- mix_mode: 1,
87
- email: mixEncode(options.email),
88
- password: mixEncode(options.password)
89
- };
90
- // Start login
91
- const { success: loginSuccess, msg: loginMsg, cookies } = await userLogin(loginType, requestParams, proxy);
92
- if (!loginSuccess) {
93
- console.log(chalk.red(`[CLI LOGIN ERROR]: ${loginMsg}`));
94
- return;
95
- }
96
- await saveUserCookies(cookies, options.cacheDir);
97
- const { success: checkSuccess, msg: checkMsg } = await getUserData(proxy);
98
- if (!checkSuccess) {
99
- console.log(chalk.red(`[CLI LOGIN ERROR]: ${checkMsg}`));
100
- return;
101
- }
102
- outputResult('success', loginType, ` 🎉 Login success`);
103
- }
104
-
105
- async function checkLoginType(options) {
106
- let loginType = '';
107
- if (options.mobile) {
108
- loginType = 'mobile';
109
- } else if (options.email) {
110
- loginType = 'email';
111
- } else {
112
- const { action } = await inquirer.prompt([
113
- {
114
- name: 'action',
115
- type: 'list',
116
- message: `Please choose login type:`,
117
- choices: [
118
- { name: 'Mobile', value: 'mobile' },
119
- { name: 'Email', value: 'email' },
120
- { name: 'Cancel', value: false }
121
- ]
122
- }
123
- ]);
124
- if (!action) {
125
- return;
126
- } else {
127
- loginType = action;
128
- }
129
- }
130
- return loginType;
131
- }
132
-
133
- module.exports = (...args) => {
134
- if (args[0].type === 'direct') {
135
- return loginDirect(args[0]).catch(err => {
136
- console.log(chalk.red(`[CLI LOGIN ERROR]: ${err}`));
137
- process.exit(1);
138
- });
139
- } else {
140
- return auth(...args).catch(err => {
141
- console.log(chalk.red(`[CLI LOGIN ERROR]: ${err}`));
142
- process.exit(1);
143
- });
144
- }
145
- }
package/lib/build-npm.js DELETED
@@ -1,22 +0,0 @@
1
- const { packNpm } = require('@tt-miniprogram/ext-pack');
2
-
3
- const buildNpm = async (options) => {
4
- // console.log('buildNpm收到的options是:::', options);
5
- let projectPath = options.projectPath || process.cwd();
6
- return new Promise((resolve, reject) => {
7
- packNpm({
8
- rootPath: projectPath,
9
- isWatch: false
10
- }, function(err, info) {
11
- if (err) {
12
- console.log({buildSuccess: false, reason: err});
13
- reject({buildSuccess: false, reason: err});
14
- } else {
15
- console.log({buildSuccess: true, reason: info});
16
- resolve({buildSuccess: true, reason: info});
17
- }
18
- });
19
- });
20
- };
21
-
22
- module.exports = buildNpm;
package/lib/create.js DELETED
@@ -1,106 +0,0 @@
1
- // 创建小程序模版
2
- const fs = require('fs-extra');
3
- const path = require('path');
4
- const inquirer = require('inquirer');
5
- const chalk = require('chalk');
6
- const axios = require('axios');
7
- const unzipper = require('unzipper');
8
- const { createProjectConfigFile } = require('./util/config');
9
- const { clearConsole } = require('./util/logger');
10
- const { getVersion } = require('./util/version');
11
- const TEMPLATE_DOWNLOAD_URL = 'https://sf1-cdn-tos.douyinstatic.com/obj/microapp/frontend/ide/template/tma-showcase.zip';
12
-
13
- async function create(projectName, options) {
14
- const cwd = options.cwd || process.cwd();
15
- const targetDir = path.resolve(cwd, projectName || '.');
16
- clearConsole(chalk.bold.green(`miniprogram ide CLI v${getVersion()}`));
17
- if (fs.existsSync(targetDir)) {
18
- if (options.force) {
19
- await fs.remove(targetDir);
20
- } else {
21
- const { action } = await inquirer.prompt([
22
- {
23
- name: 'action',
24
- type: 'list',
25
- message: `Target directory ${chalk.cyan(targetDir)} already exists. Pick an action:`,
26
- choices: [
27
- { name: 'Overwrite', value: 'overwrite' },
28
- { name: 'Cancel', value: false }
29
- ]
30
- }
31
- ]);
32
- if (!action) {
33
- return;
34
- } else if (action === 'overwrite') {
35
- console.log(`\nRemoving ${chalk.cyan(targetDir)}...`);
36
- await fs.remove(targetDir);
37
- }
38
- }
39
- }
40
- // Choose template
41
- const { action } = await inquirer.prompt([
42
- {
43
- name: 'action',
44
- type: 'list',
45
- message: `Please select a template:`,
46
- choices: [
47
- { name: 'Blank template', value: 'blank' },
48
- { name: 'Capability-rich template', value: 'rich' },
49
- { name: 'Cancel', value: false }
50
- ]
51
- }
52
- ]);
53
-
54
- if (!action) return;
55
-
56
- fs.ensureDirSync(targetDir);
57
- if (action === 'rich') {
58
- // Pull the template from the web
59
- console.log(`⚙\u{fe0f} Installing template. This might take a while....`);
60
- await downloadRemoteTemplate(TEMPLATE_DOWNLOAD_URL, targetDir)
61
- } else {
62
- // Copy template from local
63
- await fs.copy(path.join(__dirname, '../template'), targetDir);
64
- await createProjectConfigFile(projectName, targetDir);
65
- }
66
-
67
- console.log(`🎉 Successfully created project ${chalk.yellow(projectName)}.`);
68
- }
69
-
70
- async function downloadRemoteTemplate(sourcePath, targetPath) {
71
- return new Promise(async (resolve, reject) => {
72
- const zipPath = path.join(targetPath, 'template.zip');
73
- const stream = fs.createWriteStream(zipPath);
74
- const response = await axios({
75
- url: sourcePath,
76
- method: "GET",
77
- responseType: "stream",
78
- });
79
- response.data.pipe(stream);
80
-
81
- stream.on('finish', () => {
82
- fs.createReadStream(zipPath).
83
- pipe(unzipper.Extract({ path: targetPath }))
84
- .on('close', () => {
85
- fs.unlinkSync(zipPath);
86
- resolve();
87
- })
88
- .on('error', (err) => {
89
- fs.unlinkSync(zipPath);
90
- reject(err);
91
- });
92
- });
93
-
94
- stream.on('error', (err) => {
95
- reject(err);
96
- });
97
- });
98
- }
99
-
100
-
101
- module.exports = (...args) => {
102
- return create(...args).catch(err => {
103
- console.log(chalk.red(`[CLI CREATE ERROR]: ${err}`));
104
- process.exit(1);
105
- });
106
- }
package/lib/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- interface PreviewOptions {
2
- entry?: string;
3
- copy?: boolean;
4
- force?: boolean;
5
- small?: boolean;
6
- proxy?: string;
7
- }
8
-
9
- interface UploadOptions {
10
- entry?: string;
11
- version: string;
12
- changeLog: string;
13
- proxy?: string;
14
- copy?: boolean;
15
- }
16
-
17
- declare namespace ttIdeCli {
18
- function create(projectName: string, options: { force?: boolean }): void;
19
- function loginByName(email: string, password: string): void;
20
- function login(options: { type?: string; proxy?: string }): void;
21
- function preview(options: PreviewOptions): void;
22
- function upload(options: UploadOptions): void;
23
- }