create-faas-app 0.0.2-beta.95 → 0.0.3-beta.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/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # create-faas-app
2
2
 
3
- 创建 FaasJS 项目命令行。
4
-
5
- [![License: MIT](https://img.shields.io/npm/l/create-faas-app.svg)](https://github.com/faasjs/faasjs/blob/master/packages/create-faas-app/LICENSE)
3
+ [![License: MIT](https://img.shields.io/npm/l/create-faas-app.svg)](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
6
4
  [![NPM Version](https://img.shields.io/npm/v/create-faas-app.svg)](https://www.npmjs.com/package/create-faas-app)
7
5
 
8
- https://faasjs.com/
6
+ Quick way to create a FaasJS project.
7
+
8
+ ## Usage
9
+
10
+ npx create-faas-app
package/dist/index.js ADDED
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ default: () => src_default
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var import_commander = require("commander");
27
+
28
+ // src/action.ts
29
+ var import_enquirer = require("enquirer");
30
+ var import_fs = require("fs");
31
+ var import_path = require("path");
32
+ var import_child_process = require("child_process");
33
+ var Validator = {
34
+ name(input) {
35
+ const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
36
+ if (match !== true)
37
+ return match;
38
+ if ((0, import_fs.existsSync)(input))
39
+ return `${input} folder exists, please try another name`;
40
+ return true;
41
+ }
42
+ };
43
+ async function action(options = {}) {
44
+ const answers = Object.assign(options, {});
45
+ if (!options.name || Validator.name(options.name) !== true)
46
+ answers.name = await (0, import_enquirer.prompt)({
47
+ type: "input",
48
+ name: "value",
49
+ message: "Project name",
50
+ initial: "faasjs",
51
+ validate: Validator.name
52
+ }).then((res) => res.value);
53
+ if (typeof answers.example === "undefined")
54
+ answers.example = await (0, import_enquirer.prompt)({
55
+ type: "confirm",
56
+ name: "value",
57
+ message: "Add example files",
58
+ initial: true
59
+ }).then((res) => res.value);
60
+ if (!answers.name)
61
+ return;
62
+ (0, import_fs.mkdirSync)(answers.name);
63
+ (0, import_fs.writeFileSync)(
64
+ (0, import_path.join)(answers.name, "faas.yaml"),
65
+ `defaults:
66
+ plugins:
67
+ development:
68
+ testing:
69
+ staging:
70
+ production:
71
+ `
72
+ );
73
+ (0, import_fs.writeFileSync)(
74
+ (0, import_path.join)(answers.name, "package.json"),
75
+ `{
76
+ "name": "${answers.name}",
77
+ "version": "0.0.0",
78
+ "private": true,
79
+ "scripts": {
80
+ "serve": "faas server",
81
+ "lint": "eslint --ext .ts .",
82
+ "test": "jest"
83
+ },
84
+ "dependencies": {
85
+ "faasjs": "*"
86
+ },
87
+ "devDependencies": {
88
+ "@faasjs/eslint-config-recommended": "*",
89
+ "@faasjs/jest": "*"
90
+ },
91
+ "eslintConfig": {
92
+ "extends": [
93
+ "@faasjs/recommended"
94
+ ]
95
+ },
96
+ "eslintIgnore": [
97
+ "tmp",
98
+ "coverage"
99
+ ],
100
+ "jest": {
101
+ "transform": {
102
+ ".(jsx|tsx?)": "@faasjs/jest"
103
+ },
104
+ "collectCoverage": true,
105
+ "collectCoverageFrom": [
106
+ "**/*.ts"
107
+ ],
108
+ "testRegex": "/*\\\\.test\\\\.ts$",
109
+ "modulePathIgnorePatterns": [
110
+ "/tmp/",
111
+ "/coverage/"
112
+ ]
113
+ }
114
+ }`
115
+ );
116
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, "tsconfig.json"), `{
117
+ "compilerOptions": {
118
+ "downlevelIteration": true,
119
+ "esModuleInterop": true,
120
+ "target": "ES2019",
121
+ "module": "ESNext",
122
+ "moduleResolution": "node",
123
+ "baseUrl": "."
124
+ }
125
+ }
126
+ `);
127
+ (0, import_fs.writeFileSync)((0, import_path.join)(answers.name, ".gitignore"), `node_modules/
128
+ tmp/
129
+ coverage/
130
+ *.tmp.js
131
+ `);
132
+ (0, import_fs.mkdirSync)((0, import_path.join)(answers.name, ".vscode"));
133
+ (0, import_fs.writeFileSync)(
134
+ (0, import_path.join)(answers.name, ".vscode", "settings.json"),
135
+ `{
136
+ "editor.detectIndentation": true,
137
+ "editor.insertSpaces": true,
138
+ "editor.tabSize": 2,
139
+ "editor.codeActionsOnSave": {
140
+ "source.fixAll": true
141
+ },
142
+ "editor.wordWrap": "on",
143
+ "files.insertFinalNewline": true,
144
+ "files.trimFinalNewlines": true,
145
+ "files.trimTrailingWhitespace": true,
146
+ "eslint.packageManager": "npm"
147
+ }
148
+ `
149
+ );
150
+ (0, import_fs.writeFileSync)(
151
+ (0, import_path.join)(answers.name, ".vscode", "extensions.json"),
152
+ `{
153
+ "recommendations": [
154
+ "dbaeumer.vscode-eslint",
155
+ "faasjs.faasjs-snippets"
156
+ ]
157
+ }
158
+ `
159
+ );
160
+ (0, import_child_process.execSync)(`cd ${answers.name} && npm install`, { stdio: "inherit" });
161
+ if (answers.example) {
162
+ (0, import_fs.writeFileSync)(
163
+ (0, import_path.join)(answers.name, "index.func.ts"),
164
+ `import { useFunc } from '@faasjs/func'
165
+ import { useHttp } from '@faasjs/http'
166
+
167
+ export default useFunc(function () {
168
+ const http useHttp<{ name: string }>()
169
+
170
+ return async function () {
171
+ return 'Hello, ' + http.params.name
172
+ }
173
+ })
174
+ `
175
+ );
176
+ (0, import_fs.mkdirSync)((0, import_path.join)(answers.name, "__tests__"));
177
+ (0, import_fs.writeFileSync)(
178
+ (0, import_path.join)(answers.name, "__tests__", "index.test.ts"),
179
+ `import { test } from '@faasjs/test'
180
+
181
+ describe('hello', function () {
182
+ it('should work', async function () {
183
+ const func = test(require.resolve('../index.func'))
184
+
185
+ const { statusCode, data } = await func.JSONhandler<string>({ name: 'world' })
186
+
187
+ expect(statusCode).toEqual(200)
188
+ expect(data).toEqual('Hello, world')
189
+ })
190
+ })
191
+ `
192
+ );
193
+ (0, import_child_process.execSync)(`cd ${answers.name} && npm exec jest`, { stdio: "inherit" });
194
+ }
195
+ }
196
+ function action_default(program) {
197
+ program.description("\u521B\u5EFA\u65B0\u9879\u76EE").on("--help", function() {
198
+ console.log(`
199
+ Examples:
200
+ npx create-faas-app`);
201
+ }).option("--name <name>", "\u9879\u76EE\u540D\u5B57").action(action);
202
+ }
203
+
204
+ // src/index.ts
205
+ var commander = new import_commander.Command();
206
+ commander.storeOptionsAsProperties(false).allowUnknownOption(true).version("beta").name("create-faas-app");
207
+ action_default(commander);
208
+ async function main() {
209
+ try {
210
+ if (!process.env.CI && process.argv[0] !== "fake")
211
+ await commander.parseAsync(process.argv);
212
+ } catch (error) {
213
+ console.error(error);
214
+ process.exit(1);
215
+ }
216
+ }
217
+ var src_default = main();
218
+ // Annotate the CommonJS export names for ESM import in node:
219
+ 0 && (module.exports = {});
package/dist/index.mjs ADDED
@@ -0,0 +1,200 @@
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 Validator = {
14
+ name(input) {
15
+ const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
16
+ if (match !== true)
17
+ return match;
18
+ if (existsSync(input))
19
+ return `${input} folder exists, please try another name`;
20
+ return true;
21
+ }
22
+ };
23
+ async function action(options = {}) {
24
+ const answers = Object.assign(options, {});
25
+ if (!options.name || Validator.name(options.name) !== true)
26
+ answers.name = await prompt({
27
+ type: "input",
28
+ name: "value",
29
+ message: "Project name",
30
+ initial: "faasjs",
31
+ validate: Validator.name
32
+ }).then((res) => res.value);
33
+ if (typeof answers.example === "undefined")
34
+ answers.example = await prompt({
35
+ type: "confirm",
36
+ name: "value",
37
+ message: "Add example files",
38
+ initial: true
39
+ }).then((res) => res.value);
40
+ if (!answers.name)
41
+ return;
42
+ mkdirSync(answers.name);
43
+ writeFileSync(
44
+ join(answers.name, "faas.yaml"),
45
+ `defaults:
46
+ plugins:
47
+ development:
48
+ testing:
49
+ staging:
50
+ production:
51
+ `
52
+ );
53
+ writeFileSync(
54
+ join(answers.name, "package.json"),
55
+ `{
56
+ "name": "${answers.name}",
57
+ "version": "0.0.0",
58
+ "private": true,
59
+ "scripts": {
60
+ "serve": "faas server",
61
+ "lint": "eslint --ext .ts .",
62
+ "test": "jest"
63
+ },
64
+ "dependencies": {
65
+ "faasjs": "*"
66
+ },
67
+ "devDependencies": {
68
+ "@faasjs/eslint-config-recommended": "*",
69
+ "@faasjs/jest": "*"
70
+ },
71
+ "eslintConfig": {
72
+ "extends": [
73
+ "@faasjs/recommended"
74
+ ]
75
+ },
76
+ "eslintIgnore": [
77
+ "tmp",
78
+ "coverage"
79
+ ],
80
+ "jest": {
81
+ "transform": {
82
+ ".(jsx|tsx?)": "@faasjs/jest"
83
+ },
84
+ "collectCoverage": true,
85
+ "collectCoverageFrom": [
86
+ "**/*.ts"
87
+ ],
88
+ "testRegex": "/*\\\\.test\\\\.ts$",
89
+ "modulePathIgnorePatterns": [
90
+ "/tmp/",
91
+ "/coverage/"
92
+ ]
93
+ }
94
+ }`
95
+ );
96
+ writeFileSync(join(answers.name, "tsconfig.json"), `{
97
+ "compilerOptions": {
98
+ "downlevelIteration": true,
99
+ "esModuleInterop": true,
100
+ "target": "ES2019",
101
+ "module": "ESNext",
102
+ "moduleResolution": "node",
103
+ "baseUrl": "."
104
+ }
105
+ }
106
+ `);
107
+ writeFileSync(join(answers.name, ".gitignore"), `node_modules/
108
+ tmp/
109
+ coverage/
110
+ *.tmp.js
111
+ `);
112
+ mkdirSync(join(answers.name, ".vscode"));
113
+ writeFileSync(
114
+ join(answers.name, ".vscode", "settings.json"),
115
+ `{
116
+ "editor.detectIndentation": true,
117
+ "editor.insertSpaces": true,
118
+ "editor.tabSize": 2,
119
+ "editor.codeActionsOnSave": {
120
+ "source.fixAll": true
121
+ },
122
+ "editor.wordWrap": "on",
123
+ "files.insertFinalNewline": true,
124
+ "files.trimFinalNewlines": true,
125
+ "files.trimTrailingWhitespace": true,
126
+ "eslint.packageManager": "npm"
127
+ }
128
+ `
129
+ );
130
+ writeFileSync(
131
+ join(answers.name, ".vscode", "extensions.json"),
132
+ `{
133
+ "recommendations": [
134
+ "dbaeumer.vscode-eslint",
135
+ "faasjs.faasjs-snippets"
136
+ ]
137
+ }
138
+ `
139
+ );
140
+ execSync(`cd ${answers.name} && npm install`, { stdio: "inherit" });
141
+ if (answers.example) {
142
+ writeFileSync(
143
+ join(answers.name, "index.func.ts"),
144
+ `import { useFunc } from '@faasjs/func'
145
+ import { useHttp } from '@faasjs/http'
146
+
147
+ export default useFunc(function () {
148
+ const http useHttp<{ name: string }>()
149
+
150
+ return async function () {
151
+ return 'Hello, ' + http.params.name
152
+ }
153
+ })
154
+ `
155
+ );
156
+ mkdirSync(join(answers.name, "__tests__"));
157
+ writeFileSync(
158
+ join(answers.name, "__tests__", "index.test.ts"),
159
+ `import { test } from '@faasjs/test'
160
+
161
+ describe('hello', function () {
162
+ it('should work', async function () {
163
+ const func = test(require.resolve('../index.func'))
164
+
165
+ const { statusCode, data } = await func.JSONhandler<string>({ name: 'world' })
166
+
167
+ expect(statusCode).toEqual(200)
168
+ expect(data).toEqual('Hello, world')
169
+ })
170
+ })
171
+ `
172
+ );
173
+ execSync(`cd ${answers.name} && npm exec jest`, { stdio: "inherit" });
174
+ }
175
+ }
176
+ function action_default(program) {
177
+ program.description("\u521B\u5EFA\u65B0\u9879\u76EE").on("--help", function() {
178
+ console.log(`
179
+ Examples:
180
+ npx create-faas-app`);
181
+ }).option("--name <name>", "\u9879\u76EE\u540D\u5B57").action(action);
182
+ }
183
+
184
+ // src/index.ts
185
+ var commander = new Command();
186
+ commander.storeOptionsAsProperties(false).allowUnknownOption(true).version("beta").name("create-faas-app");
187
+ action_default(commander);
188
+ async function main() {
189
+ try {
190
+ if (!process.env.CI && process.argv[0] !== "fake")
191
+ await commander.parseAsync(process.argv);
192
+ } catch (error) {
193
+ console.error(error);
194
+ process.exit(1);
195
+ }
196
+ }
197
+ var src_default = main();
198
+ export {
199
+ src_default as default
200
+ };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ require('./dist/index')
package/package.json CHANGED
@@ -1,25 +1,35 @@
1
1
  {
2
2
  "name": "create-faas-app",
3
- "version": "0.0.2-beta.95",
3
+ "version": "0.0.3-beta.2",
4
4
  "license": "MIT",
5
- "main": "lib/index.js",
5
+ "main": "dist/index.js",
6
6
  "bin": {
7
- "create-faas-app": "lib/index.js"
7
+ "create-faas-app": "index.js"
8
8
  },
9
+ "homepage": "https://faasjs.com/doc/create-faas-app",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/faasjs/faasjs.git",
13
+ "directory": "packages/create-faas-app"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/faasjs/faasjs/issues"
17
+ },
18
+ "funding": "https://github.com/sponsors/faasjs",
9
19
  "scripts": {
10
- "prepack": "rm -rf ./lib && rollup -c"
20
+ "build": "tsup-node src/index.ts --format esm,cjs"
11
21
  },
12
22
  "files": [
13
- "lib"
23
+ "dist",
24
+ "index.js"
14
25
  ],
15
26
  "dependencies": {
16
27
  "commander": "*",
17
28
  "enquirer": "*",
18
- "typescript": "*"
19
- },
20
- "devDependencies": {
21
- "rollup": "*",
22
- "rollup-plugin-typescript2": "*"
29
+ "lodash-es": "*"
23
30
  },
24
- "gitHead": "e5955ed30661b9cb7ddda79cc4f75567113801f0"
31
+ "engines": {
32
+ "npm": ">=8.0.0",
33
+ "node": ">=16.0.0"
34
+ }
25
35
  }
package/lib/action.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function action(options?: {
3
- name?: string;
4
- region?: string;
5
- appId?: string;
6
- secretId?: string;
7
- secretKey?: string;
8
- example?: boolean;
9
- }): Promise<void>;
10
- export default function (program: Command): void;
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const commander: import("commander").Command;
2
- export default commander;
package/lib/index.js DELETED
@@ -1,219 +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 = ['ap-beijing', 'ap-shanghai', 'ap-guangzhou', 'ap-hongkong'];
12
- const Validator = {
13
- name(input) {
14
- const match = /^[a-z0-9-_]+$/i.test(input) ? true : 'Must be a-z, 0-9 or -_';
15
- if (match !== true)
16
- return match;
17
- if (fs.existsSync(input))
18
- return `${input} folder exists, please try another name`;
19
- return true;
20
- },
21
- provider(input) {
22
- return Provider.includes(input) ? true : 'Unknow provider';
23
- },
24
- region(input) {
25
- return Region.includes(input) ? true : 'Unknown region';
26
- },
27
- appId(input) {
28
- return /^[0-9]+$/.test(input) ? true : 'Wrong format';
29
- },
30
- secretId(input) {
31
- return /^[a-zA-Z0-9]+$/.test(input) ? true : 'Wrong format';
32
- },
33
- secretKey(input) {
34
- return /^[a-zA-Z0-9]+$/.test(input) ? true : 'Wrong format';
35
- }
36
- };
37
- async function action(options) {
38
- const answers = Object.assign(options, {});
39
- if (!options.name || Validator.name(options.name) !== true)
40
- answers.name = await enquirer.prompt({
41
- type: 'input',
42
- name: 'value',
43
- message: 'Project name',
44
- validate: Validator.name
45
- }).then((res) => res.value);
46
- answers.provider = await enquirer.prompt({
47
- type: 'select',
48
- name: 'value',
49
- message: 'Provider',
50
- choices: [
51
- {
52
- name: 'null',
53
- message: '暂不配置'
54
- },
55
- {
56
- name: 'tencentcloud',
57
- message: '腾讯云'
58
- },
59
- ]
60
- }).then((res) => res.value);
61
- if (answers.provider === 'tencentcloud') {
62
- if (!answers.region || Validator.region(answers.region) !== true)
63
- answers.region = await enquirer.prompt({
64
- type: 'select',
65
- name: 'value',
66
- message: 'Region',
67
- choices: Region.concat([]),
68
- validate: Validator.region
69
- }).then((res) => res.value);
70
- if (!answers.appId || Validator.appId(answers.appId) !== true)
71
- answers.appId = await enquirer.prompt({
72
- type: 'input',
73
- name: 'value',
74
- message: 'appId (from https://console.cloud.tencent.com/developer)',
75
- validate: Validator.appId
76
- }).then((res) => res.value);
77
- if (!answers.secretId || Validator.secretId(answers.secretId) !== true)
78
- answers.secretId = await enquirer.prompt({
79
- type: 'input',
80
- name: 'value',
81
- message: 'secretId (from https://console.cloud.tencent.com/cam/capi)',
82
- validate: Validator.secretId
83
- }).then((res) => res.value);
84
- if (!answers.secretKey || Validator.secretKey(answers.secretKey) !== true)
85
- answers.secretKey = await enquirer.prompt({
86
- type: 'input',
87
- name: 'value',
88
- message: 'secretKey (from https://console.cloud.tencent.com/cam/capi)',
89
- validate: Validator.secretKey
90
- }).then((res) => res.value);
91
- }
92
- if (answers.example !== false)
93
- answers.example = await enquirer.prompt({
94
- type: 'confirm',
95
- name: 'value',
96
- message: 'Add example files',
97
- initial: true
98
- }).then((res) => res.value);
99
- fs.mkdirSync(answers.name);
100
- fs.writeFileSync(path.join(answers.name, 'faas.yaml'), `defaults:
101
- providers:
102
- tencentcloud:
103
- type: '@faasjs/tencentcloud'
104
- config: # https://faasjs.com/guide/tencentcloud.html
105
- appId: ${answers.appId || ''}
106
- secretId: ${answers.secretId || ''}
107
- secretKey: ${answers.secretKey || ''}
108
- region: ${answers.region || ''}
109
- plugins:
110
- cloud_function:
111
- provider: tencentcloud
112
- type: cloud_function
113
- http:
114
- provider: tencentcloud
115
- type: http
116
- development:
117
- testing:
118
- production:`);
119
- fs.writeFileSync(path.join(answers.name, 'package.json'), `{
120
- "name": "${answers.name}",
121
- "version": "0.0.0",
122
- "private": true,
123
- "scripts": {
124
- "lint": "eslint --ext .ts ."
125
- },
126
- "dependencies": {
127
- "faasjs": "beta",
128
- "@faasjs/eslint-config-recommended": "beta"
129
- },
130
- "eslintConfig": {
131
- "extends": [
132
- "@faasjs/recommended"
133
- ]
134
- },
135
- "eslintIgnore": [
136
- "tmp"
137
- ],
138
- "jest": {
139
- "preset": "ts-jest",
140
- "collectCoverage": true,
141
- "collectCoverageFrom": [
142
- "**/*.ts"
143
- ],
144
- "testRegex": "/*\\\\.test\\\\.ts$",
145
- "modulePathIgnorePatterns": [
146
- "/tmp/"
147
- ]
148
- }
149
- }`);
150
- fs.writeFileSync(path.join(answers.name, 'tsconfig.json'), '{}');
151
- fs.writeFileSync(path.join(answers.name, '.gitignore'), `node_modules/
152
- tmp/
153
- *.tmp.js`);
154
- fs.mkdirSync(path.join(answers.name, '.vscode'));
155
- fs.writeFileSync(path.join(answers.name, '.vscode', 'settings.json'), `{
156
- "eslint.packageManager": "yarn",
157
- "eslint.autoFixOnSave": true,
158
- "editor.codeActionsOnSave": {
159
- "source.fixAll": true
160
- },
161
- "editor.detectIndentation": false,
162
- "editor.tabSize": 2,
163
- "editor.formatOnSave": true,
164
- "files.insertFinalNewline": true,
165
- "files.trimFinalNewlines": true
166
- }`);
167
- child_process.execSync(`yarn --cwd ${answers.name} install`, { stdio: 'inherit' });
168
- if (answers.example) {
169
- fs.writeFileSync(path.join(answers.name, 'index.func.ts'), `import { Func } from '@faasjs/func';
170
- import { Http } from '@faasjs/http';
171
-
172
- export default new Func({
173
- plugins: [new Http()],
174
- handler () {
175
- return 'Hello, world';
176
- }
177
- });`);
178
- fs.mkdirSync(path.join(answers.name, '__tests__'));
179
- fs.writeFileSync(path.join(answers.name, '__tests__', 'index.test.ts'), `import { FuncWarpper } from '@faasjs/test';
180
-
181
- describe('hello', function () {
182
- test('should work', async function () {
183
- const func = new FuncWarpper(require.resolve('../index.func'));
184
-
185
- const res = await func.handler({});
186
-
187
- expect(res.body).toEqual('{"data":"Hello, world"}');
188
- });
189
- });`);
190
- child_process.execSync(`yarn --cwd ${answers.name} jest`, { stdio: 'inherit' });
191
- }
192
- }
193
- function action$1 (program) {
194
- program
195
- .description('创建新项目')
196
- .on('--help', function () {
197
- console.log(`
198
- Examples:
199
- yarn new`);
200
- })
201
- .option('--name <name>', '项目名字')
202
- .option('--region <region>', '可用区')
203
- .option('--appId <appid>', 'appId')
204
- .option('--secretId <secretId>', 'secretId')
205
- .option('--secretKey <secretKey>', 'secretKey')
206
- .option('--example', '创建示例文件')
207
- .action(action);
208
- }
209
-
210
- const commander = new commander$1.Command();
211
- // 设置命令
212
- commander
213
- .version('beta');
214
- // 加载命令
215
- action$1(commander);
216
- if (!process.env.CI && process.argv[0] !== 'fake')
217
- commander.parse(process.argv);
218
-
219
- module.exports = commander;