-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
3,464 additions
and
1,384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { spawn } from "node:child_process"; | ||
import { readFile, unlink, writeFile } from "node:fs/promises"; | ||
import { basename } from "node:path"; | ||
|
||
await Promise.all([removeLines(), commands(), updatePackageJson()]); | ||
await unlink(new URL(import.meta.url).pathname); | ||
|
||
await updatePackageJson(); | ||
|
||
async function removeLines() { | ||
async function removeLinesFromFile(filePath, fence) { | ||
console.log(`removing lines from: ${filePath}`); | ||
|
||
try { | ||
const data = await readFile(filePath, "utf8"); | ||
const lines = data.split("\n"); | ||
const res = []; | ||
let isInFence = false; | ||
|
||
for (const line of lines) { | ||
if (line.trim() === fence[0]) { | ||
isInFence = true; | ||
} | ||
if (!isInFence) { | ||
res.push(line); | ||
} | ||
if (line.trim() === fence[1]) { | ||
isInFence = false; | ||
} | ||
} | ||
|
||
await writeFile(filePath, res.join("\n")); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
const fences = [["### 👉 please remove ###", "########################"]]; | ||
const files = [ | ||
[".gitignore", fences[0]], | ||
[".github/workflows/ci.yml", fences[0]], | ||
]; | ||
|
||
await Promise.all( | ||
files.map(async ([file, fence]) => await removeLinesFromFile(file, fence)), | ||
); | ||
} | ||
|
||
async function commands() { | ||
const commands = ["pnpm dev:db:setup", "pnpm fmt", "pnpm db:stop"]; | ||
|
||
for (const command of commands) { | ||
console.log(`running: ${command}`); | ||
|
||
const [cmd, ...args] = command.split(" "); | ||
|
||
await new Promise((resolve, reject) => { | ||
const child = spawn(cmd, args, { stdio: "inherit" }); | ||
|
||
child.stdout?.on("data", (data) => { | ||
console.log(data); | ||
}); | ||
|
||
child.stderr?.on("data", (data) => { | ||
console.log(data); | ||
}); | ||
|
||
child.on("exit", (code) => { | ||
if (code === 0) { | ||
resolve(); | ||
} else { | ||
reject(new Error(`command failed with code ${code}`)); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
async function updatePackageJson() { | ||
const packageJsonPath = new URL("./package.json", import.meta.url); | ||
const packageJson = await readFile(packageJsonPath, "utf8"); | ||
const parsed = JSON.parse(packageJson); | ||
const currentDirectoryName = basename(process.cwd()); | ||
|
||
parsed.name = currentDirectoryName; | ||
|
||
await writeFile(packageJsonPath, JSON.stringify(parsed, null, 2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "web-app-template", | ||
"name": "", | ||
"version": "0.0.0", | ||
"description": "", | ||
"packageManager": "[email protected]", | ||
|
@@ -24,7 +24,7 @@ | |
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint && biome lint .", | ||
"fmt": "biome format --write .", | ||
"fmt": "prettier -w . && biome format --write .", | ||
"check": "biome check --apply ." | ||
}, | ||
"dependencies": { | ||
|
Oops, something went wrong.