diff --git a/README.md b/README.md
index 25767aa..76ef05a 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
-## `This project currently only supports creation of React + vite and raw JS projects with Biomejs as lint and formatter`
+## `This project currently only supports creation of React + vite and vanilla JS projects with Biomejs as lint and formatter`
# Monorepo Automator
@@ -56,6 +56,8 @@ monorepo-automator create [name] [options]
Option | Description
---|---
`-p` or `--path` | Provide path where you want to create the monorepo project
+
+
##
- ### Add
@@ -67,6 +69,9 @@ monorepo-automator add [options]
Option | Description
---|---
`-e` or `--env` | Provide a development environment to the new app, ex: vite
+`-p` or `--path` | Provide path where you want to create new app
+
+
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
diff --git a/commands/add.js b/commands/add.js
index 4dbe545..8207fb2 100644
--- a/commands/add.js
+++ b/commands/add.js
@@ -11,7 +11,7 @@ const errorStyle = chalk.red.bold;
export default async (cmd, opts, appDir) => {
let appName = cmd ?? null;
let devEnv = opts.env ?? null;
- let appPath;
+ let appPath = opts.path ?? null;
try {
appName = appName.replace(/\s/g, "_");
@@ -22,15 +22,17 @@ export default async (cmd, opts, appDir) => {
handleError("Invalid project name. Project name must be a valid folder name format.");
}
- await promisifyQuestion(
- `❔ Where do you want to create the app ${appName}? (leave empty for current path)\n`,
- ).then(path => {
- if (path === "." || path.length === 0) {
- appPath = "./";
- } else {
- appPath = path;
- }
- });
+ if (!appPath) {
+ await promisifyQuestion(
+ `❔ Where do you want to create the app ${appName}? (leave empty for current path)\n`,
+ ).then(path => {
+ if (path === "." || path.length === 0) {
+ appPath = "./";
+ } else {
+ appPath = path;
+ }
+ });
+ }
//check if parent dir exists
if (!existsSync(appPath)) {
@@ -55,24 +57,35 @@ export default async (cmd, opts, appDir) => {
message: "❔ Do you want to install any development environment?",
choices: ["vite", "none"],
}).then(res => {
- if (res.devEnv !== "none") {
- devEnv = res.devEnv;
- }
+ devEnv = res.devEnv;
});
}
- startAnimation();
-
- if (devEnv) {
+ if (devEnv !== "none") {
if (devEnv !== "vite") {
handleError(`${devEnv} is not supported dev environment. Use vite instead.`, `${appPath}${appName}`);
return;
}
+ //Substituir por @inquirer/select
+ const framework = await list({
+ name: "framework",
+ message: `❔ Pick a framework for the app ${appName}?`,
+ choices: ["vue", "react", "preact", "lit", "svelte", "solid", "qwik"],
+ });
+
+ console.log(framework);
+
+ startAnimation();
+
setMessage(`Creating ${appName} - Installing and initializing vite`);
//init vite
- await runCommandOnFolder(`${appPath}`, `npm create vite@latest ${appName} -- --template react`);
+ await runCommandOnFolder(
+ `${appPath}`,
+ `npm create vite@latest ${appName} -- --template ${framework.framework}`,
+ );
+ console.log("ehre");
//install dependencies
await runCommandOnFolder(`${appPath}${appName}`, "npm install");
@@ -83,6 +96,7 @@ export default async (cmd, opts, appDir) => {
await fsPromises.rm(`${appPath}${appName}/README.md`);
setMessage(`Creating ${appName} - Setting package.json scripts`);
+
//change package.json scripts, vite config and create envDir
const contents = await fsPromises.readFile(`${appPath}${appName}/package.json`, "utf-8");
const replacement = contents
@@ -94,7 +108,6 @@ export default async (cmd, opts, appDir) => {
.replace(/"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",\n/, "");
await fsPromises.writeFile(`${appPath}${appName}/package.json`, replacement);
-
//copy vite config template
setMessage(`Creating ${appName} - Updating vite config`);
await fsPromises.copyFile(`${appDir}/filesTemplate/vite.config.js`, `${appPath}${appName}/vite.config.js`);
@@ -107,6 +120,8 @@ export default async (cmd, opts, appDir) => {
await fsPromises.writeFile(`${appPath}${appName}/envDir/.env.production`, "", "utf-8");
await fsPromises.writeFile(`${appPath}${appName}/envDir/.env.development`, "", "utf-8");
} else {
+ startAnimation();
+
//create server folder
setMessage(`Creating ${appName}`);
await createDirectory(`${appPath}${appName}`);
diff --git a/commands/create.js b/commands/create.js
index 361fa39..4bae7c2 100644
--- a/commands/create.js
+++ b/commands/create.js
@@ -84,9 +84,7 @@ export default async (cmd, opts, appDir) => {
message: `❔ Do you want to install any development environment on ${app.name}?`,
choices: ["vite", "none"],
}).then(res => {
- if (res.devEnv !== "none") {
- app.devEnv = res.devEnv;
- }
+ app.devEnv = res.devEnv;
});
}
@@ -97,7 +95,7 @@ export default async (cmd, opts, appDir) => {
setMessage(`Creating ${app.name}`);
- if (app.devEnv) {
+ if (app.devEnv !== "none") {
if (app.devEnv !== "vite") {
handleError(
`${app.devEnv} is not supported dev environment. Use vite instead.`,
diff --git a/index.js b/index.js
index 14a05ce..215abeb 100755
--- a/index.js
+++ b/index.js
@@ -17,6 +17,7 @@ program
.command("add ")
.description("Add new app to project. Ex: add server")
.option("-e, --env [ENV]", "Set development environment to the app. Ex: add client -e vite")
+ .option("-p, --path [PATH]", "Set the path for the new project. EX: add client -p ./my_project_folder")
.action((cmd, opts) => add(cmd, opts, rootDir));
program.parse();
diff --git a/package-lock.json b/package-lock.json
index f6b771c..5d19120 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4211,14 +4211,15 @@
}
},
"node_modules/set-function-length": {
- "version": "1.1.1",
- "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz",
- "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==",
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.0.tgz",
+ "integrity": "sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==",
"dependencies": {
"define-data-property": "^1.1.1",
- "get-intrinsic": "^1.2.1",
+ "function-bind": "^1.1.2",
+ "get-intrinsic": "^1.2.2",
"gopd": "^1.0.1",
- "has-property-descriptors": "^1.0.0"
+ "has-property-descriptors": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
diff --git a/package.json b/package.json
index e63d891..1565d7b 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,11 @@
"type": "module",
"keywords": [
"monorepo",
- "boilerplate"
+ "boilerplate",
+ "cli",
+ "command-line",
+ "generator",
+ "javascript"
],
"description": "Monorepo project auto generator",
"main": "index.js",