Skip to content

Commit ae3117d

Browse files
dthampyJesse MacFadyen
authored andcommitted
Acna 3518 clean all build artifacts (#858)
* feat: add initial commit for clean command * fix: fix the dist directory path * chore: update readme * fix: lint errors * chore: fixing tests and adding missing coverage * chore: add additional test coverage * fix: lint error * fix: remove unnecessary comments * feat: add 100% coverage * fix: comments * fix: added the missing lint fix * fix: refactored to simplify the command to clean all the artifacts to give a clean state * fix: lint errors * fix: extracted tracking filenames into separate constants for future maintenance * fix: revert README changes from local prepack script run
1 parent 0edbd67 commit ae3117d

5 files changed

Lines changed: 382 additions & 36 deletions

File tree

README.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
aio-cli-plugin-app
2-
==================
1+
# aio-cli-plugin-app
32

43
Create, Build and Deploy Adobe I/O Apps
54

@@ -10,13 +9,14 @@ Create, Build and Deploy Adobe I/O Apps
109
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
1110
[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-cli-plugin-app/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-cli-plugin-app/)
1211

13-
1412
<!-- toc -->
15-
* [Usage](#usage)
16-
* [Commands](#commands)
13+
14+
- [Usage](#usage)
15+
- [Commands](#commands)
1716
<!-- tocstop -->
1817

1918
# Usage
19+
2020
```sh-session
2121
$ aio plugins:install -g @adobe/aio-cli-plugin-app
2222
$ # OR
@@ -25,36 +25,38 @@ $ aio app --help
2525
```
2626

2727
# Commands
28+
2829
<!-- commands -->
29-
* [`aio app`](#aio-app)
30-
* [`aio app add`](#aio-app-add)
31-
* [`aio app add action`](#aio-app-add-action)
32-
* [`aio app add ci`](#aio-app-add-ci)
33-
* [`aio app add event`](#aio-app-add-event)
34-
* [`aio app add extension`](#aio-app-add-extension)
35-
* [`aio app add service`](#aio-app-add-service)
36-
* [`aio app add web-assets`](#aio-app-add-web-assets)
37-
* [`aio app build`](#aio-app-build)
38-
* [`aio app create [PATH]`](#aio-app-create-path)
39-
* [`aio app delete`](#aio-app-delete)
40-
* [`aio app delete action [ACTION-NAME]`](#aio-app-delete-action-action-name)
41-
* [`aio app delete ci`](#aio-app-delete-ci)
42-
* [`aio app delete extension`](#aio-app-delete-extension)
43-
* [`aio app delete service`](#aio-app-delete-service)
44-
* [`aio app delete web-assets`](#aio-app-delete-web-assets)
45-
* [`aio app deploy`](#aio-app-deploy)
46-
* [`aio app get-url [ACTION]`](#aio-app-get-url-action)
47-
* [`aio app info`](#aio-app-info)
48-
* [`aio app init [PATH]`](#aio-app-init-path)
49-
* [`aio app install PATH`](#aio-app-install-path)
50-
* [`aio app list`](#aio-app-list)
51-
* [`aio app list extension`](#aio-app-list-extension)
52-
* [`aio app logs`](#aio-app-logs)
53-
* [`aio app pack [PATH]`](#aio-app-pack-path)
54-
* [`aio app run`](#aio-app-run)
55-
* [`aio app test`](#aio-app-test)
56-
* [`aio app undeploy`](#aio-app-undeploy)
57-
* [`aio app use [CONFIG_FILE_PATH]`](#aio-app-use-config_file_path)
30+
31+
- [`aio app`](#aio-app)
32+
- [`aio app add`](#aio-app-add)
33+
- [`aio app add action`](#aio-app-add-action)
34+
- [`aio app add ci`](#aio-app-add-ci)
35+
- [`aio app add event`](#aio-app-add-event)
36+
- [`aio app add extension`](#aio-app-add-extension)
37+
- [`aio app add service`](#aio-app-add-service)
38+
- [`aio app add web-assets`](#aio-app-add-web-assets)
39+
- [`aio app build`](#aio-app-build)
40+
- [`aio app create [PATH]`](#aio-app-create-path)
41+
- [`aio app delete`](#aio-app-delete)
42+
- [`aio app delete action [ACTION-NAME]`](#aio-app-delete-action-action-name)
43+
- [`aio app delete ci`](#aio-app-delete-ci)
44+
- [`aio app delete extension`](#aio-app-delete-extension)
45+
- [`aio app delete service`](#aio-app-delete-service)
46+
- [`aio app delete web-assets`](#aio-app-delete-web-assets)
47+
- [`aio app deploy`](#aio-app-deploy)
48+
- [`aio app get-url [ACTION]`](#aio-app-get-url-action)
49+
- [`aio app info`](#aio-app-info)
50+
- [`aio app init [PATH]`](#aio-app-init-path)
51+
- [`aio app install PATH`](#aio-app-install-path)
52+
- [`aio app list`](#aio-app-list)
53+
- [`aio app list extension`](#aio-app-list-extension)
54+
- [`aio app logs`](#aio-app-logs)
55+
- [`aio app pack [PATH]`](#aio-app-pack-path)
56+
- [`aio app run`](#aio-app-run)
57+
- [`aio app test`](#aio-app-test)
58+
- [`aio app undeploy`](#aio-app-undeploy)
59+
- [`aio app use [CONFIG_FILE_PATH]`](#aio-app-use-config_file_path)
5860

5961
## `aio app`
6062

@@ -810,4 +812,5 @@ DESCRIPTION
810812
```
811813

812814
_See code: [src/commands/app/use.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.3.0/src/commands/app/use.js)_
815+
813816
<!-- commandsstop -->

src/commands/app/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Build extends BaseCommand {
7979
aioLogger.debug(`run hook for 'build-actions' for actions in '${name}' returned ${script}`)
8080
spinner.start(`Building actions for '${name}'`)
8181
if (!script) {
82-
builtList = await RuntimeLib.buildActions(config, filterActions, flags['force-build']) // skipCheck is false
82+
builtList = await RuntimeLib.buildActions(config, filterActions, flags['force-build'])
8383
}
8484
if (builtList.length > 0) {
8585
spinner.succeed(chalk.green(`Built ${builtList.length} action(s) for '${name}'`))

src/commands/app/clean-build.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Copyright 2025 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
const ora = require('ora')
14+
const chalk = require('chalk')
15+
const fs = require('fs-extra')
16+
const path = require('path')
17+
18+
const BaseCommand = require('../../BaseCommand')
19+
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:clean-build', { provider: 'debug' })
20+
const { LAST_BUILT_ACTIONS_FILENAME, LAST_DEPLOYED_ACTIONS_FILENAME } = require('../../lib/defaults')
21+
22+
class CleanBuild extends BaseCommand {
23+
async run () {
24+
const { flags } = await this.parse(CleanBuild)
25+
const configs = await this.getAppExtConfigs(flags)
26+
27+
const spinner = ora()
28+
29+
try {
30+
for (const [name, config] of Object.entries(configs)) {
31+
await this.cleanAllBuildArtifacts(name, config, spinner)
32+
}
33+
34+
this.log(chalk.green(chalk.bold('Build artifacts cleaned up successfully!')))
35+
} catch (error) {
36+
spinner.stop()
37+
throw error
38+
}
39+
}
40+
41+
async cleanAllBuildArtifacts (name, config, spinner) {
42+
try {
43+
spinner.start(`Cleaning build artifacts for '${name}'`)
44+
45+
if (!config || !config.root) {
46+
spinner.info(`No root directory found for extension '${name}'`)
47+
return
48+
}
49+
50+
const locations = []
51+
52+
if (config.app && config.app.dist && fs.existsSync(config.app.dist)) {
53+
locations.push(config.app.dist)
54+
}
55+
56+
if (config.dist && fs.existsSync(config.dist)) {
57+
locations.push(config.dist)
58+
}
59+
60+
const rootDist = path.join(config.root, 'dist')
61+
if (fs.existsSync(rootDist)) {
62+
locations.push(rootDist)
63+
}
64+
65+
aioLogger.debug(`Cleaning locations for ${name}: ${locations.join(', ')}`)
66+
67+
// Clean all possible locations
68+
for (const location of locations) {
69+
// First try to remove tracking files explicitly
70+
const builtPath = path.join(location, LAST_BUILT_ACTIONS_FILENAME)
71+
const deployedPath = path.join(location, LAST_DEPLOYED_ACTIONS_FILENAME)
72+
73+
if (fs.existsSync(builtPath)) {
74+
await fs.remove(builtPath)
75+
aioLogger.debug(`Removed tracking file: ${builtPath}`)
76+
}
77+
78+
if (fs.existsSync(deployedPath)) {
79+
await fs.remove(deployedPath)
80+
aioLogger.debug(`Removed tracking file: ${deployedPath}`)
81+
}
82+
83+
// Then empty the directory
84+
await fs.emptyDir(location)
85+
aioLogger.debug(`Emptied directory: ${location}`)
86+
}
87+
88+
spinner.succeed(chalk.green(`Cleaned build artifacts for '${name}'`))
89+
} catch (err) {
90+
aioLogger.debug(`Error cleaning artifacts for ${name}: ${err.message}`)
91+
spinner.fail(chalk.red(`Failed to clean build artifacts for '${name}': ${err.message}`))
92+
throw err
93+
}
94+
}
95+
}
96+
97+
CleanBuild.description = `Remove all build artifacts from the local machine
98+
This command completely cleans all build artifacts from the dist directory including:
99+
- Action build files
100+
- Web assets (both production and development)
101+
- Build tracking files
102+
- Deployment tracking files
103+
104+
Note that this will require a full rebuild on your next build command.`
105+
106+
CleanBuild.flags = {
107+
...BaseCommand.flags
108+
}
109+
110+
module.exports = CleanBuild

src/lib/defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ module.exports = {
3636
LEGACY_RUNTIME_MANIFEST: 'manifest.yml',
3737
INCLUDE_DIRECTIVE: '$include',
3838
APPLICATION_CONFIG_KEY: 'application',
39-
EXTENSIONS_CONFIG_KEY: 'extensions'
39+
EXTENSIONS_CONFIG_KEY: 'extensions',
40+
// Adding tracking file constants
41+
LAST_BUILT_ACTIONS_FILENAME: 'last-built-actions.json',
42+
LAST_DEPLOYED_ACTIONS_FILENAME: 'last-deployed-actions.json'
4043
}

0 commit comments

Comments
 (0)