From f4d719d3e6eba79d8c211b8770c767938a699e24 Mon Sep 17 00:00:00 2001 From: Mattia Primavera Date: Sat, 17 Oct 2020 18:56:29 +0200 Subject: [PATCH] fix(cli): fix build error when manually deleting a model, repository or controller - force a clean build in prestart npm script - add rebuild script to more concisely express "clean && build" procedure & remove code duplication fix #3259 Signed-off-by: Mattia Primavera --- .../cli/generators/project/templates/package.json.ejs | 10 ++++++---- .../project/templates/package.plain.json.ejs | 10 ++++++---- packages/cli/test/integration/lib/project-generator.js | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/cli/generators/project/templates/package.json.ejs b/packages/cli/generators/project/templates/package.json.ejs index c08f134813be..acc1a5760570 100644 --- a/packages/cli/generators/project/templates/package.json.ejs +++ b/packages/cli/generators/project/templates/package.json.ejs @@ -61,9 +61,9 @@ <% } -%> <% } -%> <% if (packageManager === 'yarn') { -%> - "pretest": "yarn run clean && yarn run build", + "pretest": "yarn run rebuild", <% } else { -%> - "pretest": "npm run clean && npm run build", + "pretest": "npm run rebuild", <% } -%> <% if (project.mocha) { -%> "test": "lb-mocha --allow-console-logs \"dist/__tests__\"", @@ -94,9 +94,11 @@ "preopenapi-spec": "npm run build", "openapi-spec": "node ./dist/openapi-spec", <% if (packageManager === 'yarn') { -%> - "prestart": "yarn run build", + "rebuild": "yarn run clean && yarn run build", + "prestart": "yarn run rebuild", <% } else { -%> - "prestart": "npm run build", + "rebuild": "npm run clean && npm run build", + "prestart": "npm run rebuild", <% } -%> "start": "node -r source-map-support/register .", <% } -%> diff --git a/packages/cli/generators/project/templates/package.plain.json.ejs b/packages/cli/generators/project/templates/package.plain.json.ejs index 53ce2b72aff3..445acf2ed33f 100644 --- a/packages/cli/generators/project/templates/package.plain.json.ejs +++ b/packages/cli/generators/project/templates/package.plain.json.ejs @@ -62,9 +62,9 @@ <% } -%> <% } -%> <% if (packageManager === 'yarn') { -%> - "pretest": "yarn run clean && yarn run build", + "pretest": "yarn run rebuild", <% } else { -%> - "pretest": "npm run clean && npm run build", + "pretest": "npm run rebuild", <% } -%> <% if (project.mocha) { -%> "test": "mocha dist/__tests__", @@ -93,9 +93,11 @@ "migrate": "node ./dist/migrate", "openapi-spec": "node ./dist/openapi-spec", <% if (packageManager === 'yarn') { -%> - "prestart": "yarn run build", + "rebuild": "yarn run clean && yarn run build", + "prestart": "yarn run rebuild", <% } else { -%> - "prestart": "npm run build", + "rebuild": "npm run clean && npm run build", + "prestart": "npm run rebuild", <% } -%> "start": "node -r source-map-support/register .", <% } -%> diff --git a/packages/cli/test/integration/lib/project-generator.js b/packages/cli/test/integration/lib/project-generator.js index d8a8146ca5a4..666661a32297 100644 --- a/packages/cli/test/integration/lib/project-generator.js +++ b/packages/cli/test/integration/lib/project-generator.js @@ -283,7 +283,8 @@ module.exports = function (projGenerator, props, projectType) { ); assert.jsonFileContent('package.json', { scripts: { - prestart: 'npm run build', + rebuild: 'npm run clean && npm run build', + prestart: 'npm run rebuild', start: 'node -r source-map-support/register .', }, }); @@ -296,7 +297,8 @@ module.exports = function (projGenerator, props, projectType) { assert.noFileContent('package.json', '"@loopback/rest"'); assert.noFileContent('package.json', '"@loopback/openapi-v3"'); assert.noJsonFileContent('package.json', { - prestart: 'npm run build', + rebuild: 'npm run clean && npm run build', + prestart: 'npm run rebuild', start: 'node .', }); }