Skip to content

Commit

Permalink
feat: add emptyDist param to buildActions (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron authored Aug 15, 2024
1 parent da90917 commit 6eede3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/build-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const zipActions = async (buildsList, lastBuildsPath, distFolder, skipCheck) =>
return builtList
}

const buildActions = async (config, filterActions, skipCheck = false) => {
const buildActions = async (config, filterActions, skipCheck = false, emptyDist = true) => {
if (!config.app.hasBackend) {
throw new Error('cannot build actions, app has no backend')
}
Expand All @@ -299,7 +299,9 @@ const buildActions = async (config, filterActions, skipCheck = false) => {
const distFolder = config.actions.dist

// clear out dist dir
fs.emptyDirSync(distFolder)
if (emptyDist) {
fs.emptyDirSync(distFolder)
}
const toBuildList = []
const lastBuiltActionsPath = path.join(config.root, 'dist', 'last-built-actions.json')
for (const [pkgName, pkg] of Object.entries(modifiedConfig.manifest.full.packages)) {
Expand Down
15 changes: 15 additions & 0 deletions test/build.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ beforeEach(() => {

execa.mockReset()
utils.zip.mockReset()
fs.emptyDirSync = jest.fn()
})

describe('build by zipping js action folder', () => {
Expand Down Expand Up @@ -1156,6 +1157,20 @@ test('should not zip files if the action was built before (skipCheck=false)', as
expect(utils.zip).not.toHaveBeenCalled()
})

test('should not delete dist folder when emptyDist=false', async () => {
addSampleAppFiles()
const config = deepClone(global.sampleAppConfig)
await buildActions(config, ['action'], false /* skipCheck */, false /* emptyDist */)
expect(fs.emptyDirSync).not.toHaveBeenCalled()
})

test('should delete dist folder when emptyDist=true', async () => {
addSampleAppFiles()
const config = deepClone(global.sampleAppConfig)
await buildActions(config, ['action'], false /* skipCheck */, true /* emptyDist */)
expect(fs.emptyDirSync).toHaveBeenCalled()
})

test('No backend is present', async () => {
addSampleAppFiles()
const config = deepClone(global.sampleAppConfig)
Expand Down

0 comments on commit 6eede3a

Please sign in to comment.