Skip to content

Commit

Permalink
feat: add refresh executor (#163)
Browse files Browse the repository at this point in the history
Fixes #151.
  • Loading branch information
TriPSs authored Oct 2, 2023
2 parents 9b16a72 + 70b59d8 commit d5eff34
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
5 changes: 5 additions & 0 deletions packages/pulumi/src/executors/refresh/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit'

import previewExecutor from './refresh.impl'

export default convertNxExecutor(previewExecutor)
37 changes: 37 additions & 0 deletions packages/pulumi/src/executors/refresh/refresh.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { buildCommand } from '@nx-extend/core'
import { ExecutorContext } from '@nx/devkit'
import { execSync } from 'child_process'
import { which } from 'shelljs'

export interface RefreshOptions {
stack?: string,
skipPreview?: boolean,
yes?: boolean,
}

export default async function createExecutor(
options: RefreshOptions,
context: ExecutorContext
): Promise<{ success: boolean }> {
if (!which('pulumi')) {
throw new Error('pulumi is not installed!')
}

const { sourceRoot } = context.workspace.projects[context.projectName]

execSync(
buildCommand([
'PULUMI_EXPERIMENTAL=true',
'pulumi refresh',
options.stack && `--stack=${options.stack}`,
options.skipPreview && '--skip-preview',
options.yes && '--yes'
]),
{
cwd: sourceRoot,
stdio: 'inherit'
}
)

return Promise.resolve({ success: true })
}
9 changes: 9 additions & 0 deletions packages/pulumi/src/executors/refresh/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"$schema": "http://json-schema.org/schema",
"type": "object",
"title": "Refresh executor",
"description": "Refresh",
"properties": {}
}
2 changes: 1 addition & 1 deletion packages/pulumi/src/executors/up/up.impl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext } from '@nx/devkit'
import { buildCommand, USE_VERBOSE_LOGGING_MINIMAL } from '@nx-extend/core'
import { ExecutorContext } from '@nx/devkit'
import { execSync } from 'child_process'
import { which } from 'shelljs'

Expand Down
18 changes: 11 additions & 7 deletions packages/pulumi/src/generators/init/init.impl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
buildCommand,
DefaultGeneratorOptions,
execCommand,
NormalizedSchema,
normalizeOptions
} from '@nx-extend/core'
import {
addDependenciesToPackageJson,
addProjectConfiguration,
Expand All @@ -9,13 +16,6 @@ import {
runTasksInSerial,
Tree
} from '@nx/devkit'
import {
buildCommand,
DefaultGeneratorOptions,
execCommand,
NormalizedSchema,
normalizeOptions
} from '@nx-extend/core'
import { readFileSync, unlinkSync } from 'fs'
import { join } from 'path'
import { which } from 'shelljs'
Expand Down Expand Up @@ -134,6 +134,10 @@ export default async function (tree: Tree, rawOptions: InitOptions) {
preview: {
executor: '@nx-extend/pulumi:preview',
options: {}
},
refresh: {
executor: '@nx-extend/pulumi:refresh',
options: {}
}
},
tags: options.parsedTags
Expand Down

0 comments on commit d5eff34

Please sign in to comment.