Skip to content

Commit

Permalink
feat: add option to pass compile flag to publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Willemse authored and danielwillemse committed Feb 3, 2022
1 parent d6500a2 commit ae8a567
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/bb-functions-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ program
.name('bb functions publish')
.option('-b, --bump', 'Bump the revision number.')
.option('-s, --skip', 'Skip building the custom functions bundle.')
.option('-c, --compile', 'Compile the application.')
.option(
'-h, --host <host>',
'Set hostname to publish to. Defaults to <identifier>.bettyblocks.com',
)
.parse(process.argv);

const bumpRevision = program.bump;
const skipBuild = program.skip;
const { host } = program;
const { host, compile, skip, bump } = program;

/* execute command */

Expand Down Expand Up @@ -62,7 +61,7 @@ void (async (): Promise<void> => {
const valid = await validateFunctions();

if (valid) {
await publishAppFunctions();
await publishAppFunctions({ compile });
} else {
console.log(
`${chalk.red(
Expand All @@ -71,6 +70,6 @@ void (async (): Promise<void> => {
);
}
} else {
publishCustomFunctions(host, bumpRevision, skipBuild);
publishCustomFunctions(host, bump, skip);
}
})();
14 changes: 13 additions & 1 deletion src/functions/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type GlobalConfig = {
[key: string]: string | undefined;
};
applicationMap: { [key: string]: string };
compile?: boolean;
};

export type LocalConfig = {
Expand All @@ -22,6 +23,11 @@ export type LocalConfig = {
host?: string;
zone?: string;
applicationId?: string;
compile?: boolean;
};

export type CustomConfig = {
compile: boolean;
};

class Config {
Expand Down Expand Up @@ -118,6 +124,7 @@ class Config {
fusionAuthUrl: 'https://fusionauth{ZONEPOSTFIX}.betty.services',
builderApiUrl: '{HOST}/api/builder',
domain: 'bettyblocks.com',
compile: false,
} as LocalConfig;
};

Expand All @@ -132,13 +139,18 @@ class Config {

private _applicationId?: string;

constructor() {
constructor(config?: CustomConfig) {
this.config = {
...Config.defaultConfig(),
...Config.readConfig(),
...(config || {}),
};
}

get compile(): boolean {
return !!this.config.compile;
}

get identifier(): string {
if (!this._identifier) {
this._identifier =
Expand Down
14 changes: 11 additions & 3 deletions src/functions/publishAppFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type PublishResponse = {
deleted: FunctionResult[];
};

type PublishOptions = {
compile: boolean;
};

const logResult = (
{ status, name, error }: FunctionResult,
operation: string,
Expand All @@ -59,6 +63,7 @@ const uploadAppFunctions = async (

const form = new FormData();
form.append('functions', functionsJson);
form.append('options', JSON.stringify({ compile: config.compile }));
form.append('file', fs.createReadStream(functionDefinitionsFile));

const applicationId = await config.applicationId();
Expand Down Expand Up @@ -106,9 +111,12 @@ const publishFunctions = async (config: Config): Promise<void> => {
await uploadAppFunctions(zipFile, functionsJson, config);
};

const publishAppFunctions = async (): Promise<void> => {
const config = new Config();
console.log(`Publishing to ${config.host} (${config.zone}) ...`);
const publishAppFunctions = async ({
compile,
}: PublishOptions): Promise<void> => {
const config = new Config({ compile });

console.log(`Publishing to ${config.host}(${config.zone})`);
await publishFunctions(config);
console.log('Done.');
};
Expand Down

0 comments on commit ae8a567

Please sign in to comment.