create-plasmic-app 0.0.100 → 0.0.101

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/index.js CHANGED
@@ -62,7 +62,7 @@ const argv = yargs_1.default
62
62
  })
63
63
  .option("platform", {
64
64
  describe: "Target platform",
65
- choices: ["", "nextjs", "gatsby", "react"],
65
+ choices: ["", "nextjs", "gatsby", "react", "tanstack"],
66
66
  })
67
67
  .option("scheme", {
68
68
  describe: "Plasmic integration scheme",
@@ -185,6 +185,11 @@ function run() {
185
185
  name: "Gatsby",
186
186
  value: "gatsby",
187
187
  },
188
+ {
189
+ name: "TanStack Start",
190
+ short: "TanStack Start",
191
+ value: "tanstack",
192
+ },
188
193
  {
189
194
  name: "React (Vite)",
190
195
  short: "React (Vite)",
package/dist/lib.js CHANGED
@@ -51,6 +51,8 @@ function getCPAStrategy(platform) {
51
51
  return (yield Promise.resolve().then(() => __importStar(require("./gatsby/gatsby")))).gatsbyStrategy;
52
52
  case "react":
53
53
  return (yield Promise.resolve().then(() => __importStar(require("./react/react")))).reactStrategy;
54
+ case "tanstack":
55
+ return (yield Promise.resolve().then(() => __importStar(require("./tanstack/tanstack")))).tanstackStrategy;
54
56
  }
55
57
  });
56
58
  }
@@ -82,7 +84,7 @@ function create(args) {
82
84
  }
83
85
  // Calling `npx create-XXX` means we don't have to keep these dependencies up to date
84
86
  banner("CREATING THE PROJECT");
