create-middag-ui 0.10.2 → 0.10.3

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 (3) hide show
  1. package/cli.js +5 -1
  2. package/lib/scaffold.js +102 -11
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -28,6 +28,8 @@ import {
28
28
  scaffoldPackageJson,
29
29
  scaffoldTsconfig,
30
30
  scaffoldViteConfig,
31
+ scaffoldEslintConfig,
32
+ scaffoldPrettierConfig,
31
33
  scaffoldIndexHtml,
32
34
  scaffoldDemoFiles,
33
35
  scaffoldPageExamples,
@@ -117,6 +119,8 @@ heading(5, TOTAL_STEPS, "Scaffolding config files");
117
119
  scaffoldPackageJson(targetDir, host, cwd, registryPath);
118
120
  scaffoldTsconfig(targetDir);
119
121
  scaffoldViteConfig(targetDir, host, registryPath);
122
+ scaffoldEslintConfig(targetDir);
123
+ scaffoldPrettierConfig(targetDir);
120
124
  scaffoldIndexHtml(targetDir);
121
125
 
122
126
  // ── Step 6: Scaffold ~/.npmrc (GitHub path only) ─────────────────────────
@@ -145,7 +149,7 @@ scaffoldPageExamples(targetDir);
145
149
 
146
150
  if (isPro) {
147
151
  scaffoldProApp(targetDir);
148
- success("PRO: using MockProductShell + HostAdapter from @middag-io/react/mock");
152
+ success("PRO: using MockProductShell from @middag-io/react/mock");
149
153
  } else {
150
154
  scaffoldFreeAdapters(targetDir);
151
155
  scaffoldDevShell(targetDir);
package/lib/scaffold.js CHANGED
@@ -103,6 +103,8 @@ export function scaffoldPackageJson(targetDir, host, cwd, registryPath) {
103
103
  typecheck: "tsc --noEmit",
104
104
  lint: "eslint .",
105
105
  "lint:fix": "eslint . --fix",
106
+ format: 'prettier --write "src/**/*.{ts,tsx,css}"',
107
+ "format:check": 'prettier --check "src/**/*.{ts,tsx,css}"',
106
108
  },
107
109
  dependencies: deps,
108
110
  devDependencies: {
@@ -115,6 +117,14 @@ export function scaffoldPackageJson(targetDir, host, cwd, registryPath) {
115
117
  typescript: "^5.7.0",
116
118
  vite: "^6.0.0",
117
119
  "@vitejs/plugin-react": "^4.0.0",
120
+ "@eslint/js": "^9.0.0",
121
+ "typescript-eslint": "^8.0.0",
122
+ "eslint-plugin-react-hooks": "^5.0.0",
123
+ "eslint-plugin-react-refresh": "^0.5.0",
124
+ "eslint-config-prettier": "^10.0.0",
125
+ eslint: "^9.0.0",
126
+ prettier: "^3.0.0",
127
+ "prettier-plugin-tailwindcss": "^0.6.0",
118
128
  },
119
129
  };
120
130
 
@@ -157,16 +167,9 @@ export function scaffoldViteConfig(targetDir, host, registryPath) {
157
167
  const filePath = join(targetDir, "vite.config.ts");
158
168
  if (skipIfExists(filePath, "vite.config.ts")) return;
159
169
 
160
- const isPro = registryPath === "github";
161
- const adapterComment = isPro
162
- ? "// PRO: Inertia mocks from @middag-io/react/mock"
170
+ const adapterComment = registryPath === "github"
171
+ ? "// PRO: Inertia mocks re-exported from @middag-io/react/mock (same context)"
163
172
  : "// FREE: Inertia mocks from local adapters";
164
- const adapterReact = isPro
165
- ? 'resolve(__dirname, "node_modules/@middag-io/react/mock/adapters/inertia-react.ts")'
166
- : 'resolve(__dirname, "src/adapters/inertia-react.ts")';
167
- const adapterCore = isPro
168
- ? 'resolve(__dirname, "node_modules/@middag-io/react/mock/adapters/inertia-core.ts")'
169
- : 'resolve(__dirname, "src/adapters/inertia-core.ts")';
170
173
 
171
174
  const content = `/**
172
175
  * Vite config \u2014 used by \`npm run dev\` and \`npm run build\`.
@@ -186,8 +189,8 @@ export default defineConfig({
186
189
  alias: {
187
190
  "@/": resolve(__dirname, "src") + "/",
188
191
  ${adapterComment}
189
- "@inertiajs/react": ${adapterReact},
190
- "@inertiajs/core": ${adapterCore},
192
+ "@inertiajs/react": resolve(__dirname, "src/adapters/inertia-react.ts"),
193
+ "@inertiajs/core": resolve(__dirname, "src/adapters/inertia-core.ts"),
191
194
  },
192
195
  },
193
196
  });
@@ -196,6 +199,70 @@ export default defineConfig({
196
199
  writeFile(filePath, content, "vite.config.ts");
197
200
  }
198
201
 
202
+ /**
203
+ * Scaffold eslint.config.js.
204
+ */
205
+ export function scaffoldEslintConfig(targetDir) {
206
+ const filePath = join(targetDir, "eslint.config.js");
207
+ if (skipIfExists(filePath, "eslint.config.js")) return;
208
+
209
+ writeFile(
210
+ filePath,
211
+ `import js from "@eslint/js";
212
+ import tseslint from "typescript-eslint";
213
+ import reactHooks from "eslint-plugin-react-hooks";
214
+ import reactRefresh from "eslint-plugin-react-refresh";
215
+ import prettierConfig from "eslint-config-prettier";
216
+
217
+ export default tseslint.config(
218
+ { ignores: ["dist/", "node_modules/"] },
219
+ js.configs.recommended,
220
+ ...tseslint.configs.recommended,
221
+ {
222
+ files: ["**/*.{ts,tsx}"],
223
+ plugins: {
224
+ "react-hooks": reactHooks,
225
+ "react-refresh": reactRefresh,
226
+ },
227
+ rules: {
228
+ ...reactHooks.configs.recommended.rules,
229
+ "react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
230
+ "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
231
+ "@typescript-eslint/no-explicit-any": "warn",
232
+ },
233
+ },
234
+ prettierConfig,
235
+ );
236
+ `,
237
+ "eslint.config.js",
238
+ );
239
+ }
240
+
241
+ /**
242
+ * Scaffold .prettierrc.
243
+ */
244
+ export function scaffoldPrettierConfig(targetDir) {
245
+ const filePath = join(targetDir, ".prettierrc");
246
+ if (skipIfExists(filePath, ".prettierrc")) return;
247
+
248
+ writeFile(
249
+ filePath,
250
+ JSON.stringify(
251
+ {
252
+ semi: true,
253
+ singleQuote: false,
254
+ tabWidth: 2,
255
+ trailingComma: "all",
256
+ printWidth: 100,
257
+ plugins: ["prettier-plugin-tailwindcss"],
258
+ },
259
+ null,
260
+ 2,
261
+ ) + "\n",
262
+ ".prettierrc",
263
+ );
264
+ }
265
+
199
266
  /**
200
267
  * Scaffold index.html at project root.
201
268
  */
@@ -803,6 +870,30 @@ export const settingsContract: PageContract = {
803
870
  */
804
871
  export function scaffoldProApp(targetDir) {
805
872
  ensureDir(join(targetDir, "src"));
873
+ ensureDir(join(targetDir, "src", "adapters"));
874
+
875
+ // Inertia adapter shims — re-export from pre-built mock bundle
876
+ // so usePage() shares the same MockPageContext as MockPageProvider.
877
+ const adapterReactPath = join(targetDir, "src", "adapters", "inertia-react.ts");
878
+ if (!skipIfExists(adapterReactPath, "src/adapters/inertia-react.ts")) {
879
+ writeFile(adapterReactPath, `/**
880
+ * Mock @inertiajs/react — re-exports from pre-built @middag-io/react/mock.
881
+ *
882
+ * This ensures usePage() reads from the same MockPageContext as
883
+ * MockPageProvider (both live in the pre-built ESM bundle).
884
+ */
885
+ export { usePage, Head, Link, router } from "@middag-io/react/mock";
886
+ `, "src/adapters/inertia-react.ts");
887
+ }
888
+
889
+ const adapterCorePath = join(targetDir, "src", "adapters", "inertia-core.ts");
890
+ if (!skipIfExists(adapterCorePath, "src/adapters/inertia-core.ts")) {
891
+ writeFile(adapterCorePath, `/**
892
+ * Mock @inertiajs/core — re-exports from pre-built @middag-io/react/mock.
893
+ */
894
+ export { router, setMockNavigate } from "@middag-io/react/mock";
895
+ `, "src/adapters/inertia-core.ts");
896
+ }
806
897
 
807
898
  const mainPath = join(targetDir, "src", "main.tsx");
808
899
  if (!skipIfExists(mainPath, "src/main.tsx")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-middag-ui",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "type": "module",
5
5
  "description": "Bootstrap a MIDDAG React UI layer in your Moodle or WordPress plugin",
6
6
  "bin": {