create-faas-app 0.0.2-beta.310 → 0.0.2-beta.314

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.
@@ -1,3 +1,5 @@
1
- import { Command } from 'commander';
2
- declare const commander: Command;
3
- export default commander;
1
+ import { Command } from 'commander';
2
+
3
+ declare const commander: Command;
4
+
5
+ export { commander as default };
package/dist/index.js ADDED
@@ -0,0 +1,292 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __reExport = (target, module2, copyDefault, desc) => {
11
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
12
+ for (let key of __getOwnPropNames(module2))
13
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
14
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
15
+ }
16
+ return target;
17
+ };
18
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
19
+ return (module2, temp) => {
20
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
21
+ };
22
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
23
+
24
+ // src/index.ts
25
+ var src_exports = {};
26
+ __export(src_exports, {
27
+ default: () => src_default
28
+ });
29
+ var import_commander = require("commander");
30
+
31
+ // src/action.ts
32
+ var import_enquirer = require("enquirer");
33
+ var import_fs = require("fs");
34
+ var import_path = require("path");
35
+ var import_child_process = require("child_process");
36
+ var Provider = ["tencentcloud", null];
37
+ var Region = [
38
+ "ap-beijing",
39
+ "ap-shanghai",
40
+ "ap-guangzhou",
41
+ "ap-hongkong"
42
+ ];
43
+ var Validator = {
44
+ name(input) {
45
+ const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
46
+ if (match !== true)
47
+ return match;
48
+ if ((0, import_fs.existsSync)(input))
49
+ return `${input} folder exists, please try another name`;
50
+ return true;
51
+ },
52
+ provider(input) {
53
+ return Provider.includes(input) ? true : "Unknow provider";
54
+ },
55
+ region(input) {
56
+ return Region.includes(input) ? true : "Unknown region";
57
+ },
58
+ appId(input) {
59
+ return /^[0-9]+$/.test(input) ? true : "Wrong format";
60
+ },
61
+ secretId(input) {
62
+ return /^[a-zA-Z0-9]+$/.test(input) ? true : "Wrong format";
63
+ },
64
+ secretKey(input) {
65
+ return /^[a-zA-Z0-9]+$/.test(input) ? true : "Wrong format";
66
+ }
67
+ };
68
+ async function action(options = {}) {
69
+ const answers = Object.assign(options, {});
70
+ if (!options.name || Validator.name(options.name) !== true)
71
+ answers.name = await (0, import_enquirer.prompt)({
72
+ type: "input",
73
+ name: "value",
74
+ message: "Project name",
75
+ validate: Validator.name
76
+ }).then((res) => res.value);
77
+ if (!options.noprovider) {
78
+ if (!answers.provider || Validator.provider(answers.provider) !== true)
79
+ answers.provider = await (0, import_enquirer.prompt)({
80
+ type: "select",
81
+ name: "value",
82
+ message: "Provider",
83
+ choices: [
84
+ {
85
+ name: "null",
86
+ message: "\u6682\u4E0D\u914D\u7F6E"
87
+ },
88
+ {
89
+ name: "tencentcloud",
90
+ message: "\u817E\u8BAF\u4E91"
91
+ }
92
+ ]
93
+ }).then((res) => res.value);
94
+ if (answers.provider === "tencentcloud") {
95
+ if (!answers.region || Validator.region(answers.region) !== true)
96
+ answers.region = await (0, import_enquirer.prompt)({
97
+ type: "select",
98
+ name: "value",
99
+ message: "Region",
100
+ choices: Region.concat([]),
101
+ validate: Validator.region
102
+ }).then((res) => res.value);
103
+ if (!answers.appId || Validator.appId(answers.appId) !== true)
104
+ answers.appId = await (0, import_enquirer.prompt)({
105
+ type: "input",
106
+ name: "value",
107
+ message: "appId (from https://console.cloud.tencent.com/developer)",
108
+ validate: Validator.appId
109
+ }).then((res) => res.value);
110
+ if (!answers.secretId || Validator.secretId(answers.secretId) !== true)
111
+ answers.secretId = await (0, import_enquirer.prompt)({
112
+ type: "input",
113
+ name: "value",
114
+ message: "secretId (from https://console.cloud.tencent.com/cam/capi)",
115
+ validate: Validator.secretId
116
+ }).then((res) => res.value);
117
+ if (!answers.secretKey || Validator.secretKey(answers.secretKey) !== true)
118
+ answers.secretKey = await (0, import_enquirer.prompt)({
119
+ type: "input",
120
+ name: "value",
121
+ message: "secretKey (from https://console.cloud.tencent.com/cam/capi)",
122
+ validate: Validator.secretKey
123
+ }).then((res) => res.value);
124
+ }
125
+ }
126
+ if (typeof answers.example === "undefined")
127
+ answers.example = await (0, import_enquirer.prompt)({
128
+ type: "confirm",
129
+ name: "value",
130
+ message: "Add example files",
131
+ initial: true
132
+ }).then((res) => res.value);
133
+ if (!answers.name)
134
+ return;
135
+ (0, import_fs.mkdirSync)(answers.name);
136
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, "faas.yaml"), `defaults:
137
+ providers:
138
+ tencentcloud:
139
+ type: '@faasjs/tencentcloud'
140
+ config: # https://faasjs.com/guide/tencentcloud.html
141
+ appId: ${answers.appId || ""}
142
+ secretId: ${answers.secretId || ""}
143
+ secretKey: ${answers.secretKey || ""}
144
+ region: ${answers.region || ""}
145
+ plugins:
146
+ cloud_function:
147
+ provider: tencentcloud
148
+ type: cloud_function
149
+ http:
150
+ provider: tencentcloud
151
+ type: http
152
+ development:
153
+ testing:
154
+ staging:
155
+ production:
156
+ `);
157
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, "package.json"), `{
158
+ "name": "${answers.name}",
159
+ "version": "0.0.0",
160
+ "private": true,
161
+ "scripts": {
162
+ "serve": "faas server",
163
+ "lint": "eslint --ext .ts .",
164
+ "test": "jest"
165
+ },
166
+ "dependencies": {
167
+ "faasjs": "beta",
168
+ "@faasjs/eslint-config-recommended": "beta"
169
+ },
170
+ "eslintConfig": {
171
+ "extends": [
172
+ "@faasjs/recommended"
173
+ ]
174
+ },
175
+ "eslintIgnore": [
176
+ "tmp",
177
+ "coverage"
178
+ ],
179
+ "jest": {
180
+ "verbose": false,
181
+ "transform": {
182
+ ".(jsx|tsx?)": "@swc/jest"
183
+ },
184
+ "collectCoverage": true,
185
+ "collectCoverageFrom": [
186
+ "**/*.ts"
187
+ ],
188
+ "testRegex": "/*\\\\.test\\\\.ts$",
189
+ "modulePathIgnorePatterns": [
190
+ "/tmp/",
191
+ "/coverage/"
192
+ ]
193
+ }
194
+ }`);
195
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, "tsconfig.json"), `{
196
+ "compilerOptions": {
197
+ "downlevelIteration": true,
198
+ "esModuleInterop": true,
199
+ "target": "ES2019",
200
+ "module": "ESNext",
201
+ "moduleResolution": "node",
202
+ "baseUrl": "."
203
+ }
204
+ }
205
+ `);
206
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, ".gitignore"), `node_modules/
207
+ tmp/
208
+ coverage/
209
+ *.tmp.js
210
+ `);
211
+ (0, import_fs.mkdirSync)((0, import_path.join)(answers.name, ".vscode"));
212
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, ".vscode", "settings.json"), `{
213
+ "editor.detectIndentation": true,
214
+ "editor.insertSpaces": true,
215
+ "editor.tabSize": 2,
216
+ "editor.codeActionsOnSave": {
217
+ "source.fixAll": true
218
+ },
219
+ "files.insertFinalNewline": true,
220
+ "files.trimFinalNewlines": true,
221
+ "editor.wordWrap": "on",
222
+ "files.trimTrailingWhitespace": true,
223
+ "editor.minimap.renderCharacters": false,
224
+ "editor.minimap.maxColumn": 200,
225
+ "editor.smoothScrolling": true,
226
+ "editor.cursorBlinking": "phase",
227
+ "search.exclude": {
228
+ "**/node_modules": true,
229
+ "**/coverage": true,
230
+ "**/dist": true,
231
+ "**/tmp": true
232
+ },
233
+ "eslint.packageManager": "npm",
234
+ "eslint.validate": [
235
+ "javascript",
236
+ "javascriptreact",
237
+ "typescript",
238
+ "typescriptreact",
239
+ "vue"
240
+ ],
241
+ "grunt.autoDetect": "off",
242
+ "jake.autoDetect": "off",
243
+ "gulp.autoDetect": "off",
244
+ "npm.autoDetect": "off"
245
+ }`);
246
+ (0, import_child_process.execSync)(`cd ${answers.name} && npm install`, { stdio: "inherit" });
247
+ if (answers.example) {
248
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, "index.func.ts"), `import { useFunc } from '@faasjs/func';
249
+ import { useHttp } from '@faasjs/http';
250
+
251
+ export default useFunc(function () {
252
+ useHttp();
253
+
254
+ return async function () {
255
+ return 'Hello, world';
256
+ };
257
+ });
258
+ `);
259
+ (0, import_fs.mkdirSync)((0, import_path.join)(answers.name, "__tests__"));
260
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, "__tests__", "index.test.ts"), `import { FuncWarper } from '@faasjs/test';
261
+
262
+ describe('hello', function () {
263
+ test('should work', async function () {
264
+ const func = new FuncWarper(require.resolve('../index.func'));
265
+
266
+ const { data } = await func.JSONhandler<string>({});
267
+
268
+ expect(data).toEqual('Hello, world');
269
+ });
270
+ });
271
+ `);
272
+ (0, import_child_process.execSync)(`cd ${answers.name} && npm exec jest`, { stdio: "inherit" });
273
+ }
274
+ }
275
+ function action_default(program) {
276
+ program.description("\u521B\u5EFA\u65B0\u9879\u76EE").on("--help", function() {
277
+ console.log(`
278
+ Examples:
279
+ npx create-faas-app`);
280
+ }).option("--name <name>", "\u9879\u76EE\u540D\u5B57").option("--region <region>", "\u53EF\u7528\u533A").option("--appId <appid>", "appId").option("--secretId <secretId>", "secretId").option("--secretKey <secretKey>", "secretKey").option("--example", "\u521B\u5EFA\u793A\u4F8B\u6587\u4EF6").option("--noprovider", "\u6682\u4E0D\u914D\u7F6E\u670D\u52A1\u5546").action(action);
281
+ }
282
+
283
+ // src/index.ts
284
+ var commander = new import_commander.Command();
285
+ commander.storeOptionsAsProperties(false).version("beta").name("create-faas-app");
286
+ action_default(commander);
287
+ if (!process.env.CI && process.argv[0] !== "fake")
288
+ commander.parseAsync(process.argv);
289
+ var src_default = commander;
290
+ module.exports = __toCommonJS(src_exports);
291
+ // Annotate the CommonJS export names for ESM import in node:
292
+ 0 && (module.exports = {});
package/dist/index.mjs ADDED
@@ -0,0 +1,269 @@
1
+ // src/index.ts
2
+ import { Command } from "commander";
3
+
4
+ // src/action.ts
5
+ import { prompt } from "enquirer";
6
+ import {
7
+ mkdirSync,
8
+ writeFileSync,
9
+ existsSync
10
+ } from "fs";
11
+ import { join } from "path";
12
+ import { execSync } from "child_process";
13
+ var Provider = ["tencentcloud", null];
14
+ var Region = [
15
+ "ap-beijing",
16
+ "ap-shanghai",
17
+ "ap-guangzhou",
18
+ "ap-hongkong"
19
+ ];
20
+ var Validator = {
21
+ name(input) {
22
+ const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
23
+ if (match !== true)
24
+ return match;
25
+ if (existsSync(input))
26
+ return `${input} folder exists, please try another name`;
27
+ return true;
28
+ },
29
+ provider(input) {
30
+ return Provider.includes(input) ? true : "Unknow provider";
31
+ },
32
+ region(input) {
33
+ return Region.includes(input) ? true : "Unknown region";
34
+ },
35
+ appId(input) {
36
+ return /^[0-9]+$/.test(input) ? true : "Wrong format";
37
+ },
38
+ secretId(input) {
39
+ return /^[a-zA-Z0-9]+$/.test(input) ? true : "Wrong format";
40
+ },
41
+ secretKey(input) {
42
+ return /^[a-zA-Z0-9]+$/.test(input) ? true : "Wrong format";
43
+ }
44
+ };
45
+ async function action(options = {}) {
46
+ const answers = Object.assign(options, {});
47
+ if (!options.name || Validator.name(options.name) !== true)
48
+ answers.name = await prompt({
49
+ type: "input",
50
+ name: "value",
51
+ message: "Project name",
52
+ validate: Validator.name
53
+ }).then((res) => res.value);
54
+ if (!options.noprovider) {
55
+ if (!answers.provider || Validator.provider(answers.provider) !== true)
56
+ answers.provider = await prompt({
57
+ type: "select",
58
+ name: "value",
59
+ message: "Provider",
60
+ choices: [
61
+ {
62
+ name: "null",
63
+ message: "\u6682\u4E0D\u914D\u7F6E"
64
+ },
65
+ {
66
+ name: "tencentcloud",
67
+ message: "\u817E\u8BAF\u4E91"
68
+ }
69
+ ]
70
+ }).then((res) => res.value);
71
+ if (answers.provider === "tencentcloud") {
72
+ if (!answers.region || Validator.region(answers.region) !== true)
73
+ answers.region = await prompt({
74
+ type: "select",
75
+ name: "value",
76
+ message: "Region",
77
+ choices: Region.concat([]),
78
+ validate: Validator.region
79
+ }).then((res) => res.value);
80
+ if (!answers.appId || Validator.appId(answers.appId) !== true)
81
+ answers.appId = await prompt({
82
+ type: "input",
83
+ name: "value",
84
+ message: "appId (from https://console.cloud.tencent.com/developer)",
85
+ validate: Validator.appId
86
+ }).then((res) => res.value);
87
+ if (!answers.secretId || Validator.secretId(answers.secretId) !== true)
88
+ answers.secretId = await prompt({
89
+ type: "input",
90
+ name: "value",
91
+ message: "secretId (from https://console.cloud.tencent.com/cam/capi)",
92
+ validate: Validator.secretId
93
+ }).then((res) => res.value);
94
+ if (!answers.secretKey || Validator.secretKey(answers.secretKey) !== true)
95
+ answers.secretKey = await prompt({
96
+ type: "input",
97
+ name: "value",
98
+ message: "secretKey (from https://console.cloud.tencent.com/cam/capi)",
99
+ validate: Validator.secretKey
100
+ }).then((res) => res.value);
101
+ }
102
+ }
103
+ if (typeof answers.example === "undefined")
104
+ answers.example = await prompt({
105
+ type: "confirm",
106
+ name: "value",
107
+ message: "Add example files",
108
+ initial: true
109
+ }).then((res) => res.value);
110
+ if (!answers.name)
111
+ return;
112
+ mkdirSync(answers.name);
113
+ writeFileSync(join(answers.name, "faas.yaml"), `defaults:
114
+ providers:
115
+ tencentcloud:
116
+ type: '@faasjs/tencentcloud'
117
+ config: # https://faasjs.com/guide/tencentcloud.html
118
+ appId: ${answers.appId || ""}
119
+ secretId: ${answers.secretId || ""}
120
+ secretKey: ${answers.secretKey || ""}
121
+ region: ${answers.region || ""}
122
+ plugins:
123
+ cloud_function:
124
+ provider: tencentcloud
125
+ type: cloud_function
126
+ http:
127
+ provider: tencentcloud
128
+ type: http
129
+ development:
130
+ testing:
131
+ staging:
132
+ production:
133
+ `);
134
+ writeFileSync(join(answers.name, "package.json"), `{
135
+ "name": "${answers.name}",
136
+ "version": "0.0.0",
137
+ "private": true,
138
+ "scripts": {
139
+ "serve": "faas server",
140
+ "lint": "eslint --ext .ts .",
141
+ "test": "jest"
142
+ },
143
+ "dependencies": {
144
+ "faasjs": "beta",
145
+ "@faasjs/eslint-config-recommended": "beta"
146
+ },
147
+ "eslintConfig": {
148
+ "extends": [
149
+ "@faasjs/recommended"
150
+ ]
151
+ },
152
+ "eslintIgnore": [
153
+ "tmp",
154
+ "coverage"
155
+ ],
156
+ "jest": {
157
+ "verbose": false,
158
+ "transform": {
159
+ ".(jsx|tsx?)": "@swc/jest"
160
+ },
161
+ "collectCoverage": true,
162
+ "collectCoverageFrom": [
163
+ "**/*.ts"
164
+ ],
165
+ "testRegex": "/*\\\\.test\\\\.ts$",
166
+ "modulePathIgnorePatterns": [
167
+ "/tmp/",
168
+ "/coverage/"
169
+ ]
170
+ }
171
+ }`);
172
+ writeFileSync(join(answers.name, "tsconfig.json"), `{
173
+ "compilerOptions": {
174
+ "downlevelIteration": true,
175
+ "esModuleInterop": true,
176
+ "target": "ES2019",
177
+ "module": "ESNext",
178
+ "moduleResolution": "node",
179
+ "baseUrl": "."
180
+ }
181
+ }
182
+ `);
183
+ writeFileSync(join(answers.name, ".gitignore"), `node_modules/
184
+ tmp/
185
+ coverage/
186
+ *.tmp.js
187
+ `);
188
+ mkdirSync(join(answers.name, ".vscode"));
189
+ writeFileSync(join(answers.name, ".vscode", "settings.json"), `{
190
+ "editor.detectIndentation": true,
191
+ "editor.insertSpaces": true,
192
+ "editor.tabSize": 2,
193
+ "editor.codeActionsOnSave": {
194
+ "source.fixAll": true
195
+ },
196
+ "files.insertFinalNewline": true,
197
+ "files.trimFinalNewlines": true,
198
+ "editor.wordWrap": "on",
199
+ "files.trimTrailingWhitespace": true,
200
+ "editor.minimap.renderCharacters": false,
201
+ "editor.minimap.maxColumn": 200,
202
+ "editor.smoothScrolling": true,
203
+ "editor.cursorBlinking": "phase",
204
+ "search.exclude": {
205
+ "**/node_modules": true,
206
+ "**/coverage": true,
207
+ "**/dist": true,
208
+ "**/tmp": true
209
+ },
210
+ "eslint.packageManager": "npm",
211
+ "eslint.validate": [
212
+ "javascript",
213
+ "javascriptreact",
214
+ "typescript",
215
+ "typescriptreact",
216
+ "vue"
217
+ ],
218
+ "grunt.autoDetect": "off",
219
+ "jake.autoDetect": "off",
220
+ "gulp.autoDetect": "off",
221
+ "npm.autoDetect": "off"
222
+ }`);
223
+ execSync(`cd ${answers.name} && npm install`, { stdio: "inherit" });
224
+ if (answers.example) {
225
+ writeFileSync(join(answers.name, "index.func.ts"), `import { useFunc } from '@faasjs/func';
226
+ import { useHttp } from '@faasjs/http';
227
+
228
+ export default useFunc(function () {
229
+ useHttp();
230
+
231
+ return async function () {
232
+ return 'Hello, world';
233
+ };
234
+ });
235
+ `);
236
+ mkdirSync(join(answers.name, "__tests__"));
237
+ writeFileSync(join(answers.name, "__tests__", "index.test.ts"), `import { FuncWarper } from '@faasjs/test';
238
+
239
+ describe('hello', function () {
240
+ test('should work', async function () {
241
+ const func = new FuncWarper(require.resolve('../index.func'));
242
+
243
+ const { data } = await func.JSONhandler<string>({});
244
+
245
+ expect(data).toEqual('Hello, world');
246
+ });
247
+ });
248
+ `);
249
+ execSync(`cd ${answers.name} && npm exec jest`, { stdio: "inherit" });
250
+ }
251
+ }
252
+ function action_default(program) {
253
+ program.description("\u521B\u5EFA\u65B0\u9879\u76EE").on("--help", function() {
254
+ console.log(`
255
+ Examples:
256
+ npx create-faas-app`);
257
+ }).option("--name <name>", "\u9879\u76EE\u540D\u5B57").option("--region <region>", "\u53EF\u7528\u533A").option("--appId <appid>", "appId").option("--secretId <secretId>", "secretId").option("--secretKey <secretKey>", "secretKey").option("--example", "\u521B\u5EFA\u793A\u4F8B\u6587\u4EF6").option("--noprovider", "\u6682\u4E0D\u914D\u7F6E\u670D\u52A1\u5546").action(action);
258
+ }
259
+
260
+ // src/index.ts
261
+ var commander = new Command();
262
+ commander.storeOptionsAsProperties(false).version("beta").name("create-faas-app");
263
+ action_default(commander);
264
+ if (!process.env.CI && process.argv[0] !== "fake")
265
+ commander.parseAsync(process.argv);
266
+ var src_default = commander;
267
+ export {
268
+ src_default as default
269
+ };
package/index.js CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  'use strict';
4
4
 
