Skip to content

Commit

Permalink
Merge pull request #78 from bcgov-nr/feat/licenseBackstage
Browse files Browse the repository at this point in the history
feat: add license and fix prompts for backstage values
  • Loading branch information
mbystedt authored Jan 8, 2025
2 parents 43c573b + b008635 commit 823c6a8
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 95 deletions.
120 changes: 75 additions & 45 deletions generators/backstage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
BACKSTAGE_FILENAME,
pathToProps,
extractFromYaml,
generateSetDefaultFromDoc,
generateSetAnswerPropPredicate,
writePropToPath,
} from '../util/yaml.js';
import { extractGitHubSlug, getGitRepoOriginUrl } from '../util/git.js';
Expand All @@ -27,58 +27,88 @@ export default class extends Generator {
}

async prompting() {
const promptless = !!this.options.promptless;
this.answers = extractFromYaml(this.backstageDoc, pathToProps);

this.log(yosay('Welcome to the backstage file generator!'));

// Attempt to read origin url
const repoOrigin = getGitRepoOriginUrl();

const prompts = [
{
type: 'input',
name: 'projectName',
message: 'Project:',
},
{
type: 'input',
name: 'serviceName',
message: 'Service:',
},
{
type: 'input',
name: 'description',
message: 'Description:',
},
{
type: 'input',
name: 'title',
message: 'Title:',
},
{
type: 'input',
name: 'type',
message: 'Type (service, website, library):',
},
{
type: 'input',
name: 'lifecycle',
message: 'Lifecycle (experimental, production, deprecated):',
},
{
type: 'input',
name: 'owner',
message: 'Owner:',
},
{
type: 'input',
name: 'githubProjectSlug',
message: 'GitHub Slug (<organization or owner>/<repository>):',
default: extractGitHubSlug(repoOrigin) ?? '',
},
].map(generateSetDefaultFromDoc(this.answers));
const backstageAnswer = promptless
? { skip: true }
: await this.prompt([
{
type: 'confirm',
name: 'skip',
message: `Skip prompts for values found in Backstage file (${BACKSTAGE_FILENAME}):`,
default: true,
},
]);

this.answers = await this.prompt(prompts);
this.answers = {
...this.answers,
...(await this.prompt(
[
{
type: 'input',
name: 'projectName',
message: 'Project:',
},
{
type: 'input',
name: 'serviceName',
message: 'Service:',
},
{
type: 'input',
name: 'description',
message: 'Description:',
},
{
type: 'input',
name: 'title',
message: 'Title:',
},
{
type: 'input',
name: 'type',
message: 'Type (service, website, library):',
},
{
type: 'input',
name: 'lifecycle',
message: 'Lifecycle (experimental, production, deprecated):',
},
{
type: 'input',
name: 'license',
default: 'Apache-2.0',
message: 'License (SPDX):',
},
{
type: 'input',
name: 'owner',
message: 'Owner:',
},
{
type: 'input',
name: 'githubProjectSlug',
message: 'GitHub Slug (<organization or owner>/<repository>):',
default: extractGitHubSlug(repoOrigin) ?? '',
},
]
.filter(
generateSetAnswerPropPredicate(this.answers, !backstageAnswer.skip),
)
.map((question) => {
if (this.answers[question?.name]) {
question.default = this.answers[question.name];
}
return question;
}),
)),
};
}

writingBackstage() {
Expand Down
43 changes: 19 additions & 24 deletions generators/gh-maven-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ export default class extends Generator {
? { skip: true }
: await this.prompt([
{
type: 'checkbox',
type: 'confirm',
name: 'skip',
message: `Skip prompts for values found in Backstage file (${BACKSTAGE_FILENAME}):`,
choices: ['yes', 'no'],
default: 'yes',
store: true,
default: true,
},
]);

Expand All @@ -127,27 +125,29 @@ export default class extends Generator {
type: 'input',
name: 'projectName',
message: 'Project:',
store: true,
},
{
type: 'input',
name: 'serviceName',
message: 'Service:',
store: true,
},
{
type: 'input',
name: 'license',
default: 'Apache-2.0',
message: 'License (SPDX):',
},
{
type: 'input',
name: 'clientId',
message: 'Client ID:',
default: '',
store: true,
},
{
type: 'input',
name: 'pomRoot',
message: 'Pom root:',
default: './',
store: true,
},
{
type: 'input',
Expand All @@ -161,82 +161,76 @@ export default class extends Generator {
name: 'gitHubPackages',
message: 'Publish to GitHub Packages:',
default: false,
store: true,
},
{
type: 'input',
name: 'gitHubOwnerPack',
message: 'GitHub Owner with repo path (e.g. bcgov-nr/results-war):',
store: true,
when: (answers) => answers.gitHubPackages,
},
{
type: 'input',
name: 'artifactoryProject',
message: 'Artifactory:',
default: 'cc20',
store: true,
when: (answers) => !answers.gitHubPackages,
},
{
type: 'input',
name: 'artifactoryPackageType',
message: 'Artifactory Package Type (maven, ivy, npm):',
default: 'maven',
store: true,
when: (answers) => !answers.gitHubPackages,
},
{
type: 'confirm',
name: 'deployOnPrem',
message: 'Deploy on-prem:',
default: false,
store: true,
},
{
type: 'input',
name: 'playbookPath',
message: 'Playbook path:',
default: 'playbooks',
store: true,
when: (answers) => answers.deployOnPrem,
},
{
type: 'input',
name: 'tomcatContext',
message: 'Tomcat Context (e.g. ext#results):',
store: true,
when: (answers) => answers.deployOnPrem,
},
{
type: 'confirm',
name: 'useAltAppDirName',
message: 'Use alternative webapp directory:',
default: false,
store: true,
when: (answers) => answers.deployOnPrem,
},
{
type: 'input',
name: 'altAppDirName',
message: 'Alternative webapp directory name:',
store: true,
when: (answers) => answers.useAltAppDirName,
},
{
type: 'confirm',
name: 'addWebadeConfig',
message: 'Add Webade configuration:',
default: false,
store: true,
when: (answers) => answers.deployOnPrem,
},
].filter(
generateSetAnswerPropPredicate(
this.answers,
backstageAnswer.skip === 'yes',
),
),
]
.filter(
generateSetAnswerPropPredicate(this.answers, !backstageAnswer.skip),
)
.map((question) => {
if (this.answers[question?.name]) {
question.default = this.answers[question.name];
}
return question;
}),
)),
};
}
Expand Down Expand Up @@ -274,6 +268,7 @@ export default class extends Generator {
{
projectName: this.answers.projectName,
serviceName: this.answers.serviceName,
license: this.answers.license,
},
);
this.fs.copyTpl(
Expand Down
4 changes: 3 additions & 1 deletion generators/gh-maven-build/templates/build-intention.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"environment": "tools"
},
"package": {
"architecture": "jvm",
"version": "",
"buildVersion": "",
"buildNumber": 0,
"name": "<%= serviceName %>",
"type": "war"
"type": "war",
"license": "<%= license %>"
}
}
],
Expand Down
Loading

0 comments on commit 823c6a8

Please sign in to comment.