feat: logging

This commit is contained in:
Artemy 2023-07-19 15:50:35 +03:00
parent aff35696b1
commit 94b94ec0c8
3 changed files with 29 additions and 6 deletions

View file

@ -2,7 +2,14 @@
const config = { const config = {
packages: { packages: {
dev: ["@types/node", "ts-node", "typescript"], dev: [
"@types/node",
"ts-node",
"typescript",
"eslint",
"@typescript-eslint/parser",
"@typescript-eslint/eslint-plugin",
],
dep: ["dotenv"], dep: ["dotenv"],
}, },
}; };
@ -12,20 +19,30 @@ const fs = require("fs");
const path = require("path"); const path = require("path");
//check if package.json exists //check if package.json exists
console.log("Check if package.json exists");
if (!fs.existsSync("package.json")) { if (!fs.existsSync("package.json")) {
console.log("package.json does not exist, creating...");
spawn.sync("npm", ["init", "-y"], { stdio: "inherit" }); spawn.sync("npm", ["init", "-y"], { stdio: "inherit" });
} else {
console.log("package.json exists, skipping...");
} }
//install packages //install packages
spawn.sync("npm", ["i", "-D", ...config.dev.packages]); console.log("Install packages");
spawn.sync("npm", ["i", ...config.dep.packages]); spawn.sync("npm", ["i", "-D", ...config.packages.dev], { stdio: "inherit" });
spawn.sync("npm", ["i", ...config.packages.dep], { stdio: "inherit" });
console.log("Packages installed");
//copy files //copy files
console.log("Copy files");
fs.cpSync(path.join(__dirname, "files"), "./", { recursive: true }); fs.cpSync(path.join(__dirname, "files"), "./", { recursive: true });
console.log("Files copied");
//modify package.json //modify package.json
console.log("Modify package.json");
const package = JSON.parse(fs.readFileSync("package.json", "utf-8")); const package = JSON.parse(fs.readFileSync("package.json", "utf-8"));
package.main = "dist/app.js"; package.main = "dist/app.js";
@ -34,3 +51,6 @@ package.scripts.dev = "ts-node src/app.ts";
package.scripts.start = "node dist/app.js"; package.scripts.start = "node dist/app.js";
fs.writeFileSync("package.json", JSON.stringify(package, null, 2)); fs.writeFileSync("package.json", JSON.stringify(package, null, 2));
console.log("package.json modified");
console.log("Done");

7
package-lock.json generated
View file

@ -1,15 +1,18 @@
{ {
"name": "@artegoser/create-ts-prod", "name": "@artegoser/create-ts-prod",
"version": "1.0.0", "version": "1.0.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@artegoser/create-ts-prod", "name": "@artegoser/create-ts-prod",
"version": "1.0.0", "version": "1.0.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cross-spawn": "^7.0.3" "cross-spawn": "^7.0.3"
},
"bin": {
"create-ts-prod": "index.js"
} }
}, },
"node_modules/cross-spawn": { "node_modules/cross-spawn": {

View file

@ -1,6 +1,6 @@
{ {
"name": "@artegoser/create-ts-prod", "name": "@artegoser/create-ts-prod",
"version": "1.0.0", "version": "1.1.0",
"description": "Boilerplate for TypeScript projects", "description": "Boilerplate for TypeScript projects",
"main": "index.js", "main": "index.js",
"bin": { "bin": {