Skip to content

Commit 2ebf69f

Browse files
committed
fix: Fix cli templates
Add missing dependency of `@loopback/rest` for apps Use newline-trimming ending tags in EJS
1 parent feb27db commit 2ebf69f

File tree

8 files changed

+88
-65
lines changed

8 files changed

+88
-65
lines changed
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "<%= project.name %>",
2+
"name": "<%= project.name -%>",
33
"version": "1.0.0",
4-
"description": "<%= project.description %>",
4+
"description": "<%= project.description -%>",
55
"keywords": [
6-
"loopback-<%= project.projectType %>",
6+
"loopback-<%= project.projectType -%>",
77
"loopback"
88
],
99
"main": "index.js",
@@ -14,32 +14,32 @@
1414
"build": "lb-tsc",
1515
"build:watch": "lb-tsc --watch",
1616
"clean": "lb-clean",
17-
<% if (project.prettier && project.tslint) { %>
17+
<% if (project.prettier && project.tslint) { -%>
1818
"lint": "npm run prettier:check && npm run tslint",
1919
"lint:fix": "npm run prettier:fix && npm run tslint:fix",
20-
<% } else if (project.prettier) { %>
20+
<% } else if (project.prettier) { -%>
2121
"lint": "npm run prettier:check",
2222
"lint:fix": "npm run prettier:fix",
23-
<% } else if (project.tslint) { %>
23+
<% } else if (project.tslint) { -%>
2424
"lint": "npm run tslint",
2525
"lint:fix": "npm run tslint:fix",
26-
<% } %>
27-
<% if (project.prettier) { %>
26+
<% } -%>
27+
<% if (project.prettier) { -%>
2828
"prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
2929
"prettier:check": "npm run prettier:cli -- -l",
3030
"prettier:fix": "npm run prettier:cli -- --write",
31-
<% } %>
32-
<% if (project.tslint) { %>
31+
<% } -%>
32+
<% if (project.tslint) { -%>
3333
"tslint": "lb-tslint",
3434
"tslint:fix": "npm run tslint -- --fix",
35-
<% } %>
35+
<% } -%>
3636
"pretest": "npm run clean && npm run build",
37-
<% if (project.mocha) { %>
37+
<% if (project.mocha) { -%>
3838
"test": "lb-dist mocha DIST/test",
39-
<% } %>
40-
<% if (project.prettier || project.tslint) { %>
39+
<% } -%>
40+
<% if (project.prettier || project.tslint) { -%>
4141
"posttest": "npm run lint",
42-
<% } %>
42+
<% } -%>
4343
"prepare": "npm run build"
4444
},
4545
"repository": {
@@ -55,17 +55,22 @@
5555
"dist6"
5656
],
5757
"dependencies": {
58-
"@loopback/context": "^4.0.0-alpha.14",
59-
"@loopback/core": "^4.0.0-alpha.16"
58+
"@loopback/context": "^4.0.0-alpha.18",
59+
<% if (project.projectType === 'application') { -%>
60+
"@loopback/core": "^4.0.0-alpha.20",
61+
"@loopback/rest": "^4.0.0-alpha.7"
62+
<% } else { -%>
63+
"@loopback/core": "^4.0.0-alpha.20"
64+
<% } -%>
6065
},
6166
"devDependencies": {
62-
"@loopback/build": "^4.0.0-alpha.3",
63-
<% if (project.mocha) { %>
64-
"@loopback/testlab": "^4.0.0-alpha.9",
67+
"@loopback/build": "^4.0.0-alpha.4",
68+
<% if (project.mocha) { -%>
69+
"@loopback/testlab": "^4.0.0-alpha.13",
6570
"@types/mocha": "^2.2.43",
6671
"mocha": "^4.0.1"
67-
<% } else { %>
68-
"@loopback/testlab": "^4.0.0-alpha.9"
69-
<% } %>
72+
<% } else { -%>
73+
"@loopback/testlab": "^4.0.0-alpha.13"
74+
<% } -%>
7075
}
7176
}
Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "<%= project.name %>",
2+
"name": "<%= project.name -%>",
33
"version": "1.0.0",
4-
"description": "<%= project.description %>",
4+
"description": "<%= project.description -%>",
55
"keywords": [
6-
"loopback-<%= project.projectType %>",
6+
"loopback-<%= project.projectType -%>",
77
"loopback"
88
],
99
"main": "index.js",
@@ -14,32 +14,32 @@
1414
"build": "tsc --outDir dist --target es2017",
1515
"build:watch": "tsc --outDir dist --target es2017 --watch",
1616
"clean": "rm -rf dist",
17-
<% if (project.prettier && project.tslint) { %>
17+
<% if (project.prettier && project.tslint) { -%>
1818
"lint": "npm run prettier:check && npm run tslint",
1919
"lint:fix": "npm run prettier:fix && npm run tslint:fix",
20-
<% } else if (project.prettier) { %>
20+
<% } else if (project.prettier) { -%>
2121
"lint": "npm run prettier:check",
2222
"lint:fix": "npm run prettier:fix",
23-
<% } else if (project.tslint) { %>
23+
<% } else if (project.tslint) { -%>
2424
"lint": "npm run tslint",
2525
"lint:fix": "npm run tslint:fix",
26-
<% } %>
27-
<% if (project.prettier) { %>
26+
<% } -%>
27+
<% if (project.prettier) { -%>
2828
"prettier:cli": "prettier \"**/*.ts\" \"**/*.js\"",
2929
"prettier:check": "npm run prettier:cli -- -l",
3030
"prettier:fix": "npm run prettier:cli -- --write",
31-
<% } %>
32-
<% if (project.tslint) { %>
31+
<% } -%>
32+
<% if (project.tslint) { -%>
3333
"tslint": "tslint",
3434
"tslint:fix": "npm run tslint -- --fix",
35-
<% } %>
35+
<% } -%>
3636
"pretest": "npm run clean && npm run build",
37-
<% if (project.mocha) { %>
37+
<% if (project.mocha) { -%>
3838
"test": "mocha dist/test",
39-
<% } %>
40-
<% if (project.prettier || project.tslint) { %>
39+
<% } -%>
40+
<% if (project.prettier || project.tslint) { -%>
4141
"posttest": "npm run lint",
42-
<% } %>
42+
<% } -%>
4343
"prepare": "npm run build"
4444
},
4545
"repository": {
@@ -54,21 +54,26 @@
5454
"dist"
5555
],
5656
"dependencies": {
57-
"@loopback/context": "^4.0.0-alpha.14",
58-
"@loopback/core": "^4.0.0-alpha.16"
57+
"@loopback/context": "^4.0.0-alpha.18",
58+
<% if (project.projectType === 'application') { -%>
59+
"@loopback/core": "^4.0.0-alpha.20",
60+
"@loopback/rest": "^4.0.0-alpha.7"
61+
<% } else { -%>
62+
"@loopback/core": "^4.0.0-alpha.20"
63+
<% } -%>
5964
},
6065
"devDependencies": {
61-
<% if (project.prettier) { %>
66+
<% if (project.prettier) { -%>
6267
"prettier": "^1.7.3",
63-
<% } %>
64-
<% if (project.tslint) { %>
68+
<% } -%>
69+
<% if (project.tslint) { -%>
6570
"tslint": "^5.7.0",
66-
<% } %>
67-
"@loopback/testlab": "^4.0.0-alpha.9",
68-
<% if (project.mocha) { %>
71+
<% } -%>
72+
"@loopback/testlab": "^4.0.0-alpha.13",
73+
<% if (project.mocha) { -%>
6974
"@types/mocha": "^2.2.43",
7075
"mocha": "^4.0.1",
71-
<% } %>
76+
<% } -%>
7277
"typescript": "^2.5.3"
7378
}
7479
}

