@tanstack/cta-engine 0.14.3 → 0.14.4
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/dist/add-ons.js +5 -91
- package/dist/add-to-app.js +171 -0
- package/dist/config-file.js +34 -11
- package/dist/constants.js +0 -2
- package/dist/create-app.js +142 -451
- package/dist/custom-add-ons/add-on.js +175 -0
- package/dist/custom-add-ons/shared.js +116 -0
- package/dist/custom-add-ons/starter.js +84 -0
- package/dist/environment.js +67 -44
- package/dist/file-helpers.js +165 -0
- package/dist/frameworks.js +92 -0
- package/dist/index.js +18 -1
- package/dist/integrations/git.js +4 -0
- package/dist/integrations/shadcn.js +33 -0
- package/dist/options.js +9 -333
- package/dist/package-json.js +48 -0
- package/dist/package-manager.js +51 -6
- package/dist/registry.js +56 -0
- package/dist/special-steps/index.js +24 -0
- package/dist/special-steps/rimraf-node-modules.js +16 -0
- package/dist/template-file.js +112 -0
- package/dist/types/add-ons.d.ts +3 -8
- package/dist/types/add-to-app.d.ts +17 -0
- package/dist/types/config-file.d.ts +7 -4
- package/dist/types/constants.d.ts +0 -3
- package/dist/types/create-app.d.ts +1 -7
- package/dist/types/custom-add-ons/add-on.d.ts +69 -0
- package/dist/types/custom-add-ons/shared.d.ts +15 -0
- package/dist/types/custom-add-ons/starter.d.ts +7 -0
- package/dist/types/environment.d.ts +2 -1
- package/dist/types/file-helpers.d.ts +15 -0
- package/dist/types/frameworks.d.ts +7 -0
- package/dist/types/index.d.ts +21 -1
- package/dist/types/integrations/git.d.ts +2 -0
- package/dist/types/integrations/shadcn.d.ts +2 -0
- package/dist/types/options.d.ts +2 -6
- package/dist/types/package-json.d.ts +7 -0
- package/dist/types/package-manager.d.ts +18 -1
- package/dist/types/registry.d.ts +25 -0
- package/dist/types/special-steps/index.d.ts +2 -0
- package/dist/types/special-steps/rimraf-node-modules.d.ts +2 -0
- package/dist/types/template-file.d.ts +2 -0
- package/dist/types/types.d.ts +788 -85
- package/dist/types/utils.d.ts +5 -0
- package/dist/types.js +65 -1
- package/dist/utils.js +9 -0
- package/package.json +9 -12
- package/src/add-ons.ts +7 -123
- package/src/add-to-app.ts +276 -0
- package/src/config-file.ts +51 -20
- package/src/constants.ts +0 -5
- package/src/create-app.ts +180 -730
- package/src/custom-add-ons/add-on.ts +261 -0
- package/src/custom-add-ons/shared.ts +160 -0
- package/src/custom-add-ons/starter.ts +126 -0
- package/src/environment.ts +80 -45
- package/src/file-helpers.ts +235 -0
- package/src/frameworks.ts +134 -0
- package/src/index.ts +85 -1
- package/src/integrations/git.ts +7 -0
- package/src/integrations/shadcn.ts +54 -0
- package/src/options.ts +8 -409
- package/src/package-json.ts +69 -0
- package/src/package-manager.ts +80 -9
- package/src/registry.ts +92 -0
- package/src/special-steps/index.ts +36 -0
- package/src/special-steps/rimraf-node-modules.ts +25 -0
- package/src/template-file.ts +150 -0
- package/src/types.ts +175 -87
- package/src/utils.ts +17 -0
- package/tests/add-ons.test.ts +67 -0
- package/tests/add-to-app.test.ts +358 -0
- package/tests/config-file.test.ts +105 -0
- package/tests/create-app.test.ts +120 -0
- package/tests/custom-add-ons/add-on.test.ts +12 -0
- package/tests/custom-add-ons/shared.test.ts +253 -0
- package/tests/custom-add-ons/starter.test.ts +58 -0
- package/tests/environment.test.ts +115 -0
- package/tests/file-helper.test.ts +90 -0
- package/tests/frameworks.test.ts +95 -0
- package/tests/index.test.ts +9 -0
- package/tests/integrations/git.test.ts +20 -0
- package/tests/integrations/shadcn.test.ts +91 -0
- package/tests/options.test.ts +42 -0
- package/tests/package-json.test.ts +63 -0
- package/tests/package-manager.test.ts +154 -0
- package/tests/setupVitest.ts +6 -0
- package/tests/template-file.test.ts +178 -0
- package/tests/utils.test.ts +23 -0
- package/vitest.config.ts +21 -0
- package/dist/add.js +0 -125
- package/dist/cli.js +0 -132
- package/dist/custom-add-on.js +0 -254
- package/dist/file-helper.js +0 -18
- package/dist/mcp.js +0 -229
- package/dist/templates.js +0 -6
- package/dist/toolchain.js +0 -6
- package/dist/types/add.d.ts +0 -3
- package/dist/types/cli.d.ts +0 -7
- package/dist/types/custom-add-on.d.ts +0 -3
- package/dist/types/file-helper.d.ts +0 -2
- package/dist/types/mcp.d.ts +0 -7
- package/dist/types/templates.d.ts +0 -1
- package/dist/types/toolchain.d.ts +0 -3
- package/src/add.ts +0 -186
- package/src/cli.ts +0 -210
- package/src/custom-add-on.ts +0 -325
- package/src/file-helper.ts +0 -20
- package/src/mcp.ts +0 -302
- package/src/templates.ts +0 -7
- package/src/toolchain.ts +0 -7
- package/templates/react/add-on/clerk/README.md +0 -3
- package/templates/react/add-on/clerk/assets/_dot_env.local.append +0 -2
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/header-user.tsx +0 -19
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/provider.tsx +0 -18
- package/templates/react/add-on/clerk/assets/src/routes/demo.clerk.tsx +0 -20
- package/templates/react/add-on/clerk/info.json +0 -13
- package/templates/react/add-on/clerk/package.json +0 -5
- package/templates/react/add-on/convex/README.md +0 -4
- package/templates/react/add-on/convex/assets/_dot_cursorrules.append +0 -93
- package/templates/react/add-on/convex/assets/_dot_env.local.append +0 -3
- package/templates/react/add-on/convex/assets/convex/products.ts +0 -8
- package/templates/react/add-on/convex/assets/convex/schema.ts +0 -10
- package/templates/react/add-on/convex/assets/src/integrations/convex/provider.tsx +0 -20
- package/templates/react/add-on/convex/assets/src/routes/demo.convex.tsx +0 -33
- package/templates/react/add-on/convex/info.json +0 -13
- package/templates/react/add-on/convex/package.json +0 -6
- package/templates/react/add-on/form/assets/src/components/demo.FormComponents.tsx.ejs +0 -300
- package/templates/react/add-on/form/assets/src/hooks/demo.form-context.ts +0 -4
- package/templates/react/add-on/form/assets/src/hooks/demo.form.ts +0 -22
- package/templates/react/add-on/form/assets/src/routes/demo.form.address.tsx.ejs +0 -213
- package/templates/react/add-on/form/assets/src/routes/demo.form.simple.tsx.ejs +0 -77
- package/templates/react/add-on/form/info.json +0 -26
- package/templates/react/add-on/form/package.json +0 -6
- package/templates/react/add-on/module-federation/assets/module-federation.config.js.ejs +0 -31
- package/templates/react/add-on/module-federation/assets/src/demo-mf-component.tsx +0 -3
- package/templates/react/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +0 -11
- package/templates/react/add-on/module-federation/info.json +0 -7
- package/templates/react/add-on/module-federation/package.json +0 -5
- package/templates/react/add-on/netlify/README.md +0 -11
- package/templates/react/add-on/netlify/info.json +0 -7
- package/templates/react/add-on/sentry/assets/_dot_cursorrules.append +0 -22
- package/templates/react/add-on/sentry/assets/_dot_env.local.append +0 -11
- package/templates/react/add-on/sentry/assets/src/app/global-middleware.ts +0 -11
- package/templates/react/add-on/sentry/assets/src/routes/demo.sentry.testing.tsx +0 -489
- package/templates/react/add-on/sentry/info.json +0 -14
- package/templates/react/add-on/sentry/package.json +0 -5
- package/templates/react/add-on/shadcn/README.md +0 -7
- package/templates/react/add-on/shadcn/assets/_dot_cursorrules.append +0 -7
- package/templates/react/add-on/shadcn/assets/components.json +0 -21
- package/templates/react/add-on/shadcn/assets/src/lib/utils.ts +0 -6
- package/templates/react/add-on/shadcn/assets/src/styles.css +0 -138
- package/templates/react/add-on/shadcn/info.json +0 -7
- package/templates/react/add-on/shadcn/package.json +0 -9
- package/templates/react/add-on/start/assets/_dot_gitignore.append +0 -2
- package/templates/react/add-on/start/assets/app.config.ts.ejs +0 -32
- package/templates/react/add-on/start/assets/src/api.ts +0 -6
- package/templates/react/add-on/start/assets/src/client.tsx.ejs +0 -33
- package/templates/react/add-on/start/assets/src/router.tsx.ejs +0 -48
- package/templates/react/add-on/start/assets/src/routes/api.demo-names.ts +0 -11
- package/templates/react/add-on/start/assets/src/routes/demo.start.api-request.tsx.ejs +0 -33
- package/templates/react/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +0 -50
- package/templates/react/add-on/start/assets/src/ssr.tsx.ejs +0 -30
- package/templates/react/add-on/start/info.json +0 -18
- package/templates/react/add-on/start/package.json +0 -13
- package/templates/react/add-on/store/assets/src/lib/demo-store.ts +0 -13
- package/templates/react/add-on/store/assets/src/routes/demo.store.tsx.ejs +0 -75
- package/templates/react/add-on/store/info.json +0 -13
- package/templates/react/add-on/store/package.json +0 -6
- package/templates/react/add-on/t3env/README.md +0 -16
- package/templates/react/add-on/t3env/assets/src/env.ts +0 -39
- package/templates/react/add-on/t3env/info.json +0 -10
- package/templates/react/add-on/t3env/package.json +0 -6
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/init.ts +0 -9
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/react.ts +0 -4
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/router.ts +0 -18
- package/templates/react/add-on/tRPC/assets/src/routes/api.trpc.$.tsx +0 -16
- package/templates/react/add-on/tRPC/info.json +0 -9
- package/templates/react/add-on/tRPC/package.json +0 -9
- package/templates/react/add-on/table/assets/src/data/demo-table-data.ts +0 -50
- package/templates/react/add-on/table/assets/src/routes/demo.table.tsx.ejs +0 -373
- package/templates/react/add-on/table/info.json +0 -13
- package/templates/react/add-on/table/package.json +0 -7
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/layout.tsx +0 -5
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +0 -70
- package/templates/react/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx.ejs +0 -53
- package/templates/react/add-on/tanstack-query/info.json +0 -13
- package/templates/react/add-on/tanstack-query/package.json +0 -6
- package/templates/react/base/README.md.ejs +0 -558
- package/templates/react/base/_dot_gitignore +0 -5
- package/templates/react/base/_dot_vscode/settings.biome.json +0 -38
- package/templates/react/base/_dot_vscode/settings.json +0 -11
- package/templates/react/base/index.html.ejs +0 -20
- package/templates/react/base/package.biome.json +0 -10
- package/templates/react/base/package.eslintprettier.json +0 -11
- package/templates/react/base/package.json +0 -30
- package/templates/react/base/package.ts.json +0 -7
- package/templates/react/base/package.tw.json +0 -6
- package/templates/react/base/public/favicon.ico +0 -0
- package/templates/react/base/public/logo192.png +0 -0
- package/templates/react/base/public/logo512.png +0 -0
- package/templates/react/base/public/manifest.json +0 -25
- package/templates/react/base/public/robots.txt +0 -3
- package/templates/react/base/src/App.css +0 -38
- package/templates/react/base/src/App.test.tsx.ejs +0 -10
- package/templates/react/base/src/App.tsx.ejs +0 -74
- package/templates/react/base/src/components/Header.tsx.ejs +0 -27
- package/templates/react/base/src/logo.svg +0 -44
- package/templates/react/base/src/reportWebVitals.ts.ejs +0 -28
- package/templates/react/base/src/styles.css.ejs +0 -15
- package/templates/react/base/toolchain/.prettierignore +0 -3
- package/templates/react/base/toolchain/biome.json +0 -31
- package/templates/react/base/toolchain/eslint.config.js +0 -5
- package/templates/react/base/toolchain/prettier.config.js +0 -10
- package/templates/react/base/tsconfig.json.ejs +0 -29
- package/templates/react/base/vite.config.js.ejs +0 -23
- package/templates/react/code-router/src/main.tsx.ejs +0 -92
- package/templates/react/example/tanchat/README.md +0 -37
- package/templates/react/example/tanchat/assets/_dot_env.local.append +0 -2
- package/templates/react/example/tanchat/assets/public/example-guitar-flowers.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-motherboard.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-racing.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-steamer-trunk.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-superhero.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-traveling.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-video-games.jpg +0 -0
- package/templates/react/example/tanchat/assets/src/components/example-AIAssistant.tsx +0 -173
- package/templates/react/example/tanchat/assets/src/components/example-GuitarRecommendation.tsx +0 -47
- package/templates/react/example/tanchat/assets/src/data/example-guitars.ts +0 -83
- package/templates/react/example/tanchat/assets/src/demo.index.css +0 -220
- package/templates/react/example/tanchat/assets/src/integrations/tanchat/header-user.tsx +0 -5
- package/templates/react/example/tanchat/assets/src/routes/api.messages.ts +0 -24
- package/templates/react/example/tanchat/assets/src/routes/api.sse.ts +0 -23
- package/templates/react/example/tanchat/assets/src/routes/example.chat.tsx +0 -159
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/$guitarId.tsx +0 -50
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/index.tsx +0 -54
- package/templates/react/example/tanchat/assets/src/store/example-assistant.ts +0 -3
- package/templates/react/example/tanchat/assets/src/utils/demo.ai.ts +0 -62
- package/templates/react/example/tanchat/assets/src/utils/demo.sse.ts +0 -31
- package/templates/react/example/tanchat/assets/src/utils/demo.tools.ts +0 -47
- package/templates/react/example/tanchat/info.json +0 -19
- package/templates/react/example/tanchat/package.json +0 -16
- package/templates/react/file-router/package.fr.json +0 -5
- package/templates/react/file-router/src/main.tsx.ejs +0 -55
- package/templates/react/file-router/src/routes/__root.tsx.ejs +0 -82
- package/templates/solid/add-on/form/assets/src/routes/demo.form.tsx.ejs +0 -352
- package/templates/solid/add-on/form/info.json +0 -13
- package/templates/solid/add-on/form/package.json +0 -5
- package/templates/solid/add-on/module-federation/assets/module-federation.config.js.ejs +0 -27
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-component.tsx +0 -3
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +0 -9
- package/templates/solid/add-on/module-federation/info.json +0 -7
- package/templates/solid/add-on/module-federation/package.json +0 -5
- package/templates/solid/add-on/sentry/assets/_dot_cursorrules.append +0 -22
- package/templates/solid/add-on/sentry/assets/_dot_env.local.append +0 -2
- package/templates/solid/add-on/sentry/assets/src/routes/demo.sentry.bad-event-handler.tsx +0 -20
- package/templates/solid/add-on/sentry/info.json +0 -13
- package/templates/solid/add-on/sentry/package.json +0 -5
- package/templates/solid/add-on/solid-ui/README.md +0 -9
- package/templates/solid/add-on/solid-ui/assets/src/lib/utils.ts +0 -6
- package/templates/solid/add-on/solid-ui/assets/src/styles.css +0 -138
- package/templates/solid/add-on/solid-ui/assets/ui.config.json +0 -13
- package/templates/solid/add-on/solid-ui/info.json +0 -11
- package/templates/solid/add-on/solid-ui/package.json +0 -9
- package/templates/solid/add-on/start/assets/app.config.ts +0 -16
- package/templates/solid/add-on/start/assets/src/api.ts +0 -6
- package/templates/solid/add-on/start/assets/src/client.tsx +0 -7
- package/templates/solid/add-on/start/assets/src/router.tsx.ejs +0 -24
- package/templates/solid/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +0 -49
- package/templates/solid/add-on/start/assets/src/ssr.tsx +0 -12
- package/templates/solid/add-on/start/info.json +0 -14
- package/templates/solid/add-on/start/package.json +0 -12
- package/templates/solid/add-on/store/assets/src/lib/demo-store.ts +0 -13
- package/templates/solid/add-on/store/assets/src/routes/demo.store.tsx.ejs +0 -77
- package/templates/solid/add-on/store/info.json +0 -13
- package/templates/solid/add-on/store/package.json +0 -6
- package/templates/solid/add-on/t3env/README.md +0 -16
- package/templates/solid/add-on/t3env/assets/src/env.ts +0 -39
- package/templates/solid/add-on/t3env/info.json +0 -10
- package/templates/solid/add-on/t3env/package.json +0 -6
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/header-user.tsx +0 -5
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/provider.tsx +0 -15
- package/templates/solid/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx +0 -30
- package/templates/solid/add-on/tanstack-query/info.json +0 -13
- package/templates/solid/add-on/tanstack-query/package.json +0 -6
- package/templates/solid/base/README.md.ejs +0 -215
- package/templates/solid/base/_dot_cursorrules.append +0 -35
- package/templates/solid/base/_dot_gitignore +0 -5
- package/templates/solid/base/_dot_vscode/settings.biome.json +0 -38
- package/templates/solid/base/_dot_vscode/settings.json +0 -11
- package/templates/solid/base/index.html.ejs +0 -20
- package/templates/solid/base/package.biome.json +0 -10
- package/templates/solid/base/package.eslintprettier.json +0 -11
- package/templates/solid/base/package.json +0 -23
- package/templates/solid/base/package.ts.json +0 -5
- package/templates/solid/base/package.tw.json +0 -6
- package/templates/solid/base/public/favicon.ico +0 -0
- package/templates/solid/base/public/logo192.png +0 -0
- package/templates/solid/base/public/logo512.png +0 -0
- package/templates/solid/base/public/manifest.json +0 -25
- package/templates/solid/base/public/robots.txt +0 -3
- package/templates/solid/base/src/App.css +0 -0
- package/templates/solid/base/src/App.tsx.ejs +0 -47
- package/templates/solid/base/src/components/Header.tsx.ejs +0 -26
- package/templates/solid/base/src/logo.svg +0 -120
- package/templates/solid/base/src/styles.css.ejs +0 -15
- package/templates/solid/base/toolchain/.prettierignore +0 -3
- package/templates/solid/base/toolchain/biome.json +0 -31
- package/templates/solid/base/toolchain/eslint.config.js +0 -5
- package/templates/solid/base/toolchain/prettier.config.js +0 -10
- package/templates/solid/base/tsconfig.json.ejs +0 -31
- package/templates/solid/base/vite.config.js.ejs +0 -22
- package/templates/solid/code-router/src/main.tsx.ejs +0 -71
- package/templates/solid/example/tanchat/README.md +0 -52
- package/templates/solid/example/tanchat/assets/ai-streaming-server/README.md +0 -110
- package/templates/solid/example/tanchat/assets/ai-streaming-server/_dot_env.example +0 -1
- package/templates/solid/example/tanchat/assets/ai-streaming-server/package.json +0 -26
- package/templates/solid/example/tanchat/assets/ai-streaming-server/src/index.ts +0 -102
- package/templates/solid/example/tanchat/assets/ai-streaming-server/tsconfig.json +0 -15
- package/templates/solid/example/tanchat/assets/src/components/demo.SettingsDialog.tsx +0 -149
- package/templates/solid/example/tanchat/assets/src/demo.index.css +0 -227
- package/templates/solid/example/tanchat/assets/src/lib/demo-store.ts +0 -13
- package/templates/solid/example/tanchat/assets/src/routes/example.chat.tsx +0 -435
- package/templates/solid/example/tanchat/assets/src/store/demo.hooks.ts +0 -17
- package/templates/solid/example/tanchat/assets/src/store/demo.store.ts +0 -133
- package/templates/solid/example/tanchat/info.json +0 -14
- package/templates/solid/example/tanchat/package.json +0 -7
- package/templates/solid/file-router/package.fr.json +0 -5
- package/templates/solid/file-router/src/main.tsx.ejs +0 -47
- package/templates/solid/file-router/src/routes/__root.tsx.ejs +0 -41
- package/templates/solid/file-router/src/routes/index.tsx +0 -43
- package/tests/cra.test.ts +0 -293
- package/tests/snapshots/cra/cr-js-npm.json +0 -33
- package/tests/snapshots/cra/cr-ts-npm.json +0 -34
- package/tests/snapshots/cra/cr-ts-start-npm.json +0 -38
- package/tests/snapshots/cra/fr-ts-npm.json +0 -34
- package/tests/snapshots/cra/fr-ts-tw-npm.json +0 -33
- package/tests/snapshots/cra/solid-cr-js-npm.json +0 -31
- package/tests/snapshots/cra/solid-cr-ts-npm.json +0 -32
- package/tests/snapshots/cra/solid-cr-ts-start-npm.json +0 -36
- package/tests/snapshots/cra/solid-fr-ts-npm.json +0 -33
- package/tests/snapshots/cra/solid-fr-ts-tw-npm.json +0 -32
- package/tests/test-utilities.ts +0 -87
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
4
|
+
import { AddOnCompiledSchema } from '../types.js';
|
|
5
|
+
import { createIgnore, recursivelyGatherFiles } from '../file-helpers.js';
|
|
6
|
+
import { compareFilesRecursively, createAppOptionsFromPersisted, createPackageAdditions, readCurrentProjectOptions, runCreateApp, } from './shared.js';
|
|
7
|
+
const ADD_ON_DIR = '.add-on';
|
|
8
|
+
export const ADD_ON_IGNORE_FILES = [
|
|
9
|
+
'main.jsx',
|
|
10
|
+
'App.jsx',
|
|
11
|
+
'main.tsx',
|
|
12
|
+
'App.tsx',
|
|
13
|
+
'routeTree.gen.ts',
|
|
14
|
+
];
|
|
15
|
+
const INFO_FILE = '.add-on/info.json';
|
|
16
|
+
const COMPILED_FILE = 'add-on.json';
|
|
17
|
+
const ASSETS_DIR = 'assets';
|
|
18
|
+
export function camelCase(str) {
|
|
19
|
+
return str
|
|
20
|
+
.split(/(\.|-|\/)/)
|
|
21
|
+
.filter((part) => /^[a-zA-Z]+$/.test(part))
|
|
22
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
23
|
+
.join('');
|
|
24
|
+
}
|
|
25
|
+
export function templatize(routeCode, routeFile) {
|
|
26
|
+
let code = routeCode;
|
|
27
|
+
// Replace the import
|
|
28
|
+
code = code.replace(/import { createFileRoute } from ['"]@tanstack\/react-router['"]/g, `import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/react-router'`);
|
|
29
|
+
// Extract route path and definition, then transform the route declaration
|
|
30
|
+
const routeMatch = code.match(/export\s+const\s+Route\s*=\s*createFileRoute\(['"]([^'"]+)['"]\)\s*\(\{([^}]+)\}\)/);
|
|
31
|
+
let path = '';
|
|
32
|
+
if (routeMatch) {
|
|
33
|
+
const fullMatch = routeMatch[0];
|
|
34
|
+
path = routeMatch[1];
|
|
35
|
+
const routeDefinition = routeMatch[2];
|
|
36
|
+
code = code.replace(fullMatch, `<% if (codeRouter) { %>
|
|
37
|
+
import type { RootRoute } from '@tanstack/react-router'
|
|
38
|
+
<% } else { %>
|
|
39
|
+
export const Route = createFileRoute('${path}')({${routeDefinition}})
|
|
40
|
+
<% } %>`);
|
|
41
|
+
code += `
|
|
42
|
+
<% if (codeRouter) { %>
|
|
43
|
+
export default (parentRoute: RootRoute) => createRoute({
|
|
44
|
+
path: '${path}',
|
|
45
|
+
${routeDefinition}
|
|
46
|
+
getParentRoute: () => parentRoute,
|
|
47
|
+
})
|
|
48
|
+
<% } %>
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.error(`No route found in the file: ${routeFile}`);
|
|
53
|
+
}
|
|
54
|
+
const name = basename(path)
|
|
55
|
+
.replace('.tsx', '')
|
|
56
|
+
.replace(/^demo/, '')
|
|
57
|
+
.replace('.', ' ')
|
|
58
|
+
.trim();
|
|
59
|
+
const jsName = camelCase(basename(path));
|
|
60
|
+
return { url: path, code, name, jsName };
|
|
61
|
+
}
|
|
62
|
+
export async function validateAddOnSetup(environment) {
|
|
63
|
+
const options = await readCurrentProjectOptions(environment);
|
|
64
|
+
if (options.mode !== 'file-router') {
|
|
65
|
+
environment.error('This project is not using file-router mode.', 'To create an add-on, the project must be created with the file-router mode.');
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
if (!options.tailwind) {
|
|
69
|
+
environment.error('This project is not using Tailwind CSS.', 'To create an add-on, the project must be created with Tailwind CSS.');
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
if (!options.typescript) {
|
|
73
|
+
environment.error('This project is not using TypeScript.', 'To create an add-on, the project must be created with TypeScript.');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export async function readOrGenerateAddOnInfo(options) {
|
|
78
|
+
return existsSync(INFO_FILE)
|
|
79
|
+
? JSON.parse((await readFile(INFO_FILE)).toString())
|
|
80
|
+
: {
|
|
81
|
+
id: `${options.projectName}-add-on`,
|
|
82
|
+
name: `${options.projectName}-add-on`,
|
|
83
|
+
version: '0.0.1',
|
|
84
|
+
description: 'Add-on',
|
|
85
|
+
author: 'Jane Smith <jane.smith@example.com>',
|
|
86
|
+
license: 'MIT',
|
|
87
|
+
link: `https://github.com/jane-smith/${options.projectName}-add-on`,
|
|
88
|
+
shadcnComponents: [],
|
|
89
|
+
framework: options.framework,
|
|
90
|
+
modes: [options.mode],
|
|
91
|
+
routes: [],
|
|
92
|
+
warning: '',
|
|
93
|
+
phase: 'add-on',
|
|
94
|
+
type: 'add-on',
|
|
95
|
+
packageAdditions: {
|
|
96
|
+
scripts: {},
|
|
97
|
+
dependencies: {},
|
|
98
|
+
devDependencies: {},
|
|
99
|
+
},
|
|
100
|
+
dependsOn: options.chosenAddOns,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export async function generateProject(persistedOptions) {
|
|
104
|
+
const info = await readOrGenerateAddOnInfo(persistedOptions);
|
|
105
|
+
const output = await runCreateApp((await createAppOptionsFromPersisted(persistedOptions)));
|
|
106
|
+
return { info, output };
|
|
107
|
+
}
|
|
108
|
+
export async function buildAssetsDirectory(output, info) {
|
|
109
|
+
const assetsDir = resolve(ADD_ON_DIR, ASSETS_DIR);
|
|
110
|
+
const ignore = createIgnore(process.cwd());
|
|
111
|
+
if (!existsSync(assetsDir)) {
|
|
112
|
+
const changedFiles = {};
|
|
113
|
+
await compareFilesRecursively('.', ignore, output.files, changedFiles);
|
|
114
|
+
for (const file of Object.keys(changedFiles).filter((file) => !ADD_ON_IGNORE_FILES.includes(basename(file)))) {
|
|
115
|
+
mkdirSync(dirname(resolve(assetsDir, file)), {
|
|
116
|
+
recursive: true,
|
|
117
|
+
});
|
|
118
|
+
if (file.includes('/routes/')) {
|
|
119
|
+
const { url, code, name, jsName } = templatize(changedFiles[file], file);
|
|
120
|
+
info.routes || (info.routes = []);
|
|
121
|
+
if (!info.routes.find((r) => r.url === url)) {
|
|
122
|
+
info.routes.push({
|
|
123
|
+
url,
|
|
124
|
+
name,
|
|
125
|
+
jsName,
|
|
126
|
+
path: file,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
writeFileSync(resolve(assetsDir, `${file}.ejs`), code);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
writeFileSync(resolve(assetsDir, file), changedFiles[file]);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export async function updateAddOnInfo(environment) {
|
|
138
|
+
const { info, output } = await generateProject(await readCurrentProjectOptions(environment));
|
|
139
|
+
info.packageAdditions = createPackageAdditions(JSON.parse(output.files['./package.json']), JSON.parse((await readFile('package.json')).toString()));
|
|
140
|
+
await buildAssetsDirectory(output, info);
|
|
141
|
+
mkdirSync(resolve(dirname(INFO_FILE)), { recursive: true });
|
|
142
|
+
writeFileSync(INFO_FILE, JSON.stringify(info, null, 2));
|
|
143
|
+
}
|
|
144
|
+
export async function compileAddOn(environment) {
|
|
145
|
+
const info = await readOrGenerateAddOnInfo(await readCurrentProjectOptions(environment));
|
|
146
|
+
const assetsDir = resolve(ADD_ON_DIR, ASSETS_DIR);
|
|
147
|
+
const compiledInfo = {
|
|
148
|
+
...info,
|
|
149
|
+
files: await recursivelyGatherFiles(assetsDir),
|
|
150
|
+
deletedFiles: [],
|
|
151
|
+
};
|
|
152
|
+
writeFileSync(COMPILED_FILE, JSON.stringify(compiledInfo, null, 2));
|
|
153
|
+
}
|
|
154
|
+
export async function initAddOn(environment) {
|
|
155
|
+
await validateAddOnSetup(environment);
|
|
156
|
+
await updateAddOnInfo(environment);
|
|
157
|
+
await compileAddOn(environment);
|
|
158
|
+
}
|
|
159
|
+
export async function loadRemoteAddOn(url) {
|
|
160
|
+
const response = await fetch(url);
|
|
161
|
+
const jsonContent = await response.json();
|
|
162
|
+
const checked = AddOnCompiledSchema.safeParse(jsonContent);
|
|
163
|
+
if (!checked.success) {
|
|
164
|
+
throw new Error(`Invalid add-on: ${url}`);
|
|
165
|
+
}
|
|
166
|
+
const addOn = checked.data;
|
|
167
|
+
addOn.id = url;
|
|
168
|
+
const out = {
|
|
169
|
+
...addOn,
|
|
170
|
+
getFiles: () => Promise.resolve(Object.keys(addOn.files)),
|
|
171
|
+
getFileContents: (path) => Promise.resolve(addOn.files[path]),
|
|
172
|
+
getDeletedFiles: () => Promise.resolve(addOn.deletedFiles),
|
|
173
|
+
};
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { createApp } from '../create-app.js';
|
|
4
|
+
import { createMemoryEnvironment } from '../environment.js';
|
|
5
|
+
import { finalizeAddOns } from '../add-ons.js';
|
|
6
|
+
import { getFrameworkById } from '../frameworks.js';
|
|
7
|
+
import { readConfigFileFromEnvironment } from '../config-file.js';
|
|
8
|
+
import { readFileHelper } from '../file-helpers.js';
|
|
9
|
+
import { loadStarter } from '../custom-add-ons/starter.js';
|
|
10
|
+
export function createPackageAdditions(originalPackageJson, currentPackageJson) {
|
|
11
|
+
const packageAdditions = {};
|
|
12
|
+
const scripts = {};
|
|
13
|
+
for (const script of Object.keys(currentPackageJson.scripts || {})) {
|
|
14
|
+
if (originalPackageJson.scripts[script] !== currentPackageJson.scripts[script]) {
|
|
15
|
+
scripts[script] = currentPackageJson.scripts[script];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
packageAdditions.scripts = Object.keys(scripts).length ? scripts : undefined;
|
|
19
|
+
const dependencies = {};
|
|
20
|
+
for (const dependency of Object.keys(currentPackageJson.dependencies || {})) {
|
|
21
|
+
if (originalPackageJson.dependencies[dependency] !==
|
|
22
|
+
currentPackageJson.dependencies[dependency]) {
|
|
23
|
+
dependencies[dependency] = currentPackageJson.dependencies[dependency];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
packageAdditions.dependencies = Object.keys(dependencies).length
|
|
27
|
+
? dependencies
|
|
28
|
+
: undefined;
|
|
29
|
+
const devDependencies = {};
|
|
30
|
+
for (const dependency of Object.keys(currentPackageJson.devDependencies || {})) {
|
|
31
|
+
if (originalPackageJson.devDependencies[dependency] !==
|
|
32
|
+
currentPackageJson.devDependencies[dependency]) {
|
|
33
|
+
devDependencies[dependency] =
|
|
34
|
+
currentPackageJson.devDependencies[dependency];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
packageAdditions.devDependencies = Object.keys(devDependencies).length
|
|
38
|
+
? devDependencies
|
|
39
|
+
: undefined;
|
|
40
|
+
return packageAdditions;
|
|
41
|
+
}
|
|
42
|
+
export async function createAppOptionsFromPersisted(json) {
|
|
43
|
+
/* eslint-disable unused-imports/no-unused-vars */
|
|
44
|
+
const { version, ...rest } = json;
|
|
45
|
+
/* eslint-enable unused-imports/no-unused-vars */
|
|
46
|
+
const framework = getFrameworkById(rest.framework);
|
|
47
|
+
return {
|
|
48
|
+
...rest,
|
|
49
|
+
mode: json.mode,
|
|
50
|
+
projectName: json.projectName,
|
|
51
|
+
typescript: json.typescript,
|
|
52
|
+
tailwind: json.tailwind,
|
|
53
|
+
git: json.git,
|
|
54
|
+
packageManager: json.packageManager,
|
|
55
|
+
targetDir: '',
|
|
56
|
+
framework: framework,
|
|
57
|
+
starter: json.starter ? await loadStarter(json.starter) : undefined,
|
|
58
|
+
chosenAddOns: await finalizeAddOns(framework, json.mode, [
|
|
59
|
+
...json.chosenAddOns,
|
|
60
|
+
]),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function createSerializedOptionsFromPersisted(json) {
|
|
64
|
+
/* eslint-disable unused-imports/no-unused-vars */
|
|
65
|
+
const { version, ...rest } = json;
|
|
66
|
+
/* eslint-enable unused-imports/no-unused-vars */
|
|
67
|
+
return {
|
|
68
|
+
...rest,
|
|
69
|
+
mode: json.mode,
|
|
70
|
+
projectName: json.projectName,
|
|
71
|
+
typescript: json.typescript,
|
|
72
|
+
tailwind: json.tailwind,
|
|
73
|
+
git: json.git,
|
|
74
|
+
packageManager: json.packageManager,
|
|
75
|
+
targetDir: '',
|
|
76
|
+
framework: json.framework,
|
|
77
|
+
starter: json.starter,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export async function runCreateApp(options) {
|
|
81
|
+
const { environment, output } = createMemoryEnvironment();
|
|
82
|
+
const targetDir = resolve(process.cwd());
|
|
83
|
+
await createApp(environment, {
|
|
84
|
+
...options,
|
|
85
|
+
targetDir,
|
|
86
|
+
});
|
|
87
|
+
output.files = Object.fromEntries(Object.entries(output.files).map(([key, value]) => {
|
|
88
|
+
return [key.replace(targetDir, '.'), value];
|
|
89
|
+
}));
|
|
90
|
+
return output;
|
|
91
|
+
}
|
|
92
|
+
export async function compareFilesRecursively(path, ignore, original, changedFiles) {
|
|
93
|
+
const files = await readdir(path, { withFileTypes: true });
|
|
94
|
+
for (const file of files) {
|
|
95
|
+
const filePath = `${path}/${file.name}`;
|
|
96
|
+
if (!ignore(file.name)) {
|
|
97
|
+
if (file.isDirectory()) {
|
|
98
|
+
await compareFilesRecursively(filePath, ignore, original, changedFiles);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const contents = await readFileHelper(filePath);
|
|
102
|
+
if (!original[filePath] || original[filePath] !== contents) {
|
|
103
|
+
changedFiles[filePath] = contents;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export async function readCurrentProjectOptions(environment) {
|
|
110
|
+
const persistedOptions = await readConfigFileFromEnvironment(environment, process.cwd());
|
|
111
|
+
if (!persistedOptions) {
|
|
112
|
+
environment.error('There is no .cta.json file in your project.', `This is probably because this was created with an older version of create-tsrouter-app.`);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
return persistedOptions;
|
|
116
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { StarterCompiledSchema } from '../types.js';
|
|
5
|
+
import { createIgnore } from '../file-helpers.js';
|
|
6
|
+
import { compareFilesRecursively, createAppOptionsFromPersisted, createPackageAdditions, readCurrentProjectOptions, runCreateApp, } from './shared.js';
|
|
7
|
+
const INFO_FILE = 'starter-info.json';
|
|
8
|
+
const COMPILED_FILE = 'starter.json';
|
|
9
|
+
export async function readOrGenerateStarterInfo(options) {
|
|
10
|
+
return existsSync(INFO_FILE)
|
|
11
|
+
? JSON.parse((await readFile(INFO_FILE)).toString())
|
|
12
|
+
: {
|
|
13
|
+
id: `${options.projectName}-starter`,
|
|
14
|
+
name: `${options.projectName}-starter`,
|
|
15
|
+
version: '0.0.1',
|
|
16
|
+
description: 'Project starter',
|
|
17
|
+
author: 'Jane Smith <jane.smith@example.com>',
|
|
18
|
+
license: 'MIT',
|
|
19
|
+
link: `https://github.com/jane-smith/${options.projectName}-starter`,
|
|
20
|
+
shadcnComponents: [],
|
|
21
|
+
framework: options.framework,
|
|
22
|
+
mode: options.mode,
|
|
23
|
+
routes: [],
|
|
24
|
+
warning: '',
|
|
25
|
+
type: 'starter',
|
|
26
|
+
packageAdditions: {
|
|
27
|
+
scripts: {},
|
|
28
|
+
dependencies: {},
|
|
29
|
+
devDependencies: {},
|
|
30
|
+
},
|
|
31
|
+
dependsOn: options.chosenAddOns,
|
|
32
|
+
typescript: options.typescript,
|
|
33
|
+
tailwind: options.tailwind,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function loadCurrentStarterInfo(environment) {
|
|
37
|
+
const persistedOptions = await readCurrentProjectOptions(environment);
|
|
38
|
+
const info = await readOrGenerateStarterInfo(persistedOptions);
|
|
39
|
+
const output = await runCreateApp((await createAppOptionsFromPersisted(persistedOptions)));
|
|
40
|
+
return { info, output };
|
|
41
|
+
}
|
|
42
|
+
export async function updateStarterInfo(environment) {
|
|
43
|
+
const { info, output } = await loadCurrentStarterInfo(environment);
|
|
44
|
+
info.packageAdditions = createPackageAdditions(JSON.parse(output.files['./package.json']), JSON.parse((await readFile('package.json')).toString()));
|
|
45
|
+
writeFileSync(INFO_FILE, JSON.stringify(info, null, 2));
|
|
46
|
+
}
|
|
47
|
+
export async function compileStarter(environment) {
|
|
48
|
+
const { info, output } = await loadCurrentStarterInfo(environment);
|
|
49
|
+
const ignore = createIgnore(process.cwd());
|
|
50
|
+
const changedFiles = {};
|
|
51
|
+
await compareFilesRecursively('.', ignore, output.files, changedFiles);
|
|
52
|
+
const deletedFiles = [];
|
|
53
|
+
for (const file of Object.keys(output.files)) {
|
|
54
|
+
if (!existsSync(resolve(process.cwd(), file))) {
|
|
55
|
+
deletedFiles.push(file);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const compiledInfo = {
|
|
59
|
+
...info,
|
|
60
|
+
files: changedFiles,
|
|
61
|
+
deletedFiles,
|
|
62
|
+
};
|
|
63
|
+
writeFileSync(COMPILED_FILE, JSON.stringify(compiledInfo, null, 2));
|
|
64
|
+
}
|
|
65
|
+
export async function initStarter(environment) {
|
|
66
|
+
await updateStarterInfo(environment);
|
|
67
|
+
await compileStarter(environment);
|
|
68
|
+
}
|
|
69
|
+
export async function loadStarter(url) {
|
|
70
|
+
const response = await fetch(url);
|
|
71
|
+
const jsonContent = await response.json();
|
|
72
|
+
const checked = StarterCompiledSchema.safeParse(jsonContent);
|
|
73
|
+
if (!checked.success) {
|
|
74
|
+
throw new Error(`Invalid starter: ${url}`);
|
|
75
|
+
}
|
|
76
|
+
const starter = checked.data;
|
|
77
|
+
starter.id = url;
|
|
78
|
+
return {
|
|
79
|
+
...starter,
|
|
80
|
+
getFiles: () => Promise.resolve(Object.keys(starter.files)),
|
|
81
|
+
getFileContents: (path) => Promise.resolve(starter.files[path]),
|
|
82
|
+
getDeletedFiles: () => Promise.resolve(starter.deletedFiles),
|
|
83
|
+
};
|
|
84
|
+
}
|
package/dist/environment.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { appendFile, copyFile, mkdir, readFile, unlink, writeFile, } from 'node:fs/promises';
|
|
2
|
-
import { existsSync,
|
|
1
|
+
import { appendFile, copyFile, mkdir, readFile, readdir, unlink, writeFile, } from 'node:fs/promises';
|
|
2
|
+
import { existsSync, statSync } from 'node:fs';
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
import { execa } from 'execa';
|
|
5
5
|
import { memfs } from 'memfs';
|
|
6
|
+
import { rimraf } from 'rimraf';
|
|
7
|
+
import { cleanUpFileArray, cleanUpFiles, getBinaryFile, } from './file-helpers.js';
|
|
6
8
|
export function createDefaultEnvironment() {
|
|
7
9
|
let errors = [];
|
|
8
10
|
return {
|
|
@@ -23,95 +25,116 @@ export function createDefaultEnvironment() {
|
|
|
23
25
|
await mkdir(dirname(path), { recursive: true });
|
|
24
26
|
return writeFile(path, contents);
|
|
25
27
|
},
|
|
28
|
+
writeFileBase64: async (path, base64Contents) => {
|
|
29
|
+
await mkdir(dirname(path), { recursive: true });
|
|
30
|
+
return writeFile(path, getBinaryFile(base64Contents));
|
|
31
|
+
},
|
|
26
32
|
execute: async (command, args, cwd) => {
|
|
27
33
|
try {
|
|
28
|
-
await execa(command, args, {
|
|
34
|
+
const result = await execa(command, args, {
|
|
29
35
|
cwd,
|
|
30
36
|
});
|
|
37
|
+
return { stdout: result.stdout };
|
|
31
38
|
}
|
|
32
39
|
catch {
|
|
33
40
|
errors.push(`Command "${command} ${args.join(' ')}" did not run successfully. Please run this manually in your project.`);
|
|
41
|
+
return { stdout: '' };
|
|
34
42
|
}
|
|
35
43
|
},
|
|
36
44
|
deleteFile: async (path) => {
|
|
37
|
-
|
|
45
|
+
if (existsSync(path)) {
|
|
46
|
+
await unlink(path);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
readFile: async (path) => {
|
|
50
|
+
return (await readFile(path)).toString();
|
|
38
51
|
},
|
|
39
|
-
readFile: (path, encoding) => readFile(path, { encoding: encoding || 'utf8' }),
|
|
40
52
|
exists: (path) => existsSync(path),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
isDirectory: (path) => statSync(path).isDirectory(),
|
|
54
|
+
readdir: async (path) => readdir(path),
|
|
55
|
+
rimraf: async (path) => {
|
|
56
|
+
await rimraf(path);
|
|
45
57
|
},
|
|
58
|
+
appName: 'TanStack',
|
|
59
|
+
startStep: () => { },
|
|
60
|
+
finishStep: () => { },
|
|
61
|
+
intro: () => { },
|
|
62
|
+
outro: () => { },
|
|
63
|
+
info: () => { },
|
|
64
|
+
error: () => { },
|
|
65
|
+
warn: () => { },
|
|
66
|
+
confirm: () => Promise.resolve(true),
|
|
67
|
+
spinner: () => ({
|
|
68
|
+
start: () => { },
|
|
69
|
+
stop: () => { },
|
|
70
|
+
}),
|
|
46
71
|
};
|
|
47
72
|
}
|
|
48
|
-
export function createMemoryEnvironment() {
|
|
73
|
+
export function createMemoryEnvironment(returnPathsRelativeTo = '') {
|
|
49
74
|
const environment = createDefaultEnvironment();
|
|
50
75
|
const output = {
|
|
51
76
|
files: {},
|
|
52
77
|
commands: [],
|
|
78
|
+
deletedFiles: [],
|
|
53
79
|
};
|
|
54
80
|
const { fs, vol } = memfs({});
|
|
55
|
-
const cwd = process.cwd();
|
|
56
|
-
const isInCwd = (path) => path.startsWith(cwd);
|
|
57
|
-
const isTemplatePath = (path) => !isInCwd(path);
|
|
58
81
|
environment.appendFile = async (path, contents) => {
|
|
59
82
|
fs.mkdirSync(dirname(path), { recursive: true });
|
|
60
83
|
await fs.appendFileSync(path, contents);
|
|
61
84
|
};
|
|
62
85
|
environment.copyFile = async (from, to) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
fs.writeFileSync(to, contents);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
fs.mkdirSync(dirname(to), { recursive: true });
|
|
70
|
-
fs.copyFileSync(from, to);
|
|
71
|
-
}
|
|
86
|
+
fs.mkdirSync(dirname(to), { recursive: true });
|
|
87
|
+
fs.copyFileSync(from, to);
|
|
88
|
+
return Promise.resolve();
|
|
72
89
|
};
|
|
73
90
|
environment.execute = async (command, args) => {
|
|
74
91
|
output.commands.push({
|
|
75
92
|
command,
|
|
76
93
|
args,
|
|
77
94
|
});
|
|
78
|
-
return Promise.resolve();
|
|
95
|
+
return Promise.resolve({ stdout: '' });
|
|
79
96
|
};
|
|
80
|
-
environment.readFile = async (path
|
|
81
|
-
|
|
82
|
-
return (await readFile(path, encoding)).toString();
|
|
83
|
-
}
|
|
84
|
-
return fs.readFileSync(path, 'utf8').toString();
|
|
97
|
+
environment.readFile = async (path) => {
|
|
98
|
+
return Promise.resolve(fs.readFileSync(path, 'utf-8').toString());
|
|
85
99
|
};
|
|
86
100
|
environment.writeFile = async (path, contents) => {
|
|
87
101
|
fs.mkdirSync(dirname(path), { recursive: true });
|
|
88
102
|
await fs.writeFileSync(path, contents);
|
|
89
103
|
};
|
|
90
|
-
environment.
|
|
91
|
-
|
|
104
|
+
environment.writeFileBase64 = async (path, contents) => {
|
|
105
|
+
// For the in-memory file system, we are not converting the base64 to binary
|
|
106
|
+
// because it's not needed.
|
|
107
|
+
fs.mkdirSync(dirname(path), { recursive: true });
|
|
108
|
+
await fs.writeFileSync(path, contents);
|
|
92
109
|
};
|
|
93
|
-
environment.
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
environment.deleteFile = async (path) => {
|
|
111
|
+
output.deletedFiles.push(path);
|
|
112
|
+
if (fs.existsSync(path)) {
|
|
113
|
+
await fs.unlinkSync(path);
|
|
96
114
|
}
|
|
97
|
-
return fs.existsSync(path);
|
|
98
115
|
};
|
|
99
|
-
environment.
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
environment.finishRun = () => {
|
|
117
|
+
output.files = vol.toJSON();
|
|
118
|
+
for (const file of Object.keys(output.files)) {
|
|
119
|
+
if (fs.statSync(file).isDirectory()) {
|
|
120
|
+
delete output.files[file];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (returnPathsRelativeTo.length) {
|
|
124
|
+
output.files = cleanUpFiles(output.files, returnPathsRelativeTo);
|
|
125
|
+
output.deletedFiles = cleanUpFileArray(output.deletedFiles, returnPathsRelativeTo);
|
|
102
126
|
}
|
|
103
|
-
|
|
127
|
+
};
|
|
128
|
+
environment.exists = (path) => {
|
|
129
|
+
return fs.existsSync(path);
|
|
104
130
|
};
|
|
105
131
|
environment.isDirectory = (path) => {
|
|
106
|
-
if (isTemplatePath(path)) {
|
|
107
|
-
const stat = statSync(path);
|
|
108
|
-
return stat.isDirectory();
|
|
109
|
-
}
|
|
110
132
|
return fs.statSync(path).isDirectory();
|
|
111
133
|
};
|
|
112
|
-
environment.
|
|
113
|
-
|
|
134
|
+
environment.readdir = async (path) => {
|
|
135
|
+
return Promise.resolve(fs.readdirSync(path).map((d) => d.toString()));
|
|
114
136
|
};
|
|
137
|
+
environment.rimraf = async () => { };
|
|
115
138
|
return {
|
|
116
139
|
environment,
|
|
117
140
|
output,
|