create-minista 0.0.0 → 0.1.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/README.md CHANGED
@@ -1 +1,69 @@
1
- # create-minista
1
+ # create-minista
2
+
3
+ <p>
4
+ <a aria-label="Made by QRANOKO" href="https://qranoko.jp">
5
+ <img src="https://img.shields.io/badge/MADE%20BY%20QRANOKO-212121.svg?style=for-the-badge&labelColor=212121">
6
+ </a>
7
+ <a aria-label="NPM version" href="https://www.npmjs.com/package/create-minista">
8
+ <img alt="" src="https://img.shields.io/npm/v/create-minista.svg?style=for-the-badge&labelColor=212121">
9
+ </a>
10
+ <a aria-label="License" href="https://github.com/qrac/create-minista/blob/master/LICENSE">
11
+ <img alt="" src="https://img.shields.io/npm/l/create-minista.svg?style=for-the-badge&labelColor=212121">
12
+ </a>
13
+ </p>
14
+
15
+ ## About
16
+
17
+ minista プロジェクトをテンプレートからスタートできます。
18
+
19
+ ## How To Use
20
+
21
+ **NPM**
22
+
23
+ ```bash
24
+ npm init minista
25
+ ```
26
+
27
+ **Yarn**
28
+
29
+ ```bash
30
+ yarn create minista
31
+ ```
32
+
33
+ ```bash
34
+ # npm 6.x
35
+ npm init minista my-minista-project --template ts
36
+
37
+ # npm 7+, extra double-dash is needed:
38
+ npm init minista my-minista-project -- --template ts
39
+
40
+ # yarn
41
+ yarn create minista my-minista-project --template ts
42
+ ```
43
+
44
+ `--template` にはリポジトリの[Templates](https://github.com/qrac/create-minista/tree/main/templates)が使えます。
45
+
46
+ - `basic`: TypeScript・サイトマップ・Zip 圧縮等の納品基本セット
47
+ - `ts`: TypeScript の最小限構成
48
+ - `js`: JavaScript の最小限構成
49
+
50
+ テンプレートとして任意の GitHub リポジトリを使用することもできます。
51
+
52
+ ```bash
53
+ npm init minista my-minista-project -- --template qrac/minista-blog-with-rest-api
54
+ ```
55
+
56
+ ## Fork & Respect!!
57
+
58
+ - [astro/packages/create-astro at main · withastro/astro](https://github.com/withastro/astro/tree/main/packages/create-astro)
59
+ - [vite/packages/create-vite at main · vitejs/vite](https://github.com/vitejs/vite/tree/main/packages/create-vite)
60
+ - [vite/cli.ts at main · vitejs/vite](https://github.com/vitejs/vite/blob/main/packages/vite/src/node/cli.ts)
61
+
62
+ ## License
63
+
64
+ - MIT
65
+
66
+ ## Credit
67
+
68
+ - Author: [Qrac](https://qrac.jp)
69
+ - Organization: [QRANOKO](https://qranoko.jp)
package/cli.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ "use strict"
3
+ import("./dist/index.js").then(({ main }) => main())
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { bold, cyan, gray, green, red } from "kleur/colors";
4
+ import prompts from "prompts";
5
+ import degit from "degit";
6
+ import yargs from "yargs-parser";
7
+ import { TEMPLATES } from "./templates.js";
8
+ const cleanArgv = process.argv.filter((arg) => arg !== "--");
9
+ const args = yargs(cleanArgv);
10
+ prompts.override(args);
11
+ const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
12
+ //const POSTPROCESS_FILES = ["package.json", "project.json"]
13
+ export function mkdirp(dir) {
14
+ try {
15
+ fs.mkdirSync(dir, { recursive: true });
16
+ }
17
+ catch (e) {
18
+ if (e.code === "EEXIST")
19
+ return;
20
+ throw e;
21
+ }
22
+ }
23
+ export async function main() {
24
+ console.log(`\n${bold("create-minista")} ${gray(`(v${version})`)}`);
25
+ const cwd = args["_"][2] || ".";
26
+ if (fs.existsSync(cwd)) {
27
+ if (fs.readdirSync(cwd).length > 0) {
28
+ const response = await prompts({
29
+ type: "confirm",
30
+ name: "forceOverwrite",
31
+ message: "Directory not empty. Continue [force overwrite]?",
32
+ initial: false,
33
+ });
34
+ if (!response.forceOverwrite) {
35
+ process.exit(1);
36
+ }
37
+ mkdirp(cwd);
38
+ }
39
+ }
40
+ else {
41
+ mkdirp(cwd);
42
+ }
43
+ const options = await prompts([
44
+ {
45
+ type: "select",
46
+ name: "template",
47
+ message: "Which template would you like to use?",
48
+ choices: TEMPLATES,
49
+ },
50
+ ]);
51
+ if (!options.template) {
52
+ process.exit(1);
53
+ }
54
+ const hash = args.commit ? `#${args.commit}` : "";
55
+ const templateTarget = options.template.includes("/")
56
+ ? options.template
57
+ : `qrac/create-minista/templates/${options.template}`;
58
+ const emitter = degit(`${templateTarget}${hash}`, {
59
+ cache: false,
60
+ force: true,
61
+ verbose: false,
62
+ });
63
+ /*const selectedTemplate = TEMPLATES.find(
64
+ (template) => template.value === options.template
65
+ )*/
66
+ try {
67
+ console.log(`${green(`>`)} ${gray(`Copying project files...`)}`);
68
+ await emitter.clone(cwd);
69
+ }
70
+ catch (err) {
71
+ console.error(red(err.message));
72
+ process.exit(1);
73
+ }
74
+ /*await Promise.all(
75
+ POSTPROCESS_FILES.map(async (file) => {
76
+ const fileLoc = path.resolve(path.join(cwd, file))
77
+
78
+ if (fs.existsSync(fileLoc)) {
79
+ switch (file) {
80
+ case "package.json":
81
+ case "project.json": {
82
+ const fileJSON = JSON.parse(
83
+ await fs.promises.readFile(fileLoc, "utf8")
84
+ )
85
+ fileJSON.name = cwd
86
+
87
+ await fs.promises.writeFile(
88
+ fileLoc,
89
+ JSON.stringify(fileJSON, undefined, 2)
90
+ )
91
+ break
92
+ }
93
+ }
94
+ }
95
+ })
96
+ )*/
97
+ console.log(bold(green("✔") + " Done!"));
98
+ console.log("\nNext steps:");
99
+ let i = 1;
100
+ const relative = path.relative(process.cwd(), cwd);
101
+ if (relative !== "") {
102
+ console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
103
+ }
104
+ console.log(` ${i++}: ${bold(cyan("npm install"))} (or pnpm install, yarn, etc)`);
105
+ console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional step)`);
106
+ console.log(` ${i++}: ${bold(cyan("npm run dev"))} (or pnpm, yarn, etc)`);
107
+ console.log(`\nTo close the dev server, hit ${bold(cyan("Ctrl-C"))}`);
108
+ }
@@ -0,0 +1,14 @@
1
+ export const TEMPLATES = [
2
+ {
3
+ title: "Basic (Typescript)",
4
+ value: "basic",
5
+ },
6
+ {
7
+ title: "Typescript",
8
+ value: "ts",
9
+ },
10
+ {
11
+ title: "JavaScript",
12
+ value: "js",
13
+ },
14
+ ];
@@ -0,0 +1,2 @@
1
+ export declare function mkdirp(dir: string): void;
2
+ export declare function main(): Promise<void>;
@@ -0,0 +1,4 @@
1
+ export declare const TEMPLATES: {
2
+ title: string;
3
+ value: string;
4
+ }[];
package/package.json CHANGED
@@ -1,7 +1,36 @@
1
1
  {
2
2
  "name": "create-minista",
3
- "version": "0.0.0",
3
+ "description": "Scaffolding for minista projects",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-minista": "./cli.mjs"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "cli.js"
12
+ ],
4
13
  "license": "MIT",
14
+ "homepage": "https://github.com/qrac/create-minista",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/qrac/create-minista"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/qrac/create-minista/issues"
21
+ },
22
+ "keywords": [
23
+ "static-site-generator",
24
+ "ssg",
25
+ "coding",
26
+ "react",
27
+ "jsx",
28
+ "tsx",
29
+ "typescript",
30
+ "webpack",
31
+ "japanese",
32
+ "minista"
33
+ ],
5
34
  "author": {
6
35
  "name": "Qrac",
7
36
  "url": "https://qrac.jp"
@@ -9,5 +38,25 @@
9
38
  "organization": {
10
39
  "name": "QRANOKO",
11
40
  "url": "https://qranoko.jp"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "prepublishOnly": "npm run build",
45
+ "clean": "trash ./dist"
46
+ },
47
+ "prettier": {
48
+ "semi": false
49
+ },
50
+ "dependencies": {
51
+ "degit": "^2.8.4",
52
+ "kleur": "^4.1.4",
53
+ "prompts": "^2.4.2",
54
+ "yargs-parser": "^21.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "@types/degit": "^2.8.3",
58
+ "@types/prompts": "^2.0.14",
59
+ "@types/yargs-parser": "^20.2.1",
60
+ "typescript": "^4.5.4"
12
61
  }
13
62
  }