init: initial commit

This commit is contained in:
2026-06-02 12:21:35 +05:30
commit ba1e0963f8
6 changed files with 192 additions and 0 deletions

38
.gitignore vendored Normal file
View File

@@ -0,0 +1,38 @@
# dependencies (bun install)
node_modules
# output
out
dist
*.tgz
# code coverage
coverage
*.lcov
# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# caches
.eslintcache
.cache
*.tsbuildinfo
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store
# project related
pm2.csv
ecosystem.config.js

15
README.md Normal file
View File

@@ -0,0 +1,15 @@
# pm2edit
To install dependencies:
```bash
bun install
```
To run:
```bash
bun run index.ts
```
This project was created using `bun init` in bun v1.3.13. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

41
bun.lock Normal file
View File

@@ -0,0 +1,41 @@
{
"lockfileVersion": 1,
"configVersion": 1,
"workspaces": {
"": {
"name": "pm2edit",
"dependencies": {
"commander": "^15.0.0",
"papaparse": "^5.5.3",
"prettier": "^3.8.3",
},
"devDependencies": {
"@types/bun": "latest",
"@types/node": "^25.9.1",
"@types/papaparse": "^5.5.2",
},
"peerDependencies": {
"typescript": "^5",
},
},
},
"packages": {
"@types/bun": ["@types/bun@1.3.14", "", { "dependencies": { "bun-types": "1.3.14" } }, "sha512-h1hFqFVcvAvD9j9K7ZW7vd82aSA+rTdznZa+5bwvCwqSB1jmmfLcbIWhOLx1/+boy/xmjgCs/OMUL8hRJSmnPw=="],
"@types/node": ["@types/node@25.9.1", "", { "dependencies": { "undici-types": ">=7.24.0 <7.24.7" } }, "sha512-xfrlY7UD5rMJk3ZVJP8BNzS28J36YJg+xp+LPXV1TdWxr8uMH5A860QNxYDGQe/ylDSgjxE52Q9VnO7p75tJxg=="],
"@types/papaparse": ["@types/papaparse@5.5.2", "", { "dependencies": { "@types/node": "*" } }, "sha512-gFnFp/JMzLHCwRf7tQHrNnfhN4eYBVYYI897CGX4MY1tzY9l2aLkVyx2IlKZ/SAqDbB3I1AOZW5gTMGGsqWliA=="],
"bun-types": ["bun-types@1.3.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-4N0ig0fEomHt5R0KCFWjovxow98rIoRwKolrYdCcknNwMekCXRnWEUvgu5soYV8QXtVsrUD8B95MBOZGPvr6KQ=="],
"commander": ["commander@15.0.0", "", {}, "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg=="],
"papaparse": ["papaparse@5.5.3", "", {}, "sha512-5QvjGxYVjxO59MGU2lHVYpRWBBtKHnlIAcSe1uNFCkkptUh63NFRj0FJQm7nR67puEruUci/ZkjmEFrjCAyP4A=="],
"prettier": ["prettier@3.8.3", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw=="],
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
"undici-types": ["undici-types@7.24.6", "", {}, "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg=="],
}
}

49
index.ts Executable file
View 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);

19
package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "pm2edit",
"module": "index.ts",
"type": "module",
"private": true,
"devDependencies": {
"@types/bun": "latest",
"@types/node": "^25.9.1",
"@types/papaparse": "^5.5.2"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"commander": "^15.0.0",
"papaparse": "^5.5.3",
"prettier": "^3.8.3"
}
}

30
tsconfig.json Normal file
View File

@@ -0,0 +1,30 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
"types": ["bun"],
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}