@loopback/cli 4.0.0-alpha.8 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yo-rc.json +1719 -0
- package/{generators/project/templates/LICENSE → LICENSE} +2 -1
- package/README.md +44 -43
- package/bin/cli-main.js +61 -0
- package/generators/app/index.js +109 -15
- package/generators/app/templates/.dockerignore +5 -0
- package/generators/app/templates/Dockerfile +28 -0
- package/generators/app/templates/README.md.ejs +130 -0
- package/generators/app/templates/public/index.html.ejs +88 -0
- package/generators/app/templates/{test → src/__tests__}/README.md +0 -1
- package/generators/app/templates/src/__tests__/acceptance/home-page.acceptance.ts.ejs +31 -0
- package/generators/app/templates/src/__tests__/acceptance/ping.controller.acceptance.ts.ejs +21 -0
- package/generators/app/templates/src/__tests__/acceptance/test-helper.ts.ejs +32 -0
- package/generators/app/templates/src/application.ts.ejs +70 -0
- package/generators/app/templates/src/controllers/README.md +6 -0
- package/generators/app/templates/src/controllers/index.ts.ejs +1 -0
- package/generators/app/templates/src/controllers/ping.controller.ts.ejs +55 -0
- package/generators/app/templates/src/datasources/README.md +3 -0
- package/generators/app/templates/src/index.ts.ejs +39 -0
- package/generators/app/templates/src/migrate.ts.ejs +20 -0
- package/generators/app/templates/src/models/README.md +3 -0
- package/generators/app/templates/src/openapi-spec.ts.ejs +23 -0
- package/generators/app/templates/src/sequence.ts.ejs +3 -0
- package/generators/controller/index.js +240 -23
- package/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs +150 -0
- package/generators/controller/templates/src/controllers/{controller-template.ts → controller-template.ts.ejs} +2 -2
- package/generators/copyright/fs.js +46 -0
- package/generators/copyright/git.js +78 -0
- package/generators/copyright/header.js +306 -0
- package/generators/copyright/index.js +230 -0
- package/generators/copyright/license.js +105 -0
- package/generators/datasource/index.js +341 -0
- package/generators/datasource/templates/datasource.ts.ejs +22 -0
- package/generators/discover/import-discovered-model.js +70 -0
- package/generators/discover/index.js +411 -0
- package/generators/example/downloader.js +16 -0
- package/generators/example/index.js +176 -0
- package/generators/extension/index.js +34 -5
- package/generators/extension/templates/README.md.ejs +32 -0
- package/generators/extension/templates/{test → src/__tests__}/acceptance/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/integration/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/unit/README.md +0 -0
- package/generators/extension/templates/src/component.ts.ejs +22 -0
- package/generators/extension/templates/src/controllers/README.md +3 -2
- package/generators/extension/templates/src/decorators/README.md +10 -4
- package/generators/extension/templates/src/index.ts.ejs +3 -0
- package/generators/extension/templates/src/keys.ts.ejs +11 -0
- package/generators/extension/templates/src/mixins/README.md +77 -21
- package/generators/extension/templates/src/providers/README.md +51 -25
- package/generators/extension/templates/src/repositories/README.md +1 -1
- package/generators/extension/templates/src/types.ts.ejs +15 -0
- package/generators/import-lb3-models/index.js +197 -0
- package/generators/import-lb3-models/lb3app-loader.js +31 -0
- package/generators/import-lb3-models/migrate-model.js +249 -0
- package/generators/import-lb3-models/model-names.js +32 -0
- package/generators/interceptor/index.js +178 -0
- package/generators/interceptor/templates/interceptor-template.ts.ejs +62 -0
- package/generators/model/index.js +536 -0
- package/generators/model/property-definition.js +85 -0
- package/generators/model/templates/model.ts.ejs +49 -0
- package/generators/observer/index.js +132 -0
- package/generators/observer/templates/observer-template.ts.ejs +40 -0
- package/generators/openapi/README.md +211 -0
- package/generators/openapi/index.js +535 -0
- package/generators/openapi/schema-helper.js +447 -0
- package/generators/openapi/spec-helper.js +484 -0
- package/generators/openapi/spec-loader.js +75 -0
- package/generators/openapi/templates/src/controllers/controller-template.ts.ejs +43 -0
- package/generators/openapi/templates/src/datasources/datasource.ts.ejs +42 -0
- package/generators/openapi/templates/src/models/model-template.ts.ejs +71 -0
- package/generators/openapi/templates/src/models/type-template.ts.ejs +13 -0
- package/generators/openapi/templates/src/services/service-proxy-template.ts.ejs +55 -0
- package/generators/openapi/utils.js +322 -0
- package/generators/project/templates/.eslintignore +4 -0
- package/generators/project/templates/.eslintrc.js.ejs +3 -0
- package/generators/project/templates/.mocharc.json +5 -0
- package/generators/project/templates/.prettierignore +0 -2
- package/generators/project/templates/.prettierrc +2 -1
- package/generators/project/templates/.vscode/launch.json +38 -0
- package/generators/project/templates/.vscode/settings.json +32 -0
- package/generators/project/templates/.vscode/tasks.json +29 -0
- package/generators/project/templates/DEVELOPING.md +36 -0
- package/generators/project/templates/_.gitignore +3 -5
- package/generators/project/templates/package.json.ejs +175 -0
- package/generators/project/templates/package.plain.json.ejs +176 -0
- package/generators/project/templates/tsconfig.json.ejs +39 -0
- package/generators/relation/base-relation.generator.js +220 -0
- package/generators/relation/belongs-to-relation.generator.js +196 -0
- package/generators/relation/has-many-relation.generator.js +200 -0
- package/generators/relation/has-many-through-relation.generator.js +331 -0
- package/generators/relation/has-one-relation.generator.js +200 -0
- package/generators/relation/index.js +795 -0
- package/generators/relation/references-many-relation.generator.js +142 -0
- package/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs +38 -0
- package/generators/relation/templates/controller-relation-template-has-many-through.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-many.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-one.ts.ejs +110 -0
- package/generators/relation/utils.generator.js +260 -0
- package/generators/repository/index.js +576 -0
- package/generators/repository/templates/src/repositories/repository-crud-default-template.ts.ejs +21 -0
- package/generators/repository/templates/src/repositories/repository-kv-template.ts.ejs +19 -0
- package/generators/rest-crud/crud-rest-component.js +63 -0
- package/generators/rest-crud/index.js +423 -0
- package/generators/rest-crud/templates/src/model-endpoints/model.rest-config-template.ts.ejs +11 -0
- package/generators/service/index.js +351 -0
- package/generators/service/templates/local-service-class-template.ts.ejs +10 -0
- package/generators/service/templates/local-service-provider-template.ts.ejs +19 -0
- package/generators/service/templates/remote-service-proxy-template.ts.ejs +21 -0
- package/generators/update/index.js +55 -0
- package/intl/cs/messages.json +204 -0
- package/intl/de/messages.json +204 -0
- package/intl/en/messages.json +204 -0
- package/intl/es/messages.json +204 -0
- package/intl/fr/messages.json +204 -0
- package/intl/it/messages.json +204 -0
- package/intl/ja/messages.json +204 -0
- package/intl/ko/messages.json +204 -0
- package/intl/nl/messages.json +204 -0
- package/intl/pl/messages.json +204 -0
- package/intl/pt/messages.json +204 -0
- package/intl/ru/messages.json +204 -0
- package/intl/tr/messages.json +204 -0
- package/intl/zh-Hans/messages.json +204 -0
- package/intl/zh-Hant/messages.json +204 -0
- package/lib/artifact-generator.js +137 -39
- package/lib/ast-helper.js +214 -0
- package/lib/base-generator.js +509 -0
- package/lib/cli.js +233 -0
- package/lib/connectors.json +894 -0
- package/lib/debug.js +16 -0
- package/lib/globalize.js +12 -0
- package/lib/model-discoverer.js +118 -0
- package/lib/project-generator.js +154 -57
- package/lib/tab-completion.js +127 -0
- package/lib/update-index.js +44 -0
- package/lib/utils.js +689 -20
- package/lib/version-helper.js +299 -0
- package/package.json +183 -39
- package/CHANGELOG.md +0 -75
- package/bin/cli.js +0 -66
- package/generators/.DS_Store +0 -0
- package/generators/app/templates/index.js +0 -14
- package/generators/app/templates/src/application.ts +0 -27
- package/generators/app/templates/src/controllers/ping-controller.ts +0 -25
- package/generators/app/templates/src/index.ts +0 -25
- package/generators/app/templates/test/ping-controller.test.ts +0 -46
- package/generators/extension/templates/index.js +0 -8
- package/generators/extension/templates/src/component.ts +0 -14
- package/generators/extension/templates/src/index.ts +0 -6
- package/generators/project/templates/.npmrc +0 -1
- package/generators/project/templates/.yo-rc.json +0 -1
- package/generators/project/templates/README.md +0 -4
- package/generators/project/templates/index.d.ts +0 -6
- package/generators/project/templates/index.ts +0 -11
- package/generators/project/templates/package.json +0 -79
- package/generators/project/templates/package.plain.json +0 -82
- package/generators/project/templates/test/mocha.opts +0 -1
- package/generators/project/templates/tsconfig.json +0 -29
- package/generators/project/templates/tslint.build.json +0 -17
- package/generators/project/templates/tslint.json +0 -33
package/lib/cli.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/cli
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const camelCaseKeys = require('camelcase-keys');
|
|
9
|
+
const debug = require('./debug')();
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const fs = require('fs-extra');
|
|
12
|
+
const yeoman = require('yeoman-environment');
|
|
13
|
+
const PREFIX = 'loopback4:';
|
|
14
|
+
const {printVersions} = require('./version-helper');
|
|
15
|
+
|
|
16
|
+
const {tabCompletionCommands} = require('./tab-completion');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse arguments and run corresponding command
|
|
20
|
+
* @param env - Yeoman env
|
|
21
|
+
* @param {*} opts Command options
|
|
22
|
+
* @param log - Log function
|
|
23
|
+
*/
|
|
24
|
+
function runCommand(env, opts, log) {
|
|
25
|
+
const dryRun = opts.dryRun || opts['dry-run'];
|
|
26
|
+
const args = opts._;
|
|
27
|
+
const originalCommand = args.shift();
|
|
28
|
+
let command = PREFIX + (originalCommand || 'app');
|
|
29
|
+
const supportedCommands = env.getGeneratorsMeta();
|
|
30
|
+
if (!(command in supportedCommands)) {
|
|
31
|
+
command = PREFIX + 'app';
|
|
32
|
+
args.unshift(originalCommand);
|
|
33
|
+
args.unshift(command);
|
|
34
|
+
} else {
|
|
35
|
+
args.unshift(command);
|
|
36
|
+
}
|
|
37
|
+
debug('invoking generator', args);
|
|
38
|
+
// `yo` is adding flags converted to CamelCase
|
|
39
|
+
const options = camelCaseKeys(opts, {exclude: ['--', /^\w$/, 'argv']});
|
|
40
|
+
Object.assign(options, opts);
|
|
41
|
+
debug('env.run %j %j', args, options);
|
|
42
|
+
if (!dryRun) {
|
|
43
|
+
env.run(args, options);
|
|
44
|
+
}
|
|
45
|
+
// list generators
|
|
46
|
+
if (opts.help && !originalCommand) {
|
|
47
|
+
printCommands(env, log);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Set up yeoman generators
|
|
53
|
+
*/
|
|
54
|
+
function setupGenerators() {
|
|
55
|
+
const env = yeoman.createEnv();
|
|
56
|
+
env.register(path.join(__dirname, '../generators/app'), PREFIX + 'app');
|
|
57
|
+
env.register(
|
|
58
|
+
path.join(__dirname, '../generators/extension'),
|
|
59
|
+
PREFIX + 'extension',
|
|
60
|
+
);
|
|
61
|
+
env.register(
|
|
62
|
+
path.join(__dirname, '../generators/controller'),
|
|
63
|
+
PREFIX + 'controller',
|
|
64
|
+
);
|
|
65
|
+
env.register(
|
|
66
|
+
path.join(__dirname, '../generators/datasource'),
|
|
67
|
+
PREFIX + 'datasource',
|
|
68
|
+
);
|
|
69
|
+
env.register(
|
|
70
|
+
path.join(__dirname, '../generators/import-lb3-models'),
|
|
71
|
+
PREFIX + 'import-lb3-models',
|
|
72
|
+
);
|
|
73
|
+
env.register(path.join(__dirname, '../generators/model'), PREFIX + 'model');
|
|
74
|
+
env.register(
|
|
75
|
+
path.join(__dirname, '../generators/repository'),
|
|
76
|
+
PREFIX + 'repository',
|
|
77
|
+
);
|
|
78
|
+
env.register(
|
|
79
|
+
path.join(__dirname, '../generators/service'),
|
|
80
|
+
PREFIX + 'service',
|
|
81
|
+
);
|
|
82
|
+
env.register(
|
|
83
|
+
path.join(__dirname, '../generators/example'),
|
|
84
|
+
PREFIX + 'example',
|
|
85
|
+
);
|
|
86
|
+
env.register(
|
|
87
|
+
path.join(__dirname, '../generators/openapi'),
|
|
88
|
+
PREFIX + 'openapi',
|
|
89
|
+
);
|
|
90
|
+
env.register(
|
|
91
|
+
path.join(__dirname, '../generators/observer'),
|
|
92
|
+
PREFIX + 'observer',
|
|
93
|
+
);
|
|
94
|
+
env.register(
|
|
95
|
+
path.join(__dirname, '../generators/interceptor'),
|
|
96
|
+
PREFIX + 'interceptor',
|
|
97
|
+
);
|
|
98
|
+
env.register(
|
|
99
|
+
path.join(__dirname, '../generators/discover'),
|
|
100
|
+
PREFIX + 'discover',
|
|
101
|
+
);
|
|
102
|
+
env.register(
|
|
103
|
+
path.join(__dirname, '../generators/relation'),
|
|
104
|
+
PREFIX + 'relation',
|
|
105
|
+
);
|
|
106
|
+
env.register(path.join(__dirname, '../generators/update'), PREFIX + 'update');
|
|
107
|
+
env.register(
|
|
108
|
+
path.join(__dirname, '../generators/relation'),
|
|
109
|
+
PREFIX + 'relation',
|
|
110
|
+
);
|
|
111
|
+
env.register(
|
|
112
|
+
path.join(__dirname, '../generators/rest-crud'),
|
|
113
|
+
PREFIX + 'rest-crud',
|
|
114
|
+
);
|
|
115
|
+
env.register(
|
|
116
|
+
path.join(__dirname, '../generators/copyright'),
|
|
117
|
+
PREFIX + 'copyright',
|
|
118
|
+
);
|
|
119
|
+
return env;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Print a list of available commands
|
|
124
|
+
* @param {*} env Yeoman env
|
|
125
|
+
* @param log - Log function
|
|
126
|
+
*/
|
|
127
|
+
function printCommands(env, log) {
|
|
128
|
+
log('Available commands:');
|
|
129
|
+
const prefix = ' lb4 ';
|
|
130
|
+
const generatorCommands = Object.keys(env.getGeneratorsMeta())
|
|
131
|
+
.filter(name => /^loopback4:/.test(name))
|
|
132
|
+
.map(name => name.replace(/^loopback4:/, prefix));
|
|
133
|
+
const completionCommands = tabCompletionCommands
|
|
134
|
+
.filter(command => command !== 'completion')
|
|
135
|
+
.map(command => `${prefix}${command}`);
|
|
136
|
+
const list = [...generatorCommands, ...completionCommands];
|
|
137
|
+
log(list.join('\n'));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const baseOptions = {
|
|
141
|
+
help: {
|
|
142
|
+
name: 'help',
|
|
143
|
+
type: 'Boolean',
|
|
144
|
+
alias: 'h',
|
|
145
|
+
description: "Print the generator's options and usage",
|
|
146
|
+
},
|
|
147
|
+
'skip-cache': {
|
|
148
|
+
name: 'skip-cache',
|
|
149
|
+
type: 'Boolean',
|
|
150
|
+
description: 'Do not remember prompt answers',
|
|
151
|
+
default: false,
|
|
152
|
+
},
|
|
153
|
+
'skip-install': {
|
|
154
|
+
name: 'skip-install',
|
|
155
|
+
type: 'Boolean',
|
|
156
|
+
description: 'Do not automatically install dependencies',
|
|
157
|
+
default: false,
|
|
158
|
+
},
|
|
159
|
+
'force-install': {
|
|
160
|
+
name: 'force-install',
|
|
161
|
+
type: 'Boolean',
|
|
162
|
+
description: 'Fail on install dependencies error',
|
|
163
|
+
default: false,
|
|
164
|
+
},
|
|
165
|
+
'ask-answered': {
|
|
166
|
+
type: 'Boolean',
|
|
167
|
+
description: 'Show prompts for already configured options',
|
|
168
|
+
default: false,
|
|
169
|
+
name: 'ask-answered',
|
|
170
|
+
hide: false,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function main(opts, log) {
|
|
175
|
+
const dryRun = opts.dryRun || opts['dry-run'];
|
|
176
|
+
log = log || console.log;
|
|
177
|
+
if (opts.version) {
|
|
178
|
+
printVersions(log);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const env = setupGenerators();
|
|
183
|
+
|
|
184
|
+
// list generators
|
|
185
|
+
if (opts.commands) {
|
|
186
|
+
printCommands(env, log);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const yoJsonFile = path.join(__dirname, '../.yo-rc.json');
|
|
191
|
+
if (opts.meta) {
|
|
192
|
+
const optionsAndArgs = {
|
|
193
|
+
base: baseOptions,
|
|
194
|
+
};
|
|
195
|
+
const meta = env.getGeneratorsMeta();
|
|
196
|
+
for (const ns in meta) {
|
|
197
|
+
const gen = env.create(ns, {options: {help: true}});
|
|
198
|
+
const name = ns.substring('loopback4:'.length);
|
|
199
|
+
const commandOptions = {};
|
|
200
|
+
for (const n in gen._options) {
|
|
201
|
+
const opt = gen._options[n];
|
|
202
|
+
commandOptions[n] = {...opt, type: opt.type.name};
|
|
203
|
+
}
|
|
204
|
+
const commandArgs = [];
|
|
205
|
+
for (const arg of gen._arguments) {
|
|
206
|
+
commandArgs.push({...arg, type: arg.type.name});
|
|
207
|
+
}
|
|
208
|
+
optionsAndArgs[name] = {
|
|
209
|
+
options: commandOptions,
|
|
210
|
+
arguments: commandArgs,
|
|
211
|
+
name,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const yoJson = fs.readJsonSync(yoJsonFile);
|
|
216
|
+
const str = JSON.stringify(yoJson.commands, null, 2);
|
|
217
|
+
yoJson.commands = optionsAndArgs;
|
|
218
|
+
if (str !== JSON.stringify(optionsAndArgs, null, 2)) {
|
|
219
|
+
if (!dryRun) {
|
|
220
|
+
fs.writeJsonSync(yoJsonFile, yoJson, {spaces: 2, encoding: 'utf-8'});
|
|
221
|
+
}
|
|
222
|
+
log('%s has been updated.', path.relative(process.cwd(), yoJsonFile));
|
|
223
|
+
} else {
|
|
224
|
+
log('%s is up to date.', path.relative(process.cwd(), yoJsonFile));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return optionsAndArgs;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
runCommand(env, opts, log);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
module.exports = main;
|