Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI - add --build-file-name to deploy build command #4759

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/@ionic/cli/src/commands/deploy/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isSuperAgentError } from '../../guards';
import { input, strong, weak } from '../../lib/color';
import { Command } from '../../lib/command';
import { FatalException } from '../../lib/errors';
import { fileUtils } from '../../lib/utils/file';
import { createRequest, download } from '../../lib/utils/http';

const debug = Debug('ionic:commands:deploy:build');
Expand Down Expand Up @@ -96,6 +97,12 @@ Customizing the build:
spec: { value: 'name' },
default: false,
},
{
name: 'build-file-name',
summary: 'An optional name for the downloaded web artifacts.',
type: String,
spec: { value: 'name' },
},
],
};
}
Expand Down Expand Up @@ -144,7 +151,13 @@ Customizing the build:
throw new Error('Missing URL in response');
}

const filename = await this.downloadBuild(url.url, build.artifact_name);
let buildFilename = build.artifact_name;

if (options['build-file-name']) {
buildFilename = await this.sanitizeString(options['build-file-name']);
}

const filename = await this.downloadBuild(url.url, buildFilename);
this.env.log.ok(`Artifact downloaded: ${filename}`);

}
Expand Down Expand Up @@ -270,4 +283,17 @@ Customizing the build:
return filename;
}

async sanitizeString(value: string | string[] | boolean | null | undefined): Promise<string> {

if (!value || typeof (value) !== 'string') {
return '';
}

if (!fileUtils.isValidFileName(value)) {
throw new FatalException(`${strong(String(value))} is not a valid file name`);
}

return String(value);
}

}