diff --git a/packages/cli/generators/logbar.js b/packages/cli/generators/logbar.js new file mode 100644 index 0000000000..c9ede07710 --- /dev/null +++ b/packages/cli/generators/logbar.js @@ -0,0 +1,14 @@ +exports.logBarStart = function(bar1, start){ + // start the progress bar with a total value of 200 and start value of 0 + bar1.start(start, 0); +} + +exports.logBar = function(bar1){ + // update the current value in your application.. + bar1.increment(1); +} + +exports.logBarStop = function(bar1){ + // stop the progress bar + bar1.stop(); +} diff --git a/packages/cli/generators/microservice/index.js b/packages/cli/generators/microservice/index.js index da08be2b52..f6599d4388 100644 --- a/packages/cli/generators/microservice/index.js +++ b/packages/cli/generators/microservice/index.js @@ -9,6 +9,10 @@ const path = require('path'); const spawnProcess = require('../spawn'); const fs = require('fs'); const g = require('@loopback/cli/lib/globalize'); +const {logBar, logBarStart, logBarStop} = require('../logbar'); +const cliProgress = require('cli-progress'); + +const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic); module.exports = class MGenerator extends AppGenerator { constructor(args, opts) { @@ -118,6 +122,7 @@ module.exports = class MGenerator extends AppGenerator { install() { const packageJsonFile = path.join(process.cwd(), 'package.json'); const packageJson = require(packageJsonFile); + packageJson.name = `${this.answers.uniquePrefix}-${packageJson.name}`; const scripts = packageJson.scripts; const symlinkresolver = 'symlink-resolver'; this._setupMicroservice(packageJson.name); @@ -126,12 +131,12 @@ module.exports = class MGenerator extends AppGenerator { scripts['prestart'] = "npm run rebuild && npm run openapi-spec"; scripts['rebuild'] = "npm run clean && npm run build"; scripts['start'] = "node -r ./dist/opentelemetry-registry.js -r source-map-support/register ."; - scripts['docker:build'] = `DOCKER_BUILDKIT=1 sudo docker build --build-arg NR_ENABLED=$NR_ENABLED_VALUE -t $IMAGE_REPO_NAME/ - ${this.answers.uniquePrefix} -$npm_package_name:$npm_package_version .`; - scripts['docker:push'] = `sudo docker push $IMAGE_REPO_NAME/ ${this.answers.uniquePrefix} -$npm_package_name:$npm_package_version`; - scripts['docker:build:dev'] = `DOCKER_BUILDKIT=1 sudo docker build --build-arg NR_ENABLED=$NR_ENABLED_VALUE -t $IMAGE_REPO_NAME/ - ${this.answers.uniquePrefix} -$npm_package_name:$IMAGE_TAG_VERSION .`; - scripts['docker:push:dev'] = `sudo docker push $IMAGE_REPO_NAME/ ${this.answers.uniquePrefix} -$npm_package_name:$IMAGE_TAG_VERSION`; + scripts['docker:build'] = `DOCKER_BUILDKIT=1 sudo docker build --build-arg NR_ENABLED=$NR_ENABLED_VALUE -t $IMAGE_REPO_NAME/ + ${this.answers.uniquePrefix}-$npm_package_name:$npm_package_version .`; + scripts['docker:push'] = `sudo docker push $IMAGE_REPO_NAME/${this.answers.uniquePrefix}-$npm_package_name:$npm_package_version`; + scripts['docker:build:dev'] = `DOCKER_BUILDKIT=1 sudo docker build --build-arg NR_ENABLED=$NR_ENABLED_VALUE -t $IMAGE_REPO_NAME/ + ${this.answers.uniquePrefix}-$npm_package_name:$IMAGE_TAG_VERSION .`; + scripts['docker:push:dev'] = `sudo docker push $IMAGE_REPO_NAME/${this.answers.uniquePrefix}-$npm_package_name:$IMAGE_TAG_VERSION`; scripts['coverage'] = "nyc npm run test"; packageJson.scripts = scripts; fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson), null, 2); @@ -146,9 +151,11 @@ module.exports = class MGenerator extends AppGenerator { this._swaggerStat(packageName).then(() => this._opentelemetry(packageName).then(() => this._nyc(packageName).then(() => - this._promclient(packageName).then(() => - this._addDependency(packageName).then(() => - this._openapi(packageName), + this._addDependency(packageName).then(() => + this._promclient(packageName).then(() => + this._openapi(packageName).then(() => + this._prettierfix(packageName), + ), ), ), ), @@ -164,32 +171,39 @@ module.exports = class MGenerator extends AppGenerator { } async _symlink(packageName){ + logBarStart(bar1, 11); await spawnProcess('npx', ['lerna', 'add', '-D', 'symlink-resolver', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _dotenv(packageName){ await spawnProcess('npx', ['lerna', 'add', 'dotenv', '--scope='+`${packageName}`], {packageName}); await spawnProcess('npx', ['lerna', 'add', 'dotenv-extended', '--scope='+`${packageName}`], {packageName}); await spawnProcess('npx', ['lerna', 'add', '-D', '@types/dotenv', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _sourceloopCore(packageName){ await spawnProcess('npx', ['lerna', 'add', '@sourceloop/core', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _addDependency(packageName){ if(this.answers.serviceSelect === 'y' || this.answers.serviceSelect === 'Y'){ await spawnProcess('npx', ['lerna', 'add', '@sourceloop/'+`${this.service.selector}`, '--scope='+`${packageName}`], {packageName}); } + logBar(bar1); } async _bearerVerifier(packageName){ await spawnProcess('npx', ['lerna', 'add', 'loopback4-authentication', '--scope='+`${packageName}`], {packageName}); await spawnProcess('npx', ['lerna', 'add', 'loopback4-authorization', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _swaggerStat(packageName){ await spawnProcess('npx', ['lerna', 'add', 'swagger-stats', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _opentelemetry(packageName){ @@ -201,18 +215,28 @@ module.exports = class MGenerator extends AppGenerator { await spawnProcess('npx', ['lerna', 'add', '@opentelemetry/plugin-pg', '--scope='+`${packageName}`], {packageName}); await spawnProcess('npx', ['lerna', 'add', '@opentelemetry/plugin-pg-pool', '--scope='+`${packageName}`], {packageName}); await spawnProcess('npx', ['lerna', 'add', '@opentelemetry/tracing', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _nyc(packageName){ await spawnProcess('npx', ['lerna', 'add', '-D', '@istanbuljs/nyc-config-typescript', '--scope='+`${packageName}`], {packageName}); await spawnProcess('npx', ['lerna', 'add', '-D', 'nyc', '--scope='+`${packageName}`], {packageName}); + logBar(bar1); } async _promclient(packageName){ await spawnProcess('npm', ['i', 'prom-client'], {packageName}); + logBar(bar1); } async _openapi(packageName){ await spawnProcess('npm', ['run', 'openapi-spec'], {packageName}); + logBar(bar1); + } + + async _prettierfix(packageName){ + await spawnProcess('npm',['run', 'prettier:fix'], {packageName}); + logBar(bar1); + logBarStop(bar1); } end() { diff --git a/packages/cli/generators/scaffold/index.js b/packages/cli/generators/scaffold/index.js index 3a9ba6214d..f393ef7867 100644 --- a/packages/cli/generators/scaffold/index.js +++ b/packages/cli/generators/scaffold/index.js @@ -28,9 +28,6 @@ module.exports = class extends Generator { // refactor since this is calling every function and order matters. Order should not matter initProject() { - const templatePath = this.templatePath(); - console.log(`Template path: ${templatePath}`); - console.log(`Creating directory ${this.answers.projectDir}`); fs.mkdir(this.answers.projectDir, {recursive: true}, (err) => { if (err) { throw err; @@ -113,16 +110,13 @@ module.exports = class extends Generator { _copyTemplates() { fs.readdirSync(this.templatePath()).forEach(file => { - console.log(this.templatePath()); const targetFileName = file.replace('.tpl', ''); const sourcePath = this.templatePath(file); - console.log(`Source path: ${sourcePath}`); const destinationPath = path.join(this.answers.projectDir, targetFileName); this.fs.copyTpl(sourcePath, destinationPath, { upperDbKey: this.answers.dbKey.toUpperCase(), ...this.answers }); - console.log(file); }); fs.mkdirSync(path.join(this.answers.projectDir, 'services')); diff --git a/packages/cli/package.json b/packages/cli/package.json index e23a6964ce..45fc88bbc2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -27,6 +27,7 @@ "camelcase-keys": "^7.0.0", "chalk": "^4.1.2", "change-case": "^4.1.2", + "cli-progress": "^3.10.0", "db-migrate": "^0.11.12", "debug": "^4.3.2", "fs-extra": "^10.0.0",