create-minista 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32 -28
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { bold, cyan, gray, green, red } from "kleur/colors";
|
|
3
|
+
import { bold, cyan, gray, green, red, reset } from "kleur/colors";
|
|
4
4
|
import prompts from "prompts";
|
|
5
5
|
import degit from "degit";
|
|
6
6
|
import yargs from "yargs-parser";
|
|
7
|
+
import replace from "replace-in-file";
|
|
7
8
|
import { TEMPLATES } from "./templates.js";
|
|
8
9
|
const cleanArgv = process.argv.filter((arg) => arg !== "--");
|
|
9
10
|
const args = yargs(cleanArgv);
|
|
10
11
|
prompts.override(args);
|
|
11
12
|
const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
12
|
-
|
|
13
|
+
const POSTPROCESS_FILES = ["package.json", "project.json", "README.md"];
|
|
13
14
|
export function mkdirp(dir) {
|
|
14
15
|
try {
|
|
15
16
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -23,6 +24,8 @@ export function mkdirp(dir) {
|
|
|
23
24
|
export async function main() {
|
|
24
25
|
console.log(`\n${bold("create-minista")} ${gray(`(v${version})`)}`);
|
|
25
26
|
const cwd = args["_"][2] || ".";
|
|
27
|
+
const defaultProjectName = cwd === "." ? "minista-project" : cwd;
|
|
28
|
+
const officialTemplatesPath = "qrac/create-minista/templates";
|
|
26
29
|
if (fs.existsSync(cwd)) {
|
|
27
30
|
if (fs.readdirSync(cwd).length > 0) {
|
|
28
31
|
const response = await prompts({
|
|
@@ -41,6 +44,12 @@ export async function main() {
|
|
|
41
44
|
mkdirp(cwd);
|
|
42
45
|
}
|
|
43
46
|
const options = await prompts([
|
|
47
|
+
{
|
|
48
|
+
type: "text",
|
|
49
|
+
name: "projectName",
|
|
50
|
+
message: reset("Project name (in the file):"),
|
|
51
|
+
initial: defaultProjectName,
|
|
52
|
+
},
|
|
44
53
|
{
|
|
45
54
|
type: "select",
|
|
46
55
|
name: "template",
|
|
@@ -51,18 +60,18 @@ export async function main() {
|
|
|
51
60
|
if (!options.template) {
|
|
52
61
|
process.exit(1);
|
|
53
62
|
}
|
|
63
|
+
const projectName = options.projectName
|
|
64
|
+
? options.projectName
|
|
65
|
+
: defaultProjectName;
|
|
54
66
|
const hash = args.commit ? `#${args.commit}` : "";
|
|
55
67
|
const templateTarget = options.template.includes("/")
|
|
56
68
|
? options.template
|
|
57
|
-
:
|
|
69
|
+
: `${officialTemplatesPath}/${options.template}`;
|
|
58
70
|
const emitter = degit(`${templateTarget}${hash}`, {
|
|
59
71
|
cache: false,
|
|
60
72
|
force: true,
|
|
61
73
|
verbose: false,
|
|
62
74
|
});
|
|
63
|
-
/*const selectedTemplate = TEMPLATES.find(
|
|
64
|
-
(template) => template.value === options.template
|
|
65
|
-
)*/
|
|
66
75
|
try {
|
|
67
76
|
console.log(`${green(`>`)} ${gray(`Copying project files...`)}`);
|
|
68
77
|
await emitter.clone(cwd);
|
|
@@ -71,29 +80,24 @@ export async function main() {
|
|
|
71
80
|
console.error(red(err.message));
|
|
72
81
|
process.exit(1);
|
|
73
82
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
JSON.stringify(fileJSON, undefined, 2)
|
|
90
|
-
)
|
|
91
|
-
break
|
|
83
|
+
if (projectName !== "minista-project" && !options.template.includes("/")) {
|
|
84
|
+
await Promise.all(POSTPROCESS_FILES.map(async (file) => {
|
|
85
|
+
const fileLoc = path.resolve(path.join(cwd, file));
|
|
86
|
+
if (fs.existsSync(fileLoc)) {
|
|
87
|
+
try {
|
|
88
|
+
replace.sync({
|
|
89
|
+
files: fileLoc,
|
|
90
|
+
from: /minista-project/g,
|
|
91
|
+
to: projectName,
|
|
92
|
+
});
|
|
93
|
+
//console.log("Replacement:", results)
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
console.error("Error occurred:", err);
|
|
97
|
+
}
|
|
92
98
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
)*/
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
97
101
|
console.log(bold(green("✔") + " Done!"));
|
|
98
102
|
console.log("\nNext steps:");
|
|
99
103
|
let i = 1;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-minista",
|
|
3
3
|
"description": "Scaffolding for minista projects",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-minista": "./cli.mjs"
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc",
|
|
44
44
|
"prepublishOnly": "npm run build",
|
|
45
|
+
"test": "cd test && node ../cli.mjs",
|
|
45
46
|
"clean": "trash ./dist"
|
|
46
47
|
},
|
|
47
48
|
"prettier": {
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"degit": "^2.8.4",
|
|
52
53
|
"kleur": "^4.1.4",
|
|
53
54
|
"prompts": "^2.4.2",
|
|
55
|
+
"replace-in-file": "^6.3.2",
|
|
54
56
|
"yargs-parser": "^21.0.1"
|
|
55
57
|
},
|
|
56
58
|
"devDependencies": {
|