packages/cli/generators/project/templates/tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"$schema": "http://json.schemastore.org/tsconfig",
3-
<% if (project.loopbackBuild) { %>
3+
<% if (project.loopbackBuild) { -%>
44
"extends": "./node_modules/@loopback/build/config/tsconfig.common.json",
5-
<% } else { %>
5+
<% } else { -%>
66
"compilerOptions": {
77
"emitDecoratorMetadata": true,
88
"experimentalDecorators": true,
99
"noImplicitAny": true,
1010
"strictNullChecks": true,
11-
11+
1212
"lib": ["es2017", "dom"],
1313
"module": "commonjs",
1414
"moduleResolution": "node",
1515
"target": "es6",
1616
"sourceMap": true,
1717
"declaration": true
1818
},
19-
<% } %>
19+
<% } -%>
2020
"include": [
2121
"src",
2222
"test"

packages/cli/generators/project/templates/tslint.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"$schema": "http://json.schemastore.org/tslint",
3-
<% if (project.loopbackBuild) { %>
3+
<% if (project.loopbackBuild) { -%>
44
"extends": ["./node_modules/@loopback/build/config/tslint.common.json"]
5-
<% } else { %>
5+
<% } else { -%>
66
// See https://palantir.github.io/tslint/rules/
77
"rules": {
88
// These rules find errors related to TypeScript features.
@@ -29,5 +29,5 @@
2929
"triple-equals": [true, "allow-null-check", "allow-undefined-check"],
3030
"typeof-compare": true
3131
}
32-
<% } %>
32+
<% } -%>
3333
}

