From b07a7d4db7350eb8908eeb9b4c4a0570379d1b64 Mon Sep 17 00:00:00 2001 From: oktavianidewi Date: Mon, 15 Jul 2019 12:43:48 +0700 Subject: [PATCH 1/2] Add select-project with name --- components/projects/project.ts | 42 +++++++++++++++++++++++++----- lib/components/projects/project.js | 39 ++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/components/projects/project.ts b/components/projects/project.ts index 0e2e892..3a37c15 100644 --- a/components/projects/project.ts +++ b/components/projects/project.ts @@ -219,13 +219,43 @@ export default class Project { } } - public async select() { - const chosen = await this.choose() - if (chosen) { - this.helper.setProp("projectId", chosen.id); - this.helper.setProp("projectName", chosen.name); - console.log(colors.green(`Project "${ chosen.name }" (${ chosen.id }) is successfully selected`)); + public async select(projectName?: string) { + let chosen: any; + if (projectName || typeof projectName === "string") { + chosen = await this.getDataByName(projectName); + if (chosen !== undefined) { + // project name found + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + } else { + // project name not found, select through inquirer + console.log(`Project with name ${projectName} is not found. Instead, please choose listed project name below:`); + chosen = await this.choose() + if (chosen) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + } + } + } else { + // projectName is empty + chosen = await this.choose() + if (chosen) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + } } + console.log(colors.green(`Project "${ chosen.name }" (${ chosen.id }) is successfully selected`)); + + if (!chosen || chosen === undefined) { + chosen = await this.choose() + if (chosen) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + console.log(colors.green(`Project "${ chosen.name }" (${ chosen.id }) is successfully selected`)); + } + } + + } public async delete(projectName?: string) { diff --git a/lib/components/projects/project.js b/lib/components/projects/project.js index 2c170ec..667c12a 100644 --- a/lib/components/projects/project.js +++ b/lib/components/projects/project.js @@ -208,13 +208,40 @@ class Project { } }); } - select() { + select(projectName) { return __awaiter(this, void 0, void 0, function* () { - const chosen = yield this.choose(); - if (chosen) { - this.helper.setProp("projectId", chosen.id); - this.helper.setProp("projectName", chosen.name); - console.log(colors.green(`Project "${chosen.name}" (${chosen.id}) is successfully selected`)); + let chosen; + if (projectName || typeof projectName === "string") { + chosen = yield this.getDataByName(projectName); + if (chosen !== undefined) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + } + else { + console.log(`Project with name ${projectName} is not found. Instead, please choose listed project name below:`); + chosen = yield this.choose(); + if (chosen) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + } + } + } + else { + // projectName is empty + chosen = yield this.choose(); + if (chosen) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + } + } + console.log(colors.green(`Project "${chosen.name}" (${chosen.id}) is successfully selected`)); + if (!chosen || chosen === undefined) { + chosen = yield this.choose(); + if (chosen) { + this.helper.setProp("projectId", chosen.id); + this.helper.setProp("projectName", chosen.name); + console.log(colors.green(`Project "${chosen.name}" (${chosen.id}) is successfully selected`)); + } } }); } From 872f950212e0770dfce1808f6710f17ddd7bcc15 Mon Sep 17 00:00:00 2001 From: oktavianidewi Date: Mon, 26 Aug 2019 14:06:44 +0700 Subject: [PATCH 2/2] Give condition for empty projectName --- components/projects/project.ts | 6 ++++-- components/scripts/helper.ts | 2 +- lib/components/projects/project.js | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/projects/project.ts b/components/projects/project.ts index 3a37c15..5a2df6d 100644 --- a/components/projects/project.ts +++ b/components/projects/project.ts @@ -221,7 +221,7 @@ export default class Project { public async select(projectName?: string) { let chosen: any; - if (projectName || typeof projectName === "string") { + if (typeof projectName === "string") { chosen = await this.getDataByName(projectName); if (chosen !== undefined) { // project name found @@ -229,7 +229,9 @@ export default class Project { this.helper.setProp("projectName", chosen.name); } else { // project name not found, select through inquirer - console.log(`Project with name ${projectName} is not found. Instead, please choose listed project name below:`); + console.log( + `Project with name ${colors.green(projectName)} is not found. ` + + `Please choose listed project name below:`); chosen = await this.choose() if (chosen) { this.helper.setProp("projectId", chosen.id); diff --git a/components/scripts/helper.ts b/components/scripts/helper.ts index ca9e1f9..47989c7 100644 --- a/components/scripts/helper.ts +++ b/components/scripts/helper.ts @@ -213,7 +213,7 @@ export default class Helper extends Component { public difference(object : any, base : any) { function changes(object : any, base : any) { - return _.transform(object, function(result, value, key) { + return _.transform(object, function(result: any, value, key) { if (!_.isEqual(value, base[key])) { result[key] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value; } diff --git a/lib/components/projects/project.js b/lib/components/projects/project.js index 667c12a..d16bd54 100644 --- a/lib/components/projects/project.js +++ b/lib/components/projects/project.js @@ -211,14 +211,17 @@ class Project { select(projectName) { return __awaiter(this, void 0, void 0, function* () { let chosen; - if (projectName || typeof projectName === "string") { + if (typeof projectName === "string") { chosen = yield this.getDataByName(projectName); if (chosen !== undefined) { + // project name found this.helper.setProp("projectId", chosen.id); this.helper.setProp("projectName", chosen.name); } else { - console.log(`Project with name ${projectName} is not found. Instead, please choose listed project name below:`); + // project name not found, select through inquirer + console.log(`Project with name ${colors.green(projectName)} is not found. ` + + `Please choose listed project name below:`); chosen = yield this.choose(); if (chosen) { this.helper.setProp("projectId", chosen.id);