-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 changed file
with
97 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,120 @@ | ||
#!/usr/bin/env node | ||
|
||
import { execSync } from "node:child_process"; | ||
import { existsSync, readFileSync, writeFileSync } from "fs"; | ||
import { execSync } from "node:child_process" | ||
import { existsSync, readFileSync, writeFileSync } from "fs" | ||
|
||
console.log("\nStarting sda setup for NodeJS..."); | ||
console.log("\nStarting sda setup for NodeJS...") | ||
|
||
const args = process.argv.slice(2); | ||
const args = process.argv.slice(2) | ||
|
||
const runtime = args.includes("--bun") ? "bun" : "nodejs"; | ||
let language = args.includes("--js") ? "js" : "ts"; | ||
const force = args.includes("--force"); | ||
const runtime = args.includes("--bun") ? "bun" : "nodejs" | ||
let language = args.includes("--js") ? "js" : "ts" | ||
const force = args.includes("--force") | ||
|
||
if (existsSync("package.json") && force === false) { | ||
console.log( | ||
"\n/!\\ There is already a package.json here. Not doing the setup." | ||
); | ||
console.log( | ||
"/!\\ Start over in a new folder or pass the option --force to overwrite files." | ||
); | ||
console.log("/!\\ Bye bye!\n"); | ||
process.exit(1); | ||
console.log( | ||
"\n/!\\ There is already a package.json here. Not doing the setup." | ||
) | ||
console.log( | ||
"/!\\ Start over in a new folder or pass the option --force to overwrite files." | ||
) | ||
console.log("/!\\ Bye bye!\n") | ||
process.exit(1) | ||
} else { | ||
console.log("\n1 - Checking options..."); | ||
console.log("\n1 - Checking options...") | ||
|
||
if (runtime === "bun") { | ||
console.log(" => Setting things up for Bun."); | ||
if (language === "js") { | ||
console.log(" => Setting things up for JavaScript."); | ||
if (runtime === "bun") { | ||
console.log(" => Setting things up for Bun.") | ||
if (language === "js") { | ||
console.log(" => Setting things up for JavaScript.") | ||
} else { | ||
console.log(" => Setting things up for TypeScript.") | ||
} | ||
} else { | ||
console.log(" => Setting things up for TypeScript."); | ||
console.log(" => Setting things up for Node.js.") | ||
if (language === "ts") { | ||
const nodeVersion = process.version | ||
.split(".") | ||
.map((d) => parseInt(d.replace("v", ""))) | ||
if (nodeVersion[0] >= 22 && nodeVersion[1] >= 6) { | ||
console.log( | ||
" => Node.js version is >= 22.6.0. Setting things up for TypeScript." | ||
) | ||
} else { | ||
console.log( | ||
" => Node.js version is < 22.6.0. Setting things up for JavaScript." | ||
) | ||
language = "js" | ||
} | ||
} else { | ||
console.log(" => Setting things up for JavaScript.") | ||
} | ||
} | ||
} else { | ||
console.log(" => Setting things up for Node.js."); | ||
if (language === "ts") { | ||
const nodeVersion = process.version | ||
.split(".") | ||
.map((d) => parseInt(d.replace("v", ""))); | ||
if (nodeVersion[0] >= 22 && nodeVersion[1] >= 6) { | ||
console.log( | ||
" => Node.js version is >= 22.6.0. Setting things up for TypeScript." | ||
); | ||
} else { | ||
console.log( | ||
" => Node.js version is < 22.6.0. Setting things up for JavaScript." | ||
); | ||
language = "js"; | ||
} | ||
if (force) { | ||
console.log(" => Option force is true. Files will be overwritten.") | ||
} | ||
|
||
console.log("\n2 - Installing libraries with npm...") | ||
execSync("npm i simple-data-analysis --silent", { | ||
stdio: "ignore", | ||
}) | ||
console.log(" => simple-data-analysis has been installed.") | ||
execSync("npm i journalism --silent", { | ||
stdio: "ignore", | ||
}) | ||
console.log(" => journalism has been installed.") | ||
|
||
console.log("\n3 - Creating and updating relevant files...") | ||
const packageJson = JSON.parse(readFileSync("package.json", "utf8")) | ||
packageJson.type = "module" | ||
if (runtime === "bun") { | ||
if (language === "ts") { | ||
packageJson.scripts = { | ||
sda: "bun --watch index.ts", | ||
} | ||
} else { | ||
packageJson.scripts = { | ||
sda: "bun --watch index.js", | ||
} | ||
} | ||
} else { | ||
console.log(" => Setting things up for JavaScript."); | ||
if (language === "ts") { | ||
packageJson.scripts = { | ||
sda: "node --experimental-strip-types --no-warnings --watch index.ts", | ||
} | ||
} else { | ||
packageJson.scripts = { | ||
sda: "node --no-warnings --watch index.js", | ||
} | ||
} | ||
} | ||
writeFileSync("package.json", JSON.stringify(packageJson, null, 2)) | ||
console.log(" => package.json has been updated.") | ||
|
||
if (runtime === "nodejs" && language === "ts") { | ||
const tsconfigContent = readFileSync("tsconfig-content.json", "utf-8") | ||
writeFileSync("tsconfig.json", tsconfigContent) | ||
console.log(" => tsconfig.json has been created.") | ||
} | ||
} | ||
if (force) { | ||
console.log(" => Option force is true. Files will be overwritten."); | ||
} | ||
|
||
console.log("\n2 - Installing libraries with npm..."); | ||
execSync("npm i simple-data-analysis --silent", { | ||
stdio: "ignore", | ||
}); | ||
console.log(" => simple-data-analysis has been installed."); | ||
execSync("npm i journalism --silent", { | ||
stdio: "ignore", | ||
}); | ||
console.log(" => journalism has been installed."); | ||
writeFileSync(".gitignore", "node_modules\n.temp\n.sda-cache") | ||
console.log(" => .gitignore has been created.") | ||
|
||
console.log("\n3 - Creating and updating relevant files..."); | ||
const packageJson = JSON.parse(readFileSync("package.json", "utf8")); | ||
packageJson.type = "module"; | ||
if (runtime === "bun") { | ||
const indexContent = readFileSync("index-content.js", "utf-8") | ||
if (language === "ts") { | ||
packageJson.scripts = { | ||
sda: "bun --watch index.ts", | ||
}; | ||
writeFileSync("index.ts", indexContent) | ||
console.log(" => index.ts has been created.") | ||
} else { | ||
packageJson.scripts = { | ||
sda: "bun --watch index.js", | ||
}; | ||
writeFileSync("index.js", indexContent) | ||
console.log(" => index.js has been created.") | ||
} | ||
} else { | ||
|
||
console.log("\nSetup is done!") | ||
if (language === "ts") { | ||
packageJson.scripts = { | ||
sda: "node --experimental-strip-types --no-warnings --watch index.ts", | ||
}; | ||
console.log(" => Run npm run sda to watch index.ts.") | ||
} else { | ||
packageJson.scripts = { | ||
sda: "node --no-warnings --watch index.js", | ||
}; | ||
console.log(" => Run npm run sda to watch index.js.") | ||
} | ||
} | ||
writeFileSync("package.json", JSON.stringify(packageJson, null, 2)); | ||
console.log(" => package.json has been updated."); | ||
|
||
if (runtime === "nodejs" && language === "ts") { | ||
const indexContent = readFileSync("tsconfig-content.json", "utf-8"); | ||
writeFileSync("tsconfig.json", indexContent); | ||
console.log(" => tsconfig.json has been created."); | ||
} | ||
|
||
writeFileSync(".gitignore", "node_modules\n.temp\n.sda-cache"); | ||
console.log(" => .gitignore has been created."); | ||
|
||
const indexContent = readFileSync("index-content.js", "utf-8"); | ||
if (language === "ts") { | ||
writeFileSync("index.ts", indexContent); | ||
console.log(" => index.ts has been created."); | ||
} else { | ||
writeFileSync("index.js", indexContent); | ||
console.log(" => index.js has been created."); | ||
} | ||
|
||
console.log("\nSetup is done!"); | ||
if (language === "ts") { | ||
console.log(" => Run npm run sda to watch index.ts."); | ||
} else { | ||
console.log(" => Run npm run sda to watch index.js."); | ||
} | ||
|
||
console.log(" => Have fun. ^_^\n"); | ||
console.log(" => Have fun. ^_^\n") | ||
} |