create-basicjs 0.0.1 → 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,5 +1,30 @@
1
1
  # create-basicjs
2
2
 
3
- Work in progress: this version only reserves the name.
3
+ Create a project with [basic.js](https://bug7a.github.io/basic.js/) and the JS-Component Kit, ready to build with AI tools.
4
4
 
5
- It will create a project with [basic.js](https://bug7a.github.io/basic.js/) and the JS-Component Kit, ready to build with AI tools.
5
+ ```sh
6
+ npm create basicjs@latest my-app
7
+ cd my-app
8
+ npx serve
9
+ ```
10
+
11
+ The project has everything in one folder: `index.htm`, your code in `app/`, and the library, components, examples and documents in `_basic/`. `AGENTS.md` and `CLAUDE.md` give the rules to AI coding tools, so you can open the folder in one and describe your app.
12
+
13
+ ## Templates
14
+
15
+ ```sh
16
+ npm create basicjs@latest my-shop -- --template shop
17
+ npm create basicjs@latest -- --list
18
+ ```
19
+
20
+ ## Tools in a project
21
+
22
+ | Command | What it does |
23
+ | :--- | :--- |
24
+ | `node _basic/tools/check.js` | Opens the app in Chrome or Edge at a phone and a desktop width and lists errors, missing files, and things that leave the screen or are cut |
25
+ | `node _basic/tools/build.js` | Makes the ready site in `dist/` |
26
+ | `npx create-basicjs@latest update` | Replaces only `_basic/` |
27
+
28
+ It needs Node.js 18 or newer. The app itself has no dependencies.
29
+
30
+ Documents: [Handbook](https://bug7a.github.io/basic.js-handbook/) · [Components](https://bug7a.github.io/js-components/)
@@ -1,4 +1,107 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
- console.log("create-basicjs is not ready yet. Follow it at https://github.com/bug7a/js-components");
4
+ // npm create basicjs@latest my-app
5
+ // npm create basicjs@latest my-app -- --template shop
6
+ // npx create-basicjs@latest update (in a project: replaces only _basic/)
7
+
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+
11
+ const PACKAGE = path.resolve(__dirname, "..");
12
+ const STARTER = path.join(PACKAGE, "payload", "starter");
13
+ const TEMPLATES = path.join(PACKAGE, "payload", "templates");
14
+ const VERSION = JSON.parse(fs.readFileSync(path.join(PACKAGE, "package.json"), "utf8")).version;
15
+ const DEFAULT_FOLDER = "my-app";
16
+
17
+ const HELP = `create-basicjs ${VERSION}
18
+
19
+ npm create basicjs@latest my-app a new project
20
+ npm create basicjs@latest my-app -- --template shop a project from a template
21
+ npm create basicjs@latest -- --list the templates
22
+ npx create-basicjs@latest update in a project: replaces only _basic/
23
+ `;
24
+
25
+ const stop = function (text) {
26
+ console.error(text);
27
+ process.exit(1);
28
+ };
29
+
30
+ const templateNames = function () {
31
+ return fs.readdirSync(TEMPLATES, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
32
+ };
33
+
34
+ const readArguments = function () {
35
+ const args = process.argv.slice(2);
36
+ const options = { command: "create", folder: "", template: "" };
37
+ for (let index = 0; index < args.length; index++) {
38
+ const arg = args[index];
39
+ if (arg === "--help" || arg === "-h") options.command = "help";
40
+ else if (arg === "--list") options.command = "list";
41
+ else if (arg === "--template" || arg === "-t") options.template = args[++index] || "";
42
+ else if (arg === "update" && !options.folder) options.command = "update";
43
+ else if (arg.startsWith("-")) stop("Unknown option: " + arg + "\n\n" + HELP);
44
+ else options.folder = arg;
45
+ }
46
+ return options;
47
+ };
48
+
49
+ const useProjectName = function (target, name) {
50
+ ["README.md", "index.htm"].forEach(function (fileName) {
51
+ const file = path.join(target, fileName);
52
+ if (!fs.existsSync(file)) return;
53
+ fs.writeFileSync(file, fs.readFileSync(file, "utf8").replace(/My App/g, name));
54
+ });
55
+ };
56
+
57
+ const addTemplate = function (target, name) {
58
+ const from = path.join(TEMPLATES, name);
59
+ if (!fs.existsSync(from)) stop('There is no template "' + name + '". The templates: ' + templateNames().join(", "));
60
+ fs.rmSync(path.join(target, "app"), { recursive: true, force: true });
61
+ fs.rmSync(path.join(target, "index.htm"), { force: true });
62
+ fs.cpSync(from, target, { recursive: true, force: true });
63
+ };
64
+
65
+ const create = function (options) {
66
+ const folder = options.folder || DEFAULT_FOLDER;
67
+ const target = path.resolve(folder);
68
+ if (fs.existsSync(target) && fs.readdirSync(target).length) stop(folder + " is not empty: choose another folder.");
69
+
70
+ fs.cpSync(STARTER, target, { recursive: true });
71
+ fs.renameSync(path.join(target, "gitignore"), path.join(target, ".gitignore")); // WHY: npm leaves a .gitignore out of a package
72
+ fs.mkdirSync(path.join(target, "assets"), { recursive: true });
73
+ if (options.template) addTemplate(target, options.template);
74
+ useProjectName(target, path.basename(target));
75
+
76
+ console.log("Ready: " + folder + (options.template ? " (template: " + options.template + ")" : ""));
77
+ console.log("\n cd " + folder + "\n npx serve\n");
78
+ console.log("Open the folder in an AI coding tool and describe your app. To publish: node _basic/tools/build.js");
79
+ };
80
+
81
+ const update = function () {
82
+ const basicFolder = path.resolve("_basic");
83
+ if (!fs.existsSync(basicFolder)) stop("There is no _basic folder here: run this in a project.");
84
+ const versionFile = path.join(basicFolder, "VERSION");
85
+ const oldVersion = fs.existsSync(versionFile) ? fs.readFileSync(versionFile, "utf8").trim() : "unknown";
86
+ if (oldVersion === VERSION) {
87
+ console.log("_basic/ is already " + VERSION + ".");
88
+ return;
89
+ }
90
+ const newFolder = basicFolder + "-new";
91
+ fs.rmSync(newFolder, { recursive: true, force: true });
92
+ fs.cpSync(path.join(STARTER, "_basic"), newFolder, { recursive: true });
93
+ fs.rmSync(basicFolder, { recursive: true, force: true });
94
+ fs.renameSync(newFolder, basicFolder);
95
+ console.log("_basic/ updated: " + oldVersion + " -> " + VERSION);
96
+ const agentsFile = path.resolve("AGENTS.md");
97
+ if (fs.existsSync(agentsFile) && fs.readFileSync(agentsFile, "utf8") !== fs.readFileSync(path.join(STARTER, "AGENTS.md"), "utf8")) {
98
+ console.log("AGENTS.md was not changed: yours is different from the one in this version.");
99
+ }
100
+ console.log("Check your app after an update: node _basic/tools/check.js");
101
+ };
102
+
103
+ const options = readArguments();
104
+ if (options.command === "help") console.log(HELP);
105
+ else if (options.command === "list") console.log(templateNames().join("\n"));
106
+ else if (options.command === "update") update();
107
+ else create(options);
package/package.json CHANGED
@@ -1,12 +1,30 @@
1
1
  {
2
2
  "name": "create-basicjs",
3
- "version": "0.0.1",
4
- "description": "Create a project with basic.js and the JS-Component Kit, ready to build with AI tools. Work in progress.",
5
- "bin": { "create-basicjs": "bin/create-basicjs.js" },
6
- "files": ["bin"],
7
- "keywords": ["basic.js", "basicjs", "create", "javascript", "ui", "components"],
3
+ "version": "0.1.0",
4
+ "description": "Create a project with basic.js and the JS-Component Kit, ready to build with AI tools.",
5
+ "bin": {
6
+ "create-basicjs": "bin/create-basicjs.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "payload"
11
+ ],
12
+ "keywords": [
13
+ "basic.js",
14
+ "basicjs",
15
+ "create",
16
+ "javascript",
17
+ "ui",
18
+ "components"
19
+ ],
8
20
  "license": "Apache-2.0",
9
21
  "author": "Bugra Ozden (https://bug7a.github.io/)",
10
22
  "homepage": "https://bug7a.github.io/basic.js/",
11
- "repository": { "type": "git", "url": "git+https://github.com/bug7a/js-components.git" }
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/bug7a/js-components.git"
26
+ },
27
+ "engines": {
28
+ "node": ">=18"
29
+ }
12
30
  }