@treelocator/init 0.1.4 → 0.1.6

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/dist/index.js +61 -11
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -49,9 +49,26 @@ function detectProject() {
49
49
  info.framework = "svelte";
50
50
  } else if (deps.preact) {
51
51
  info.framework = "preact";
52
- } else if (deps["solid-js"]) {
52
+ } else if (deps["solid-js"] || deps["vite-plugin-solid"]) {
53
53
  info.framework = "solid";
54
54
  }
55
+ if (info.buildTool === "vite" && info.configFile) {
56
+ try {
57
+ const viteConfig = fs.readFileSync(info.configFile, "utf-8");
58
+ if (viteConfig.includes("vite-plugin-solid") || viteConfig.includes("solidPlugin")) {
59
+ info.framework = "solid";
60
+ } else if (viteConfig.includes("@vitejs/plugin-react") || viteConfig.includes("react()")) {
61
+ info.framework = "react";
62
+ } else if (viteConfig.includes("@vitejs/plugin-vue") || viteConfig.includes("vue()")) {
63
+ info.framework = "vue";
64
+ } else if (viteConfig.includes("@sveltejs/vite-plugin-svelte") || viteConfig.includes("svelte()")) {
65
+ info.framework = "svelte";
66
+ } else if (viteConfig.includes("@preact/preset-vite") || viteConfig.includes("preact()")) {
67
+ info.framework = "preact";
68
+ }
69
+ } catch {
70
+ }
71
+ }
55
72
  const entryPaths = [
56
73
  "src/main.tsx",
57
74
  "src/main.ts",
@@ -95,6 +112,11 @@ function updateViteConfig(configFile, framework) {
95
112
  console.log(pc.yellow("TreeLocatorJS babel plugin already configured in vite.config"));
96
113
  return;
97
114
  }
115
+ const babelConfig = `babel: {
116
+ plugins: [
117
+ ["@locator/babel-jsx/dist", { env: "development" }],
118
+ ],
119
+ }`;
98
120
  if (framework === "react") {
99
121
  const reactPluginRegex = /react\(\s*\)/;
100
122
  const reactPluginWithOptionsRegex = /react\(\s*\{/;
@@ -102,22 +124,50 @@ function updateViteConfig(configFile, framework) {
102
124
  content = content.replace(
103
125
  reactPluginRegex,
104
126
  `react({
105
- babel: {
106
- plugins: [
107
- ["@locator/babel-jsx/dist", { env: "development" }],
108
- ],
109
- },
127
+ ${babelConfig},
110
128
  })`
111
129
  );
112
130
  } else if (reactPluginWithOptionsRegex.test(content)) {
113
131
  content = content.replace(
114
132
  /react\(\s*\{/,
115
133
  `react({
116
- babel: {
117
- plugins: [
118
- ["@locator/babel-jsx/dist", { env: "development" }],
119
- ],
120
- },`
134
+ ${babelConfig},`
135
+ );
136
+ }
137
+ }
138
+ if (framework === "solid") {
139
+ const solidPluginRegex = /solidPlugin\(\s*\)/;
140
+ const solidPluginWithOptionsRegex = /solidPlugin\(\s*\{/;
141
+ if (solidPluginRegex.test(content)) {
142
+ content = content.replace(
143
+ solidPluginRegex,
144
+ `solidPlugin({
145
+ ${babelConfig},
146
+ })`
147
+ );
148
+ } else if (solidPluginWithOptionsRegex.test(content)) {
149
+ content = content.replace(
150
+ /solidPlugin\(\s*\{/,
151
+ `solidPlugin({
152
+ ${babelConfig},`
153
+ );
154
+ }
155
+ }
156
+ if (framework === "preact") {
157
+ const preactPluginRegex = /preact\(\s*\)/;
158
+ const preactPluginWithOptionsRegex = /preact\(\s*\{/;
159
+ if (preactPluginRegex.test(content)) {
160
+ content = content.replace(
161
+ preactPluginRegex,
162
+ `preact({
163
+ ${babelConfig},
164
+ })`
165
+ );
166
+ } else if (preactPluginWithOptionsRegex.test(content)) {
167
+ content = content.replace(
168
+ /preact\(\s*\{/,
169
+ `preact({
170
+ ${babelConfig},`
121
171
  );
122
172
  }
123
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treelocator/init",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Setup wizard for TreeLocatorJS - auto-configure component ancestry tracking",
5
5
  "bin": {
6
6
  "treelocatorjs": "./dist/index.js",
@@ -48,5 +48,5 @@
48
48
  "component-ancestry"
49
49
  ],
50
50
  "license": "MIT",
51
- "gitHead": "a36be153e103505d6814e0d8b5c3a5cb17c1df0c"
51
+ "gitHead": "d2ab8db8032c185681da7d9a667e13105a1b0db4"
52
52
  }