From 38be23f46f02ea380f1290f12704078925d264cd Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Sat, 28 Mar 2020 10:21:54 -0700 Subject: [PATCH] fix(cli): make sure generated package.json is well formatted --- .../generators/project/templates/package.json.ejs | 13 ++++++------- .../project/templates/package.plain.json.ejs | 10 +++++----- .../test/integration/generators/app.integration.js | 2 +- .../cli/test/integration/lib/project-generator.js | 5 +++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/cli/generators/project/templates/package.json.ejs b/packages/cli/generators/project/templates/package.json.ejs index 95572747716a..3c8da37fa25c 100644 --- a/packages/cli/generators/project/templates/package.json.ejs +++ b/packages/cli/generators/project/templates/package.json.ejs @@ -13,7 +13,6 @@ "scripts": { "build": "lb-tsc", "build:watch": "lb-tsc --watch", - "clean": "lb-clean dist *.tsbuildinfo", <% if (project.prettier && project.eslint) { -%> "lint": "npm run prettier:check && npm run eslint", "lint:fix": "npm run eslint:fix && npm run prettier:fix", @@ -46,15 +45,15 @@ "test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js", <% } -%> <% if (project.projectType === 'application') { -%> - <% if (project.docker) { -%> + <%_ if (project.docker) { -%> "docker:build": "docker build -t <%= project.name -%> .", "docker:run": "docker run -p 3000:3000 -d <%= project.name -%>", - <% } -%> + <%_ } -%> "migrate": "node ./dist/migrate", "prestart": "npm run build", "start": "node -r source-map-support/register .", <% } -%> - "prepublishOnly": "npm run test" + "clean": "lb-clean dist *.tsbuildinfo .eslintcache" }, "repository": { "type": "git" @@ -91,14 +90,14 @@ <% } else { /* NOT AN APPLICATION */-%> "@loopback/core": "<%= project.dependencies['@loopback/core'] -%>", <% } -%> - "tslib": "<%= project.dependencies['tslib'] -%>" + "tslib": "<%= project.dependencies['tslib'] -%>" }, "devDependencies": { "@loopback/build": "<%= project.dependencies['@loopback/build'] -%>", "source-map-support": "<%= project.dependencies['source-map-support'] -%>", "@loopback/testlab": "<%= project.dependencies['@loopback/testlab'] -%>", "@types/node": "<%= project.dependencies['@types/node'] -%>", - <% if (project.eslint) { -%> +<% if (project.eslint) { -%> "@typescript-eslint/parser": "<%= project.dependencies['@typescript-eslint/parser'] -%>", "@typescript-eslint/eslint-plugin": "<%= project.dependencies['@typescript-eslint/eslint-plugin'] -%>", "@loopback/eslint-config": "<%= project.dependencies['@loopback/eslint-config'] -%>", @@ -106,7 +105,7 @@ "eslint-config-prettier": "<%= project.dependencies['eslint-config-prettier'] -%>", "eslint-plugin-eslint-plugin": "<%= project.dependencies['eslint-plugin-eslint-plugin'] -%>", "eslint-plugin-mocha": "<%= project.dependencies['eslint-plugin-mocha'] -%>", - <% } -%> +<% } -%> "typescript": "<%= project.dependencies['typescript'] -%>" } } diff --git a/packages/cli/generators/project/templates/package.plain.json.ejs b/packages/cli/generators/project/templates/package.plain.json.ejs index 914fa22cd7a3..3e057ef092c0 100644 --- a/packages/cli/generators/project/templates/package.plain.json.ejs +++ b/packages/cli/generators/project/templates/package.plain.json.ejs @@ -13,7 +13,7 @@ "scripts": { "build": "tsc", "build:watch": "tsc --watch", - "clean": "rimraf dist *.tsbuildinfo", + "clean": "rimraf dist *.tsbuildinfo .eslintcache", <% if (project.prettier && project.eslint) { -%> "lint": "npm run prettier:check && npm run eslint", "lint:fix": "npm run eslint:fix && npm run prettier:fix", @@ -46,10 +46,10 @@ "test:dev": "mocha dist/__tests__/**/*.js", <% } -%> <% if (project.projectType === 'application') { -%> - <% if (project.docker) { -%> + <%_ if (project.docker) { -%> "docker:build": "docker build -t <%= project.name -%> .", "docker:run": "docker run -p 3000:3000 -d <%= project.name -%>", - <% } -%> + <%_ } -%> "migrate": "node ./dist/migrate", "start": "npm run build && node -r source-map-support/register .", <% } -%> @@ -83,7 +83,7 @@ <% } else { -%> "@loopback/core": "<%= project.dependencies['@loopback/core'] -%>", <% } -%> - "tslib": "<%= project.dependencies['tslib'] -%>" + "tslib": "<%= project.dependencies['tslib'] -%>" }, "devDependencies": { "rimraf": "<%= project.dependencies['rimraf'] -%>", @@ -110,7 +110,7 @@ "eslint-config-prettier": "<%= project.dependencies['eslint-config-prettier'] -%>", "eslint-plugin-eslint-plugin": "<%= project.dependencies['eslint-plugin-eslint-plugin'] -%>", "eslint-plugin-mocha": "<%= project.dependencies['eslint-plugin-mocha'] -%>", - <% } -%> +<% } -%> "typescript": "<%= project.dependencies['typescript'] -%>" } } diff --git a/packages/cli/test/integration/generators/app.integration.js b/packages/cli/test/integration/generators/app.integration.js index e53550b6137f..6704f9776de4 100644 --- a/packages/cli/test/integration/generators/app.integration.js +++ b/packages/cli/test/integration/generators/app.integration.js @@ -125,7 +125,7 @@ describe('app-generator specific files', () => { it('creates npm script "clean"', () => { assert.fileContent( 'package.json', - '"clean": "lb-clean dist *.tsbuildinfo"', + '"clean": "lb-clean dist *.tsbuildinfo .eslintcache"', ); }); diff --git a/packages/cli/test/integration/lib/project-generator.js b/packages/cli/test/integration/lib/project-generator.js index f3c370616f4e..18993890057e 100644 --- a/packages/cli/test/integration/lib/project-generator.js +++ b/packages/cli/test/integration/lib/project-generator.js @@ -342,8 +342,9 @@ module.exports = function (projGenerator, props, projectType) { ['tsconfig.json', '@loopback/build'], ]); assert.fileContent([ - ['package.json', '"clean": "rimraf dist *.tsbuildinfo"'], - ['package.json', '"typescript"'], + ['package.json', '"clean": "rimraf dist *.tsbuildinfo .eslintcache"'], + ['package.json', /^ {4}"typescript"/m], + ['package.json', /^ {4}"tslib"/m], ['package.json', '"eslint"'], ['package.json', 'eslint-config-prettier'], ['package.json', 'eslint-plugin-eslint-plugin'],