mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-25 08:23:13 +09:00
Add clean script to remove dist and other artifacts (#640)
* Add clean script * Switch to using yargs
This commit is contained in:
1 parent
dbc79779ea
commit
51c450727d
2 files changed
+120
-1
No files matched your search
@@ -0,0 +1,114 @@
|
|||||||
|
/**
|
||||||
|
* Clean the repository of build and execution artifacts.
|
||||||
|
*
|
||||||
|
* clean: A quick clean that removes all build artifacts making the output safe to publish
|
||||||
|
* clean-tests: Removes all build and test artifacts should not be required if tests are setup correctly.
|
||||||
|
* clean-all: Removes all build, test, and execution artifacts. Including cluster config and logs!
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs-extra");
|
||||||
|
const yargs = require("yargs");
|
||||||
|
|
||||||
|
const npmPackage = require("./package.json");
|
||||||
|
const workspaces = npmPackage.workspaces.map(p => p.slice(0, -2));
|
||||||
|
|
||||||
|
let DRY = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to remove a file / directory if it exists.
|
||||||
|
*
|
||||||
|
* @param {string} filePath The path to remove.
|
||||||
|
*/
|
||||||
|
async function tryRemove(filePath) {
|
||||||
|
if (await fs.exists(filePath)) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DRY) {
|
||||||
|
await fs.remove(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all build artifacts
|
||||||
|
*/
|
||||||
|
async function removeBuildArtifacts() {
|
||||||
|
const tasks = [];
|
||||||
|
|
||||||
|
for (const workspace of workspaces) {
|
||||||
|
const basePath = path.resolve(workspace);
|
||||||
|
const packages = await fs.readdir(basePath);
|
||||||
|
for (const packageName of packages) {
|
||||||
|
tasks.push(
|
||||||
|
tryRemove(path.join(basePath, packageName, "dist"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all test artifacts
|
||||||
|
*/
|
||||||
|
async function removeTestArtifacts() {
|
||||||
|
const artifacts = [
|
||||||
|
".nyc_output", "coverage", "temp", "static",
|
||||||
|
];
|
||||||
|
|
||||||
|
await Promise.all(artifacts.map(artifact => tryRemove(path.resolve(artifact))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all execution artifacts
|
||||||
|
*/
|
||||||
|
async function removeExecutionArtifacts() {
|
||||||
|
const artifacts = [
|
||||||
|
"database", "instances", "logs", "mods",
|
||||||
|
"config-control.json", "config-controller.json", "config-host.json",
|
||||||
|
"FactorioAdminToken.txt", "plugin-list.json",
|
||||||
|
];
|
||||||
|
|
||||||
|
await Promise.all(artifacts.map(artifact => tryRemove(path.resolve(artifact))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main function for this script
|
||||||
|
*/
|
||||||
|
async function main() {
|
||||||
|
await yargs
|
||||||
|
.scriptName("clean")
|
||||||
|
.usage("$0 <command> [options]")
|
||||||
|
.option("dry", {
|
||||||
|
nargs: 0,
|
||||||
|
describe: "Will not delete any files",
|
||||||
|
default: false,
|
||||||
|
type: "boolean",
|
||||||
|
})
|
||||||
|
.command("all", "Remove all artifacts", () => {}, argv => {
|
||||||
|
DRY = argv.dry;
|
||||||
|
removeBuildArtifacts();
|
||||||
|
removeTestArtifacts();
|
||||||
|
removeExecutionArtifacts();
|
||||||
|
})
|
||||||
|
.command("tests", "Remove all build and test artifacts", () => {}, argv => {
|
||||||
|
DRY = argv.dry;
|
||||||
|
removeBuildArtifacts();
|
||||||
|
removeTestArtifacts();
|
||||||
|
})
|
||||||
|
.command("fast", "Remove all build artifacts", () => {}, argv => {
|
||||||
|
DRY = argv.dry;
|
||||||
|
removeBuildArtifacts();
|
||||||
|
})
|
||||||
|
.demandCommand(1, "You need to specify a command to run")
|
||||||
|
.strict()
|
||||||
|
.parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run main if started from command line
|
||||||
|
if (module === require.main) {
|
||||||
|
main();
|
||||||
|
}
|
||||||
+6
-1
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "root",
|
"name": "root",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"files": [],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --build",
|
"build": "tsc --build",
|
||||||
"watch": "tsc --build --watch",
|
"watch": "tsc --build --watch",
|
||||||
@@ -11,6 +12,9 @@
|
|||||||
"ci-cover": "nyc --reporter=lcovonly pnpm run-script test",
|
"ci-cover": "nyc --reporter=lcovonly pnpm run-script test",
|
||||||
"lint": "eslint packages plugins test",
|
"lint": "eslint packages plugins test",
|
||||||
"lint-fix": "eslint --fix packages plugins test",
|
"lint-fix": "eslint --fix packages plugins test",
|
||||||
|
"clean": "node ./clean.js fast",
|
||||||
|
"clean-tests": "node ./clean.js tests",
|
||||||
|
"clean-all": "node ./clean.js all",
|
||||||
"docs": "typedoc",
|
"docs": "typedoc",
|
||||||
"bundle-dependencies": "bundle-dependencies"
|
"bundle-dependencies": "bundle-dependencies"
|
||||||
},
|
},
|
||||||
@@ -48,6 +52,7 @@
|
|||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"phin": "^3.7.0",
|
"phin": "^3.7.0",
|
||||||
"typedoc": "^0.24.8",
|
"typedoc": "^0.24.8",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.1.6",
|
||||||
|
"yargs": "^17.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user