Skip to content

Commit

Permalink
feat(nx-heroku): add separate helpers for plugins and buildpacks
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Mar 1, 2023
1 parent 5d35801 commit 157d68c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/nx-heroku/src/executors/common/heroku/buildpacks.ts
Original file line number Diff line number Diff line change
@@ -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 <appName> 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 <appName> will use <buildPack>.
await exec(
`heroku buildpacks:add ${buildPack} --app ${appName} --index ${index}`
);
}
2 changes: 2 additions & 0 deletions packages/nx-heroku/src/executors/common/heroku/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
19 changes: 19 additions & 0 deletions packages/nx-heroku/src/executors/common/heroku/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { exec } from '../utils';

export async function getPlugins(): Promise<string[]> {
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<boolean> {
const list = await getPlugins();
return list.includes(plugin);
}

export async function installPlugin(plugin: string): Promise<void> {
const { stdout, stderr } = await exec(`heroku plugins:install ${plugin}`);
console.warn('installPlugin', stdout, stderr);
}

0 comments on commit 157d68c

Please sign in to comment.