Skip to content

Commit a709a35

Browse files
committed
modify publicUrl is options filter space string
1 parent 8e9ad4b commit a709a35

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

lib/build-docker/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as child_process from 'child_process';
22
import chalk from 'chalk';
33
import ora from 'ora';
4-
import {bash, renameDockerImage} from '../script/utils';
4+
import {
5+
bash,
6+
renameDockerImage,
7+
isEmpty
8+
} from '../script/utils';
59
import {CLIError} from '../script/cli';
610
import logger from '../script/logger';
711
import {initDefault} from '../config';
@@ -15,10 +19,14 @@ interface IArgs {
1519
}
1620

1721

18-
function buildDockerImage(imageName: string, version: string, remoteAddress: string, publicUrl: string, dockerfile: string): Promise<string> {
22+
function buildDockerImage(imageName: string, version: string, remoteAddress: string, dockerfile: string, publicUrl?: string): Promise<string> {
1923

2024
return new Promise((resolve, reject) => {
21-
const dockerBuildArgs = ['build', '-t', imageName, '-f', dockerfile, '--build-arg', `PUBLIC_URL=${publicUrl}`, '.'];
25+
const options = {
26+
publicUrl: isEmpty(publicUrl) ? `PUBLIC_URL=${publicUrl}`: undefined,
27+
};
28+
const dockerBuildArgs = ['build', '-t', imageName, '-f', dockerfile, '--build-arg', options.publicUrl, '.']
29+
.filter(arg => typeof arg !== 'undefined') as string[];
2230

2331
const loader = ora();
2432
logger.info(
@@ -87,7 +95,7 @@ async function run(args?: IArgs) {
8795
console.log(`ready release ${imageName}:${imageVersion} ...`);
8896

8997
// Build Image
90-
const targetImageName = await buildDockerImage(imageName, imageVersion, remoteAddress, publicUrl, dockerfile);
98+
const targetImageName = await buildDockerImage(imageName, imageVersion, remoteAddress, dockerfile, publicUrl);
9199

92100
// By OSX Notice
93101
bash(`osascript -e 'display notification "${targetImageName} done" with title "build done"'`);

lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export const initDefault = {
22
packageName: 'bear-example',
33
packageVersion: '0.0.0',
44
dockerRegistry: 'docker.bear.com:8443',
5-
publicUrl: '/',
5+
publicUrl: undefined,
66
dockerfilePath: './Dockerfile',
77
};

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = async function bearScript () {
88
return yargs
99
.positional('publicUrl', {
1010
describe: 'react-script build public url (ex: /recommend)',
11-
default: '/',
11+
default: 'undefined',
1212
})
1313
.positional('dockerfile', {
1414
describe: 'custom dockerfile path (ex: ./)',

lib/script/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,29 @@ export const bash = (cmd: string) => {
1414
*/
1515
export const renameDockerImage = (imageName: string, version: string, remoteAddress: string): string => {
1616
return `${remoteAddress}/${imageName}:${version}`;
17+
};
18+
19+
20+
/**
21+
* 判定是否為空
22+
* @param value
23+
* @param checkOption
24+
* @returns {boolean}
25+
*/
26+
export function isEmpty(value: any, checkOption?: {
27+
isZero?: boolean,
28+
isFalse?: boolean,
29+
}): value is undefined {
30+
const defaultCheckOption = {
31+
isZero: checkOption?.isZero ?? true,
32+
isFalse: checkOption?.isFalse ?? true,
33+
};
34+
return (
35+
value === undefined
36+
|| value === null
37+
|| (defaultCheckOption.isFalse && (value === false || value === 'false'))
38+
|| (defaultCheckOption.isZero && (value === 0 || value === '0'))
39+
|| (!(value instanceof Date) && typeof value === 'object' && Object.keys(value).length === 0)
40+
|| (typeof value === 'string' && value.trim().length === 0)
41+
);
1742
}

0 commit comments

Comments
 (0)