create-lestin
Version:
Creates a new project with Lestin
143 lines (138 loc) • 5.29 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/tsup/assets/cjs_shims.js
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
// src/index.ts
var import_promises = __toESM(require("fs/promises"), 1);
var import_path = __toESM(require("path"), 1);
var import_url = require("url");
var import_child_process = require("child_process");
var import_commander = require("commander");
// package.json
var package_default = {
name: "create-lestin",
version: "0.0.2",
description: "Creates a new project with Lestin",
keywords: [
"create",
"lestin"
],
homepage: "https://github.com/movahhedi/create-lestin",
bugs: {
url: "https://github.com/movahhedi/create-lestin"
},
repository: {
type: "git",
url: "https://github.com/movahhedi/create-lestin"
},
license: "MIT",
author: "Shahab Movahhedi",
type: "module",
exports: {
".": {
import: "./dist/index.js",
require: "./dist/index.cjs",
default: "./dist/index.js"
}
},
bin: "./dist/index.js",
main: "./dist/index.js",
types: "./dist/index.d.ts",
files: [
"templates",
"dist"
],
scripts: {
build: "tsup --format esm,cjs --clean --dts",
prepublishOnly: "yarn build",
update: "npx npm-check-updates -i"
},
dependencies: {
commander: "^12.1.0"
},
devDependencies: {
"@types/node": "^20.14.11",
"npm-check-updates": "^16.14.20",
tsup: "^8.2.1",
typescript: "^5.5.3"
},
packageManager: "yarn@4.6.0"
};
// src/index.ts
var __filename2 = (0, import_url.fileURLToPath)(importMetaUrl);
var __dirname = import_path.default.dirname((0, import_url.fileURLToPath)(importMetaUrl));
var program = new import_commander.Command();
program.name("create-lestin").description("Create a new project with Lestin").version(package_default.version, "-v, -V, --version", "create-lestin's version").argument("<dir-name>", "Directory of the project").option("-f, --force", "Force create a project in a non-empty directory").option("-G, --no-git", "Don't initialize a git repository").option("-i, --install", "Install dependencies after creating the project").action(async (dirNameRaw) => {
const options = program.opts();
const dirName = import_path.default.resolve(dirNameRaw);
try {
const doesDirExist = await import_promises.default.access(dirName);
const isDirFull = (await import_promises.default.readdir(dirName)).length > 0;
if (isDirFull) {
console.error(
"The directory is not empty. To force create a project in a non-empty directory, use the `--force` flag."
);
return;
}
} catch (error) {
}
console.log("Creating project in the directory:", dirName, "\n");
await import_promises.default.mkdir(dirName, {
recursive: true
});
await import_promises.default.cp(import_path.default.resolve(__dirname, "../templates/hono-client-server"), dirName, {
recursive: true
});
const dirFiles = await import_promises.default.readdir(dirName, { recursive: true });
dirFiles.forEach(async (file) => {
const filePath = import_path.default.resolve(dirName, file);
if (filePath.endsWith("CREATECOMMAND")) {
await import_promises.default.rename(filePath, filePath.replace("CREATECOMMAND", ""));
}
});
if (!options.noGit) {
console.log("Initializing git repository...");
(0, import_child_process.execSync)("git init", {
cwd: dirName,
stdio: "inherit"
});
}
if (options.install) {
console.log("Installing dependencies...");
(0, import_child_process.execSync)("yarn install", {
cwd: dirName,
stdio: "inherit"
});
}
console.log("Project created successfully at the directory:", dirName, "\n");
console.log("To start the project, run the following commands:\n");
if (dirNameRaw !== ".") {
console.log(` cd ${dirNameRaw}`);
}
console.log(" yarn install");
console.log("\nHappy coding!");
});
program.parse(process.argv);