85
- if (!["nextjs", "gatsby", "react"].includes(platform)) {
87
+ if (!["nextjs", "gatsby", "react", "tanstack"].includes(platform)) {
86
88
  throw new Error(`Unrecognized platform: ${platform}`);
87
89
  }
88
90
  if (!["codegen", "loader"].includes(scheme)) {
@@ -0,0 +1,2 @@
1
+ import { CPAStrategy } from "../utils/strategy";
2
+ export declare const tanstackStrategy: CPAStrategy;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.tanstackStrategy = void 0;
16
+ const fs_1 = require("fs");
17
+ const path_1 = __importDefault(require("path"));
18
+ const cmd_utils_1 = require("../utils/cmd-utils");
19
+ const codegen_1 = require("../utils/codegen");
20
+ const file_utils_1 = require("../utils/file-utils");
21
+ const config_1 = require("./templates/file-router/config");
22
+ const plasmic_host_1 = require("./templates/file-router/plasmic-host");
23
+ const root_1 = require("./templates/file-router/root");
24
+ exports.tanstackStrategy = {
25
+ create: (args) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const { projectPath } = args;
27
+ const createCommand = `npx create-tsrouter-app@latest ${projectPath} --template file-router --add-ons start`;
28
+ yield (0, cmd_utils_1.spawnOrFail)(createCommand);
29
+ }),
30
+ installDeps: ({ scheme, projectPath }) => __awaiter(void 0, void 0, void 0, function* () {
31
+ if (scheme === "loader") {
32
+ throw new Error("Plasmic loader scheme is not supported for TanStack platform. Please use the codegen scheme instead.");
33
+ }
34
+ else {
35
+ return yield (0, codegen_1.installCodegenDeps)({ projectPath });
36
+ }
37
+ }),
38
+ overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const { projectPath, jsOrTs } = args;
40
+ /* We need to provide @plasmicapp/* packages in noExternal ssr packages for
41
+ * them to work properly during ssr phase.
42
+ */
43
+ if (jsOrTs === "ts") {
44
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app.config.ts"), (0, config_1.makeCustomAppConfig_file_router_codegen)());
45
+ }
46
+ }),
47
+ generateFiles: (args) => {
48
+ return generateFilesFileRouterTemplate(args);
49
+ },
50
+ build: (args) => __awaiter(void 0, void 0, void 0, function* () {
51
+ const { npmRunCmd, projectPath } = args;
52
+ yield (0, cmd_utils_1.spawnOrFail)(`${npmRunCmd} build`, projectPath);
53
+ }),
54
+ };
55
+ function generateFilesFileRouterTemplate(args) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
58
+ // Delete existing pages
59
+ (0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "src/routes", "*.*"));
60
+ if (scheme === "loader") {
61
+ throw new Error("Plasmic loader scheme is not supported for TanStack platform. Please use the codegen scheme instead.");
62
+ }
63
+ else {
64
+ // ./src/routes/__root.tsx
65
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "src/routes", `__root.${jsOrTs}x`), (0, root_1.makeCustomRoot_file_router_codegen)(jsOrTs));
66
+ // ./src/routes/plasmic-host.tsx
67
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "src/routes", `plasmic-host.${jsOrTs}x`), (0, plasmic_host_1.makePlasmicHostPage_fileRouter_codegen)());
68
+ // This should generate
69
+ // ./plasmic.json
70
+ // ./routes/index.tsx
71
+ // ./components/plasmic/**
72
+ yield (0, codegen_1.runCodegenSync)({
73
+ projectId,
74
+ projectApiToken,
75
+ projectPath,
76
+ });
77
+ }
78
+ });
79
+ }
@@ -0,0 +1 @@
1
+ export declare function makeCustomAppConfig_file_router_codegen(): string;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeCustomAppConfig_file_router_codegen = void 0;
4
+ function makeCustomAppConfig_file_router_codegen() {
5
+ return `import { defineConfig } from "@tanstack/react-start/config";
6
+ import viteTsConfigPaths from "vite-tsconfig-paths";
7
+ import tailwindcss from "@tailwindcss/vite";
8
+
9
+ export default defineConfig({
10
+ tsr: {
11
+ appDirectory: "src",
12
+ },
13
+ vite: {
14
+ plugins: [
15
+ // this is the plugin that enables path aliases
16
+ viteTsConfigPaths({
17
+ projects: ["./tsconfig.json"],
18
+ }),
19
+ tailwindcss(),
20
+ ],
21
+ ssr: {
22
+ noExternal: [
23
+ "@plasmicapp/data-sources",
24
+ "@plasmicapp/data-sources-context",
25
+ "@plasmicapp/prepass",
26
+ "@plasmicapp/query",
27
+ "@plasmicapp/react-web",
28
+ ],
29
+ },
30
+ },
31
+ })`;
32
+ }
33
+ exports.makeCustomAppConfig_file_router_codegen = makeCustomAppConfig_file_router_codegen;
@@ -0,0 +1 @@
1
+ export declare function makePlasmicHostPage_fileRouter_codegen(): string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makePlasmicHostPage_fileRouter_codegen = void 0;
4
+ function makePlasmicHostPage_fileRouter_codegen() {
5
+ return `import { createFileRoute } from '@tanstack/react-router'
6
+ import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/react-web/lib/host';
7
+
8
+ export const Route = createFileRoute('/plasmic-host')({
9
+ component: PlasmicHostRouteComponent,
10
+ })
11
+
12
+
13
+ // You can register any code components that you want to use here; see
14
+ // https://docs.plasmic.app/learn/code-components-ref/
15
+ // And configure your Plasmic project to use the host url pointing at
16
+ // the /plasmic-host page of your nextjs app (for example,
17
+ // http://localhost:3000/plasmic-host). See
18
+ // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
19
+
20
+ // registerComponent(...)
21
+
22
+ function PlasmicHostRouteComponent() {
23
+ return <PlasmicCanvasHost />
24
+ }
25
+ `;
26
+ }
27
+ exports.makePlasmicHostPage_fileRouter_codegen = makePlasmicHostPage_fileRouter_codegen;
@@ -0,0 +1,2 @@
1
+ import { JsOrTs } from "../../../utils/types";
2
+ export declare function makeCustomRoot_file_router_codegen(_jsOrTs: JsOrTs): string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeCustomRoot_file_router_codegen = void 0;
4
+ function makeCustomRoot_file_router_codegen(_jsOrTs) {
5
+ return `import { createRootRoute, HeadContent, Outlet, Scripts, Link } from '@tanstack/react-router'
6
+ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
7
+ import { PlasmicRootProvider } from "@plasmicapp/react-web"
8
+ import appCss from "../styles.css?url";
9
+
10
+ export const Route = createRootRoute({
11
+ head: () => ({
12
+ links: [
13
+ {
14
+ rel: 'stylesheet',
15
+ href: appCss,
16
+ },
17
+ ],
18
+ }),
19
+ component: () => (
20
+ <RootDocument>
21
+ <PlasmicRootProvider Link={Link}>
22
+ <Outlet />
23
+ <TanStackRouterDevtools />
24
+ </PlasmicRootProvider>
25
+ </RootDocument>
26
+ ),
27
+ })
28
+
29
+ function RootDocument({ children }: { children: React.ReactNode }) {
30
+ return (
31
+ <html lang="en">
32
+ <head>
33
+ <HeadContent />
34
+ </head>
35
+ <body>
36
+ {children}
37
+ <Scripts />
38
+ </body>
39
+ </html>
40
+ )
41
+ }
42
+ `;
43
+ }
44
+ exports.makeCustomRoot_file_router_codegen = makeCustomRoot_file_router_codegen;
@@ -1,5 +1,5 @@
1
1
  export type JsOrTs = "js" | "ts";
