@corva/create-app 0.12.0-1 → 0.12.0-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/CHANGELOG.md +8 -0
- package/README.md +32 -7
- package/constants/manifest.js +60 -14
- package/helpers/manifest.js +18 -15
- package/index.js +92 -75
- package/package.json +2 -2
- package/scripts/ui/zipAppSource.js +4 -4
- package/template/scheduler/node/__test__/processor.test.js +3 -3
- package/template/scheduler/node/gitignore +21 -0
- package/template/scheduler/node/package.json +3 -3
- package/template/scheduler/node-ts/README.md +25 -0
- package/template/scheduler/node-ts/__test__/processor.spec.ts +20 -0
- package/template/scheduler/node-ts/gitignore +25 -0
- package/template/scheduler/node-ts/index.ts +8 -0
- package/template/scheduler/node-ts/lib/processor.ts +13 -0
- package/template/scheduler/node-ts/package.json +37 -0
- package/template/scheduler/node-ts/tsconfig.build.json +11 -0
- package/template/scheduler/node-ts/tsconfig.json +33 -0
- package/template/stream/node/__test__/processor.test.js +6 -9
- package/template/stream/node/gitignore +21 -0
- package/template/stream/node/package.json +3 -3
- package/template/stream/node-ts/README.md +25 -0
- package/template/stream/node-ts/__test__/processor.spec.ts +43 -0
- package/template/stream/node-ts/gitignore +25 -0
- package/template/stream/node-ts/index.ts +8 -0
- package/template/stream/node-ts/lib/processor.ts +16 -0
- package/template/stream/node-ts/package.json +37 -0
- package/template/stream/node-ts/tsconfig.build.json +11 -0
- package/template/stream/node-ts/tsconfig.json +33 -0
- package/template/task/node/__test__/processor.test.js +18 -0
- package/template/task/node/gitignore +21 -0
- package/template/task/node/index.js +1 -1
- package/template/task/node/package.json +3 -3
- package/template/task/node/src/processor.js +0 -1
- package/template/task/node-ts/README.md +25 -0
- package/template/task/node-ts/__test__/processor.spec.ts +27 -0
- package/template/task/node-ts/gitignore +25 -0
- package/template/task/node-ts/index.ts +8 -0
- package/template/task/node-ts/package.json +37 -0
- package/template/task/node-ts/src/processor.ts +13 -0
- package/template/task/node-ts/tsconfig.build.json +11 -0
- package/template/task/node-ts/tsconfig.json +33 -0
- package/helpers/metadata.js +0 -29
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.12.0-2](https://github.com/corva-ai/create-corva-app/compare/v0.12.0-1...v0.12.0-2) (2021-09-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add typescript app templates ([f256b39](https://github.com/corva-ai/create-corva-app/commit/f256b3970b4a2f426c6f87ddd10fe5c957757658))
|
|
11
|
+
* **DC-2167:** updated node templates to use latest sdk ([#118](https://corvaqa.atlassian.net/browse/118)) ([c9dc93a](https://github.com/corva-ai/create-corva-app/commit/c9dc93a07a48b06f4c0831bcd95aca4fd5b5504c))
|
|
12
|
+
|
|
5
13
|
## [0.12.0-1](https://github.com/corva-ai/create-corva-app/compare/v0.12.0-0...v0.12.0-1) (2021-09-20)
|
|
6
14
|
|
|
7
15
|
|
package/README.md
CHANGED
|
@@ -1,32 +1,57 @@
|
|
|
1
|
-
# create-
|
|
1
|
+
# @corva/create-app
|
|
2
|
+
|
|
3
|
+
Apps generator for [corva.ai](https://corva.ai).
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- NodeJs 12+ (https://nodejs.org/en/download/)
|
|
2
8
|
|
|
3
9
|
## Installation
|
|
4
10
|
|
|
5
|
-
```
|
|
11
|
+
```sh
|
|
6
12
|
npm i -g @corva/create-app
|
|
7
13
|
```
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
## Usage
|
|
10
16
|
|
|
11
17
|
`corva-create-app` provides a user-friendly CLI wizard to create an app.
|
|
12
18
|
|
|
13
19
|
```sh
|
|
14
20
|
Usage: corva-create-app <project-directory> [options]
|
|
15
21
|
|
|
22
|
+
Arguments:
|
|
23
|
+
project-directory project directory to work with
|
|
24
|
+
|
|
16
25
|
Options:
|
|
17
|
-
-V, --version
|
|
18
|
-
-z, --zip <type>
|
|
26
|
+
-V, --version output the version number
|
|
27
|
+
-z, --zip <type> zip app source
|
|
28
|
+
-t, --useTypescript use typescript or javascript (default: false)
|
|
29
|
+
-p, --packageManager <value> package manager to use (choices: "npm", "yarn", default: "yarn")
|
|
19
30
|
--appType [value]
|
|
20
31
|
--appKey [value]
|
|
21
32
|
--appName [value]
|
|
22
33
|
--category [value]
|
|
23
34
|
--segments [value]
|
|
24
35
|
--runtime [value]
|
|
25
|
-
-h, --help
|
|
36
|
+
-h, --help display help for command
|
|
26
37
|
```
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
### Create a UI application
|
|
29
42
|
|
|
30
43
|
```sh
|
|
31
44
|
create-corva-app test --appName "Test" --segments "drilling" --category "wellDesign" --appKey "some-company.test.ui" --appType "ui" --runtime "ui"
|
|
32
45
|
```
|
|
46
|
+
|
|
47
|
+
### Create a NodeJs TypeScript application
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
create-corva-app test --appName "Test" --segments "drilling" --category "wellDesign" --appKey "some-company.test.scheduler" --appType "scheduler" --runtime "nodejs12.x" -t
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Create a Python application
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
create-corva-app test --appName "Test" --segments "drilling" --category "analytics" --appKey "some-company.test.stream" --appType "stream" --runtime "python3.8"
|
|
57
|
+
```
|
package/constants/manifest.js
CHANGED
|
@@ -79,20 +79,66 @@ const defaultDepthSchedulerSettings = {
|
|
|
79
79
|
|
|
80
80
|
const MANIFEST_MANDATORY_KEYS = ['appType', 'appKey', 'appName', 'category', 'segments', 'runtime'];
|
|
81
81
|
|
|
82
|
-
const manifestOptions =
|
|
83
|
-
developerName: 'O&G Company',
|
|
84
|
-
developerIdentifier: 'oandgc',
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
const manifestOptions = (projectName) => [
|
|
83
|
+
{ name: 'developerName', message: 'Enter the Developer Name', default: 'O&G Company' },
|
|
84
|
+
{ name: 'developerIdentifier', message: 'Enter the Developer Identifier', default: 'oandgc' },
|
|
85
|
+
{
|
|
86
|
+
type: 'rawlist',
|
|
87
|
+
name: 'appType',
|
|
88
|
+
message: 'Choose the App Type',
|
|
89
|
+
default: 'ui',
|
|
90
|
+
choices: ['ui', 'scheduler', 'stream', 'task'],
|
|
91
|
+
},
|
|
92
|
+
{ name: 'appKey', message: 'Enter the App Key', default: 'app.key-goes-here' },
|
|
93
|
+
{ name: 'appName', message: 'Enter the App Name', default: projectName },
|
|
94
|
+
{
|
|
95
|
+
name: 'description',
|
|
96
|
+
message: 'Enter description',
|
|
97
|
+
default: 'This is the description of my app. You can do great things with it!',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'summary',
|
|
101
|
+
message: 'Enter summary',
|
|
102
|
+
default: 'More information about this app goes here',
|
|
103
|
+
},
|
|
104
|
+
{ name: 'category', message: 'Enter category', default: '' },
|
|
105
|
+
{ name: 'website', message: 'Enter website', default: 'https://www.oandgexample.com/my-app/' },
|
|
106
|
+
{
|
|
107
|
+
type: 'rawlist',
|
|
108
|
+
name: 'segments',
|
|
109
|
+
message: 'Choose segments',
|
|
110
|
+
choices: ['drilling', 'completion'],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: 'rawlist',
|
|
114
|
+
name: 'runtime',
|
|
115
|
+
message: 'Choose runtime',
|
|
116
|
+
choices: ['python3.8', 'nodejs12.x'],
|
|
117
|
+
when: (answers) => answers.appType !== 'ui',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
type: 'rawlist',
|
|
121
|
+
name: 'packageManager',
|
|
122
|
+
message: 'Please select the desired package manager',
|
|
123
|
+
default: 'yarn',
|
|
124
|
+
choices: ['yarn', 'npm'],
|
|
125
|
+
when: (answers) => !answers.runtime || !answers.runtime.startsWith('python'),
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: 'confirm',
|
|
129
|
+
name: 'useTypescript',
|
|
130
|
+
message: 'Would you like to use TypesScript?',
|
|
131
|
+
default: false,
|
|
132
|
+
when: (answers) => answers.runtime && answers.runtime.startsWith('nodejs'),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'rawlist',
|
|
136
|
+
name: 'schedulerType',
|
|
137
|
+
message: 'Choose schedulerType',
|
|
138
|
+
choices: ['data_time', 'data_depth', 'natural_time'],
|
|
139
|
+
when: (answers) => answers.appType === 'scheduler',
|
|
140
|
+
},
|
|
141
|
+
];
|
|
96
142
|
|
|
97
143
|
module.exports = {
|
|
98
144
|
defaultManifest,
|
package/helpers/manifest.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
const manifestConstants = require('../constants/manifest.js');
|
|
2
2
|
|
|
3
3
|
function fillManifest(answers) {
|
|
4
|
+
const runtime = answers.runtime || 'ui';
|
|
5
|
+
|
|
4
6
|
const defaultManifestProperties = _defaultManifestProperties({
|
|
5
7
|
type: answers.appType,
|
|
6
|
-
|
|
8
|
+
// fallback to UI
|
|
9
|
+
runtime,
|
|
7
10
|
});
|
|
8
11
|
|
|
9
12
|
const manifest = {
|
|
@@ -29,7 +32,7 @@ function fillManifest(answers) {
|
|
|
29
32
|
},
|
|
30
33
|
settings: {
|
|
31
34
|
...defaultManifestProperties.settings,
|
|
32
|
-
runtime
|
|
35
|
+
runtime,
|
|
33
36
|
...defaultAppSettings({ type: answers.appType, schedulerType: answers.schedulerType }),
|
|
34
37
|
},
|
|
35
38
|
};
|
|
@@ -50,21 +53,21 @@ function _defaultManifestProperties({ type, runtime }) {
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
function defaultAppSettings({ type, schedulerType }) {
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
schedulerType == 'data_depth'
|
|
56
|
-
? manifestConstants.defaultDepthSchedulerSettings
|
|
57
|
-
: manifestConstants.defaultTimeSchedulerSettings;
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
app: {
|
|
61
|
-
...schedulerAppSettings,
|
|
62
|
-
scheduler_type: schedulerType || 'data_time',
|
|
63
|
-
},
|
|
64
|
-
};
|
|
56
|
+
if (!schedulerType) {
|
|
57
|
+
return {};
|
|
65
58
|
}
|
|
66
59
|
|
|
67
|
-
|
|
60
|
+
const schedulerAppSettings =
|
|
61
|
+
schedulerType == 'data_depth'
|
|
62
|
+
? manifestConstants.defaultDepthSchedulerSettings
|
|
63
|
+
: manifestConstants.defaultTimeSchedulerSettings;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
app: {
|
|
67
|
+
...schedulerAppSettings,
|
|
68
|
+
scheduler_type: schedulerType || 'data_time',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
module.exports = {
|
package/index.js
CHANGED
|
@@ -14,7 +14,6 @@ const semver = require('semver');
|
|
|
14
14
|
const uiScripts = require('./scripts/ui');
|
|
15
15
|
const { ensureLatestVersion } = require('./scripts/utils/version');
|
|
16
16
|
const utils = require('./helpers/utils.js');
|
|
17
|
-
const metadata = require('./helpers/metadata.js');
|
|
18
17
|
const manifestHelpers = require('./helpers/manifest.js');
|
|
19
18
|
const versioning = require('./helpers/versioning.js');
|
|
20
19
|
|
|
@@ -25,6 +24,15 @@ const packageJson = require('./package.json');
|
|
|
25
24
|
const { clear } = require('console');
|
|
26
25
|
const spawn = require('cross-spawn');
|
|
27
26
|
|
|
27
|
+
const YARN_EXECUTABLE = 'yarn';
|
|
28
|
+
|
|
29
|
+
let packageManager = YARN_EXECUTABLE;
|
|
30
|
+
let useTypescript = false;
|
|
31
|
+
|
|
32
|
+
const shouldUseYarn = () => packageManager === YARN_EXECUTABLE;
|
|
33
|
+
const getLockFileName = (manager) =>
|
|
34
|
+
manager === YARN_EXECUTABLE ? 'yarn.lock' : 'package-lock.json';
|
|
35
|
+
|
|
28
36
|
clear();
|
|
29
37
|
|
|
30
38
|
let projectName;
|
|
@@ -55,15 +63,16 @@ function checkNodeVersion() {
|
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
65
|
|
|
58
|
-
function
|
|
66
|
+
function checkOptions(opts) {
|
|
59
67
|
let isValid = true;
|
|
60
68
|
const values = {};
|
|
61
69
|
|
|
62
70
|
manifestConstants.MANIFEST_MANDATORY_KEYS.forEach((key) => {
|
|
63
|
-
if (!
|
|
71
|
+
if (!opts[key]) {
|
|
64
72
|
isValid = false;
|
|
65
73
|
}
|
|
66
|
-
|
|
74
|
+
|
|
75
|
+
values[key] = opts[key];
|
|
67
76
|
});
|
|
68
77
|
|
|
69
78
|
return {
|
|
@@ -73,15 +82,22 @@ function checkArguments() {
|
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
async function initialChecks() {
|
|
76
|
-
|
|
85
|
+
startingMessage();
|
|
86
|
+
|
|
87
|
+
program = new commander.Command('corva-create-app')
|
|
77
88
|
.version(packageJson.version)
|
|
78
|
-
.
|
|
89
|
+
.argument('[project-directory]', 'project directory to work with')
|
|
79
90
|
.usage(`${chalk.green('<project-directory>')} [options]`)
|
|
80
91
|
.action((name) => {
|
|
81
92
|
projectName = name;
|
|
82
93
|
})
|
|
83
|
-
.
|
|
84
|
-
.option('-
|
|
94
|
+
.option('-z, --zip <type>', 'zip app source')
|
|
95
|
+
.option('-t, --useTypescript', 'use typescript or javascript', false)
|
|
96
|
+
.addOption(
|
|
97
|
+
new commander.Option(`-p, --packageManager <value>`, 'package manager to use')
|
|
98
|
+
.default(YARN_EXECUTABLE)
|
|
99
|
+
.choices(['npm', YARN_EXECUTABLE])
|
|
100
|
+
);
|
|
85
101
|
|
|
86
102
|
manifestConstants.MANIFEST_MANDATORY_KEYS.forEach((key) => {
|
|
87
103
|
program.option(`--${key} [value]`);
|
|
@@ -91,16 +107,20 @@ async function initialChecks() {
|
|
|
91
107
|
|
|
92
108
|
checkNodeVersion();
|
|
93
109
|
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
const opts = program.opts();
|
|
111
|
+
|
|
112
|
+
packageManager = opts.packageManager || packageManager;
|
|
113
|
+
useTypescript = opts.useTypescript || useTypescript;
|
|
114
|
+
|
|
115
|
+
if (opts.zip) {
|
|
116
|
+
if (opts.zip === APP_TYPES.UI) {
|
|
117
|
+
return uiScripts.zipAppSource(shouldUseYarn());
|
|
118
|
+
}
|
|
96
119
|
|
|
97
120
|
process.exit(0);
|
|
98
121
|
}
|
|
99
122
|
|
|
100
|
-
|
|
101
|
-
await createApp();
|
|
102
|
-
|
|
103
|
-
if (typeof projectName === 'undefined') {
|
|
123
|
+
if (!projectName) {
|
|
104
124
|
console.error('Please specify the project directory:');
|
|
105
125
|
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}`);
|
|
106
126
|
console.log();
|
|
@@ -110,6 +130,9 @@ async function initialChecks() {
|
|
|
110
130
|
console.log(`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`);
|
|
111
131
|
process.exit(1);
|
|
112
132
|
}
|
|
133
|
+
|
|
134
|
+
// NOTE: Default action
|
|
135
|
+
await createApp(opts);
|
|
113
136
|
}
|
|
114
137
|
|
|
115
138
|
async function initPackage(manifest) {
|
|
@@ -134,6 +157,10 @@ async function initPackage(manifest) {
|
|
|
134
157
|
runtime = 'python';
|
|
135
158
|
} else if (runtime.startsWith('nodejs')) {
|
|
136
159
|
runtime = 'node';
|
|
160
|
+
|
|
161
|
+
if (useTypescript) {
|
|
162
|
+
runtime += '-ts';
|
|
163
|
+
}
|
|
137
164
|
}
|
|
138
165
|
}
|
|
139
166
|
|
|
@@ -142,49 +169,29 @@ async function initPackage(manifest) {
|
|
|
142
169
|
installApp(root, appType, runtime);
|
|
143
170
|
}
|
|
144
171
|
|
|
145
|
-
function fillAppMETA() {
|
|
146
|
-
console.log('Please fill your app Metadata');
|
|
147
|
-
|
|
148
|
-
const prompts = Object.keys(manifestConstants.manifestOptions).map((key) => ({
|
|
149
|
-
type: metadata.getType(manifestConstants.manifestOptions[key]),
|
|
150
|
-
name: key,
|
|
151
|
-
message: `${
|
|
152
|
-
typeof manifestConstants.manifestOptions[key] === 'string' ? 'Enter' : 'Choose'
|
|
153
|
-
} ${key}`,
|
|
154
|
-
default: manifestConstants.manifestOptions[key],
|
|
155
|
-
choices: metadata.getChoices(manifestConstants.manifestOptions[key]),
|
|
156
|
-
}));
|
|
157
|
-
|
|
158
|
-
inquirer.prompt(prompts).then((answers) => {
|
|
159
|
-
const manifest = manifestHelpers.fillManifest(answers);
|
|
160
|
-
initPackage(manifest);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async function createApp() {
|
|
165
|
-
const { isValid, values } = checkArguments();
|
|
166
172
|
|
|
167
|
-
|
|
173
|
+
async function createApp(opts) {
|
|
174
|
+
const { isValid, values } = checkOptions(opts);
|
|
168
175
|
|
|
169
176
|
if (isValid) {
|
|
170
177
|
Object.keys(values).forEach((key) => {
|
|
171
178
|
console.log(`${key} : ${values[key]}`);
|
|
172
179
|
});
|
|
180
|
+
|
|
173
181
|
const manifest = manifestHelpers.fillManifest(values);
|
|
182
|
+
|
|
174
183
|
await initPackage(manifest);
|
|
175
184
|
} else {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
fillAppMETA();
|
|
187
|
-
});
|
|
185
|
+
console.log('Please fill your app Metadata');
|
|
186
|
+
|
|
187
|
+
inquirer.prompt(manifestConstants.manifestOptions(projectName)).then((answers) => {
|
|
188
|
+
packageManager = answers.packageManager || packageManager;
|
|
189
|
+
useTypescript = answers.useTypescript || useTypescript;
|
|
190
|
+
|
|
191
|
+
const manifest = manifestHelpers.fillManifest(answers);
|
|
192
|
+
|
|
193
|
+
initPackage(manifest);
|
|
194
|
+
});
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
console.log();
|
|
@@ -196,19 +203,23 @@ function addTemplate(root, appType, runtime) {
|
|
|
196
203
|
|
|
197
204
|
let templateFolder = path.resolve(__dirname, 'template', appType);
|
|
198
205
|
let nameExclusion = appType;
|
|
206
|
+
|
|
199
207
|
if (appType !== APP_TYPES.UI) {
|
|
200
208
|
templateFolder = path.resolve(__dirname, 'template', appType, runtime);
|
|
209
|
+
|
|
201
210
|
nameExclusion = runtime;
|
|
202
211
|
}
|
|
203
|
-
|
|
212
|
+
|
|
204
213
|
utils.copyFolderRecursiveSync(templateFolder, root, nameExclusion);
|
|
205
214
|
|
|
206
|
-
|
|
215
|
+
const gitignore = path.join(root, 'gitignore');
|
|
216
|
+
|
|
217
|
+
if (fs.pathExistsSync(gitignore)) {
|
|
207
218
|
// We can't have .gitignore file in our templates.
|
|
208
219
|
// It's missing when @corva/create-app is installed.
|
|
209
220
|
// That's why we manually rename gitignore to .gitignore after copying template
|
|
210
221
|
|
|
211
|
-
fs.renameSync(
|
|
222
|
+
fs.renameSync(gitignore, path.join(root, '.gitignore'));
|
|
212
223
|
}
|
|
213
224
|
|
|
214
225
|
console.log(chalk.green('Done: copying app template!'));
|
|
@@ -217,8 +228,8 @@ function addTemplate(root, appType, runtime) {
|
|
|
217
228
|
function configureApp(root, appType, runtime, manifest) {
|
|
218
229
|
if (appType === APP_TYPES.UI) {
|
|
219
230
|
addPackageJSON(root, manifest.application.name);
|
|
220
|
-
} else if (runtime
|
|
221
|
-
updatePackageJSON(root, manifest.application.
|
|
231
|
+
} else if (runtime.startsWith(APP_TYPES.NODE)) {
|
|
232
|
+
updatePackageJSON(root, manifest.application.description, appType, runtime);
|
|
222
233
|
}
|
|
223
234
|
}
|
|
224
235
|
|
|
@@ -234,36 +245,40 @@ function addPackageJSON(root, appName) {
|
|
|
234
245
|
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson, null, 2) + os.EOL);
|
|
235
246
|
}
|
|
236
247
|
|
|
237
|
-
function updatePackageJSON(root,
|
|
248
|
+
function updatePackageJSON(root, description, appType, runtime) {
|
|
238
249
|
const templateFolder = path.resolve(__dirname, 'template', appType, runtime);
|
|
239
250
|
|
|
240
251
|
let packageJson = JSON.parse(fs.readFileSync(path.join(templateFolder, 'package.json'), 'utf-8'));
|
|
241
252
|
|
|
242
|
-
packageJson.name =
|
|
253
|
+
packageJson.name = projectName.replace(/\W/g, '-').toLowerCase();
|
|
254
|
+
packageJson.description = description;
|
|
255
|
+
|
|
256
|
+
packageJson.scripts.bundle = packageJson.scripts.bundle.replace(
|
|
257
|
+
'$LOCKFILE',
|
|
258
|
+
getLockFileName(packageManager)
|
|
259
|
+
);
|
|
243
260
|
|
|
244
261
|
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson, null, 2) + os.EOL);
|
|
245
262
|
}
|
|
246
263
|
|
|
247
264
|
function installApp(appPath, appType, runtime) {
|
|
248
|
-
switch (
|
|
249
|
-
case '
|
|
250
|
-
installUIApp(appPath);
|
|
265
|
+
switch (runtime) {
|
|
266
|
+
case 'python': {
|
|
251
267
|
break;
|
|
268
|
+
}
|
|
269
|
+
default: {
|
|
270
|
+
installJsApp(appPath, appType);
|
|
271
|
+
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
252
274
|
}
|
|
253
275
|
}
|
|
254
276
|
|
|
255
|
-
function
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const useYarn = true;
|
|
259
|
-
|
|
260
|
-
//@TODO: Add npm support
|
|
261
|
-
if (useYarn) {
|
|
262
|
-
command = 'yarn';
|
|
263
|
-
args = ['install'];
|
|
264
|
-
}
|
|
277
|
+
function installJsApp(appPath, appType) {
|
|
278
|
+
const command = packageManager;
|
|
279
|
+
const args = ['install'];
|
|
265
280
|
|
|
266
|
-
console.log(chalk.yellow(
|
|
281
|
+
console.log(chalk.yellow(`Installing template dependencies using ${command}...`));
|
|
267
282
|
const proc = spawn.sync(command, args, { stdio: 'inherit', cwd: appPath });
|
|
268
283
|
|
|
269
284
|
if (proc.status !== 0) {
|
|
@@ -287,14 +302,16 @@ function installUIApp(appPath) {
|
|
|
287
302
|
|
|
288
303
|
console.log();
|
|
289
304
|
console.log(`Success! Created ${projectName} at ${appPath}`);
|
|
290
|
-
console.log('Inside that directory, you can run several commands:');
|
|
291
|
-
helpCommands();
|
|
292
|
-
}
|
|
293
305
|
|
|
294
|
-
|
|
295
|
-
|
|
306
|
+
if (appType === APP_TYPES.UI) {
|
|
307
|
+
console.log('Inside that directory, you can run several commands:');
|
|
308
|
+
helpCommands();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
296
311
|
|
|
297
|
-
|
|
312
|
+
async function helpCommands() {
|
|
313
|
+
const displayedCommand = packageManager;
|
|
314
|
+
const useYarn = shouldUseYarn();
|
|
298
315
|
|
|
299
316
|
console.log();
|
|
300
317
|
console.log(chalk.cyan(` ${displayedCommand} start`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corva/create-app",
|
|
3
|
-
"version": "0.12.0-
|
|
3
|
+
"version": "0.12.0-2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Create app to use it in CORVA.AI",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"archiver": "^5.0.0",
|
|
36
36
|
"chalk": "4.1.0",
|
|
37
|
-
"commander": "
|
|
37
|
+
"commander": "^8.2.0",
|
|
38
38
|
"conventional-changelog-cli": "^2.1.0",
|
|
39
39
|
"cross-spawn": "7.0.3",
|
|
40
40
|
"envinfo": "7.5.1",
|
|
@@ -7,7 +7,7 @@ const semverInc = require('semver/functions/inc');
|
|
|
7
7
|
|
|
8
8
|
const { warnIfOutdated } = require('../utils/version');
|
|
9
9
|
|
|
10
|
-
async function compressAppToZip() {
|
|
10
|
+
async function compressAppToZip(useYarn) {
|
|
11
11
|
warnIfOutdated();
|
|
12
12
|
|
|
13
13
|
const dirname = process.cwd();
|
|
@@ -72,7 +72,7 @@ async function compressAppToZip() {
|
|
|
72
72
|
|
|
73
73
|
console.log(
|
|
74
74
|
chalk(`
|
|
75
|
-
NOTE: Version of
|
|
75
|
+
NOTE: Version of your app was updated to ${updatedVersion} (package.json), please don't lower it.
|
|
76
76
|
`)
|
|
77
77
|
);
|
|
78
78
|
|
|
@@ -85,8 +85,8 @@ async function compressAppToZip() {
|
|
|
85
85
|
name: 'package.json',
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
['manifest.json', 'config-overrides.js', 'yarn.lock'].forEach(
|
|
89
|
-
archive.file(path.resolve(dirname, name), { name })
|
|
88
|
+
['manifest.json', 'config-overrides.js', useYarn ? 'yarn.lock' : 'package-lock.json'].forEach(
|
|
89
|
+
(name) => archive.file(path.resolve(dirname, name), { name })
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
archive.directory(path.resolve(dirname, 'src'), 'src');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const Processor = require('../src/processor');
|
|
2
|
-
const loggerFactory = require('@corva/node-logger');
|
|
3
2
|
|
|
4
3
|
test('process event', async () => {
|
|
5
|
-
const
|
|
4
|
+
const fakeLogger = console;
|
|
5
|
+
const fakeApiClient = {};
|
|
6
6
|
|
|
7
7
|
const event = {
|
|
8
8
|
company: 1,
|
|
@@ -13,7 +13,7 @@ test('process event', async () => {
|
|
|
13
13
|
schedule_end: 157829400000,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const processor = new Processor({ logger });
|
|
16
|
+
const processor = new Processor({ logger: fakeLogger, apiClient: fakeApiClient });
|
|
17
17
|
|
|
18
18
|
await processor.process({ event });
|
|
19
19
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# testing
|
|
7
|
+
/coverage
|
|
8
|
+
|
|
9
|
+
# misc
|
|
10
|
+
.env
|
|
11
|
+
.DS_Store
|
|
12
|
+
.env.local
|
|
13
|
+
.env.development.local
|
|
14
|
+
.env.test.local
|
|
15
|
+
.env.production.local
|
|
16
|
+
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
|
|
21
|
+
*.zip
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
"description": "My Dev Center Polling Scheduler Data App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json
|
|
7
|
+
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json $LOCKFILE manifest.json index.js src",
|
|
8
8
|
"test": "npm audit --production && npm run unit",
|
|
9
9
|
"unit": "jest"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@corva/node-sdk": "^
|
|
12
|
+
"@corva/node-sdk": "^5.3.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"jest": "^
|
|
15
|
+
"jest": "^27.2.0"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Dev Center Node.js TypeScript Polling Scheduler Data App
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
### 1. Install Dependencies
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### 2. Run Tests
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm test
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 3. Build
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 4. Deploy
|
|
24
|
+
|
|
25
|
+
Run `npm run bundle` to create a zip package that can be uploaded to Dev Center
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Processor } from '../lib/processor';
|
|
2
|
+
import type { HandlerContext, ScheduledLambdaEvent } from '@corva/node-sdk';
|
|
3
|
+
|
|
4
|
+
test('process event', async () => {
|
|
5
|
+
const fakeLogger = console as unknown as HandlerContext['logger'];
|
|
6
|
+
const fakeApiClient = {} as unknown as HandlerContext['api'];
|
|
7
|
+
|
|
8
|
+
const event = {
|
|
9
|
+
company: 1,
|
|
10
|
+
asset_id: 1234,
|
|
11
|
+
schedule: 206977482,
|
|
12
|
+
interval: 300,
|
|
13
|
+
schedule_start: 157829100000,
|
|
14
|
+
schedule_end: 157829400000,
|
|
15
|
+
} as unknown as ScheduledLambdaEvent<any>;
|
|
16
|
+
|
|
17
|
+
const processor = new Processor(fakeApiClient, fakeLogger);
|
|
18
|
+
|
|
19
|
+
await processor.process(event);
|
|
20
|
+
});
|