@chevtek/cli
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -58,3 +58,2 @@ "use strict"; | ||
return new Promise(function (resolve, reject) { | ||
command = /^win/.test(process.platform) ? command + ".cmd" : command; | ||
var cmd = child_process_1.default.spawn(command, args, { cwd: cwd, stdio: "inherit" }); | ||
@@ -68,2 +67,4 @@ cmd.on("error", reject); | ||
}; | ||
var npmCmd = /^win/.test(process.platform) ? "npm.cmd" : "npm"; | ||
var npxCmd = /^win/.test(process.platform) ? "npx.cmd" : "npx"; | ||
exports.default = (function (dir) { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -74,4 +75,3 @@ var dirExists, files; | ||
case 0: | ||
console.log(chalk_1.default.green("Generating full-stack scaffold...")); | ||
console.log(chalk_1.default.green("Checking if \"" + dir + "\" exists...")); | ||
console.log(chalk_1.default.greenBright("Generating full-stack scaffold...")); | ||
return [4 /*yield*/, checkDirectoryExists(dir)]; | ||
@@ -81,3 +81,2 @@ case 1: | ||
if (!dirExists) return [3 /*break*/, 3]; | ||
console.log(chalk_1.default.green("Directory exists. Checking for existing files...")); | ||
return [4 /*yield*/, readdir(dir)]; | ||
@@ -87,14 +86,12 @@ case 2: | ||
if (files.length > 0) { | ||
throw new Error("Please ensure the target directory is empty."); | ||
throw new Error("Target directory is not empty."); | ||
} | ||
return [3 /*break*/, 5]; | ||
case 3: | ||
console.log(chalk_1.default.green("Creating directory...")); | ||
return [4 /*yield*/, mkdir(dir)]; | ||
case 3: return [4 /*yield*/, mkdir(dir)]; | ||
case 4: | ||
_a.sent(); | ||
console.log(chalk_1.default.greenBright("Created \"" + dir + "\" directory.")); | ||
_a.label = 5; | ||
case 5: return [4 /*yield*/, Promise.all([ | ||
createPackageJson(dir), | ||
createGitIgnore(dir), | ||
generateServerScaffold(dir), | ||
@@ -105,3 +102,6 @@ generateClientScaffold(dir) | ||
_a.sent(); | ||
console.log(chalk_1.default.green("Done!")); | ||
return [4 /*yield*/, initializeGit(dir)]; | ||
case 7: | ||
_a.sent(); | ||
console.log(chalk_1.default.greenBright("Done!")); | ||
return [2 /*return*/]; | ||
@@ -111,2 +111,44 @@ } | ||
}); }); | ||
function initializeGit(dir) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var exitCode, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, writeFile(path_1.default.join(dir, ".gitignore"), "\n node_modules\n .vscode\n build\n " | ||
.split("\n") | ||
.map(function (line) { return line.trim(); }) | ||
.join("\n"))]; | ||
case 1: | ||
_a.sent(); | ||
console.log(chalk_1.default.greenBright("Created .gitignore.")); | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 7, , 8]); | ||
return [4 /*yield*/, spawn("git", ["status"], dir)]; | ||
case 3: | ||
exitCode = _a.sent(); | ||
if (exitCode !== 128) { | ||
console.log(chalk_1.default.greenBright("Parent git repository found, skipping repo init.")); | ||
return [2 /*return*/]; | ||
} | ||
return [4 /*yield*/, spawn("git", ["init"], dir)]; | ||
case 4: | ||
_a.sent(); | ||
return [4 /*yield*/, spawn("git", ["add", "."], dir)]; | ||
case 5: | ||
_a.sent(); | ||
return [4 /*yield*/, spawn("git", ["commit", "-m", "\"Initialized full-stack project.\""], dir)]; | ||
case 6: | ||
_a.sent(); | ||
console.log(chalk_1.default.greenBright("Initialized Git repository.")); | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
err_1 = _a.sent(); | ||
console.log(chalk_1.default.redBright(err_1.message)); | ||
return [3 /*break*/, 8]; | ||
case 8: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
function createPackageJson(dir) { | ||
@@ -139,6 +181,6 @@ return __awaiter(this, void 0, void 0, function () { | ||
_a.sent(); | ||
return [4 /*yield*/, spawn("npm", ["install", "-D", "npm-run-all", "wait-on", "rimraf", "move-cli"], dir)]; | ||
return [4 /*yield*/, spawn(npmCmd, ["install", "-D", "npm-run-all", "wait-on", "rimraf", "move-cli"], dir)]; | ||
case 2: | ||
_a.sent(); | ||
console.log(chalk_1.default.green("Created root package.json file.")); | ||
console.log(chalk_1.default.greenBright("Created root package.json file.")); | ||
return [2 /*return*/]; | ||
@@ -149,18 +191,2 @@ } | ||
} | ||
function createGitIgnore(dir) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, writeFile(path_1.default.join(dir, ".gitignore"), "\n node_modules\n .vscode\n build\n " | ||
.split("\n") | ||
.map(function (line) { return line.trim(); }) | ||
.join("\n"))]; | ||
case 1: | ||
_a.sent(); | ||
console.log(chalk_1.default.green("Created .gitignore.")); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
function generateServerScaffold(dir) { | ||
@@ -187,6 +213,6 @@ return __awaiter(this, void 0, void 0, function () { | ||
_a.sent(); | ||
return [4 /*yield*/, spawn("npm", ["install", "dotenv", "koa", "mongoose", "koa-static"], serverDir)]; | ||
return [4 /*yield*/, spawn(npmCmd, ["install", "dotenv", "koa", "mongoose", "koa-static"], serverDir)]; | ||
case 3: | ||
_a.sent(); | ||
return [4 /*yield*/, spawn("npm", [ | ||
return [4 /*yield*/, spawn(npmCmd, [ | ||
"install", | ||
@@ -232,19 +258,19 @@ "-D", | ||
_c.sent(); | ||
console.log(chalk_1.default.green("Created \"client\" directory.")); | ||
return [4 /*yield*/, spawn("npx", ["create-react-app", "--template", "typescript", "."], clientDir)]; | ||
console.log(chalk_1.default.greenBright("Created \"client\" directory.")); | ||
return [4 /*yield*/, spawn(npxCmd, ["create-react-app", "--template", "typescript", "."], clientDir)]; | ||
case 2: | ||
_c.sent(); | ||
console.log(chalk_1.default.green("Created react app.")); | ||
return [4 /*yield*/, rmdir(path_1.default.join(clientDir, ".git"))]; | ||
console.log(chalk_1.default.greenBright("Created react app.")); | ||
return [4 /*yield*/, unlink(path_1.default.join(clientDir, ".gitignore"))]; | ||
case 3: | ||
_c.sent(); | ||
console.log(chalk_1.default.green("Removed .git folder from client.")); | ||
return [4 /*yield*/, unlink(path_1.default.join(clientDir, ".gitignore"))]; | ||
case 4: | ||
_c.sent(); | ||
console.log(chalk_1.default.green("Removed .gitignore file from client.")); | ||
console.log(chalk_1.default.greenBright("Removed .gitignore file from client.")); | ||
_b = (_a = JSON).parse; | ||
return [4 /*yield*/, readFile(path_1.default.join(clientDir, "package.json"))]; | ||
case 4: | ||
packageData = _b.apply(_a, [(_c.sent()).toString()]); | ||
return [4 /*yield*/, rmdir(path_1.default.join(clientDir, ".git"))]; | ||
case 5: | ||
packageData = _b.apply(_a, [(_c.sent()).toString()]); | ||
_c.sent(); | ||
console.log(chalk_1.default.greenBright("Removed .git folder from client.")); | ||
packageData.homepage = "."; | ||
@@ -255,3 +281,3 @@ packageData.proxy = "http://localhost:3001"; | ||
_c.sent(); | ||
console.log(chalk_1.default.green("Wrote homepage and proxy to package.json.")); | ||
console.log(chalk_1.default.greenBright("Wrote homepage and proxy to package.json.")); | ||
return [2 /*return*/]; | ||
@@ -264,3 +290,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var err_1; | ||
var err_2; | ||
return __generator(this, function (_a) { | ||
@@ -275,3 +301,3 @@ switch (_a.label) { | ||
case 2: | ||
err_1 = _a.sent(); | ||
err_2 = _a.sent(); | ||
return [2 /*return*/, false]; | ||
@@ -278,0 +304,0 @@ case 3: return [2 /*return*/]; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ #!/usr/bin/env node |
@@ -18,3 +18,2 @@ import fs from "fs"; | ||
new Promise((resolve, reject) => { | ||
command = /^win/.test(process.platform) ? command + ".cmd" : command; | ||
const cmd = childProcess.spawn(command, args, { cwd, stdio: "inherit" }); | ||
@@ -27,25 +26,54 @@ cmd.on("error", reject); | ||
const npmCmd = /^win/.test(process.platform) ? "npm.cmd" : "npm"; | ||
const npxCmd = /^win/.test(process.platform) ? "npx.cmd" : "npx"; | ||
export default async (dir: string) => { | ||
console.log(chalk.green("Generating full-stack scaffold...")); | ||
console.log(chalk.green(`Checking if "${dir}" exists...`)); | ||
console.log(chalk.greenBright("Generating full-stack scaffold...")); | ||
const dirExists = await checkDirectoryExists(dir); | ||
if (dirExists) { | ||
console.log(chalk.green(`Directory exists. Checking for existing files...`)); | ||
const files = await readdir(dir); | ||
if (files.length > 0) { | ||
throw new Error("Please ensure the target directory is empty."); | ||
throw new Error("Target directory is not empty."); | ||
} | ||
} else { | ||
console.log(chalk.green(`Creating directory...`)); | ||
await mkdir(dir); | ||
console.log(chalk.greenBright(`Created "${dir}" directory.`)); | ||
} | ||
await Promise.all([ | ||
createPackageJson(dir), | ||
createGitIgnore(dir), | ||
generateServerScaffold(dir), | ||
generateClientScaffold(dir) | ||
]); | ||
console.log(chalk.green("Done!")); | ||
await initializeGit(dir); | ||
console.log(chalk.greenBright("Done!")); | ||
}; | ||
async function initializeGit(dir: string) { | ||
await writeFile( | ||
path.join(dir, ".gitignore"), | ||
` | ||
node_modules | ||
.vscode | ||
build | ||
` | ||
.split("\n") | ||
.map((line) => line.trim()) | ||
.join("\n") | ||
); | ||
console.log(chalk.greenBright(`Created .gitignore.`)); | ||
try { | ||
const exitCode = await spawn("git", ["status"], dir); | ||
if (exitCode !== 128) { | ||
console.log(chalk.greenBright("Parent git repository found, skipping repo init.")); | ||
return; | ||
} | ||
await spawn("git", ["init"], dir); | ||
await spawn("git", ["add", "."], dir); | ||
await spawn("git", ["commit", "-m", `"Initialized full-stack project."`], dir); | ||
console.log(chalk.greenBright("Initialized Git repository.")); | ||
} catch (err) { | ||
console.log(chalk.redBright(err.message)); | ||
} | ||
} | ||
async function createPackageJson(dir: string) { | ||
@@ -77,24 +105,9 @@ const data = { | ||
await spawn( | ||
"npm", | ||
npmCmd, | ||
["install", "-D", "npm-run-all", "wait-on", "rimraf", "move-cli"], | ||
dir | ||
); | ||
console.log(chalk.green(`Created root package.json file.`)); | ||
console.log(chalk.greenBright(`Created root package.json file.`)); | ||
} | ||
async function createGitIgnore(dir: string) { | ||
await writeFile( | ||
path.join(dir, ".gitignore"), | ||
` | ||
node_modules | ||
.vscode | ||
build | ||
` | ||
.split("\n") | ||
.map((line) => line.trim()) | ||
.join("\n") | ||
); | ||
console.log(chalk.green(`Created .gitignore.`)); | ||
} | ||
async function generateServerScaffold(dir: string) { | ||
@@ -116,3 +129,3 @@ const serverDir = path.join(dir, "server"); | ||
await spawn( | ||
"npm", | ||
npmCmd, | ||
["install", "dotenv", "koa", "mongoose", "koa-static"], | ||
@@ -122,3 +135,3 @@ serverDir | ||
await spawn( | ||
"npm", | ||
npmCmd, | ||
[ | ||
@@ -201,16 +214,16 @@ "install", | ||
await mkdir(path.join(dir, "client")); | ||
console.log(chalk.green(`Created "client" directory.`)); | ||
console.log(chalk.greenBright(`Created "client" directory.`)); | ||
await spawn( | ||
"npx", | ||
npxCmd, | ||
["create-react-app", "--template", "typescript", "."], | ||
clientDir | ||
); | ||
console.log(chalk.green(`Created react app.`)); | ||
await rmdir(path.join(clientDir, ".git")); | ||
console.log(chalk.green(`Removed .git folder from client.`)); | ||
console.log(chalk.greenBright(`Created react app.`)); | ||
await unlink(path.join(clientDir, ".gitignore")); | ||
console.log(chalk.green(`Removed .gitignore file from client.`)); | ||
console.log(chalk.greenBright(`Removed .gitignore file from client.`)); | ||
const packageData = JSON.parse( | ||
(await readFile(path.join(clientDir, "package.json"))).toString() | ||
); | ||
await rmdir(path.join(clientDir, ".git")); | ||
console.log(chalk.greenBright(`Removed .git folder from client.`)); | ||
packageData.homepage = "."; | ||
@@ -222,3 +235,3 @@ packageData.proxy = "http://localhost:3001"; | ||
); | ||
console.log(chalk.green(`Wrote homepage and proxy to package.json.`)); | ||
console.log(chalk.greenBright(`Wrote homepage and proxy to package.json.`)); | ||
} | ||
@@ -225,0 +238,0 @@ |
@@ -0,0 +0,0 @@ import fullStack from "./full-stack"; |
@@ -0,0 +0,0 @@ #!/usr/bin/env node |
{ | ||
"name": "@chevtek/cli", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -0,0 +0,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
36453
717