2
- export type PlatformType = "nextjs" | "gatsby" | "react";
2
+ export type PlatformType = "nextjs" | "gatsby" | "react" | "tanstack";
3
3
  export type PlatformOptions = {
4
4
  nextjs?: {
5
5
  appDir: boolean;
@@ -2,6 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.platformTypeToString = void 0;
4
4
  function platformTypeToString(s) {
5
- return s === "nextjs" ? "Next.js" : s === "gatsby" ? "Gatsby" : "React";
5
+ return s === "nextjs"
6
+ ? "Next.js"
7
+ : s === "gatsby"
8
+ ? "Gatsby"
9
+ : s === "tanstack"
10
+ ? "TanStack"
11
+ : "React";
6
12
  }
7
13
  exports.platformTypeToString = platformTypeToString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -46,5 +46,5 @@
46
46
  "validate-npm-package-name": "^3.0.0",
47
47
  "yargs": "^16.2.0"
48
48
  },
49
- "gitHead": "46ededb427fd9f6b017065e6623a082de0f10ec8"
49
+ "gitHead": "7199e5b0c2c94b6e95c81c8120d9861faf98d7ee"
50
50
  }
package/run-cpa.ts CHANGED
@@ -31,6 +31,12 @@ async function run() {
31
31
  typescript,
32
32
  });
