init: initial commit
This commit is contained in:
49
index.ts
Executable file
49
index.ts
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { Command } from "commander";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import Papa from "papaparse";
|
||||
import prettier from "prettier";
|
||||
|
||||
type pm2Config = {
|
||||
name: string;
|
||||
script: string;
|
||||
args: string;
|
||||
cwd: string;
|
||||
interpreter: string;
|
||||
env: string;
|
||||
autorestart: "1" | "0";
|
||||
watch: "1" | "0";
|
||||
disabled: "1" | "0";
|
||||
}
|
||||
|
||||
const pm2edit = new Command("pm2edit")
|
||||
.description("Convert PM2 CSV to JS")
|
||||
.argument("<csvFile>", "The CSV file to convert")
|
||||
.action(async (csvFile) => {
|
||||
// read and parse csv file
|
||||
const csv = readFileSync(csvFile, "utf8");
|
||||
const parsedData = Papa.parse<pm2Config>(csv, { header: true })
|
||||
|
||||
let data = parsedData.data
|
||||
.filter((row) => row.disabled === "0")
|
||||
.map((row) => {
|
||||
return {
|
||||
...row,
|
||||
env: row.env ? Object.fromEntries(row.env.split(",").map(item => item.split("="))) : undefined,
|
||||
out_file: `home/pi/logs/${row.name}.log`,
|
||||
error_file: `home/pi/logs/${row.name}.log`,
|
||||
merge_logs: true,
|
||||
watch: row.watch === "1",
|
||||
autorestart: row.autorestart === "1",
|
||||
}
|
||||
})
|
||||
|
||||
const fileContent = `const enabled = false;\n\nmodule.exports = {apps: ${JSON.stringify(data, null, 2)}}`
|
||||
|
||||
const formattedContent = await prettier.format(fileContent, { parser: "typescript" });
|
||||
|
||||
writeFileSync("ecosystem.config.js", formattedContent);
|
||||
});
|
||||
|
||||
pm2edit.parseAsync(process.argv);
|
||||
Reference in New Issue
Block a user