From d5a8fe2cc3e1572adc8ccfa0327e283ffea76523 Mon Sep 17 00:00:00 2001 From: trickypr Date: Thu, 23 Jun 2022 13:54:39 +1000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20CI=20Commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 ++ src/cmds.ts | 15 +++++++++++++++ src/commands/ci.ts | 40 ++++++++++++++++++++++++++++++++++++++++ src/commands/set.ts | 16 ++++++++++------ src/utils/config.ts | 6 +++++- yarn.lock | 7 ++++++- 6 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 src/commands/ci.ts diff --git a/package.json b/package.json index 763921f..bcc1ba5 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "prompts": "^2.4.1", "rimraf": "^3.0.2", "rustic": "^1.2.1", + "semver": "^7.3.7", "sharp": "^0.29.1", "xmlbuilder2": "^3.0.2" }, @@ -67,6 +68,7 @@ "@types/node": "^14.14.16", "@types/prompts": "^2.0.14", "@types/rimraf": "^3.0.0", + "@types/semver": "^7.3.10", "@types/sharp": "^0.29.2", "@typescript-eslint/eslint-plugin": "^5.22.0", "@typescript-eslint/parser": "^5.22.0", diff --git a/src/cmds.ts b/src/cmds.ts index 30e4875..b0866a0 100644 --- a/src/cmds.ts +++ b/src/cmds.ts @@ -35,6 +35,21 @@ export const commands: Cmd[] = [ description: 'Get and set the dynamic config from this project', requestController: async () => (await import('./commands/set')).set, }, + { + cmd: 'ci', + description: 'Configure the CI', + requestController: async () => (await import('./commands/ci')).ci, + options: [ + { + arg: '--brand ', + description: 'Set the brand that the build is using', + }, + { + arg: '--bump
', + description: 'What version should be bumped', + }, + ], + }, { cmd: 'discard ', description: 'Discard a files changes.', diff --git a/src/commands/ci.ts b/src/commands/ci.ts new file mode 100644 index 0000000..68bbd09 --- /dev/null +++ b/src/commands/ci.ts @@ -0,0 +1,40 @@ +// Code to handle common, complex tasks that our CI servers have to do to get +// ready to build everything + +import { inc, ReleaseType } from 'semver' +import { config } from '..' +import { log } from '../log' +import { dynamicConfig, saveConfig } from '../utils' + +interface Options { + brand?: string + bump?: ReleaseType +} + +export const ci = (options: Options) => { + log.info('Set the build to release') + dynamicConfig.set('buildMode', 'release') + + if (options.brand) { + log.info(`Setting the brand to be '${options.brand}'`) + dynamicConfig.set('brand', options.brand) + } + + if (options.bump) { + const version = inc( + config.brands[dynamicConfig.get('brand')].release.displayVersion, + options.bump + ) + + config.brands[dynamicConfig.get('brand')].release.displayVersion = + version || + config.brands[dynamicConfig.get('brand')].release.displayVersion + saveConfig() + + log.info( + `Bumped the version: ${ + config.brands[dynamicConfig.get('brand')].release.displayVersion + } → ${version}` + ) + } +} diff --git a/src/commands/set.ts b/src/commands/set.ts index b3839c9..25eee66 100644 --- a/src/commands/set.ts +++ b/src/commands/set.ts @@ -1,8 +1,16 @@ +import { config } from '..' import { log } from '../log' import { dynamicConfig } from '../utils' export const set = (key: string, value?: string) => { - if (key in dynamicConfig.defaultValues) { + if (key == 'version') { + console.log( + config.brands[dynamicConfig.get('brand')].release.displayVersion + ) + return + } + + if (!(key in dynamicConfig.defaultValues)) { log.warning(`The key ${key} is not found within the dynamic config options`) return } @@ -13,9 +21,5 @@ export const set = (key: string, value?: string) => { return } - log.info( - `The key '${key}' has ${dynamicConfig.get( - key as dynamicConfig.DefaultValuesKeys - )}` - ) + console.log(dynamicConfig.get(key as dynamicConfig.DefaultValuesKeys)) } diff --git a/src/utils/config.ts b/src/utils/config.ts index b3a7747..19afeac 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -5,7 +5,7 @@ * Responsible for loading, parsing and checking the config file for melon */ -import { existsSync, readFileSync } from 'fs' +import { existsSync, readFileSync, writeFileSync } from 'fs' import { join } from 'path' import { log } from '../log' @@ -223,4 +223,8 @@ export function getConfig(): Config { return fileParsed } +export function saveConfig() { + writeFileSync(configPath, JSON.stringify(config, null, 2)) +} + export const config = getConfig() diff --git a/yarn.lock b/yarn.lock index 7c28321..0fad263 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1120,6 +1120,11 @@ "@types/glob" "*" "@types/node" "*" +"@types/semver@^7.3.10": + version "7.3.10" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.10.tgz#5f19ee40cbeff87d916eedc8c2bfe2305d957f73" + integrity sha512-zsv3fsC7S84NN6nPK06u79oWgrPVd0NvOyqgghV1haPaFcVxIrP4DLomRwGAXk0ui4HZA7mOcSFL98sMVW9viw== + "@types/sharp@^0.29.2": version "0.29.5" resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.29.5.tgz#9c7032d30d138ad16dde6326beaff2af757b91b3" @@ -3906,7 +3911,7 @@ saxes@^5.0.1: dependencies: xmlchars "^2.2.0" -semver@7.x, semver@^7.3.2, semver@^7.3.5: +semver@7.x, semver@^7.3.2, semver@^7.3.5, semver@^7.3.7: version "7.3.7" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f" integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==