Merge pull request 'release' (#5) from main into release
Some checks failed
Release / Release (push) Failing after 28s
Some checks failed
Release / Release (push) Failing after 28s
Reviewed-on: #5
This commit is contained in:
commit
69fa25bc1d
2 changed files with 111 additions and 56 deletions
156
index.ts
156
index.ts
|
@ -1,3 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import fs from "fs";
|
||||
import { confirm, select, input } from "@inquirer/prompts";
|
||||
import { exit } from "process";
|
||||
|
@ -10,66 +12,108 @@ import {
|
|||
type Project,
|
||||
} from "./configuration/configuration";
|
||||
import { execSync } from "child_process";
|
||||
import { program } from "commander";
|
||||
|
||||
if (!fs.existsSync(configPath + "config.toml")) {
|
||||
const createConfig = await confirm({
|
||||
message: "No cofig has been found. Would you like to generate a new one?",
|
||||
});
|
||||
const CLI_NAME = "pcli";
|
||||
|
||||
if (createConfig) {
|
||||
generateDefaultConfig();
|
||||
} else {
|
||||
console.log(
|
||||
"This project can not run without the config. Either create it yourself or generate the default.",
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!getProjects() ||
|
||||
getProjects().length == 0 ||
|
||||
getProjects().length == undefined
|
||||
) {
|
||||
const anwser = await select({
|
||||
message: "Create a new Project",
|
||||
choices: ["Clone a project with git", "Create a new empty Project"],
|
||||
});
|
||||
if (anwser == "Clone a project with git") {
|
||||
const repoUrl = await input({ message: "What is the url of the repo?" });
|
||||
const wantsCustomName = await confirm({
|
||||
message: "Would you like to give this project a custom name?",
|
||||
default: false,
|
||||
});
|
||||
let customName = "";
|
||||
if (wantsCustomName) {
|
||||
customName = await input({
|
||||
message: "What would you like the custom name to be?",
|
||||
program
|
||||
.name("project-cli")
|
||||
.description("A cli for managing projects")
|
||||
.action(async () => {
|
||||
if (!fs.existsSync(configPath + "config.toml")) {
|
||||
const createConfig = await confirm({
|
||||
message:
|
||||
"No cofig has been found. Would you like to generate a new one?",
|
||||
});
|
||||
|
||||
if (createConfig) {
|
||||
generateDefaultConfig();
|
||||
} else {
|
||||
console.log(
|
||||
"This project can not run without the config. Either create it yourself or generate the default.",
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
execSync(
|
||||
"cd " +
|
||||
getConfiguration().projectsDirectory +
|
||||
" && " +
|
||||
getConfiguration()
|
||||
.cloningCommand.replace("%s", repoUrl)
|
||||
.replace("%n", customName),
|
||||
);
|
||||
if (
|
||||
!getProjects() ||
|
||||
getProjects().length == 0 ||
|
||||
getProjects().length == undefined
|
||||
) {
|
||||
const anwser = await select({
|
||||
message: "Create a new Project",
|
||||
choices: ["Clone a project with git", "Create a new empty Project"],
|
||||
});
|
||||
if (anwser == "Clone a project with git") {
|
||||
const repoUrl = await input({
|
||||
message: "What is the url of the repo?",
|
||||
});
|
||||
const wantsCustomName = await confirm({
|
||||
message: "Would you like to give this project a custom name?",
|
||||
default: false,
|
||||
});
|
||||
let customName = "";
|
||||
if (wantsCustomName) {
|
||||
customName = await input({
|
||||
message: "What would you like the custom name to be?",
|
||||
});
|
||||
}
|
||||
|
||||
const newProject: Project = {
|
||||
name: customName,
|
||||
};
|
||||
addProject(newProject);
|
||||
} else if (anwser == "Create a new empty Project") {
|
||||
const name = await input({
|
||||
message: "What would you like to call the project?",
|
||||
execSync(
|
||||
"cd " +
|
||||
getConfiguration().projectsDirectory +
|
||||
" && " +
|
||||
getConfiguration()
|
||||
.cloningCommand.replace("%s", repoUrl)
|
||||
.replace("%n", customName),
|
||||
);
|
||||
|
||||
const newProject: Project = {
|
||||
name: customName,
|
||||
};
|
||||
addProject(newProject);
|
||||
} else if (anwser == "Create a new empty Project") {
|
||||
const name = await input({
|
||||
message: "What would you like to call the project?",
|
||||
});
|
||||
fs.mkdirSync(getConfiguration().projectsDirectory + "/" + name);
|
||||
const newProject: Project = {
|
||||
name: name,
|
||||
};
|
||||
addProject(newProject);
|
||||
}
|
||||
}
|
||||
|
||||
const pickedProject = await select({
|
||||
message: "Which Project would you like to go to?",
|
||||
choices: getProjects().map((project: Project) => project.name),
|
||||
});
|
||||
fs.mkdirSync(getConfiguration().projectsDirectory + "/" + name);
|
||||
const newProject: Project = {
|
||||
name: name,
|
||||
};
|
||||
addProject(newProject);
|
||||
}
|
||||
}
|
||||
console.log(getProjects());
|
||||
|
||||
process.chdir(getConfiguration().projectsDirectory + "/" + pickedProject);
|
||||
|
||||
console.log(getProjects());
|
||||
});
|
||||
|
||||
program.command("init").action(() => {
|
||||
console.log(`${CLI_NAME}() {
|
||||
local output
|
||||
output=$(command ${CLI_NAME} "$@")
|
||||
local exit_code=$?
|
||||
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
echo "$output" | while IFS= read -r line; do
|
||||
if [[ $line == __EXEC__* ]]; then
|
||||
eval "\${line#__EXEC__}"
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "$output" >&2
|
||||
return $exit_code
|
||||
fi
|
||||
}`);
|
||||
});
|
||||
|
||||
program.parse();
|
||||
|
|
11
package.json
11
package.json
|
@ -3,6 +3,17 @@
|
|||
"version": "0.2.2",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"pcli": "./dist/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bun build index.ts --outfile dist/index.js --target node",
|
||||
"dev": "bun run index.ts",
|
||||
"prepublishOnly": "bun run build"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue