Skip to content

Commit

Permalink
revert(cli): remove cdk flag from microservice command (#1721)
Browse files Browse the repository at this point in the history
remove cdk flag from microservice command

gh-1710
  • Loading branch information
Tyagi-Sunny authored Oct 19, 2023
1 parent c283f96 commit bac0866
Show file tree
Hide file tree
Showing 47 changed files with 9 additions and 9,608 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 3 additions & 36 deletions packages/cli/src/__tests__/suite/microservice-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,16 @@ export const microserviceOptionsSuite = [
name: 'microservice command to create a facade',
options: {
name: 'test',
cdk: false,
facade: true,
uniquePrefix: 'base',
},
prompts: [
{
input: {
type: 'confirm',
name: 'cdk',
message: 'include arc-cdk?',
default: false,
},
output: false,
},
],
prompts: [],
argv: ['test', '--facade', '--uniquePrefix', 'base'],
},
{
name: 'microservice command to create a microservice including migrations',
options: {
name: 'test',
cdk: false,
facade: false,
uniquePrefix: 'base',
baseOnService: true,
Expand All @@ -35,6 +23,7 @@ export const microserviceOptionsSuite = [
datasourceType: DATASOURCES.POSTGRES,
includeMigrations: true,
},
prompts: [],
argv: [
'test',
'--no-facade',
Expand All @@ -49,23 +38,11 @@ export const microserviceOptionsSuite = [
DATASOURCES.POSTGRES,
'--includeMigrations',
],
prompts: [
{
input: {
type: 'confirm',
name: 'cdk',
message: 'include arc-cdk?',
default: false,
},
output: false,
},
],
},
{
name: 'microservice command to create a microservice with custom migrations',
options: {
name: 'test',
cdk: false,
facade: false,
uniquePrefix: 'base',
baseOnService: true,
Expand All @@ -74,17 +51,7 @@ export const microserviceOptionsSuite = [
datasourceType: DATASOURCES.POSTGRES,
customMigrations: true,
},
prompts: [
{
input: {
type: 'confirm',
name: 'cdk',
message: 'include arc-cdk?',
default: false,
},
output: false,
},
],
prompts: [],
argv: [
'test',
'--no-facade',
Expand Down
30 changes: 0 additions & 30 deletions packages/cli/src/__tests__/suite/microservice-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const microservicePromptsSuite = [
name: 'microservice command to create a facade',
options: {
name: 'test',
cdk: false,
facade: true,
uniquePrefix: 'base',
},
Expand All @@ -19,15 +18,6 @@ export const microservicePromptsSuite = [
},
output: 'test',
},
{
input: {
type: 'confirm',
name: 'cdk',
message: 'include arc-cdk?',
default: false,
},
output: false,
},
{
input: {
name: 'facade',
Expand All @@ -51,7 +41,6 @@ export const microservicePromptsSuite = [
name: 'microservice command to create a microservice including migrations',
options: {
name: 'test',
cdk: false,
facade: false,
uniquePrefix: 'base',
baseOnService: true,
Expand All @@ -70,15 +59,6 @@ export const microservicePromptsSuite = [
},
output: 'test',
},
{
input: {
type: 'confirm',
name: 'cdk',
message: 'include arc-cdk?',
default: false,
},
output: false,
},
{
input: {
name: 'facade',
Expand Down Expand Up @@ -146,7 +126,6 @@ export const microservicePromptsSuite = [
name: 'microservice command to create a microservice with custom migrations',
options: {
name: 'test',
cdk: false,
facade: false,
uniquePrefix: 'base',
baseOnService: true,
Expand All @@ -166,15 +145,6 @@ export const microservicePromptsSuite = [
},
output: 'test',
},
{
input: {
type: 'confirm',
name: 'cdk',
message: 'include arc-cdk?',
default: false,
},
output: false,
},
{
input: {
name: 'facade',
Expand Down
5 changes: 0 additions & 5 deletions packages/cli/src/commands/microservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export class Microservice extends Base<MicroserviceOptions> {
name: 'help',
description: 'show manual pages',
}),
cdk: flags.boolean({
name: 'cdk',
description: 'include arc-cdk?',
allowNo: true,
}),
facade: flags.boolean({
name: 'facade',
description: 'Create as facade',
Expand Down
166 changes: 2 additions & 164 deletions packages/cli/src/generators/microservice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ const MIGRATION_TEMPLATE = join(

const MIGRATION_FOLDER = join('packages', 'migrations');

const sourceloopCdkPath = (packageName: SERVICES) =>
join('node_modules', `@sourceloop/${packageName}`, 'iac');

const sourceloopMigrationPath = (packageName: SERVICES) =>
join('node_modules', `@sourceloop/${packageName}`, 'migrations');
Expand Down Expand Up @@ -99,9 +97,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
}
}

async setCdk() {
this.projectInfo.cdk = this.options.cdk;
}


//Loopback4 prompts
async promptProjectName() {
Expand Down Expand Up @@ -215,27 +211,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
'docker:push:dev'
] = `sudo docker push $IMAGE_REPO_NAME/${this.options.uniquePrefix}-$npm_package_name:$IMAGE_TAG_VERSION`;
scripts['coverage'] = 'nyc npm run test';
if (this.options.cdk) {
packageJson.devDependencies = packageJson.devDependencies ?? {};
packageJson.devDependencies['@types/i18n'] = getDependencyVersion(
this.projectInfo.dependencies,
'@types/i18n',
);
packageJson.dependencies['@types/aws-lambda'] = getDependencyVersion(
this.projectInfo.dependencies,
'@types/aws-lambda',
);
scripts['build:layers'] = 'scripts/build-dependency-layer.sh';
scripts['build:migrations'] = 'scripts/build-migrations.sh';
scripts['build:all'] =
'npm run build && npm run build:layers && npm run build:migrations';
scripts['db:migrate'] =
"../../node_modules/db-migrate/bin/db-migrate up --config './migration/migrations/database.json'";
scripts['db:migrate:down'] =
"./node_modules/db-migrate/bin/db-migrate down --config './migrations/database.json'";
scripts['db:migrate:reset'] =
"./node_modules/db-migrate/bin/db-migrate reset --config './migrations/database.json'";
}

packageJson.scripts = scripts;
if (this.options.baseService) {
packageJson.dependencies[`@sourceloop/${this.options.baseService}`] =
Expand All @@ -255,18 +231,6 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti

this.addMigrations();

if (this.options.cdk) {
this._includeCdk();
} else {
const name = this.options.name ?? DEFAULT_NAME;
fs.unlink(
this.destinationPath(join('services', name, 'src', 'lambda.ts')),
() => { },
);
this.log(
this.destinationPath(join('services', name, 'src', 'lambda.ts')),
);
}
return true;
}
return false;
Expand All @@ -287,59 +251,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
this._addMigrationScripts();
}
}
private _includeCdk() {
const name = this.options.name ?? DEFAULT_NAME;

if (
!this.shouldExit() &&
this.options.baseService &&
fs.existsSync(
this.destinationPath(
join('services', name, sourceloopCdkPath(this.options.baseService)),
),
)
) {
this.fs.copy(
this.destinationPath(
join(
'services',
name,
sourceloopCdkPath(this.options.baseService),
'cdk',
),
),
this.destinationPath(join('services', name, 'cdk')),
);

if (!fs.existsSync(this.destinationPath(join('iac', 'dependencies')))) {
this.fs.copy(
this.destinationPath(
join(
'services',
name,
sourceloopCdkPath(this.options.baseService),
'dependencies',
),
),
this.destinationPath(join('iac', 'dependencies')),
);
}

this.fs.copy(
this.destinationPath(
join(
'services',
name,
sourceloopCdkPath(this.options.baseService),
'scripts',
),
),
this.destinationPath(join('services', name, 'scripts')),
);
} else {
// do nothing
}
}

addScope() {
let czConfig = this.fs.read(
Expand Down Expand Up @@ -522,35 +434,6 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
},
);

if (
this.options.cdk &&
this.options.baseService &&
fs.existsSync(
this.destinationPath(
join('services', name, sourceloopCdkPath(this.options.baseService)),
),
)
) {
this.fs.copyTpl(
this.templatePath(MIGRATION_TEMPLATE),
this.destinationPath(join('services', name, 'migration', dbconfig)),
{
name: name.toUpperCase(),
connector,
},
);
this.fs.copy(
this.destinationPath(
join(
'services',
name,
sourceloopMigrationPath(this.options.baseService),
'lambda.js',
),
),
this.destinationPath(join('services', name, 'migration', 'lambda.js')),
);
}
}

private _includeSourceloopMigrations() {
Expand Down Expand Up @@ -598,52 +481,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
},
);

if (
this.options.cdk &&
fs.existsSync(
this.destinationPath(
join('services', name, sourceloopCdkPath(this.options.baseService)),
),
)
) {
this.fs.copy(
this.destinationPath(
join(
'services',
name,
sourceloopMigrationPath(this.options.baseService),
),
),
this.destinationPath(
join('services', name, 'migration', 'migrations'),
),
);

this.fs.copy(
this.destinationPath(
join(
'services',
name,
sourceloopMigrationPath(this.options.baseService),
'lambda.js',
),
),
this.destinationPath(
join('services', name, 'migration', 'lambda.js'),
),
);
this.fs.delete(join('services', name, 'migration', 'migrations', 'lambda.js'));
this.fs.copy(
this.destinationPath(join(MIGRATION_FOLDER, name, dbconfig)),
this.destinationPath(join('services', name, 'migration', dbconfig)),
);
} else {
// do nothing
}
this.fs.delete(join(MIGRATION_FOLDER, name, 'migrations', 'lambda.js'));
this.log(
this.destinationPath(join(MIGRATION_FOLDER, name, 'migrations', 'lambda.js')),
);
}

}
Expand Down
Loading

0 comments on commit bac0866

Please sign in to comment.