create-minista 2.8.2 → 3.0.0-alpha.32

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/README.md CHANGED
@@ -20,29 +20,16 @@
20
20
 
21
21
  ```bash
22
22
  # Interactive
23
- $ npm init minista@latest
23
+ $ npm create minista@latest
24
24
 
25
25
  # Shortcut
26
- $ npm init minista@latest my-minista-project -- --template ts
26
+ $ npm create minista@latest my-minista-project -- --template minimal-ts
27
27
  ```
28
28
 
29
- | テンプレート | 内容 |
30
- | ------------ | ------------------------------------------------------------------------- |
31
- | `basic` | 静的サイト制作用 / 基本のコンポーネント構成(TypeScript) |
32
- | `basic-saas` | SaaS テンプレート制作用 / 納品用の目次, 納品用 Zip コマンド(TypeScript) |
33
- | `ts` | TypeScript を使った最低限の構成 |
34
- | `js` | JavaScript を使った最低限の構成 |
35
-
36
- ```bash
37
- # You can also use any GitHub repository
38
- npm init minista my-minista-project -- --template qrac/minista-blog-with-rest-api
39
- ```
40
-
41
- ## Fork & Respect
42
-
43
- - [astro/packages/create-astro at main · withastro/astro](https://github.com/withastro/astro/tree/main/packages/create-astro)
44
- - [vite/packages/create-vite at main · vitejs/vite](https://github.com/vitejs/vite/tree/main/packages/create-vite)
45
- - [vite/cli.ts at main · vitejs/vite](https://github.com/vitejs/vite/blob/main/packages/vite/src/node/cli.ts)
29
+ | テンプレート | 内容 |
30
+ | ------------ | ------------------------------- |
31
+ | `minimal-js` | JavaScript を使った最低限の構成 |
32
+ | `minimal-ts` | TypeScript を使った最低限の構成 |
46
33
 
47
34
  ## License
48
35
 
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ "use strict"
3
+
4
+ import("../dist/index.js")
package/dist/index.js CHANGED
@@ -1,112 +1,99 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { bold, cyan, gray, green, red, reset } from "kleur/colors";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import pc from "picocolors";
4
+ import { cac } from "cac";
4
5
  import prompts from "prompts";
5
6
  import degit from "degit";
6
- import yargs from "yargs-parser";
7
- import replace from "replace-in-file";
8
- import { TEMPLATES } from "./templates.js";
9
- const cleanArgv = process.argv.filter((arg) => arg !== "--");
10
- const args = yargs(cleanArgv);
11
- prompts.override(args);
12
- const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
13
- const POSTPROCESS_FILES = ["package.json", "project.json", "README.md"];
14
- export function mkdirp(dir) {
15
- try {
16
- fs.mkdirSync(dir, { recursive: true });
17
- }
18
- catch (e) {
19
- if (e.code === "EEXIST")
20
- return;
21
- throw e;
22
- }
7
+ const TEMPLATES = [
8
+ {
9
+ title: "Minimal (JavaScript)",
10
+ value: "minimal-js"
11
+ },
12
+ {
13
+ title: "Minimal (Typescript)",
14
+ value: "minimal-ts"
15
+ }
16
+ ];
17
+ function pkgVersion() {
18
+ const pkgURL = new URL("../package.json", import.meta.url);
19
+ const pkg = JSON.parse(fs.readFileSync(pkgURL, "utf8"));
20
+ return pkg.version;
23
21
  }
24
- export async function main() {
25
- console.log(`\n${bold("create-minista")} ${gray(`(v${version})`)}`);
26
- const cwd = args["_"][2] || ".";
27
- const defaultProjectName = cwd === "." ? "minista-project" : cwd;
28
- const officialTemplatesPath = "qrac/create-minista/templates";
29
- if (fs.existsSync(cwd)) {
30
- if (fs.readdirSync(cwd).length > 0) {
31
- const response = await prompts({
32
- type: "confirm",
33
- name: "forceOverwrite",
34
- message: "Directory not empty. Continue [force overwrite]?",
35
- initial: false,
36
- });
37
- if (!response.forceOverwrite) {
38
- process.exit(1);
39
- }
40
- mkdirp(cwd);
41
- }
42
- }
43
- else {
44
- mkdirp(cwd);
45
- }
46
- const options = await prompts([
47
- {
48
- type: "text",
49
- name: "projectName",
50
- message: reset("Project name (in the file):"),
51
- initial: defaultProjectName,
52
- },
53
- {
54
- type: "select",
55
- name: "template",
56
- message: "Which template would you like to use?",
57
- choices: TEMPLATES,
58
- },
59
- ]);
60
- if (!options.template) {
61
- process.exit(1);
62
- }
63
- const projectName = options.projectName
64
- ? options.projectName
65
- : defaultProjectName;
66
- const hash = args.commit ? `#${args.commit}` : "";
67
- const templateTarget = options.template.includes("/")
68
- ? options.template
69
- : `${officialTemplatesPath}/${options.template}`;
70
- const emitter = degit(`${templateTarget}${hash}`, {
71
- cache: false,
72
- force: true,
73
- verbose: false,
74
- });
75
- try {
76
- console.log(`${green(`>`)} ${gray(`Copying project files...`)}`);
77
- await emitter.clone(cwd);
22
+ function mkdirp(dir) {
23
+ try {
24
+ fs.mkdirSync(dir, { recursive: true });
25
+ } catch (e) {
26
+ if (e.code === "EEXIST")
27
+ return;
28
+ throw e;
29
+ }
30
+ }
31
+ async function main(root, options) {
32
+ console.log(`
33
+ ${pc.bold("create-minista")} ${pc.gray(`(v${pkgVersion()})`)}`);
34
+ const cwd = root || ".";
35
+ const current = cwd === ".";
36
+ const repo = "qrac/minista/packages/create-minista/templates";
37
+ const template = options.template || "";
38
+ const tag = options.tag ? "#" + options.tag : "";
39
+ const questions = {
40
+ overwrite: {
41
+ type: "confirm",
42
+ name: "overwrite",
43
+ message: "Directory not empty. Continue [force overwrite]?",
44
+ initial: false
45
+ },
46
+ template: {
47
+ type: "select",
48
+ name: "template",
49
+ message: "Which template would you like to use?",
50
+ choices: TEMPLATES
78
51
  }
79
- catch (err) {
80
- console.error(red(err.message));
52
+ };
53
+ if (fs.existsSync(cwd)) {
54
+ if (fs.readdirSync(cwd).length > 0) {
55
+ const { overwrite } = await prompts(questions.overwrite);
56
+ if (!overwrite) {
81
57
  process.exit(1);
58
+ }
59
+ !current && mkdirp(cwd);
82
60
  }
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
- }
98
- }
99
- }));
100
- }
101
- console.log(bold(green("✔") + " Done!"));
102
- console.log("\nNext steps:");
103
- let i = 1;
104
- const relative = path.relative(process.cwd(), cwd);
105
- if (relative !== "") {
106
- console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
107
- }
108
- console.log(` ${i++}: ${bold(cyan("npm install"))} (or pnpm install, yarn, etc)`);
109
- console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`);
110
- console.log(` ${i++}: ${bold(cyan("npm run dev"))} (or pnpm, yarn, etc)`);
111
- console.log(`\nTo close the dev server, hit ${bold(cyan("Ctrl-C"))}`);
61
+ } else {
62
+ !current && mkdirp(cwd);
63
+ }
64
+ const configs = {
65
+ ...template ? { template } : await prompts(questions.template)
66
+ };
67
+ const target = `${path.join(repo, configs.template)}${tag}`;
68
+ const emitter = degit(target, { cache: false, force: true, verbose: false });
69
+ try {
70
+ console.log(`${pc.green(`>`)} ${pc.gray(`Copying project files...`)}`);
71
+ await emitter.clone(cwd);
72
+ } catch (err) {
73
+ console.error(pc.red(err.message));
74
+ process.exit(1);
75
+ }
76
+ console.log(pc.bold(pc.green("\u2714") + " Done!"));
77
+ console.log("\nNext steps:");
78
+ let step = 1;
79
+ const relative = path.relative(process.cwd(), cwd);
80
+ if (relative !== "") {
81
+ console.log(` ${step++}: ${pc.bold(pc.cyan(`cd ${relative}`))}`);
82
+ }
83
+ console.log(` ${step++}: ${pc.bold(pc.cyan("npm install"))}`);
84
+ console.log(` ${step++}: ${pc.bold(pc.cyan("npm run dev"))}`);
85
+ console.log(`
86
+ To close the dev server, hit ${pc.bold(pc.cyan("Ctrl + C"))}`);
112
87
  }
88
+ const cli = cac("create-minista");
89
+ cli.command("[root]", "Scaffolding for minista projects").option("--template <template>", "[string] template direcroty").option("--tag <tag>", "[string] branch | tag | hash").action(async (root, options) => {
90
+ try {
91
+ await main(root, options);
92
+ } catch (err) {
93
+ console.log(err);
94
+ process.exit(1);
95
+ }
96
+ });
97
+ cli.help();
98
+ cli.version(pkgVersion());
99
+ cli.parse();
@@ -1,2 +1 @@
1
- export declare function mkdirp(dir: string): void;
2
- export declare function main(): Promise<void>;
1
+ export {};
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
2
  "name": "create-minista",
3
3
  "description": "Scaffolding for minista projects",
4
- "version": "2.8.2",
4
+ "version": "3.0.0-alpha.32",
5
5
  "type": "module",
6
6
  "bin": {
7
- "create-minista": "./cli.mjs"
7
+ "create-minista": "./bin/create-minista.js"
8
8
  },
9
9
  "files": [
10
10
  "dist",
11
11
  "cli.js"
12
12
  ],
13
13
  "license": "MIT",
14
- "homepage": "https://github.com/qrac/create-minista",
14
+ "homepage": "https://minista.qranoko.jp",
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://github.com/qrac/create-minista"
17
+ "url": "https://github.com/qrac/minista",
18
+ "directory": "packages/create-minista"
18
19
  },
19
20
  "bugs": {
20
- "url": "https://github.com/qrac/create-minista/issues"
21
+ "url": "https://github.com/qrac/minista/issues"
21
22
  },
22
23
  "keywords": [
23
24
  "static-site-generator",
@@ -27,7 +28,8 @@
27
28
  "jsx",
28
29
  "tsx",
29
30
  "typescript",
30
- "webpack",
31
+ "esbuild",
32
+ "vite",
31
33
  "japanese",
32
34
  "minista"
33
35
  ],
@@ -40,25 +42,16 @@
40
42
  "url": "https://qranoko.jp"
41
43
  },
42
44
  "scripts": {
43
- "build": "tsc",
44
- "prepublishOnly": "npm run build",
45
- "test": "cd test && node ../cli.mjs",
46
- "clean": "trash ./dist"
47
- },
48
- "prettier": {
49
- "semi": false
45
+ "build": "npm run clean && npm run build:src && npm run build:type",
46
+ "build:src": "tsx ../../scripts/build-sources.ts",
47
+ "build:type": "tsc",
48
+ "clean": "rimraf ./dist",
49
+ "prepublishOnly": "npm run clean && npm run build"
50
50
  },
51
51
  "dependencies": {
52
+ "cac": "^6.7.14",
52
53
  "degit": "^2.8.4",
53
- "kleur": "^4.1.4",
54
- "prompts": "^2.4.2",
55
- "replace-in-file": "^6.3.2",
56
- "yargs-parser": "^21.0.1"
57
- },
58
- "devDependencies": {
59
- "@types/degit": "^2.8.3",
60
- "@types/prompts": "^2.0.14",
61
- "@types/yargs-parser": "^21.0.0",
62
- "typescript": "^4.6.4"
54
+ "picocolors": "^1.0.0",
55
+ "prompts": "^2.4.2"
63
56
  }
64
57
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Qrac
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/cli.mjs DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict"
3
- import("./dist/index.js").then(({ main }) => main())
package/dist/templates.js DELETED
@@ -1,18 +0,0 @@
1
- export const TEMPLATES = [
2
- {
3
- title: "Basic Site (Typescript)",
4
- value: "basic",
5
- },
6
- {
7
- title: "SaaS Template (Typescript)",
8
- value: "basic-saas",
9
- },
10
- {
11
- title: "Minimal (Typescript)",
12
- value: "ts",
13
- },
14
- {
15
- title: "Minimal (JavaScript)",
16
- value: "js",
17
- },
18
- ];
@@ -1,4 +0,0 @@
1
- export declare const TEMPLATES: {
2
- title: string;
3
- value: string;
4
- }[];