Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
fix(generate): fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
rudxde committed Mar 20, 2022
1 parent ad95b57 commit c762010
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
Expand Up @@ -9,14 +9,14 @@ import { IGenerateArgs } from './args';
const isCopy = /COPY\s+(--from=\S*\s+)?(--chown=\S*\s+)?(--if-exists\s+)?(--slim\s+)?(.*)\s+(.*)/s;
const isRun = /RUN( --if-exists)? (.+)/s;

export async function applyExtendetDockerSyntax(steps: string[], pkg: Package, args: IGenerateArgs): Promise<string[]> {
export async function applyExtendedDockerSyntax(steps: string[], pkg: Package, args: IGenerateArgs): Promise<string[]> {
const result: string[] = [];
for (let step of steps) {
const isCopyMatch = step.match(isCopy);
const isRunMatch = step.match(isRun);
const transformedStep =
isCopyMatch ? await applyExtendetDockerSyntaxCopy(step, pkg) :
isRunMatch ? applyExtendetDockerSyntaxRun(step, pkg, args) :
isCopyMatch ? await applyExtendedDockerSyntaxCopy(step, pkg) :
isRunMatch ? applyExtendedDockerSyntaxRun(step, pkg, args) :
step;
if (transformedStep) {
result.push(transformedStep);
Expand All @@ -25,7 +25,7 @@ export async function applyExtendetDockerSyntax(steps: string[], pkg: Package, a
return result;
}

async function applyExtendetDockerSyntaxCopy(step: string, pkg: Package): Promise<string | undefined> {
async function applyExtendedDockerSyntaxCopy(step: string, pkg: Package): Promise<string | undefined> {
const [_, fromStage, chown, ifExistsFlag, slimFlag, filesList, destination] = step.match(isCopy)!;
if (fromStage) {
const [_, fromStageName] = fromStage.match(/--from=(\S*)/) ?? [];
Expand Down Expand Up @@ -64,7 +64,7 @@ async function slimCopy(chown: string | undefined, files: string[], destination:
return `COPY ${chown || ''} ${source} ${destination}`;
}

function applyExtendetDockerSyntaxRunIfExists(command: string, commandTokens: string[], pkg: Package, args: IGenerateArgs): string | undefined {
function applyExtendedDockerSyntaxRunIfExists(command: string, commandTokens: string[], pkg: Package, args: IGenerateArgs): string | undefined {
if (command.startsWith('npm run')) {
const npmCommand = commandTokens[2];
if(npmCommand.startsWith('$')) {
Expand Down Expand Up @@ -92,11 +92,11 @@ function applyExtendetDockerSyntaxRunIfExists(command: string, commandTokens: st
return `RUN ${command}`;
}

function applyExtendetDockerSyntaxRun(step: string, pkg: Package, args: IGenerateArgs): string | undefined {
function applyExtendedDockerSyntaxRun(step: string, pkg: Package, args: IGenerateArgs): string | undefined {
const [_, ifExists, command] = step.match(isRun)!;
const commandTokens = command.split(' ');
if (ifExists) {
return applyExtendetDockerSyntaxRunIfExists(command, commandTokens, pkg, args);
return applyExtendedDockerSyntaxRunIfExists(command, commandTokens, pkg, args);
}
return `RUN ${command}`;
}
Expand Up @@ -5,7 +5,7 @@ import { IGenerateArgs } from './args';
import { Package } from './package';
import { DockerStage } from './read-dockerfile';

export async function irrerateDependencies(
export async function iterateDependencies(
args: IGenerateArgs,
lernaPackages: lernaPackage[],
packageGraph: PackageGraph,
Expand Down
12 changes: 6 additions & 6 deletions packages/generate/src/lerna-command.ts
Expand Up @@ -2,7 +2,7 @@ import { Command } from '@lerna/command';
import { getFilteredPackages } from '@lerna/filter-options';
import { Package as LernaPackage } from '@lerna/package';
import { promises } from 'fs';
import { irrerateDependencies } from './itterate-dependencies';
import { iterateDependencies } from './iterate-dependencies';
import { getLogger } from '@lerna-dockerize/logger';
import { IGenerateArgs } from './args';
import { Package, PackageMap } from './package';
Expand Down Expand Up @@ -37,14 +37,14 @@ export class Dockerize extends Command {

const result: string[] = [];
for (let baseStage of baseDockerFile) {
result.push(getDockerFileFromInstruction(baseStage.baseImage, baseStage.name, baseStage.plattform));
result.push(getDockerFileFromInstruction(baseStage.baseImage, baseStage.name, baseStage.platform));
result.push(...baseStage.stepsBeforeInstall);
if (baseStage.install) {
result.push(`RUN ${this.args.packageManager} install`);
result.push(...baseStage.stepsAfterInstall);
}
}
const packages = await irrerateDependencies(
const packages = await iterateDependencies(
this.args,
this.filteredPackages,
this.packageGraph,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Dockerize extends Command {
}

for (let finalStage of finalStages) {
result.push(getDockerFileFromInstruction(finalStage.baseImage, finalStage.name, finalStage.plattform));
result.push(getDockerFileFromInstruction(finalStage.baseImage, finalStage.name, finalStage.platform));
result.push(...finalStage.stepsBeforeInstall);
if (finalStage.install) {
for (let pkg of packages) {
Expand All @@ -110,10 +110,10 @@ export class Dockerize extends Command {
}
}

export function getDockerFileFromInstruction(baseImage: string, stageName?: string, plattform?: string): string {
export function getDockerFileFromInstruction(baseImage: string, stageName?: string, platform?: string): string {
return [
'FROM',
...(plattform ? [`--platform=${plattform}`] : []),
...(platform ? [`--platform=${platform}`] : []),
baseImage,
...(stageName ? ['as', stageName] : []),
].join(' ');
Expand Down
14 changes: 7 additions & 7 deletions packages/generate/src/package.ts
Expand Up @@ -6,7 +6,7 @@ import { join as joinPath, relative } from 'path';
import { getDependenciesTransitive } from './get-dependencies-transitive';
import { normalizePath } from './normalize-path';
import { IGenerateArgs } from './args';
import { applyExtendetDockerSyntax } from './extendet-docker-syntax';
import { applyExtendedDockerSyntax } from './extended-docker-syntax';
import { getLogger } from '@lerna-dockerize/logger';
import { getDockerFileFromInstruction } from './lerna-command';

Expand Down Expand Up @@ -110,12 +110,12 @@ export class Package {
}
const addPrepareStage = this.args.addPrepareStages && this.stageHasInstall(stage);
if (addPrepareStage) {
result.push(getDockerFileFromInstruction(baseImage, stage.prepareStageName, stage.plattform));
result.push(getDockerFileFromInstruction(baseImage, stage.prepareStageName, stage.platform));
} else {
result.push(getDockerFileFromInstruction(baseImage, stage.name!, stage.plattform));
result.push(getDockerFileFromInstruction(baseImage, stage.name!, stage.platform));
}
result.push(`WORKDIR ${this.dockerWorkingDir}`);
result.push(...(await applyExtendetDockerSyntax(stage.stepsBeforeInstall, this, this.args)));
result.push(...(await applyExtendedDockerSyntax(stage.stepsBeforeInstall, this, this.args)));
if (!this.stageHasInstall(stage)) {
continue;
}
Expand Down Expand Up @@ -162,13 +162,13 @@ export class Package {
].join(' '));

if (addPrepareStage) {
result.push(getDockerFileFromInstruction(stage.prepareStageName!, stage.name!, stage.plattform));
result.push(getDockerFileFromInstruction(stage.prepareStageName!, stage.name!, stage.platform));
}

result.push(...dependencyCopyContent);

result.push(`WORKDIR ${this.dockerWorkingDir}`);
result.push(...(await applyExtendetDockerSyntax(stage.stepsAfterInstall, this, this.args)));
result.push(...(await applyExtendedDockerSyntax(stage.stepsAfterInstall, this, this.args)));
}
return result;
}
Expand All @@ -178,7 +178,7 @@ export class Package {
return {
baseImage: stage.baseImage,
name: stageName,
plattform: stage.plattform,
platform: stage.platform,
prepareStageName: this.args.addPrepareStages ? `${stageName}_prepare` : undefined,
originalName: stage.name,
stepsBeforeInstall: [...stage.stepsBeforeInstall],
Expand Down
8 changes: 4 additions & 4 deletions packages/generate/src/read-dockerfile.ts
Expand Up @@ -10,7 +10,7 @@ interface IInstallOptions {

export interface DockerStage {
baseImage: string;
plattform?: string;
platform?: string;
originalName?: string;
name?: string;
prepareStageName?: string;
Expand Down Expand Up @@ -43,15 +43,15 @@ export function readStage(steps: string[], startIndex: number): { stage: DockerS
let i = startIndex;
let baseImage;
let stageName;
let plattform;
let platform;
const isStageFromClause = /(FROM|from)(\s--platform=(\S+))? ([a-zA-Z0-9:_\-@.\/]*)( as ([a-zA-Z0-9:_-]*))?/;
for (; ; i++) {
if (i >= steps.length) {
return undefined;
}
const matching = steps[i].match(isStageFromClause);
if (matching) {
plattform = matching[3];
platform = matching[3];
baseImage = matching[4];
stageName = matching[6];
i++;
Expand Down Expand Up @@ -87,7 +87,7 @@ export function readStage(steps: string[], startIndex: number): { stage: DockerS
endIndex: i,
stage: {
name: stageName,
plattform: plattform,
platform: platform,
baseImage,
stepsBeforeInstall,
stepsAfterInstall,
Expand Down
20 changes: 10 additions & 10 deletions packages/generate/test/read-dockerfile.spec.ts
Expand Up @@ -34,7 +34,7 @@ describe('readDockerfile', () => {
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: ['COPY ./file ./somewhere'],
stepsAfterInstall: ['RUN npm run prepare'],
Expand All @@ -53,22 +53,22 @@ describe('readDockerfile', () => {
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'some.registry.com/somewhere/something/nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: [],
stepsAfterInstall: [],
install: undefined,
}]);
});

it('should read stage with custom plattform', async function (this: ReadDockerfileThisContext) {
it('should read stage with custom platform', async function (this: ReadDockerfileThisContext) {
this.fsReadFile.and.resolveTo([
'FROM --platform=arm/64 nginx:latest',
].join('\n'));
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'nginx:latest',
plattform: 'arm/64',
platform: 'arm/64',
name: undefined,
stepsBeforeInstall: [],
stepsAfterInstall: [],
Expand All @@ -86,7 +86,7 @@ describe('readDockerfile', () => {
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: ['COPY ./file ./somewhere'],
stepsAfterInstall: ['RUN npm run prepare'],
Expand All @@ -108,7 +108,7 @@ describe('readDockerfile', () => {
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: ['COPY ./file ./somewhere'],
stepsAfterInstall: ['RUN npm run prepare'],
Expand All @@ -130,7 +130,7 @@ describe('readDockerfile', () => {
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: ['COPY ./file ./somewhere'],
stepsAfterInstall: ['RUN npm run prepare'],
Expand All @@ -152,7 +152,7 @@ describe('readDockerfile', () => {
const result = await readDockerfile('Dockerfile');
expect(result).toEqual([{
baseImage: 'nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: ['COPY ./file ./somewhere'],
stepsAfterInstall: ['RUN npm i lerna'],
Expand All @@ -178,7 +178,7 @@ describe('readDockerfile', () => {
expect(result).toEqual([
{
baseImage: 'node:14',
plattform: undefined,
platform: undefined,
name: 'build',
stepsBeforeInstall: ['COPY ./file ./somewhere'],
stepsAfterInstall: ['RUN npm run build'],
Expand All @@ -190,7 +190,7 @@ describe('readDockerfile', () => {
},
{
baseImage: 'nginx:latest',
plattform: undefined,
platform: undefined,
name: undefined,
stepsBeforeInstall: [],
stepsAfterInstall: ['ENTRYPOINT ["entrypoint.sh"]'],
Expand Down
4 changes: 2 additions & 2 deletions packages/generate/test/slim-package.spec.ts
Expand Up @@ -27,14 +27,14 @@ describe('slimPackage', () => {
pear: 'latest',
},
};
const extendetPackage = {
const extendedPackage = {
...slimmedPackage,
scripts: {
start: 'npm run loop',
loop: 'npm start',
},
};
this.readFileSpy.and.returnValue(JSON.stringify(extendetPackage));
this.readFileSpy.and.returnValue(JSON.stringify(extendedPackage));
const packageDir = './somewhere';
const packageFilePath = `${packageDir}/package.json`;
const slimPackageFilePath = `${packageDir}/package-slim.json`;
Expand Down

0 comments on commit c762010

Please sign in to comment.