@idomatic/create 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.
Files changed (2) hide show
  1. package/index.js +63 -0
  2. package/package.json +20 -0
package/index.js ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import prompts from "prompts";
4
+ import { execSync } from "child_process";
5
+ import { writeFileSync } from "fs";
6
+
7
+ console.log("✨ Welcome to idomatic setup!");
8
+
9
+ const res = await prompts([
10
+ {
11
+ type: "select",
12
+ name: "framework",
13
+ message: "Which framework are you using?",
14
+ choices: [
15
+ { title: "React (JS/TSX)", value: "js" },
16
+ { title: "HTML / Vue / Angular", value: "html" },
17
+ ],
18
+ },
19
+ {
20
+ type: "toggle",
21
+ name: "installParsers",
22
+ message: "Install the correct parser for your project?",
23
+ initial: true,
24
+ active: "yes",
25
+ inactive: "no",
26
+ },
27
+ ]);
28
+
29
+ // Create .idsrc.json
30
+ const config = {
31
+ prefix: "auto-id-",
32
+ skipTags: [],
33
+ extensions:
34
+ res.framework === "js"
35
+ ? ["js", "jsx", "ts", "tsx"]
36
+ : ["html", "vue", "ng.html"],
37
+ };
38
+
39
+ writeFileSync(".idsrc.json", JSON.stringify(config, null, 2));
40
+ console.log("✅ .idsrc.json created");
41
+
42
+ // Detect package manager
43
+ const agent = process.env.npm_config_user_agent || "";
44
+ let pkg = "npm";
45
+ if (agent.includes("yarn")) pkg = "yarn";
46
+ else if (agent.includes("bun")) pkg = "bun";
47
+
48
+ // Install parser
49
+ if (res.installParsers) {
50
+ const parser =
51
+ res.framework === "js" ? "@idomatic/parser-js" : "@idomatic/parser-html";
52
+
53
+ const installCmd = {
54
+ npm: `npm install ${parser}`,
55
+ yarn: `yarn add ${parser}`,
56
+ bun: `bun add ${parser}`,
57
+ }[pkg];
58
+
59
+ console.log(`📦 Installing ${parser} with ${pkg}...`);
60
+ execSync(installCmd, { stdio: "inherit" });
61
+ }
62
+
63
+ console.log("🎉 You're ready to run: npx idomatic --init-scan");
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@idomatic/create",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "create": "./index.js"
7
+ },
8
+ "keywords": [
9
+ "idomatic",
10
+ "init",
11
+ "create",
12
+ "ids",
13
+ "precommit"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "Amar Smajlovic",
17
+ "dependencies": {
18
+ "prompts": "^2.4.2"
19
+ }
20
+ }