create-plasmic-app 0.0.48 → 0.0.51

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.
@@ -1,3 +1,7 @@
1
1
  import { CPAStrategy } from "./types";
2
+ export declare const GATSBY_TEMPLATES: {
3
+ js: string;
4
+ ts: string;
5
+ };
2
6
  declare const gatsbyStrategy: CPAStrategy;
3
7
  export default gatsbyStrategy;
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.GATSBY_TEMPLATES = void 0;
41
42
  const fs_1 = require("fs");
42
43
  const path_1 = __importDefault(require("path"));
43
44
  const readline = __importStar(require("readline"));
@@ -47,40 +48,42 @@ const file_utils_1 = require("../utils/file-utils");
47
48
  const lang_utils_1 = require("../utils/lang-utils");
48
49
  const npm_utils_1 = require("../utils/npm-utils");
49
50
  const common_1 = require("./common");
51
+ exports.GATSBY_TEMPLATES = {
52
+ js: `https://github.com/gatsbyjs/gatsby-starter-minimal.git`,
53
+ ts: `https://github.com/gatsbyjs/gatsby-starter-minimal-ts.git`,
54
+ };
50
55
  const gatsbyStrategy = {
51
56
  create: (args) => __awaiter(void 0, void 0, void 0, function* () {
52
57
  const { projectPath, template, useTypescript } = args;
53
58
  if (template) {
54
59
  console.log(`Warning: Ignoring template '${template}' (argument is not supported by Gatsby).`);
55
60
  }
56
- // create-gatsby does not support absolute paths as of 2022-08-12
57
- // (see https://github.com/gatsbyjs/gatsby/issues/36381).
58
- const parent = path_1.default.dirname(projectPath);
59
- yield fs_1.promises.mkdir(parent, { recursive: true });
60
- const dir = path_1.default.basename(projectPath);
61
- const createCommand = `npx -p create-gatsby create-gatsby ${useTypescript ? "-ts" : ""} -y ${dir}`;
62
- yield cmd_utils_1.spawnOrFail(`${createCommand}`, parent);
61
+ const gatsbyTemplate = exports.GATSBY_TEMPLATES[useTypescript ? "ts" : "js"];
62
+ const createCommand = `git clone ${gatsbyTemplate} ${projectPath} --recursive --depth 1 --quiet`;
63
+ yield cmd_utils_1.spawnOrFail(`${createCommand}`);
64
+ // Remove .git and LICENSE so that we don't generate linked outputs
65
+ yield cmd_utils_1.spawnOrFail(`rm -rf ${projectPath}/.git`);
66
+ yield cmd_utils_1.spawnOrFail(`rm -rf ${projectPath}/LICENSE`);
63
67
  }),
64
68
  installDeps: ({ projectPath, scheme, useTypescript }) => __awaiter(void 0, void 0, void 0, function* () {
65
- if (scheme === "loader") {
66
- const installedLoader = yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
67
- workingDir: projectPath,
68
- });
69
- const installedHelmet = yield npm_utils_1.installUpgrade("react-helmet", {
69
+ const installedHelmet = yield npm_utils_1.installUpgrade("react-helmet", {
70
+ workingDir: projectPath,
71
+ });
72
+ const installedHelmetTypes = !useTypescript ||
73
+ (yield npm_utils_1.installUpgrade("@types/react-helmet", {
70
74
  workingDir: projectPath,
71
- });
72
- const installedHelmetTypes = !useTypescript ||
73
- (yield npm_utils_1.installUpgrade("@types/react-helmet", {
74
- workingDir: projectPath,
75
- dev: true,
76
- }));
77
- const installedHelmetPlugin = yield npm_utils_1.installUpgrade("gatsby-plugin-react-helmet", {
75
+ dev: true,
76
+ }));
77
+ const installedHelmetPlugin = yield npm_utils_1.installUpgrade("gatsby-plugin-react-helmet", {
78
+ workingDir: projectPath,
79
+ });
80
+ if (!installedHelmet || !installedHelmetPlugin || !installedHelmetTypes) {
81
+ return false;
82
+ }
83
+ if (scheme === "loader") {
84
+ return yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
78
85
  workingDir: projectPath,
79
86
  });
80
- return (installedLoader &&
81
- installedHelmet &&
82
- installedHelmetPlugin &&
83
- installedHelmetTypes);
84
87
  }
85
88
  else {
86
89
  return yield common_1.installCodegenDeps({ projectPath });
@@ -90,6 +93,16 @@ const gatsbyStrategy = {
90
93
  var e_1, _a;
91
94
  const { projectId, projectPath, projectApiToken, useTypescript, scheme, } = args;
92
95
  const extension = useTypescript ? "ts" : "js";
96
+ const packageName = path_1.default.basename(projectPath);
97
+ // Update package.json: adding name and description, removing license and author
98
+ const packageJsonPath = path_1.default.join(projectPath, "package.json");
99
+ const packageJson = yield fs_1.promises.readFile(packageJsonPath, "utf8");
100
+ const packageJsonObject = JSON.parse(packageJson);
101
+ packageJsonObject.name = packageName;
102
+ packageJsonObject.description = `Plasmic app for ${projectId}`;
103
+ delete packageJsonObject.license;
104
+ delete packageJsonObject.author;
105
+ yield fs_1.promises.writeFile(packageJsonPath, JSON.stringify(packageJsonObject, null, 2));
93
106
  if (scheme === "loader") {
94
107
  // create-gatsby will create a default gatsby-config that we need to modify
95
108
  const gatsbyConfigFile = path_1.default.join(projectPath, `gatsby-config.${extension}`);
@@ -43,6 +43,7 @@ const PlasmicGatsbyPage = ({ data, location }${file_utils_1.ifTs(ts, ": PlasmicG
43
43
  prefetchedData={plasmicComponents}
44
44
  pageParams={pageMeta.params}
45
45
  pageQuery={Object.fromEntries(new URLSearchParams(location.search))}
46
+ Head={Helmet}
46
47
  >
47
48
  <Helmet>
48
49
  {pageMetadata?.title && <title>{pageMetadata.title}</title>}
@@ -212,10 +213,11 @@ function wrapAppRootForCodegen() {
212
213
  return `
213
214
  import React from "react";
214
215
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
216
+ import Helmet from "react-helmet";
215
217
 
216
218
  export const wrapRootElement = ({ element }) => {
217
219
  return (
218
- <PlasmicRootProvider>
220
+ <PlasmicRootProvider Head={Helmet}>
219
221
  {element}
220
222
  </PlasmicRootProvider>
221
223
  );
@@ -146,10 +146,11 @@ function wrapAppRootForCodegen() {
146
146
  return `
147
147
  import '../styles/globals.css'
148
148
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
149
+ import Head from "next/head";
149
150
 
150
151
  function MyApp({ Component, pageProps }) {
151
152
  return (
152
- <PlasmicRootProvider>
153
+ <PlasmicRootProvider Head={Head}>
153
154
  <Component {...pageProps} />
154
155
  </PlasmicRootProvider>
155
156
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.48",
3
+ "version": "0.0.51",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -17,6 +17,11 @@ import { installUpgrade } from "../utils/npm-utils";
17
17
  import { installCodegenDeps, runCodegenSync } from "./common";
18
18
  import { CPAStrategy } from "./types";
19
19
 
20
+ export const GATSBY_TEMPLATES = {
21
+ js: `https://github.com/gatsbyjs/gatsby-starter-minimal.git`,
22
+ ts: `https://github.com/gatsbyjs/gatsby-starter-minimal-ts.git`,
23
+ };
24
+
20
25
  const gatsbyStrategy: CPAStrategy = {
21
26
  create: async (args) => {
22
27
  const { projectPath, template, useTypescript } = args;
@@ -25,46 +30,37 @@ const gatsbyStrategy: CPAStrategy = {
25
30
  `Warning: Ignoring template '${template}' (argument is not supported by Gatsby).`
26
31
  );
27
32
  }
28
-
29
- // create-gatsby does not support absolute paths as of 2022-08-12
30
- // (see https://github.com/gatsbyjs/gatsby/issues/36381).
31
- const parent = path.dirname(projectPath);
32
- await fs.mkdir(parent, { recursive: true });
33
- const dir = path.basename(projectPath);
34
- const createCommand = `npx -p create-gatsby create-gatsby ${
35
- useTypescript ? "-ts" : ""
36
- } -y ${dir}`;
37
- await spawnOrFail(`${createCommand}`, parent);
33
+ const gatsbyTemplate = GATSBY_TEMPLATES[useTypescript ? "ts" : "js"];
34
+ const createCommand = `git clone ${gatsbyTemplate} ${projectPath} --recursive --depth 1 --quiet`;
35
+ await spawnOrFail(`${createCommand}`);
36
+ // Remove .git and LICENSE so that we don't generate linked outputs
37
+ await spawnOrFail(`rm -rf ${projectPath}/.git`);
38
+ await spawnOrFail(`rm -rf ${projectPath}/LICENSE`);
38
39
  },
39
40
  installDeps: async ({ projectPath, scheme, useTypescript }) => {
41
+ const installedHelmet = await installUpgrade("react-helmet", {
42
+ workingDir: projectPath,
43
+ });
44
+ const installedHelmetTypes =
45
+ !useTypescript ||
46
+ (await installUpgrade("@types/react-helmet", {
47
+ workingDir: projectPath,
48
+ dev: true,
49
+ }));
50
+ const installedHelmetPlugin = await installUpgrade(
51
+ "gatsby-plugin-react-helmet",
52
+ {
53
+ workingDir: projectPath,
54
+ }
55
+ );
56
+ if (!installedHelmet || !installedHelmetPlugin || !installedHelmetTypes) {
57
+ return false;
58
+ }
59
+
40
60
  if (scheme === "loader") {
41
- const installedLoader = await installUpgrade(
42
- "@plasmicapp/loader-gatsby",
43
- {
44
- workingDir: projectPath,
45
- }
46
- );
47
- const installedHelmet = await installUpgrade("react-helmet", {
61
+ return await installUpgrade("@plasmicapp/loader-gatsby", {
48
62
  workingDir: projectPath,
49
63
  });
50
- const installedHelmetTypes =
51
- !useTypescript ||
52
- (await installUpgrade("@types/react-helmet", {
53
- workingDir: projectPath,
54
- dev: true,
55
- }));
56
- const installedHelmetPlugin = await installUpgrade(
57
- "gatsby-plugin-react-helmet",
58
- {
59
- workingDir: projectPath,
60
- }
61
- );
62
- return (
63
- installedLoader &&
64
- installedHelmet &&
65
- installedHelmetPlugin &&
66
- installedHelmetTypes
67
- );
68
64
  } else {
69
65
  return await installCodegenDeps({ projectPath });
70
66
  }
@@ -79,6 +75,21 @@ const gatsbyStrategy: CPAStrategy = {
79
75
  } = args;
80
76
  const extension = useTypescript ? "ts" : "js";
81
77
 
78
+ const packageName = path.basename(projectPath);
79
+
80
+ // Update package.json: adding name and description, removing license and author
81
+ const packageJsonPath = path.join(projectPath, "package.json");
82
+ const packageJson = await fs.readFile(packageJsonPath, "utf8");
83
+ const packageJsonObject = JSON.parse(packageJson);
84
+ packageJsonObject.name = packageName;
85
+ packageJsonObject.description = `Plasmic app for ${projectId}`;
86
+ delete packageJsonObject.license;
87
+ delete packageJsonObject.author;
88
+ await fs.writeFile(
89
+ packageJsonPath,
90
+ JSON.stringify(packageJsonObject, null, 2)
91
+ );
92
+
82
93
  if (scheme === "loader") {
83
94
  // create-gatsby will create a default gatsby-config that we need to modify
84
95
  const gatsbyConfigFile = path.join(
@@ -51,6 +51,7 @@ const PlasmicGatsbyPage = ({ data, location }${ifTs(
51
51
  prefetchedData={plasmicComponents}
52
52
  pageParams={pageMeta.params}
53
53
  pageQuery={Object.fromEntries(new URLSearchParams(location.search))}
54
+ Head={Helmet}
54
55
  >
55
56
  <Helmet>
56
57
  {pageMetadata?.title && <title>{pageMetadata.title}</title>}
@@ -241,10 +242,11 @@ export function wrapAppRootForCodegen(): string {
241
242
  return `
242
243
  import React from "react";
243
244
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
245
+ import Helmet from "react-helmet";
244
246
 
245
247
  export const wrapRootElement = ({ element }) => {
246
248
  return (
247
- <PlasmicRootProvider>
249
+ <PlasmicRootProvider Head={Helmet}>
248
250
  {element}
249
251
  </PlasmicRootProvider>
250
252
  );
@@ -155,10 +155,11 @@ export function wrapAppRootForCodegen(): string {
155
155
  return `
156
156
  import '../styles/globals.css'
157
157
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
158
+ import Head from "next/head";
158
159
 
159
160
  function MyApp({ Component, pageProps }) {
160
161
  return (
161
- <PlasmicRootProvider>
162
+ <PlasmicRootProvider Head={Head}>
162
163
  <Component {...pageProps} />
163
164
  </PlasmicRootProvider>
164
165
  );