From c139faa9844229e79d8f2d06f72cd4935d1704e6 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Mon, 26 Sep 2022 22:31:53 +0530 Subject: [PATCH 01/14] Update generate.ts --- packages/blitz/src/cli/commands/generate.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/blitz/src/cli/commands/generate.ts b/packages/blitz/src/cli/commands/generate.ts index 706175e167..e4aced8c71 100644 --- a/packages/blitz/src/cli/commands/generate.ts +++ b/packages/blitz/src/cli/commands/generate.ts @@ -230,6 +230,7 @@ const generate: CliCommand = async () => { for (const GeneratorClass of generators) { const generator = new GeneratorClass({ destinationRoot: require("path").resolve(), + templateDir: blitzConfig.codegen?.templateDir, extraArgs: args["_"].slice(3) as string[], modelName: singularRootContext, modelNames: modelNames(singularRootContext), From 3131586feb8a6a621a77997da2b840668f80851e Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 27 Sep 2022 00:10:38 +0530 Subject: [PATCH 02/14] add custom template back to toolkit --- apps/toolkit-app/app/blitz-server.ts | 7 + packages/blitz/package.json | 1 + packages/blitz/src/cli/commands/generate.ts | 41 +++- packages/blitz/src/types.ts | 4 + pnpm-lock.yaml | 246 +++++++------------- 5 files changed, 135 insertions(+), 164 deletions(-) diff --git a/apps/toolkit-app/app/blitz-server.ts b/apps/toolkit-app/app/blitz-server.ts index 37f87cd202..1040fd9d59 100644 --- a/apps/toolkit-app/app/blitz-server.ts +++ b/apps/toolkit-app/app/blitz-server.ts @@ -2,6 +2,7 @@ import { setupBlitzServer } from "@blitzjs/next" import { AuthServerPlugin, PrismaStorage } from "@blitzjs/auth" import db from "db" import { simpleRolesIsAuthorized } from "@blitzjs/auth" +import type { BlitzServerConfig } from "blitz" const { gSSP, gSP, api } = setupBlitzServer({ plugins: [ @@ -13,4 +14,10 @@ const { gSSP, gSP, api } = setupBlitzServer({ ], }) +const config: BlitzServerConfig = { + customTemplates: "app/templates", +} + export { gSSP, gSP, api } + +export default config diff --git a/packages/blitz/package.json b/packages/blitz/package.json index b167c39065..ee0af8bf97 100644 --- a/packages/blitz/package.json +++ b/packages/blitz/package.json @@ -35,6 +35,7 @@ "dotenv-expand": "8.0.3", "envinfo": "7.8.1", "esbuild": "0.14.34", + "esbuild-register": "3.3.3", "find-up": "4.1.0", "fs-extra": "10.0.1", "hasbin": "1.2.3", diff --git a/packages/blitz/src/cli/commands/generate.ts b/packages/blitz/src/cli/commands/generate.ts index e4aced8c71..c56f64c320 100644 --- a/packages/blitz/src/cli/commands/generate.ts +++ b/packages/blitz/src/cli/commands/generate.ts @@ -16,6 +16,7 @@ import { ModelGenerator, QueryGenerator, } from "@blitzjs/generator" +import {log} from "../../logging" const getIsTypeScript = async () => require("fs").existsSync(require("path").join(process.cwd(), "tsconfig.json")) @@ -72,6 +73,7 @@ const args = arg( "--parent": String, "--dry-run": Boolean, "--env": String, + "--generate-custom-templates": Boolean, // Aliases "-e": "--env", @@ -213,8 +215,35 @@ const getHelp = async () => { } } +const createCustomTemplates = async () => { + if (args["--generate-custom-templates"]) { + const continuePrompt = await prompts({ + type: "confirm", + name: "value", + message: `This will copy the default templates to your app/templates folder. Do you want to continue?`, + }) + if (!continuePrompt.value) { + process.exit(0) + } + const customTemplatesPath = require("path").join(process.cwd(), "app") + //copy the templates folder in the @blitzjs/generator package to the app folder + const fsExtra = await import("fs-extra") + const blitzGeneratorPath = require.resolve("@blitzjs/generator") + const templateFolder = ["form", "page", "query", "mutation", "queries", "mutations"] + for (const template of templateFolder) { + await fsExtra.copy( + require("path").join(blitzGeneratorPath, "..", "templates", template), + require("path").join(customTemplatesPath, "templates", template), + ) + } + log.success("🚀 Custom templates created in app/templates directory") + process.exit(0) + } +} + const generate: CliCommand = async () => { await getHelp() + await createCustomTemplates() await determineType() if (!selectedModelName) { await determineName() @@ -227,10 +256,20 @@ const generate: CliCommand = async () => { const generators = generatorMap[selectedType as keyof typeof generatorMap] + const isTypeScript = await getIsTypeScript() + const blitzServerPath = isTypeScript ? "app/blitz-server.ts" : "app/blitz-server.js" + const blitzServer = require("path").join(process.cwd(), blitzServerPath) + const {register} = require("esbuild-register/dist/node") + const {unregister} = register({ + target: "es6", + }) + const blitzConfig = require(blitzServer).default + unregister() + for (const GeneratorClass of generators) { const generator = new GeneratorClass({ destinationRoot: require("path").resolve(), - templateDir: blitzConfig.codegen?.templateDir, + templateDir: blitzConfig?.customTemplates, extraArgs: args["_"].slice(3) as string[], modelName: singularRootContext, modelNames: modelNames(singularRootContext), diff --git a/packages/blitz/src/types.ts b/packages/blitz/src/types.ts index 5ab173491a..6eecec7caa 100644 --- a/packages/blitz/src/types.ts +++ b/packages/blitz/src/types.ts @@ -6,6 +6,10 @@ export interface RouteUrlObject extends Pick { pathname: string } +export type BlitzServerConfig = { + customTemplates?: string +} + export const isRouteUrlObject = (x: any): x is RouteUrlObject => { return typeof x === "object" && "pathname" in x && typeof x.pathname === "string" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d446740eaf..48a1d7c59b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: 5.4 +lockfileVersion: 5.3 importers: .: @@ -678,6 +678,7 @@ importers: dotenv-expand: 8.0.3 envinfo: 7.8.1 esbuild: 0.14.34 + esbuild-register: 3.3.3 express: 4.17.3 find-up: 4.1.0 fs-extra: 10.0.1 @@ -711,11 +712,12 @@ importers: console-table-printer: 2.10.0 cross-spawn: 7.0.3 debug: 4.3.3_supports-color@8.1.1 - detect-port: 1.3.0_supports-color@8.1.1 + detect-port: 1.3.0 dotenv: 16.0.0 dotenv-expand: 8.0.3 envinfo: 7.8.1 esbuild: 0.14.34 + esbuild-register: 3.3.3_esbuild@0.14.34 find-up: 4.1.0 fs-extra: 10.0.1 hasbin: 1.2.3 @@ -751,7 +753,7 @@ importers: "@types/react-dom": 17.0.14 "@types/test-listen": 1.1.0 "@types/watchpack": 1.1.1 - express: 4.17.3_supports-color@8.1.1 + express: 4.17.3 react: 18.2.0 test-listen: 1.1.0 typescript: 4.6.3 @@ -1176,6 +1178,7 @@ packages: source-map: 0.5.7 transitivePeerDependencies: - supports-color + dev: false /@babel/core/7.12.10_supports-color@8.1.1: resolution: @@ -1201,6 +1204,7 @@ packages: source-map: 0.5.7 transitivePeerDependencies: - supports-color + dev: false /@babel/core/7.18.2: resolution: @@ -1590,6 +1594,7 @@ packages: "@babel/types": 7.18.4 transitivePeerDependencies: - supports-color + dev: true /@babel/helper-remap-async-to-generator/7.16.8_supports-color@8.1.1: resolution: @@ -1690,6 +1695,7 @@ packages: "@babel/types": 7.18.4 transitivePeerDependencies: - supports-color + dev: true /@babel/helper-wrap-function/7.16.8_supports-color@8.1.1: resolution: @@ -1768,6 +1774,7 @@ packages: "@babel/plugin-syntax-async-generators": 7.8.4_@babel+core@7.12.10 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-proposal-async-generator-functions/7.17.12_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2013,6 +2020,7 @@ packages: "@babel/helper-plugin-utils": 7.17.12 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-proposal-private-methods/7.17.12_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2400,6 +2408,7 @@ packages: "@babel/helper-remap-async-to-generator": 7.16.8 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-async-to-generator/7.17.12_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2462,6 +2471,7 @@ packages: globals: 11.12.0 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-classes/7.18.4_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2626,6 +2636,7 @@ packages: babel-plugin-dynamic-import-node: 2.3.3 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-modules-amd/7.18.0_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2660,6 +2671,7 @@ packages: babel-plugin-dynamic-import-node: 2.3.3 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-modules-commonjs/7.18.2_@babel+core@7.18.2: resolution: @@ -2732,6 +2744,7 @@ packages: babel-plugin-dynamic-import-node: 2.3.3 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-modules-systemjs/7.18.4_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2766,6 +2779,7 @@ packages: "@babel/helper-plugin-utils": 7.17.12 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-modules-umd/7.18.0_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -2822,6 +2836,7 @@ packages: "@babel/helper-replace-supers": 7.18.2 transitivePeerDependencies: - supports-color + dev: true /@babel/plugin-transform-object-super/7.16.7_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -3157,6 +3172,7 @@ packages: semver: 5.7.1 transitivePeerDependencies: - supports-color + dev: true /@babel/preset-env/7.12.10_ps3yxa7qdojvlda5ukda3zlwie: resolution: @@ -3455,8 +3471,6 @@ packages: semver: 6.3.0 spawndamnit: 2.0.0 validate-npm-package-name: 3.0.0 - transitivePeerDependencies: - - supports-color dev: false /@changesets/apply-release-plan/6.0.0: @@ -3719,6 +3733,7 @@ packages: integrity: sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==, } engines: {node: ">= 12"} + dev: false /@cspotcode/source-map-support/0.7.0: resolution: @@ -3728,6 +3743,7 @@ packages: engines: {node: ">=12"} dependencies: "@cspotcode/source-map-consumer": 0.8.0 + dev: false /@cspotcode/source-map-support/0.8.1: resolution: @@ -5291,6 +5307,7 @@ packages: { integrity: sha512-ydLaGVfQOQ6hI1xK2A5nVh8bl0OGoIfYMxPWHqqYe9bTkWCfqiVvZoh2I/QF2sNSkZzZyROBoTefIEI+PB6iIA==, } + dev: true /@types/node/17.0.24: resolution: @@ -5889,6 +5906,7 @@ packages: typescript: 4.6.3 transitivePeerDependencies: - supports-color + dev: false /@typescript-eslint/parser/5.9.1_ep4k34urm5hxazyxrevmf7goie: resolution: @@ -6930,29 +6948,6 @@ packages: qs: 6.9.7 raw-body: 2.4.3 type-is: 1.6.18 - transitivePeerDependencies: - - supports-color - dev: true - - /body-parser/1.19.2_supports-color@8.1.1: - resolution: - { - integrity: sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==, - } - engines: {node: ">= 0.8"} - dependencies: - bytes: 3.1.2 - content-type: 1.0.4 - debug: 2.6.9_supports-color@8.1.1 - depd: 1.1.2 - http-errors: 1.8.1 - iconv-lite: 0.4.24 - on-finished: 2.3.0 - qs: 6.9.7 - raw-body: 2.4.3 - type-is: 1.6.18 - transitivePeerDependencies: - - supports-color dev: true /boxen/4.2.0: @@ -7024,8 +7019,6 @@ packages: snapdragon-node: 2.1.1 split-string: 3.1.0 to-regex: 3.0.2 - transitivePeerDependencies: - - supports-color dev: false /braces/2.3.2_supports-color@8.1.1: @@ -8026,11 +8019,6 @@ packages: { integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==, } - peerDependencies: - supports-color: "*" - peerDependenciesMeta: - supports-color: - optional: true dependencies: ms: 2.0.0 @@ -8047,6 +8035,7 @@ packages: dependencies: ms: 2.0.0 supports-color: 8.1.1 + dev: false /debug/3.2.7: resolution: @@ -8403,7 +8392,7 @@ packages: } engines: {node: ">=8"} - /detect-port/1.3.0_supports-color@8.1.1: + /detect-port/1.3.0: resolution: { integrity: sha512-E+B1gzkl2gqxt1IhUzwjrxBKRqx1UzC3WLONHinn8S3T6lwV/agVCyitiFOsGJ/eYuEUBvD71MZHy3Pv1G9doQ==, @@ -8412,9 +8401,7 @@ packages: hasBin: true dependencies: address: 1.2.0 - debug: 2.6.9_supports-color@8.1.1 - transitivePeerDependencies: - - supports-color + debug: 2.6.9 dev: false /diff-sequences/27.5.1: @@ -9333,6 +9320,17 @@ packages: dev: true optional: true + /esbuild-register/3.3.3_esbuild@0.14.34: + resolution: + { + integrity: sha512-eFHOkutgIMJY5gc8LUp/7c+LLlDqzNi9T6AwCZ2WKKl3HmT+5ef3ZRyPPxDOynInML0fgaC50yszPKfPnjC0NQ==, + } + peerDependencies: + esbuild: ">=0.12 <1" + dependencies: + esbuild: 0.14.34 + dev: false + /esbuild-sunos-64/0.14.34: resolution: { @@ -9782,6 +9780,7 @@ packages: tsconfig-paths: 3.14.1 transitivePeerDependencies: - supports-color + dev: false /eslint-import-resolver-typescript/2.7.1_hpmu7kn6tcn2vnxpfzvv33bxmy: resolution: @@ -9864,6 +9863,7 @@ packages: - eslint-import-resolver-typescript - eslint-import-resolver-webpack - supports-color + dev: false /eslint-plugin-import/2.26.0_zhtk6rij7obli3ams3sxis7j7e: resolution: @@ -10389,8 +10389,6 @@ packages: regex-not: 1.0.2 snapdragon: 0.8.2 to-regex: 3.0.2 - transitivePeerDependencies: - - supports-color dev: false /expand-brackets/2.1.4_supports-color@8.1.1: @@ -10460,49 +10458,6 @@ packages: type-is: 1.6.18 utils-merge: 1.0.1 vary: 1.1.2 - transitivePeerDependencies: - - supports-color - dev: true - - /express/4.17.3_supports-color@8.1.1: - resolution: - { - integrity: sha512-yuSQpz5I+Ch7gFrPCk4/c+dIBKlQUxtgwqzph132bsT6qhuzss6I8cLJQz7B3rFblzd6wtcI0ZbGltH/C4LjUg==, - } - engines: {node: ">= 0.10.0"} - dependencies: - accepts: 1.3.8 - array-flatten: 1.1.1 - body-parser: 1.19.2_supports-color@8.1.1 - content-disposition: 0.5.4 - content-type: 1.0.4 - cookie: 0.4.2 - cookie-signature: 1.0.6 - debug: 2.6.9_supports-color@8.1.1 - depd: 1.1.2 - encodeurl: 1.0.2 - escape-html: 1.0.3 - etag: 1.8.1 - finalhandler: 1.1.2_supports-color@8.1.1 - fresh: 0.5.2 - merge-descriptors: 1.0.1 - methods: 1.1.2 - on-finished: 2.3.0 - parseurl: 1.3.3 - path-to-regexp: 0.1.7 - proxy-addr: 2.0.7 - qs: 6.9.7 - range-parser: 1.2.1 - safe-buffer: 5.2.1 - send: 0.17.2_supports-color@8.1.1 - serve-static: 1.14.2_supports-color@8.1.1 - setprototypeof: 1.2.0 - statuses: 1.5.0 - type-is: 1.6.18 - utils-merge: 1.0.1 - vary: 1.1.2 - transitivePeerDependencies: - - supports-color dev: true /extend-shallow/2.0.1: @@ -10560,8 +10515,6 @@ packages: regex-not: 1.0.2 snapdragon: 0.8.2 to-regex: 3.0.2 - transitivePeerDependencies: - - supports-color dev: false /extglob/2.0.4_supports-color@8.1.1: @@ -10619,8 +10572,6 @@ packages: is-glob: 4.0.3 merge2: 1.4.1 micromatch: 3.1.10 - transitivePeerDependencies: - - supports-color dev: false /fast-glob/3.2.11: @@ -10737,26 +10688,6 @@ packages: parseurl: 1.3.3 statuses: 1.5.0 unpipe: 1.0.0 - transitivePeerDependencies: - - supports-color - dev: true - - /finalhandler/1.1.2_supports-color@8.1.1: - resolution: - { - integrity: sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==, - } - engines: {node: ">= 0.8"} - dependencies: - debug: 2.6.9_supports-color@8.1.1 - encodeurl: 1.0.2 - escape-html: 1.0.3 - on-finished: 2.3.0 - parseurl: 1.3.3 - statuses: 1.5.0 - unpipe: 1.0.0 - transitivePeerDependencies: - - supports-color dev: true /find-cache-dir/2.1.0: @@ -11129,8 +11060,6 @@ packages: fs-extra: 7.0.1 globby: 9.2.0 read-yaml-file: 1.1.0 - transitivePeerDependencies: - - supports-color dev: false /glob-parent/3.1.0: @@ -11244,8 +11173,6 @@ packages: ignore: 4.0.6 pify: 4.0.1 slash: 2.0.0 - transitivePeerDependencies: - - supports-color dev: false /got/11.8.1: @@ -13938,8 +13865,6 @@ packages: regex-not: 1.0.2 snapdragon: 0.8.2 to-regex: 3.0.2 - transitivePeerDependencies: - - supports-color dev: false /micromatch/3.1.10_supports-color@8.1.1: @@ -14252,8 +14177,6 @@ packages: regex-not: 1.0.2 snapdragon: 0.8.2 to-regex: 3.0.2 - transitivePeerDependencies: - - supports-color dev: false /nanomatch/1.2.13_supports-color@8.1.1: @@ -16361,6 +16284,44 @@ packages: "@babel/code-frame": 7.16.7 dev: true + /rollup-plugin-dts/4.2.2_rollup@2.77.2+typescript@4.7.4: + resolution: + { + integrity: sha512-A3g6Rogyko/PXeKoUlkjxkP++8UDVpgA7C+Tdl77Xj4fgEaIjPSnxRmR53EzvoYy97VMVwLAOcWJudaVAuxneQ==, + } + engines: {node: ">=v12.22.11"} + peerDependencies: + rollup: ^2.55 + typescript: ^4.1 + dependencies: + magic-string: 0.26.2 + rollup: 2.77.2 + typescript: 4.7.4 + optionalDependencies: + "@babel/code-frame": 7.16.7 + dev: true + + /rollup-plugin-esbuild/4.9.1_732fc8c30ba0be4bf7546580b6b6ccfb: + resolution: + { + integrity: sha512-qn/x7Wz9p3Xnva99qcb+nopH0d2VJwVnsxJTGEg+Sh2Z3tqQl33MhOwzekVo1YTKgv+yAmosjcBRJygMfGrtLw==, + } + engines: {node: ">=12"} + peerDependencies: + esbuild: ">=0.10.1" + rollup: ^1.20.0 || ^2.0.0 + dependencies: + "@rollup/pluginutils": 4.2.1 + debug: 4.3.4_supports-color@8.1.1 + es-module-lexer: 0.9.3 + esbuild: 0.14.51 + joycon: 3.1.1 + jsonc-parser: 3.0.0 + rollup: 2.77.2 + transitivePeerDependencies: + - supports-color + dev: true + /rollup-plugin-esbuild/4.9.1_ecpsl2p7zl5puhr4xxlpah6uzm: resolution: { @@ -16587,32 +16548,6 @@ packages: on-finished: 2.3.0 range-parser: 1.2.1 statuses: 1.5.0 - transitivePeerDependencies: - - supports-color - dev: true - - /send/0.17.2_supports-color@8.1.1: - resolution: - { - integrity: sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==, - } - engines: {node: ">= 0.8.0"} - dependencies: - debug: 2.6.9_supports-color@8.1.1 - depd: 1.1.2 - destroy: 1.0.4 - encodeurl: 1.0.2 - escape-html: 1.0.3 - etag: 1.8.1 - fresh: 0.5.2 - http-errors: 1.8.1 - mime: 1.6.0 - ms: 2.1.3 - on-finished: 2.3.0 - range-parser: 1.2.1 - statuses: 1.5.0 - transitivePeerDependencies: - - supports-color dev: true /serve-static/1.14.2: @@ -16626,23 +16561,6 @@ packages: escape-html: 1.0.3 parseurl: 1.3.3 send: 0.17.2 - transitivePeerDependencies: - - supports-color - dev: true - - /serve-static/1.14.2_supports-color@8.1.1: - resolution: - { - integrity: sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==, - } - engines: {node: ">= 0.8.0"} - dependencies: - encodeurl: 1.0.2 - escape-html: 1.0.3 - parseurl: 1.3.3 - send: 0.17.2_supports-color@8.1.1 - transitivePeerDependencies: - - supports-color dev: true /set-blocking/2.0.0: @@ -16870,8 +16788,6 @@ packages: source-map: 0.5.7 source-map-resolve: 0.5.3 use: 3.1.1 - transitivePeerDependencies: - - supports-color dev: false /snapdragon/0.8.2_supports-color@8.1.1: @@ -16958,6 +16874,7 @@ packages: integrity: sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==, } engines: {node: ">=0.10.0"} + dev: false /source-map/0.6.1: resolution: @@ -17805,6 +17722,7 @@ packages: typescript: 4.6.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + dev: false /ts-node/10.9.1_kakyiqi62sfonxvjmz3ft5vt7y: resolution: @@ -18208,6 +18126,7 @@ packages: } engines: {node: ">=4.2.0"} hasBin: true + dev: true /typescript/4.7.4: resolution: @@ -18216,6 +18135,7 @@ packages: } engines: {node: ">=4.2.0"} hasBin: true + dev: true /uc.micro/1.0.6: resolution: @@ -18340,8 +18260,8 @@ packages: pretty-bytes: 6.0.0 rimraf: 3.0.2 rollup: 2.77.2 - rollup-plugin-dts: 4.2.2_oo3i3f3qmqiztdz5qgxrrjmd5e - rollup-plugin-esbuild: 4.9.1_omx4rqyluc7ex52umwalnnwm7m + rollup-plugin-dts: 4.2.2_rollup@2.77.2+typescript@4.7.4 + rollup-plugin-esbuild: 4.9.1_732fc8c30ba0be4bf7546580b6b6ccfb scule: 0.2.1 typescript: 4.7.4 untyped: 0.4.4_supports-color@8.1.1 From c85f85d928534d11f015dd2fa853b5de52816cf8 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 27 Sep 2022 00:24:10 +0530 Subject: [PATCH 03/14] cleanup --- packages/blitz/src/cli/commands/generate.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/blitz/src/cli/commands/generate.ts b/packages/blitz/src/cli/commands/generate.ts index c56f64c320..b006cbc36e 100644 --- a/packages/blitz/src/cli/commands/generate.ts +++ b/packages/blitz/src/cli/commands/generate.ts @@ -226,7 +226,6 @@ const createCustomTemplates = async () => { process.exit(0) } const customTemplatesPath = require("path").join(process.cwd(), "app") - //copy the templates folder in the @blitzjs/generator package to the app folder const fsExtra = await import("fs-extra") const blitzGeneratorPath = require.resolve("@blitzjs/generator") const templateFolder = ["form", "page", "query", "mutation", "queries", "mutations"] From d260c09008c17d1add3dd1e4bca457070080efe1 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 27 Sep 2022 13:20:38 +0530 Subject: [PATCH 04/14] update blitz-server.ts when user generates custom templates --- apps/toolkit-app/app/blitz-server.ts | 7 --- packages/blitz/src/cli/commands/generate.ts | 15 ++++- packages/generator/src/generator.ts | 62 +++++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/apps/toolkit-app/app/blitz-server.ts b/apps/toolkit-app/app/blitz-server.ts index 1040fd9d59..37f87cd202 100644 --- a/apps/toolkit-app/app/blitz-server.ts +++ b/apps/toolkit-app/app/blitz-server.ts @@ -2,7 +2,6 @@ import { setupBlitzServer } from "@blitzjs/next" import { AuthServerPlugin, PrismaStorage } from "@blitzjs/auth" import db from "db" import { simpleRolesIsAuthorized } from "@blitzjs/auth" -import type { BlitzServerConfig } from "blitz" const { gSSP, gSP, api } = setupBlitzServer({ plugins: [ @@ -14,10 +13,4 @@ const { gSSP, gSP, api } = setupBlitzServer({ ], }) -const config: BlitzServerConfig = { - customTemplates: "app/templates", -} - export { gSSP, gSP, api } - -export default config diff --git a/packages/blitz/src/cli/commands/generate.ts b/packages/blitz/src/cli/commands/generate.ts index c56f64c320..52d25f188f 100644 --- a/packages/blitz/src/cli/commands/generate.ts +++ b/packages/blitz/src/cli/commands/generate.ts @@ -15,6 +15,7 @@ import { MutationsGenerator, ModelGenerator, QueryGenerator, + addCustomTemplatesBlitzConfig, } from "@blitzjs/generator" import {log} from "../../logging" @@ -225,15 +226,23 @@ const createCustomTemplates = async () => { if (!continuePrompt.value) { process.exit(0) } - const customTemplatesPath = require("path").join(process.cwd(), "app") - //copy the templates folder in the @blitzjs/generator package to the app folder + const templatesPath = await prompts({ + type: "text", + name: "value", + message: `Enter the path to save the custom templates folder`, + initial: "app/templates", + }) + const templatesPathValue: string = templatesPath.value + const isTypeScript = await getIsTypeScript() + addCustomTemplatesBlitzConfig(templatesPathValue, isTypeScript) + const customTemplatesPath = require("path").join(process.cwd(), templatesPathValue) const fsExtra = await import("fs-extra") const blitzGeneratorPath = require.resolve("@blitzjs/generator") const templateFolder = ["form", "page", "query", "mutation", "queries", "mutations"] for (const template of templateFolder) { await fsExtra.copy( require("path").join(blitzGeneratorPath, "..", "templates", template), - require("path").join(customTemplatesPath, "templates", template), + require("path").join(customTemplatesPath, template), ) } log.success("🚀 Custom templates created in app/templates directory") diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index 909b1b3224..f625b19613 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -16,6 +16,68 @@ import {readdirRecursive} from "./utils/readdir-recursive" import prettier from "prettier" const debug = require("debug")("blitz:generator") +export const addCustomTemplatesBlitzConfig = ( + customTemplatesPath: string, + isTypeScript: boolean, +) => { + const blitzServerPath = require("path").join(process.cwd(), "app/blitz-server.ts") + const userConfigModuleSource = fs.readFileSync(blitzServerPath, {encoding: "utf-8"}) + const userConfigModule = j(userConfigModuleSource, {parser: customTsParser}) + const program = userConfigModule.get() + const defaultDeclaration = userConfigModule.find(j.ExportDefaultDeclaration) + const defaultConfig = defaultDeclaration.paths()[0]?.value + if (!defaultConfig) { + const config = j.identifier("config") + const configVariable = j.variableDeclaration("const", [ + j.variableDeclarator( + config, + j.objectExpression([ + j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), + ]), + ), + ]) + if (isTypeScript) { + const type = j.tsTypeAnnotation(j.tsTypeReference(j.identifier("BlitzServerConfig"))) + const declaration: any = configVariable?.declarations + declaration[0].id.typeAnnotation = type + const typeImport = j.importDeclaration( + [j.importSpecifier(j.identifier("BlitzServerConfig"))], + j.literal("blitz"), + ) + typeImport.importKind = "type" + program.node.program.body.unshift(typeImport) + } + const defaultConfig = j.exportDefaultDeclaration(j.identifier("config")) + program.node.program.body.push(configVariable) + program.node.program.body.push(defaultConfig) + } else { + const config = defaultConfig.declaration + if (config.type === "Identifier") { + const configVariable = userConfigModule.find(j.VariableDeclarator, {id: {name: config.name}}) + const customTemplates = configVariable.find(j.ObjectProperty, { + key: {name: "customTemplates"}, + }) + customTemplates.remove() + configVariable + .find(j.ObjectExpression) + .get() + .node.properties.push( + j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), + ) + } else if (config.type === "ObjectExpression") { + const customTemplates = userConfigModule.find(j.ObjectProperty, { + key: {name: "customTemplates"}, + }) + customTemplates.remove() + config.properties.push( + j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), + ) + } + } + const newSource = userConfigModule.toSource() + fs.writeFileSync(blitzServerPath, newSource) +} + export const customTsParser = { parse(source: string, options?: Overrides) { const babelOptions = getBabelOptions(options) From 19d2ba6d6198ff5b29d921e8110d936e063e0120 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 27 Sep 2022 13:41:05 +0530 Subject: [PATCH 05/14] add to help --- packages/blitz/src/cli/commands/generate.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/blitz/src/cli/commands/generate.ts b/packages/blitz/src/cli/commands/generate.ts index 52d25f188f..03969c1f4f 100644 --- a/packages/blitz/src/cli/commands/generate.ts +++ b/packages/blitz/src/cli/commands/generate.ts @@ -201,6 +201,11 @@ const getHelp = async () => { For example, this command generates pages under pages/projects/[projectId]/tasks/ > blitz generate all tasks --parent=projects + + # The '--generate-custom-templates' flag will copy the default templates to your app. + This is useful if you want to customize the templates for your app + + > blitz generate --generate-custom-templates # Database models can also be generated directly from the CLI. Model fields can be specified with any generator that generates a database model ("all", "model", "resource"). @@ -235,6 +240,7 @@ const createCustomTemplates = async () => { const templatesPathValue: string = templatesPath.value const isTypeScript = await getIsTypeScript() addCustomTemplatesBlitzConfig(templatesPathValue, isTypeScript) + log.success(`🚀 Custom templates path added/updated in app/blitz-server file`) const customTemplatesPath = require("path").join(process.cwd(), templatesPathValue) const fsExtra = await import("fs-extra") const blitzGeneratorPath = require.resolve("@blitzjs/generator") @@ -245,7 +251,7 @@ const createCustomTemplates = async () => { require("path").join(customTemplatesPath, template), ) } - log.success("🚀 Custom templates created in app/templates directory") + log.success(`🚀 Custom templates created in ${templatesPathValue} directory`) process.exit(0) } } From 6985dd92c8724152f34bedc0b6edf94ec9c5d231 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 27 Sep 2022 19:22:32 +0530 Subject: [PATCH 06/14] fix blitz-server loading in javascript --- packages/generator/src/generator.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index f625b19613..60abf43f66 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -20,7 +20,8 @@ export const addCustomTemplatesBlitzConfig = ( customTemplatesPath: string, isTypeScript: boolean, ) => { - const blitzServerPath = require("path").join(process.cwd(), "app/blitz-server.ts") + const blitzServer = isTypeScript ? "app/blitz-server.ts" : "app/blitz-server.js" + const blitzServerPath = require("path").join(process.cwd(), blitzServer) const userConfigModuleSource = fs.readFileSync(blitzServerPath, {encoding: "utf-8"}) const userConfigModule = j(userConfigModuleSource, {parser: customTsParser}) const program = userConfigModule.get() From 78fcc2a50fe1794a5171a25e615e0176f28c5d8c Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 27 Sep 2022 19:22:53 +0530 Subject: [PATCH 07/14] Create slow-impalas-tap.md --- .changeset/slow-impalas-tap.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/slow-impalas-tap.md diff --git a/.changeset/slow-impalas-tap.md b/.changeset/slow-impalas-tap.md new file mode 100644 index 0000000000..18d9852483 --- /dev/null +++ b/.changeset/slow-impalas-tap.md @@ -0,0 +1,6 @@ +--- +"blitz": patch +"@blitzjs/generator": patch +--- + +#3748 Add custom template usage back to toolkit From 5409cf1bc3df42c48cf703ff5771a409fb82f348 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 29 Sep 2022 16:53:08 +0530 Subject: [PATCH 08/14] convert flag to command, default export to named export cliConfig --- apps/toolkit-app/app/blitz-server.ts | 5 ++ packages/blitz/src/cli/commands/generate.ts | 90 +++++++++++---------- packages/generator/src/generator.ts | 70 +++++++++------- 3 files changed, 94 insertions(+), 71 deletions(-) diff --git a/apps/toolkit-app/app/blitz-server.ts b/apps/toolkit-app/app/blitz-server.ts index 37f87cd202..14d703662c 100644 --- a/apps/toolkit-app/app/blitz-server.ts +++ b/apps/toolkit-app/app/blitz-server.ts @@ -1,3 +1,4 @@ +import type { BlitzServerConfig } from "blitz" import { setupBlitzServer } from "@blitzjs/next" import { AuthServerPlugin, PrismaStorage } from "@blitzjs/auth" import db from "db" @@ -14,3 +15,7 @@ const { gSSP, gSP, api } = setupBlitzServer({ }) export { gSSP, gSP, api } + +export const cliConfig: BlitzServerConfig = { + customTemplates: "app/templates", +} diff --git a/packages/blitz/src/cli/commands/generate.ts b/packages/blitz/src/cli/commands/generate.ts index 03969c1f4f..6758eb3c2c 100644 --- a/packages/blitz/src/cli/commands/generate.ts +++ b/packages/blitz/src/cli/commands/generate.ts @@ -32,6 +32,7 @@ enum ResourceType { Mutations = "mutations", Mutation = "mutation", Resource = "resource", + CustomTemplates = "custom-templates", } function modelName(input: string = "") { @@ -47,6 +48,39 @@ function ModelNames(input: string = "") { return pluralPascal(input) } +const createCustomTemplates = async () => { + const continuePrompt = await prompts({ + type: "confirm", + name: "value", + message: `This will copy the default templates to your app/templates folder. Do you want to continue?`, + }) + if (!continuePrompt.value) { + process.exit(0) + } + const templatesPath = await prompts({ + type: "text", + name: "value", + message: `Enter the path to save the custom templates folder`, + initial: "app/templates", + }) + const templatesPathValue: string = templatesPath.value + const isTypeScript = await getIsTypeScript() + addCustomTemplatesBlitzConfig(templatesPathValue, isTypeScript) + log.success(`🚀 Custom templates path added/updated in app/blitz-server file`) + const customTemplatesPath = require("path").join(process.cwd(), templatesPathValue) + const fsExtra = await import("fs-extra") + const blitzGeneratorPath = require.resolve("@blitzjs/generator") + const templateFolder = ["form", "page", "query", "mutation", "queries", "mutations"] + for (const template of templateFolder) { + await fsExtra.copy( + require("path").join(blitzGeneratorPath, "..", "templates", template), + require("path").join(customTemplatesPath, template), + ) + } + log.success(`🚀 Custom templates created in ${templatesPathValue} directory`) + process.exit(0) +} + const generatorMap = { [ResourceType.All]: [ PageGenerator, @@ -63,6 +97,7 @@ const generatorMap = { [ResourceType.Mutations]: [MutationsGenerator], [ResourceType.Mutation]: [MutationGenerator], [ResourceType.Resource]: [QueriesGenerator, MutationsGenerator, ModelGenerator], + [ResourceType.CustomTemplates]: [], } const args = arg( @@ -74,7 +109,6 @@ const args = arg( "--parent": String, "--dry-run": Boolean, "--env": String, - "--generate-custom-templates": Boolean, // Aliases "-e": "--env", @@ -201,11 +235,13 @@ const getHelp = async () => { For example, this command generates pages under pages/projects/[projectId]/tasks/ > blitz generate all tasks --parent=projects - - # The '--generate-custom-templates' flag will copy the default templates to your app. - This is useful if you want to customize the templates for your app + + # To customize the templates used by the blitz generate command, - > blitz generate --generate-custom-templates + > blitz generate custom-templates + + This command will copy the default templates to your app and update the app/blitz-server file to enable + the custom templating feature of the blitz CLI # Database models can also be generated directly from the CLI. Model fields can be specified with any generator that generates a database model ("all", "model", "resource"). @@ -221,45 +257,12 @@ const getHelp = async () => { } } -const createCustomTemplates = async () => { - if (args["--generate-custom-templates"]) { - const continuePrompt = await prompts({ - type: "confirm", - name: "value", - message: `This will copy the default templates to your app/templates folder. Do you want to continue?`, - }) - if (!continuePrompt.value) { - process.exit(0) - } - const templatesPath = await prompts({ - type: "text", - name: "value", - message: `Enter the path to save the custom templates folder`, - initial: "app/templates", - }) - const templatesPathValue: string = templatesPath.value - const isTypeScript = await getIsTypeScript() - addCustomTemplatesBlitzConfig(templatesPathValue, isTypeScript) - log.success(`🚀 Custom templates path added/updated in app/blitz-server file`) - const customTemplatesPath = require("path").join(process.cwd(), templatesPathValue) - const fsExtra = await import("fs-extra") - const blitzGeneratorPath = require.resolve("@blitzjs/generator") - const templateFolder = ["form", "page", "query", "mutation", "queries", "mutations"] - for (const template of templateFolder) { - await fsExtra.copy( - require("path").join(blitzGeneratorPath, "..", "templates", template), - require("path").join(customTemplatesPath, template), - ) - } - log.success(`🚀 Custom templates created in ${templatesPathValue} directory`) - process.exit(0) - } -} - const generate: CliCommand = async () => { await getHelp() - await createCustomTemplates() await determineType() + if (selectedType === "custom-templates") { + await createCustomTemplates() + } if (!selectedModelName) { await determineName() } @@ -278,13 +281,14 @@ const generate: CliCommand = async () => { const {unregister} = register({ target: "es6", }) - const blitzConfig = require(blitzServer).default + const blitzConfig = require(blitzServer) + const {cliConfig} = blitzConfig unregister() for (const GeneratorClass of generators) { const generator = new GeneratorClass({ destinationRoot: require("path").resolve(), - templateDir: blitzConfig?.customTemplates, + templateDir: cliConfig?.customTemplates, extraArgs: args["_"].slice(3) as string[], modelName: singularRootContext, modelNames: modelNames(singularRootContext), diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index 60abf43f66..e77168db5b 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -25,10 +25,23 @@ export const addCustomTemplatesBlitzConfig = ( const userConfigModuleSource = fs.readFileSync(blitzServerPath, {encoding: "utf-8"}) const userConfigModule = j(userConfigModuleSource, {parser: customTsParser}) const program = userConfigModule.get() - const defaultDeclaration = userConfigModule.find(j.ExportDefaultDeclaration) - const defaultConfig = defaultDeclaration.paths()[0]?.value - if (!defaultConfig) { - const config = j.identifier("config") + const cliConfigDeclaration = userConfigModule + .find(j.ExportNamedDeclaration, { + declaration: { + type: "VariableDeclaration", + declarations: [ + { + id: { + name: "cliConfig", + }, + }, + ], + }, + }) + .paths() + .at(0) + if (!cliConfigDeclaration) { + const config = j.identifier("cliConfig") const configVariable = j.variableDeclaration("const", [ j.variableDeclarator( config, @@ -48,31 +61,32 @@ export const addCustomTemplatesBlitzConfig = ( typeImport.importKind = "type" program.node.program.body.unshift(typeImport) } - const defaultConfig = j.exportDefaultDeclaration(j.identifier("config")) - program.node.program.body.push(configVariable) - program.node.program.body.push(defaultConfig) + const exportConfig = j.exportNamedDeclaration(configVariable) + program.node.program.body.push(exportConfig) } else { - const config = defaultConfig.declaration - if (config.type === "Identifier") { - const configVariable = userConfigModule.find(j.VariableDeclarator, {id: {name: config.name}}) - const customTemplates = configVariable.find(j.ObjectProperty, { - key: {name: "customTemplates"}, - }) - customTemplates.remove() - configVariable - .find(j.ObjectExpression) - .get() - .node.properties.push( - j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), - ) - } else if (config.type === "ObjectExpression") { - const customTemplates = userConfigModule.find(j.ObjectProperty, { - key: {name: "customTemplates"}, - }) - customTemplates.remove() - config.properties.push( - j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), - ) + const configType = cliConfigDeclaration.value.declaration?.type + if (configType === "VariableDeclaration") { + const config = cliConfigDeclaration.value.declaration.declarations[0] + if (config?.type === "VariableDeclarator") { + const configProperties = config.init + if (configProperties?.type === "ObjectExpression") { + const customTemplatesProperty = configProperties.properties.find( + (property: any) => property.key.name === "customTemplates", + ) + if (!customTemplatesProperty) { + configProperties.properties.push( + j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), + ) + } else { + if (customTemplatesProperty.type === "ObjectProperty") { + const customValue = customTemplatesProperty.value + if (customValue.type === "StringLiteral") { + customValue.value = customTemplatesPath + } + } + } + } + } } } const newSource = userConfigModule.toSource() From 4189312c81a8e0df95add5967a43a02c864b2195 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 29 Sep 2022 17:03:42 +0530 Subject: [PATCH 09/14] fix types --- packages/generator/src/generator.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index e77168db5b..85d6b9391a 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -70,9 +70,14 @@ export const addCustomTemplatesBlitzConfig = ( if (config?.type === "VariableDeclarator") { const configProperties = config.init if (configProperties?.type === "ObjectExpression") { - const customTemplatesProperty = configProperties.properties.find( - (property: any) => property.key.name === "customTemplates", - ) + const customTemplatesProperty = configProperties.properties.find((property) => { + if (property.type === "ObjectProperty") { + const key = property.key + if (key.type === "Identifier") { + return key.name === "customTemplates" + } + } + }) if (!customTemplatesProperty) { configProperties.properties.push( j.objectProperty(j.identifier("customTemplates"), j.literal(customTemplatesPath)), From f62d2485a7a4fb79ea017c1e498ee3fd55bcdfa1 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 29 Sep 2022 17:06:56 +0530 Subject: [PATCH 10/14] update changeset --- .changeset/slow-impalas-tap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/slow-impalas-tap.md b/.changeset/slow-impalas-tap.md index 18d9852483..63929abf31 100644 --- a/.changeset/slow-impalas-tap.md +++ b/.changeset/slow-impalas-tap.md @@ -3,4 +3,4 @@ "@blitzjs/generator": patch --- -#3748 Add custom template usage back to toolkit +#3748 Add custom template usage back to toolkit, and a new command `blitz generate custom-templates` to provide an easy starting point for custom templates. From fea099e7a9907a025bca93332600375ddb8ddeec Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 29 Sep 2022 17:08:37 +0530 Subject: [PATCH 11/14] update changeset --- .changeset/slow-impalas-tap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/slow-impalas-tap.md b/.changeset/slow-impalas-tap.md index 63929abf31..aa310f3f34 100644 --- a/.changeset/slow-impalas-tap.md +++ b/.changeset/slow-impalas-tap.md @@ -3,4 +3,4 @@ "@blitzjs/generator": patch --- -#3748 Add custom template usage back to toolkit, and a new command `blitz generate custom-templates` to provide an easy starting point for custom templates. +#3748 Add custom template usage back to toolkit, and a new command `blitz generate custom-templates` to provide an easy starting point for users to customize the default templates. From 9cdafa49958955aa1452dd77e048a4eaffde34b7 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Thu, 29 Sep 2022 19:28:25 +0530 Subject: [PATCH 12/14] update type from BlitzServerConfig to BlitzCliConfig --- apps/toolkit-app/app/blitz-server.ts | 4 ++-- packages/blitz/src/types.ts | 2 +- packages/generator/src/generator.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/toolkit-app/app/blitz-server.ts b/apps/toolkit-app/app/blitz-server.ts index 14d703662c..b911a664b7 100644 --- a/apps/toolkit-app/app/blitz-server.ts +++ b/apps/toolkit-app/app/blitz-server.ts @@ -1,4 +1,4 @@ -import type { BlitzServerConfig } from "blitz" +import type { BlitzCliConfig } from "blitz" import { setupBlitzServer } from "@blitzjs/next" import { AuthServerPlugin, PrismaStorage } from "@blitzjs/auth" import db from "db" @@ -16,6 +16,6 @@ const { gSSP, gSP, api } = setupBlitzServer({ export { gSSP, gSP, api } -export const cliConfig: BlitzServerConfig = { +export const cliConfig: BlitzCliConfig = { customTemplates: "app/templates", } diff --git a/packages/blitz/src/types.ts b/packages/blitz/src/types.ts index 6eecec7caa..ec2b8c58aa 100644 --- a/packages/blitz/src/types.ts +++ b/packages/blitz/src/types.ts @@ -6,7 +6,7 @@ export interface RouteUrlObject extends Pick { pathname: string } -export type BlitzServerConfig = { +export type BlitzCliConfig = { customTemplates?: string } diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index 85d6b9391a..518662e6aa 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -51,11 +51,11 @@ export const addCustomTemplatesBlitzConfig = ( ), ]) if (isTypeScript) { - const type = j.tsTypeAnnotation(j.tsTypeReference(j.identifier("BlitzServerConfig"))) + const type = j.tsTypeAnnotation(j.tsTypeReference(j.identifier("BlitzCliConfig"))) const declaration: any = configVariable?.declarations declaration[0].id.typeAnnotation = type const typeImport = j.importDeclaration( - [j.importSpecifier(j.identifier("BlitzServerConfig"))], + [j.importSpecifier(j.identifier("BlitzCliConfig"))], j.literal("blitz"), ) typeImport.importKind = "type" From 16ce7ada01fdda2658af82566bb0c72c8394c706 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 11 Oct 2022 16:00:54 +0530 Subject: [PATCH 13/14] Update .changeset/slow-impalas-tap.md Co-authored-by: Aleksandra --- .changeset/slow-impalas-tap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/slow-impalas-tap.md b/.changeset/slow-impalas-tap.md index aa310f3f34..740d5bd76d 100644 --- a/.changeset/slow-impalas-tap.md +++ b/.changeset/slow-impalas-tap.md @@ -3,4 +3,4 @@ "@blitzjs/generator": patch --- -#3748 Add custom template usage back to toolkit, and a new command `blitz generate custom-templates` to provide an easy starting point for users to customize the default templates. +Allow passing custom templates to the `blitz generate` command. Extend the `generate` command with `custom-templates` to provide an easy starting point for users to customize the default templates: `blitz generate custom-templates`. From 7690ad2f9e45646467f7c62282505ea59059fb7f Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 11 Oct 2022 16:13:55 +0530 Subject: [PATCH 14/14] update pnpm-lock --- pnpm-lock.yaml | 82 +++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c09023af2..3cc33bdb3b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,7 +49,7 @@ importers: "@types/preview-email": 2.0.1 "@types/react": 18.0.17 "@typescript-eslint/eslint-plugin": 5.9.1 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 eslint: 7.32.0 eslint-config-next: 12.2.0 eslint-config-prettier: 8.5.0 @@ -120,7 +120,7 @@ importers: "@types/preview-email": 2.0.1 "@types/react": 18.0.17 "@typescript-eslint/eslint-plugin": 5.9.1 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 eslint: 7.32.0 eslint-config-next: 12.2.0 eslint-config-prettier: 8.5.0 @@ -235,7 +235,7 @@ importers: "@types/node-fetch": 2.6.1 "@types/react": 18.0.17 b64-lite: 1.4.0 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 eslint: 7.32.0 fs-extra: 10.0.1 get-port: 6.1.2 @@ -650,8 +650,8 @@ importers: packages/blitz: specifiers: - "@blitzjs/config": workspace:2.0.0-beta.10 - "@blitzjs/generator": 2.0.0-beta.10 + "@blitzjs/config": workspace:2.0.0-beta.11 + "@blitzjs/generator": 2.0.0-beta.11 "@mrleebo/prisma-ast": 0.2.6 "@types/cookie": 0.4.1 "@types/cross-spawn": 6.0.2 @@ -795,7 +795,7 @@ importers: packages/blitz-auth: specifiers: - "@blitzjs/config": workspace:2.0.0-beta.10 + "@blitzjs/config": workspace:2.0.0-beta.11 "@testing-library/react": 13.0.0 "@testing-library/react-hooks": 7.0.2 "@types/b64-lite": 1.3.0 @@ -809,7 +809,7 @@ importers: "@types/secure-password": 3.1.1 b64-lite: 1.4.0 bad-behavior: 1.0.1 - blitz: 2.0.0-beta.5 + blitz: 2.0.0-beta.11 cookie: 0.4.1 cookie-session: 2.0.0 debug: 4.3.3 @@ -862,8 +862,8 @@ importers: packages/blitz-next: specifiers: - "@blitzjs/config": workspace:2.0.0-beta.10 - "@blitzjs/rpc": 2.0.0-beta.10 + "@blitzjs/config": workspace:2.0.0-beta.11 + "@blitzjs/rpc": 2.0.0-beta.11 "@tanstack/react-query": 4.0.10 "@testing-library/dom": 8.13.0 "@testing-library/jest-dom": 5.16.3 @@ -875,7 +875,7 @@ importers: "@types/react": 18.0.17 "@types/react-dom": 17.0.14 "@types/testing-library__react-hooks": 4.0.0 - blitz: 2.0.0-beta.5 + blitz: 2.0.0-beta.11 cross-spawn: 7.0.3 debug: 4.3.3 find-up: 4.1.0 @@ -925,15 +925,15 @@ importers: packages/blitz-rpc: specifiers: - "@blitzjs/auth": 2.0.0-beta.10 - "@blitzjs/config": workspace:2.0.0-beta.10 + "@blitzjs/auth": 2.0.0-beta.11 + "@blitzjs/config": workspace:2.0.0-beta.11 "@tanstack/react-query": 4.0.10 "@types/debug": 4.1.7 "@types/react": 18.0.17 "@types/react-dom": 17.0.14 b64-lite: 1.4.0 bad-behavior: 1.0.1 - blitz: 2.0.0-beta.5 + blitz: 2.0.0-beta.11 chalk: ^4.1.0 debug: 4.3.3 next: 12.2.5 @@ -976,12 +976,12 @@ importers: "@babel/plugin-syntax-typescript": 7.17.12 "@babel/preset-env": 7.12.10 "@blitzjs/config": workspace:* - "@blitzjs/generator": 2.0.0-beta.10 + "@blitzjs/generator": 2.0.0-beta.11 "@types/jscodeshift": 0.11.2 "@types/node": 17.0.16 arg: 5.0.1 ast-types: 0.14.2 - blitz: 2.0.0-beta.5 + blitz: 2.0.0-beta.11 chalk: ^4.1.0 cross-spawn: 7.0.3 debug: 4.3.3 @@ -1036,7 +1036,7 @@ importers: "@babel/plugin-transform-typescript": 7.12.1 "@babel/preset-env": 7.12.10 "@babel/types": 7.12.10 - "@blitzjs/config": 2.0.0-beta.10 + "@blitzjs/config": 2.0.0-beta.11 "@juanm04/cpx": 2.0.1 "@mrleebo/prisma-ast": 0.4.1 "@types/babel__core": 7.1.19 @@ -1129,7 +1129,7 @@ importers: packages/pkg-template: specifiers: - "@blitzjs/config": 2.0.0-beta.10 + "@blitzjs/config": 2.0.0-beta.11 "@types/react": 18.0.17 "@types/react-dom": 17.0.14 "@typescript-eslint/eslint-plugin": 5.9.1 @@ -1153,7 +1153,7 @@ importers: recipes/base-web: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1164,7 +1164,7 @@ importers: recipes/bulma: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1176,7 +1176,7 @@ importers: specifiers: "@types/jscodeshift": 0.11.2 ast-types: 0.14.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1189,7 +1189,7 @@ importers: specifiers: "@types/jscodeshift": 0.11.2 ast-types: 0.14.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1201,7 +1201,7 @@ importers: recipes/emotion: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1211,20 +1211,20 @@ importers: recipes/gh-action-yarn-mariadb: specifiers: - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 dependencies: blitz: link:../../packages/blitz recipes/gh-action-yarn-postgres: specifiers: - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 dependencies: blitz: link:../../packages/blitz recipes/ghost: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1235,7 +1235,7 @@ importers: recipes/graphql-apollo-server: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 uuid: ^8.3.1 dependencies: @@ -1247,14 +1247,14 @@ importers: recipes/logrocket: specifiers: - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 dependencies: blitz: link:../../packages/blitz recipes/material-ui: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1266,7 +1266,7 @@ importers: specifiers: "@types/jscodeshift": 0.11.2 ast-types: 0.14.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1277,13 +1277,13 @@ importers: recipes/passenger: specifiers: - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 dependencies: blitz: link:../../packages/blitz recipes/quirrel: specifiers: - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 dependencies: blitz: link:../../packages/blitz @@ -1291,7 +1291,7 @@ importers: specifiers: "@types/jscodeshift": 0.11.2 ast-types: 0.14.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1302,14 +1302,14 @@ importers: recipes/render: specifiers: - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 dependencies: blitz: link:../../packages/blitz recipes/secureheaders: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 uuid: ^8.3.1 dependencies: @@ -1322,7 +1322,7 @@ importers: recipes/stitches: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1334,7 +1334,7 @@ importers: specifiers: "@types/jscodeshift": 0.11.2 ast-types: 0.14.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1346,7 +1346,7 @@ importers: recipes/tailwind: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1358,7 +1358,7 @@ importers: specifiers: "@types/jscodeshift": 0.11.2 ast-types: 0.14.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -1370,7 +1370,7 @@ importers: recipes/vanilla-extract: specifiers: "@types/jscodeshift": 0.11.2 - blitz: workspace:2.0.0-beta.5 + blitz: workspace:2.0.0-beta.11 jscodeshift: 0.13.0 dependencies: blitz: link:../../packages/blitz @@ -12920,7 +12920,7 @@ packages: pretty-format: 27.5.1 slash: 3.0.0 strip-json-comments: 3.1.1 - ts-node: 10.7.0_6sxvnwysvlo53egjnie7htsx5a + ts-node: 10.7.0_typescript@4.6.3 transitivePeerDependencies: - bufferutil - canvas @@ -18427,6 +18427,7 @@ packages: typescript: 4.7.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + dev: false /ts-node/10.7.0_fxg3r7oju3tntkxsvleuiot4fa: resolution: @@ -18493,7 +18494,6 @@ packages: typescript: 4.6.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - dev: false /ts-node/10.9.1_kakyiqi62sfonxvjmz3ft5vt7y: resolution: