Skip to content

Commit

Permalink
fix(cli): add missing install and build commands in the generated doc…
Browse files Browse the repository at this point in the history
…kerfile
  • Loading branch information
Romakita committed Mar 30, 2023
1 parent bf130b5 commit d17b328
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
71 changes: 37 additions & 34 deletions packages/cli/src/commands/init/InitCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,40 @@ export class InitCmd implements CommandProvider {
@Inject()
protected fs: CliFs;

static checkPrecondition(ctx: InitCmdContext) {
const isValid = (types: any, value: any) => (value ? Object.values(types).includes(value) : true);

if (!isValid(PlatformType, ctx.platform)) {
throw new Error(`Invalid selected platform: ${ctx.platform}. Possible values: ${Object.values(PlatformType).join(", ")}.`);
}

if (!isValid(ArchitectureConvention, ctx.architecture)) {
throw new Error(
`Invalid selected architecture: ${ctx.architecture}. Possible values: ${Object.values(ArchitectureConvention).join(", ")}.`
);
}

if (!isValid(ProjectConvention, ctx.convention)) {
throw new Error(`Invalid selected convention: ${ctx.convention}. Possible values: ${Object.values(ProjectConvention).join(", ")}.`);
}

if (!isValid(PackageManager, ctx.packageManager)) {
throw new Error(
`Invalid selected package manager: ${ctx.packageManager}. Possible values: ${Object.values(PackageManager).join(", ")}.`
);
}

if (ctx.features) {
ctx.features.forEach((value) => {
const feature = FeaturesMap[value.toLowerCase()];

if (!feature) {
throw new Error(`Invalid selected feature: ${value}. Possible values: ${Object.values(FeatureType).join(", ")}.`);
}
});
}
}

async $beforePrompt(initialOptions: Partial<InitOptions>) {
if (initialOptions.file) {
const file = join(this.packageJson.dir, initialOptions.file);
Expand Down Expand Up @@ -159,6 +193,9 @@ export class InitCmd implements CommandProvider {

return fillImports({
...ctx,
yarn: ctx.packageManager == PackageManager.YARN || !ctx.packageManager,
npm: ctx.packageManager == PackageManager.NPM,
pnpm: ctx.packageManager == PackageManager.PNPM,
cliVersion: ctx.cliVersion || this.cliPackageJson.version,
srcDir: this.configuration.project?.srcDir,
platformSymbol: ctx.platform && pascalCase(`Platform ${ctx.platform}`)
Expand Down Expand Up @@ -480,38 +517,4 @@ export class InitCmd implements CommandProvider {
ctx
);
}

static checkPrecondition(ctx: InitCmdContext) {
const isValid = (types: any, value: any) => (value ? Object.values(types).includes(value) : true);

if (!isValid(PlatformType, ctx.platform)) {
throw new Error(`Invalid selected platform: ${ctx.platform}. Possible values: ${Object.values(PlatformType).join(", ")}.`);
}

if (!isValid(ArchitectureConvention, ctx.architecture)) {
throw new Error(
`Invalid selected architecture: ${ctx.architecture}. Possible values: ${Object.values(ArchitectureConvention).join(", ")}.`
);
}

if (!isValid(ProjectConvention, ctx.convention)) {
throw new Error(`Invalid selected convention: ${ctx.convention}. Possible values: ${Object.values(ProjectConvention).join(", ")}.`);
}

if (!isValid(PackageManager, ctx.packageManager)) {
throw new Error(
`Invalid selected package manager: ${ctx.packageManager}. Possible values: ${Object.values(PackageManager).join(", ")}.`
);
}

if (ctx.features) {
ctx.features.forEach((value) => {
const feature = FeaturesMap[value.toLowerCase()];

if (!feature) {
throw new Error(`Invalid selected feature: ${value}. Possible values: ${Object.values(FeatureType).join(", ")}.`);
}
});
}
}
}
1 change: 0 additions & 1 deletion packages/cli/templates/init/Dockerfile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ WORKDIR /opt

COPY package.json yarn.lock tsconfig.json tsconfig.compile.json .barrelsby.json ./

RUN yarn install --pure-lockfile
{{#if yarn}}
RUN yarn install --pure-lockfile{{/if}}{{#if npm}}
RUN npm install{{/if}}{{#if pnpm}}
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/test/integrations/init/init.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe("Init cmd", () => {
platform: "express",
rootDir: "./project-data",
projectName: "project-data",
tsedVersion: "5.58.1"
tsedVersion: "5.58.1",
packageManager: "yarn"
});

expect(FakeCliFs.getKeys()).toEqual([
Expand Down Expand Up @@ -110,6 +111,11 @@ describe("Init cmd", () => {
},
"version": "1.0.0"
});

const dockerFile = FakeCliFs.entries.get("project-name/Dockerfile")!;

expect(dockerFile).toContain("RUN yarn build")
expect(dockerFile).toContain("RUN yarn install --pure-lockfile")
});
it("should generate a project with swagger", async () => {
const cliService = CliPlatformTest.get<CliService>(CliService);
Expand Down

0 comments on commit d17b328

Please sign in to comment.