packages/cli/lib/project-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = class extends Generator {
6262
}
6363

6464
setOptions() {
65-
this.projectInfo = {};
65+
this.projectInfo = {projectType: this.projectType};
6666
[
6767
'name',
6868
'description',

packages/cli/test/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ const props = {
1212
description: 'My app for LoopBack 4',
1313
};
1414

15-
const tests = require('./project')(generator, props);
15+
const tests = require('./project')(generator, props, 'application');
1616

1717
describe('generator-loopback4:app', tests);

packages/cli/test/extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ const props = {
1212
description: 'My extension for LoopBack 4',
1313
};
1414

15-
const tests = require('./project')(generator, props);
15+
const tests = require('./project')(generator, props, 'extension');
1616

1717
describe('generator-loopback4:extension', tests);

packages/cli/test/project.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ const assert = require('yeoman-assert');
99
const helpers = require('yeoman-test');
1010
const yeoman = require('yeoman-environment');
1111

12-
module.exports = function(appGenerator, props) {
12+
module.exports = function(projGenerator, props, projectType) {
1313
return function() {
1414
describe('help', () => {
1515
it('prints lb4', () => {
1616
const env = yeoman.createEnv();
17-
const name = appGenerator.substring(appGenerator.lastIndexOf('/') + 1);
18-
env.register(appGenerator, 'loopback4:' + name);
17+
const name = projGenerator.substring(
18+
projGenerator.lastIndexOf('/') + 1
19+
);
20+
env.register(projGenerator, 'loopback4:' + name);
1921
const generator = env.create('loopback4:' + name);
2022
const helpText = generator.help();
2123
assert(helpText.match(/lb4 /));
@@ -25,7 +27,7 @@ module.exports = function(appGenerator, props) {
2527

2628
describe('without settings', () => {
2729
before(() => {
28-
return helpers.run(appGenerator).withPrompts(props);
30+
return helpers.run(projGenerator).withPrompts(props);
2931
});
3032

3133
it('creates files', () => {
@@ -49,12 +51,23 @@ module.exports = function(appGenerator, props) {
4951
['tslint.json', '"rules"'],
5052
['tsconfig.json', '"compilerOptions"'],
5153
]);
54+
55+
if (projectType === 'application') {
56+
assert.fileContent('package.json', '"@loopback/core"');
57+
assert.fileContent('package.json', '"@loopback/context"');
58+
assert.fileContent('package.json', '"@loopback/rest"');
59+
}
60+
if (projectType === 'extension') {
61+
assert.fileContent('package.json', '"@loopback/core"');
62+
assert.fileContent('package.json', '"@loopback/context"');
63+
assert.noFileContent('package.json', '"@loopback/rest"');
64+
}
5265
});
5366
});
5467

5568
describe('with loopbackBuild disabled', () => {
5669
before(() => {
57-
return helpers.run(appGenerator).withPrompts(
70+
return helpers.run(projGenerator).withPrompts(
5871
Object.assign(
5972
{
6073
settings: [
@@ -89,7 +102,7 @@ module.exports = function(appGenerator, props) {
89102

90103
describe('with prettier disabled', () => {
91104
before(() => {
92-
return helpers.run(appGenerator).withPrompts(
105+
return helpers.run(projGenerator).withPrompts(
93106
Object.assign(
94107
{
95108
settings: [
@@ -112,7 +125,7 @@ module.exports = function(appGenerator, props) {
112125

113126
describe('with tslint disabled', () => {
114127
before(() => {
115-
return helpers.run(appGenerator).withPrompts(
128+
return helpers.run(projGenerator).withPrompts(
116129
Object.assign(
117130
{
118131
settings: [
@@ -135,7 +148,7 @@ module.exports = function(appGenerator, props) {
135148

136149
describe('with loopbackBuild & tslint disabled', () => {
137150
before(() => {
138-
return helpers.run(appGenerator).withPrompts(
151+
return helpers.run(projGenerator).withPrompts(
139152
Object.assign(
140153
{
141154
settings: [

0 commit comments

Comments
 (0)