5
- require('./lib/index')
5
+ require('./dist/index')
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "create-faas-app",
3
- "version": "0.0.2-beta.310",
3
+ "version": "0.0.2-beta.314",
4
4
  "license": "MIT",
5
- "main": "lib/index.js",
6
- "types": "libs/index.d.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist/index.mjs",
7
8
  "bin": {
8
9
  "create-faas-app": "index.js"
9
10
  },
@@ -18,25 +19,23 @@
18
19
  },
19
20
  "funding": "https://github.com/sponsors/faasjs",
20
21
  "scripts": {
21
- "prepack": "rm -rf ./lib && rollup -c"
22
+ "build": "rm -rf ./dist && tsup-node src/index.ts --format esm,cjs --dts"
22
23
  },
23
24
  "files": [
24
- "lib",
25
+ "dist",
25
26
  "index.js"
26
27
  ],
27
- "dependencies": {
28
+ "peerDependencies": {
28
29
  "commander": "*",
29
30
  "enquirer": "*",
30
- "lodash": "*",
31
- "typescript": "*"
31
+ "lodash": "*"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "*",
35
- "rollup": "*",
36
- "rollup-plugin-typescript2": "*"
34
+ "tsup": "*",
35
+ "typescript": "*"
37
36
  },
38
37
  "engines": {
39
38
  "npm": ">=8.0.0"
40
39
  },
41
- "gitHead": "0bfca56ec223e3b4b8fd91e51058263f010d4ea6"
40
+ "gitHead": "60be0e54eb369177b416d109a3f9a5a12dedbf24"
42
41
  }
