From 157d68c46fc09057ff3027da4818d272c0c5f176 Mon Sep 17 00:00:00 2001 From: Edouard Date: Wed, 1 Mar 2023 12:08:37 +0100 Subject: [PATCH] feat(nx-heroku): add separate helpers for plugins and buildpacks --- .../src/executors/common/heroku/buildpacks.ts | 19 +++++++++++++++++++ .../src/executors/common/heroku/index.ts | 2 ++ .../src/executors/common/heroku/plugins.ts | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 packages/nx-heroku/src/executors/common/heroku/buildpacks.ts create mode 100644 packages/nx-heroku/src/executors/common/heroku/plugins.ts diff --git a/packages/nx-heroku/src/executors/common/heroku/buildpacks.ts b/packages/nx-heroku/src/executors/common/heroku/buildpacks.ts new file mode 100644 index 0000000..7584d97 --- /dev/null +++ b/packages/nx-heroku/src/executors/common/heroku/buildpacks.ts @@ -0,0 +1,19 @@ +import { exec } from '../utils'; + +export async function clearBuildPacks(options: { appName: string }) { + const { appName } = options; + // stdout contains : Buildpacks cleared. Next release on will detect buildpacks normally. + await exec(`heroku buildpacks:clear --app ${appName}`); +} + +export async function addBuildPack(options: { + appName: string; + buildPack: string; + index: number; +}) { + const { appName, buildPack, index } = options; + // stdout contains : Buildpack added. Next release on will use . + await exec( + `heroku buildpacks:add ${buildPack} --app ${appName} --index ${index}` + ); +} diff --git a/packages/nx-heroku/src/executors/common/heroku/index.ts b/packages/nx-heroku/src/executors/common/heroku/index.ts index b3d508d..f0a3a6d 100644 --- a/packages/nx-heroku/src/executors/common/heroku/index.ts +++ b/packages/nx-heroku/src/executors/common/heroku/index.ts @@ -16,8 +16,10 @@ export async function dynoCommand(options: { export * from './addons'; export * from './apps'; export * from './auth'; +export * from './buildpacks'; export * from './config-vars'; export * from './drains'; export * from './error'; export * from './members'; +export * from './plugins'; export * from './webhooks'; diff --git a/packages/nx-heroku/src/executors/common/heroku/plugins.ts b/packages/nx-heroku/src/executors/common/heroku/plugins.ts new file mode 100644 index 0000000..be4f83e --- /dev/null +++ b/packages/nx-heroku/src/executors/common/heroku/plugins.ts @@ -0,0 +1,19 @@ +import { exec } from '../utils'; + +export async function getPlugins(): Promise { + const { stdout } = await exec('heroku plugins', { encoding: 'utf8' }); + return stdout + .trim() + .split('\n') + .map((line) => line.trim().split(' ')[0]); +} + +export async function hasPlugin(plugin: string): Promise { + const list = await getPlugins(); + return list.includes(plugin); +} + +export async function installPlugin(plugin: string): Promise { + const { stdout, stderr } = await exec(`heroku plugins:install ${plugin}`); + console.warn('installPlugin', stdout, stderr); +}