33
33
  if (scheme === "codegen") {
34
+ allArgSets.push({
35
+ platform: "tanstack",
36
+ scheme,
37
+ typescript,
38
+ });
39
+
34
40
  allArgSets.push({
35
41
  platform: "react",
36
42
  scheme,
package/src/index.ts CHANGED
@@ -33,7 +33,7 @@ const argv = yargs
33
33
  )
34
34
  .option("platform", {
35
35
  describe: "Target platform",
36
- choices: ["", "nextjs", "gatsby", "react"],
36
+ choices: ["", "nextjs", "gatsby", "react", "tanstack"],
37
37
  })
38
38
  .option("scheme", {
39
39
  describe: "Plasmic integration scheme",
@@ -173,6 +173,11 @@ async function run(): Promise<void> {
173
173
  name: "Gatsby",
174
174
  value: "gatsby",
175
175
  },
176
+ {
177
+ name: "TanStack Start",
178
+ short: "TanStack Start",
179
+ value: "tanstack",
180
+ },
176
181
  {
177
182
  name: "React (Vite)",
178
183
  short: "React (Vite)",
package/src/lib.ts CHANGED
@@ -20,6 +20,8 @@ async function getCPAStrategy(platform: PlatformType): Promise<CPAStrategy> {
20
20
  return (await import("./gatsby/gatsby")).gatsbyStrategy;
21
21
  case "react":
22
22
  return (await import("./react/react")).reactStrategy;
23
+ case "tanstack":
24
+ return (await import("./tanstack/tanstack")).tanstackStrategy;
23
25
  }
24
26
  }
25
27
 
@@ -72,7 +74,7 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
72
74
 
73
75
  // Calling `npx create-XXX` means we don't have to keep these dependencies up to date
74
76
  banner("CREATING THE PROJECT");
75
- if (!["nextjs", "gatsby", "react"].includes(platform)) {
77
+ if (!["nextjs", "gatsby", "react", "tanstack"].includes(platform)) {
76
78
  throw new Error(`Unrecognized platform: ${platform}`);
77
79
  }
78
80
 
@@ -0,0 +1,82 @@
1
+ import { promises as fs } from "fs";
2
+ import path from "path";
3
+ import { spawnOrFail } from "../utils/cmd-utils";
4
+ import { installCodegenDeps, runCodegenSync } from "../utils/codegen";
5
+ import { deleteGlob } from "../utils/file-utils";
6
+ import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
7
+ import { makeCustomAppConfig_file_router_codegen } from "./templates/file-router/config";
8
+ import { makePlasmicHostPage_fileRouter_codegen } from "./templates/file-router/plasmic-host";
9
+ import { makeCustomRoot_file_router_codegen } from "./templates/file-router/root";
10
+
11
+ export const tanstackStrategy: CPAStrategy = {
12
+ create: async (args) => {
13
+ const { projectPath } = args;
14
+ const createCommand = `npx create-tsrouter-app@latest ${projectPath} --template file-router --add-ons start`;
15
+
16
+ await spawnOrFail(createCommand);
17
+ },
18
+ installDeps: async ({ scheme, projectPath }) => {
19
+ if (scheme === "loader") {
20
+ throw new Error(
21
+ "Plasmic loader scheme is not supported for TanStack platform. Please use the codegen scheme instead."
22
+ );
23
+ } else {
24
+ return await installCodegenDeps({ projectPath });
25
+ }
26
+ },
27
+ overwriteConfig: async (args) => {
28
+ const { projectPath, jsOrTs } = args;
29
+
30
+ /* We need to provide @plasmicapp/* packages in noExternal ssr packages for
31
+ * them to work properly during ssr phase.
32
+ */
33
+ if (jsOrTs === "ts") {
34
+ await fs.writeFile(
35
+ path.join(projectPath, "app.config.ts"),
36
+ makeCustomAppConfig_file_router_codegen()
37
+ );
38
+ }
39
+ },
40
+ generateFiles: (args) => {
41
+ return generateFilesFileRouterTemplate(args);
42
+ },
43
+ build: async (args) => {
44
+ const { npmRunCmd, projectPath } = args;
45
+ await spawnOrFail(`${npmRunCmd} build`, projectPath);
46
+ },
47
+ };
48
+
49
+ async function generateFilesFileRouterTemplate(args: GenerateFilesArgs) {
50
+ const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
51
+
52
+ // Delete existing pages
53
+ deleteGlob(path.join(projectPath, "src/routes", "*.*"));
54
+
55
+ if (scheme === "loader") {
56
+ throw new Error(
57
+ "Plasmic loader scheme is not supported for TanStack platform. Please use the codegen scheme instead."
58
+ );
59
+ } else {
60
+ // ./src/routes/__root.tsx
61
+ await fs.writeFile(
62
+ path.join(projectPath, "src/routes", `__root.${jsOrTs}x`),
63
+ makeCustomRoot_file_router_codegen(jsOrTs)
64
+ );
65
+
66
+ // ./src/routes/plasmic-host.tsx
67
+ await fs.writeFile(
68
+ path.join(projectPath, "src/routes", `plasmic-host.${jsOrTs}x`),
69
+ makePlasmicHostPage_fileRouter_codegen()
70
+ );
71
+
72
+ // This should generate
73
+ // ./plasmic.json
74
+ // ./routes/index.tsx
75
+ // ./components/plasmic/**
76
+ await runCodegenSync({
77
+ projectId,
78
+ projectApiToken,
79
+ projectPath,
80
+ });
81
+ }
82
+ }
@@ -0,0 +1,29 @@
1
+ export function makeCustomAppConfig_file_router_codegen(): string {
2
+ return `import { defineConfig } from "@tanstack/react-start/config";
3
+ import viteTsConfigPaths from "vite-tsconfig-paths";
4
+ import tailwindcss from "@tailwindcss/vite";
5
+
6
+ export default defineConfig({
7
+ tsr: {
8
+ appDirectory: "src",
9
+ },
10
+ vite: {
11
+ plugins: [
12
+ // this is the plugin that enables path aliases
13
+ viteTsConfigPaths({
14
+ projects: ["./tsconfig.json"],
15
+ }),
16
+ tailwindcss(),
17
+ ],
18
+ ssr: {
19
+ noExternal: [
20
+ "@plasmicapp/data-sources",
21
+ "@plasmicapp/data-sources-context",
22
+ "@plasmicapp/prepass",
23
+ "@plasmicapp/query",
24
+ "@plasmicapp/react-web",
25
+ ],
26
+ },
27
+ },
28
+ })`;
29
+ }
@@ -0,0 +1,23 @@
1
+ export function makePlasmicHostPage_fileRouter_codegen(): string {
2
+ return `import { createFileRoute } from '@tanstack/react-router'
3
+ import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/react-web/lib/host';
4
+
5
+ export const Route = createFileRoute('/plasmic-host')({
6
+ component: PlasmicHostRouteComponent,
7
+ })
8
+
9
+
10
+ // You can register any code components that you want to use here; see
11
+ // https://docs.plasmic.app/learn/code-components-ref/
12
+ // And configure your Plasmic project to use the host url pointing at
13
+ // the /plasmic-host page of your nextjs app (for example,
14
+ // http://localhost:3000/plasmic-host). See
15
+ // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
16
+
17
+ // registerComponent(...)
18
+
19
+ function PlasmicHostRouteComponent() {
20
+ return <PlasmicCanvasHost />
21
+ }
22
+ `;
23
+ }
@@ -0,0 +1,42 @@
1
+ import { JsOrTs } from "../../../utils/types";
2
+
3
+ export function makeCustomRoot_file_router_codegen(_jsOrTs: JsOrTs): string {
4
+ return `import { createRootRoute, HeadContent, Outlet, Scripts, Link } from '@tanstack/react-router'
5
+ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
6
+ import { PlasmicRootProvider } from "@plasmicapp/react-web"
7
+ import appCss from "../styles.css?url";
8
+
9
+ export const Route = createRootRoute({
10
+ head: () => ({
11
+ links: [
12
+ {
13
+ rel: 'stylesheet',
14
+ href: appCss,
15
+ },
16
+ ],
17
+ }),
18
+ component: () => (
19
+ <RootDocument>
20
+ <PlasmicRootProvider Link={Link}>
21
+ <Outlet />
22
+ <TanStackRouterDevtools />
23
+ </PlasmicRootProvider>
24
+ </RootDocument>
25
+ ),
26
+ })
27
+
28
+ function RootDocument({ children }: { children: React.ReactNode }) {
29
+ return (
30
+ <html lang="en">
31
+ <head>
32
+ <HeadContent />
33
+ </head>
34
+ <body>
35
+ {children}
36
+ <Scripts />
37
+ </body>
38
+ </html>
39
+ )
40
+ }
41
+ `;
42
+ }
@@ -1,5 +1,5 @@
1
1
  export type JsOrTs = "js" | "ts";
2
- export type PlatformType = "nextjs" | "gatsby" | "react";
2
+ export type PlatformType = "nextjs" | "gatsby" | "react" | "tanstack";
3
3
  export type PlatformOptions = {
4
4
  nextjs?: {
5
5
  appDir: boolean;
@@ -8,5 +8,11 @@ export type PlatformOptions = {
8
8
  export type SchemeType = "codegen" | "loader";
9
9
 
10
10
  export function platformTypeToString(s: PlatformType): string {
11
- return s === "nextjs" ? "Next.js" : s === "gatsby" ? "Gatsby" : "React";
11
+ return s === "nextjs"
12
+ ? "Next.js"
13
+ : s === "gatsby"
14
+ ? "Gatsby"
15
+ : s === "tanstack"
16
+ ? "TanStack"
17
+ : "React";
12
18
  }