package/lib/action.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function action(options?: {
3
- name?: string;
4
- provider?: string;
5
- region?: string;
6
- appId?: string;
7
- secretId?: string;
8
- secretKey?: string;
9
- example?: boolean;
10
- noprovider?: boolean;
11
- }): Promise<void>;
12
- export default function (program: Command): void;
package/lib/index.js DELETED
@@ -1,278 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var commander$1 = require('commander');
5
- var enquirer = require('enquirer');
6
- var fs = require('fs');
7
- var path = require('path');
8
- var child_process = require('child_process');
9
-
10
- const Provider = ['tencentcloud', null];
11
- const Region = [
12
- 'ap-beijing',
13
- 'ap-shanghai',
14
- 'ap-guangzhou',
15
- 'ap-hongkong'
16
- ];
17
- const Validator = {
18
- name(input) {
19
- const match = /^[a-z0-9-_]+$/i.test(input) ? true : 'Must be a-z, 0-9 or -_';
20
- if (match !== true)
21
- return match;
22
- if (fs.existsSync(input))
23
- return `${input} folder exists, please try another name`;
24
- return true;
25
- },
26
- provider(input) {
27
- return Provider.includes(input) ? true : 'Unknow provider';
28
- },
29
- region(input) {
30
- return Region.includes(input) ? true : 'Unknown region';
31
- },
32
- appId(input) {
33
- return /^[0-9]+$/.test(input) ? true : 'Wrong format';
34
- },
35
- secretId(input) {
36
- return /^[a-zA-Z0-9]+$/.test(input) ? true : 'Wrong format';
37
- },
38
- secretKey(input) {
39
- return /^[a-zA-Z0-9]+$/.test(input) ? true : 'Wrong format';
40
- }
41
- };
42
- async function action(options = {}) {
43
- const answers = Object.assign(options, {});
44
- if (!options.name || Validator.name(options.name) !== true)
45
- answers.name = await enquirer.prompt({
46
- type: 'input',
47
- name: 'value',
48
- message: 'Project name',
49
- validate: Validator.name
50
- }).then(res => res.value);
51
- if (!options.noprovider) {
52
- if (!answers.provider || Validator.provider(answers.provider) !== true)
53
- answers.provider = await enquirer.prompt({
54
- type: 'select',
55
- name: 'value',
56
- message: 'Provider',
57
- choices: [
58
- {
59
- name: 'null',
60
- message: '暂不配置'
61
- },
62
- {
63
- name: 'tencentcloud',
64
- message: '腾讯云'
65
- }
66
- ]
67
- }).then(res => res.value);
68
- if (answers.provider === 'tencentcloud') {
69
- if (!answers.region || Validator.region(answers.region) !== true)
70
- answers.region = await enquirer.prompt({
71
- type: 'select',
72
- name: 'value',
73
- message: 'Region',
74
- choices: Region.concat([]),
75
- validate: Validator.region
76
- }).then(res => res.value);
77
- if (!answers.appId || Validator.appId(answers.appId) !== true)
78
- answers.appId = await enquirer.prompt({
79
- type: 'input',
80
- name: 'value',
81
- message: 'appId (from https://console.cloud.tencent.com/developer)',
82
- validate: Validator.appId
83
- }).then(res => res.value);
84
- if (!answers.secretId || Validator.secretId(answers.secretId) !== true)
85
- answers.secretId = await enquirer.prompt({
86
- type: 'input',
87
- name: 'value',
88
- message: 'secretId (from https://console.cloud.tencent.com/cam/capi)',
89
- validate: Validator.secretId
90
- }).then(res => res.value);
91
- if (!answers.secretKey || Validator.secretKey(answers.secretKey) !== true)
92
- answers.secretKey = await enquirer.prompt({
93
- type: 'input',
94
- name: 'value',
95
- message: 'secretKey (from https://console.cloud.tencent.com/cam/capi)',
96
- validate: Validator.secretKey
97
- }).then(res => res.value);
98
- }
99
- }
100
- if (typeof answers.example === 'undefined')
101
- answers.example = await enquirer.prompt({
102
- type: 'confirm',
103
- name: 'value',
104
- message: 'Add example files',
105
- initial: true
106
- }).then(res => res.value);
107
- if (!answers.name)
108
- return;
109
- fs.mkdirSync(answers.name);
110
- fs.writeFileSync(path.join(answers.name, 'faas.yaml'), `defaults:
111
- providers:
112
- tencentcloud:
113
- type: '@faasjs/tencentcloud'
114
- config: # https://faasjs.com/guide/tencentcloud.html
115
- appId: ${answers.appId || ''}
116
- secretId: ${answers.secretId || ''}
117
- secretKey: ${answers.secretKey || ''}
118
- region: ${answers.region || ''}
119
- plugins:
120
- cloud_function:
121
- provider: tencentcloud
122
- type: cloud_function
123
- http:
124
- provider: tencentcloud
125
- type: http
126
- development:
127
- testing:
128
- staging:
129
- production:
130
- `);
131
- fs.writeFileSync(path.join(answers.name, 'package.json'), `{
132
- "name": "${answers.name}",
133
- "version": "0.0.0",
134
- "private": true,
135
- "scripts": {
136
- "serve": "faas server",
137
- "lint": "eslint --ext .ts .",
138
- "test": "jest"
139
- },
140
- "dependencies": {
141
- "faasjs": "beta",
142
- "@faasjs/eslint-config-recommended": "beta"
143
- },
144
- "eslintConfig": {
145
- "extends": [
146
- "@faasjs/recommended"
147
- ]
148
- },
149
- "eslintIgnore": [
150
- "tmp",
151
- "coverage"
152
- ],
153
- "jest": {
154
- "verbose": false,
155
- "transform": {
156
- ".(jsx|tsx?)": "@swc/jest"
157
- },
158
- "collectCoverage": true,
159
- "collectCoverageFrom": [
160
- "**/*.ts"
161
- ],
162
- "testRegex": "/*\\\\.test\\\\.ts$",
163
- "modulePathIgnorePatterns": [
164
- "/tmp/",
165
- "/coverage/"
166
- ]
167
- }
168
- }`);
169
- fs.writeFileSync(path.join(answers.name, 'tsconfig.json'), `{
170
- "compilerOptions": {
171
- "downlevelIteration": true,
172
- "esModuleInterop": true,
173
- "target": "ES2019",
174
- "module": "ESNext",
175
- "moduleResolution": "node",
176
- "baseUrl": "."
177
- }
178
- }
179
- `);
180
- fs.writeFileSync(path.join(answers.name, '.gitignore'), `node_modules/
181
- tmp/
182
- coverage/
183
- *.tmp.js
184
- `);
185
- fs.mkdirSync(path.join(answers.name, '.vscode'));
186
- fs.writeFileSync(path.join(answers.name, '.vscode', 'settings.json'), `{
187
- "editor.detectIndentation": true,
188
- "editor.insertSpaces": true,
189
- "editor.tabSize": 2,
190
- "editor.codeActionsOnSave": {
191
- "source.fixAll": true
192
- },
193
- "files.insertFinalNewline": true,
194
- "files.trimFinalNewlines": true,
195
- "editor.wordWrap": "on",
196
- "files.trimTrailingWhitespace": true,
197
- "editor.minimap.renderCharacters": false,
198
- "editor.minimap.maxColumn": 200,
199
- "editor.smoothScrolling": true,
200
- "editor.cursorBlinking": "phase",
201
- "search.exclude": {
202
- "**/node_modules": true,
203
- "**/coverage": true,
204
- "**/dist": true,
205
- "**/tmp": true
206
- },
207
- "eslint.packageManager": "npm",
208
- "eslint.validate": [
209
- "javascript",
210
- "javascriptreact",
211
- "typescript",
212
- "typescriptreact",
213
- "vue"
214
- ],
215
- "grunt.autoDetect": "off",
216
- "jake.autoDetect": "off",
217
- "gulp.autoDetect": "off",
218
- "npm.autoDetect": "off"
219
- }`);
220
- child_process.execSync(`cd ${answers.name} && npm install`, { stdio: 'inherit' });
221
- if (answers.example) {
222
- fs.writeFileSync(path.join(answers.name, 'index.func.ts'), `import { useFunc } from '@faasjs/func';
223
- import { useHttp } from '@faasjs/http';
224
-
225
- export default useFunc(function () {
226
- useHttp();
227
-
228
- return async function () {
229
- return 'Hello, world';
230
- };
231
- });
232
- `);
233
- fs.mkdirSync(path.join(answers.name, '__tests__'));
234
- fs.writeFileSync(path.join(answers.name, '__tests__', 'index.test.ts'), `import { FuncWarper } from '@faasjs/test';
235
-
236
- describe('hello', function () {
237
- test('should work', async function () {
238
- const func = new FuncWarper(require.resolve('../index.func'));
239
-
240
- const { data } = await func.JSONhandler<string>({});
241
-
242
- expect(data).toEqual('Hello, world');
243
- });
244
- });
245
- `);
246
- child_process.execSync(`cd ${answers.name} && npm exec jest`, { stdio: 'inherit' });
247
- }
248
- }
249
- function action$1 (program) {
250
- program
251
- .description('创建新项目')
252
- .on('--help', function () {
253
- console.log(`
254
- Examples:
255
- npx create-faas-app`);
256
- })
257
- .option('--name <name>', '项目名字')
258
- .option('--region <region>', '可用区')
259
- .option('--appId <appid>', 'appId')
260
- .option('--secretId <secretId>', 'secretId')
261
- .option('--secretKey <secretKey>', 'secretKey')
262
- .option('--example', '创建示例文件')
263
- .option('--noprovider', '暂不配置服务商')
264
- .action(action);
265
- }
266
-
267
- const commander = new commander$1.Command();
268
- // 设置命令
269
- commander
270
- .storeOptionsAsProperties(false)
271
- .version('beta')
272
- .name('create-faas-app');
273
- // 加载命令
274
- action$1(commander);
275
- if (!process.env.CI && process.argv[0] !== 'fake')
276
- commander.parseAsync(process.argv);
277
-
278
- module.exports = commander;