MCPcopy
hub / github.com/ampproject/amphtml / clean

Function clean

build-system/tasks/clean.js:51–98  ·  view source on GitHub ↗

* Cleans up various cache and output directories. Optionally cleans up inner * node_modules package directories, or excludes some directories from deletion. * @return {Promise }

()

Source from the content-addressed store, hash-verified

49 * @return {Promise<void>}
50 */
51async function clean() {
52 const pathsFromIgnoreList = [
53 ...(await getPathsFromIgnoreList()),
54 '!**/third_party',
55 '!**/node_modules',
56 ];
57
58 const pathsFromArgv = [];
59
60 if (argv.include_subpackages) {
61 pathsFromArgv.push('**/node_modules', '!node_modules');
62 }
63
64 // User configuration files
65 // Keep this list in sync with .gitignore
66 const customConfigs = [
67 'build-system/global-configs/custom-config.json',
68 'build-system/global-configs/custom-flavors-config.json',
69 ];
70 if (argv.include_custom_configs) {
71 pathsFromArgv.push(...customConfigs);
72 } else {
73 for (const customConfig of customConfigs) {
74 if (fs.existsSync(customConfig)) {
75 log(yellow('Skipping path:'), cyan(customConfig));
76 }
77 }
78 }
79
80 const excludes =
81 argv.exclude?.split(',').map((exclude) => `!${exclude}`) ?? [];
82
83 const delOptions = {
84 expandDirectories: false,
85 dryRun: argv.dry_run,
86 };
87 const deletedPaths = [
88 ...(await del([...pathsFromIgnoreList, ...excludes], delOptions)),
89 ...(await del([...pathsFromArgv, ...excludes], delOptions)),
90 ].sort();
91
92 if (deletedPaths.length > 0) {
93 log(argv.dry_run ? "Paths that would've been deleted:" : 'Deleted paths:');
94 deletedPaths.forEach((deletedPath) => {
95 log('\t' + cyan(path.relative(ROOT_DIR, deletedPath)));
96 });
97 }
98}
99
100module.exports = {
101 clean,

Callers 1

buildRuntimeFunction · 0.85

Calls 6

getPathsFromIgnoreListFunction · 0.85
yellowFunction · 0.85
cyanFunction · 0.85
logFunction · 0.50
pushMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected