create-plasmic-app 0.0.49 → 0.0.52

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,19 +48,22 @@ 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
69
  const installedHelmet = yield npm_utils_1.installUpgrade("react-helmet", {
@@ -89,6 +93,16 @@ const gatsbyStrategy = {
89
93
  var e_1, _a;
90
94
  const { projectId, projectPath, projectApiToken, useTypescript, scheme, } = args;
91
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));
92
106
  if (scheme === "loader") {
93
107
  // create-gatsby will create a default gatsby-config that we need to modify
94
108
  const gatsbyConfigFile = path_1.default.join(projectPath, `gatsby-config.${extension}`);
@@ -23,7 +23,7 @@ const common_1 = require("./common");
23
23
  const nextjsStrategy = {
24
24
  create: (args) => __awaiter(void 0, void 0, void 0, function* () {
25
25
  const { projectPath, template, useTypescript } = args;
26
- const createCommand = `npx -p create-next-app create-next-app ${useTypescript ? "--typescript" : ""} ${projectPath}`;
26
+ const createCommand = `npx create-next-app@latest ${useTypescript ? "--typescript" : ""} ${projectPath}`;
27
27
  const templateArg = template ? ` --template ${template}` : "";
28
28
  // Default Next.js starter already supports Typescript
29
29
  // See where we `touch tsconfig.json` later on
@@ -57,7 +57,7 @@ module.exports = {
57
57
  yield fs_1.promises.writeFile(nextjsConfigFile, `
58
58
  /** @type {import('next').NextConfig} */
59
59
  const nextConfig = {
60
- // Turn off React StrictMode for now, as react-aria (used by Plasmic)
60
+ // Turn off React StrictMode for now, as react-aria (used by Plasmic)
61
61
  // has some troubles with it. See
62
62
  // https://github.com/adobe/react-spectrum/labels/strict%20mode
63
63
  reactStrictMode: false,
@@ -42,7 +42,6 @@ import {
42
42
  } from "@plasmicapp/loader-nextjs";
43
43
  ${file_utils_1.ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
44
44
  import Error from "next/error";
45
- import Head from "next/head";
46
45
  import { useRouter } from "next/router";
47
46
  import { PLASMIC } from "../plasmic-init";
48
47
 
@@ -63,7 +62,6 @@ export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
63
62
  prefetchedQueryData={queryCache}
64
63
  pageParams={pageMeta.params}
65
64
  pageQuery={router.query}
66
- Head={Head}
67
65
  >
68
66
  <PlasmicComponent component={pageMeta.displayName} />
69
67
  </PlasmicRootProvider>
@@ -85,7 +83,6 @@ export const getStaticProps${file_utils_1.ifTs(ts, `: GetStaticProps`)} = async
85
83
  loader={PLASMIC}
86
84
  prefetchedData={plasmicData}
87
85
  pageParams={pageMeta.params}
88
- Head={Head}
89
86
  >
90
87
  <PlasmicComponent component={pageMeta.displayName} />
91
88
  </PlasmicRootProvider>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.49",
3
+ "version": "0.0.52",
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,16 +30,12 @@ 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 }) => {
40
41
  const installedHelmet = await installUpgrade("react-helmet", {
@@ -74,6 +75,21 @@ const gatsbyStrategy: CPAStrategy = {
74
75
  } = args;
75
76
  const extension = useTypescript ? "ts" : "js";
76
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
+
77
93
  if (scheme === "loader") {
78
94
  // create-gatsby will create a default gatsby-config that we need to modify
79
95
  const gatsbyConfigFile = path.join(
@@ -16,7 +16,7 @@ import { CPAStrategy } from "./types";
16
16
  const nextjsStrategy: CPAStrategy = {
17
17
  create: async (args) => {
18
18
  const { projectPath, template, useTypescript } = args;
19
- const createCommand = `npx -p create-next-app create-next-app ${
19
+ const createCommand = `npx create-next-app@latest ${
20
20
  useTypescript ? "--typescript" : ""
21
21
  } ${projectPath}`;
22
22
  const templateArg = template ? ` --template ${template}` : "";
@@ -52,11 +52,11 @@ module.exports = {
52
52
  );
53
53
  } else {
54
54
  await fs.writeFile(
55
- nextjsConfigFile,
55
+ nextjsConfigFile,
56
56
  `
57
57
  /** @type {import('next').NextConfig} */
58
58
  const nextConfig = {
59
- // Turn off React StrictMode for now, as react-aria (used by Plasmic)
59
+ // Turn off React StrictMode for now, as react-aria (used by Plasmic)
60
60
  // has some troubles with it. See
61
61
  // https://github.com/adobe/react-spectrum/labels/strict%20mode
62
62
  reactStrictMode: false,
@@ -64,7 +64,7 @@ const nextConfig = {
64
64
 
65
65
  module.exports = nextConfig
66
66
  `
67
- )
67
+ );
68
68
  }
69
69
  },
70
70
  generateFiles: async (args) => {
@@ -45,7 +45,6 @@ import {
45
45
  } from "@plasmicapp/loader-nextjs";
46
46
  ${ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
47
47
  import Error from "next/error";
48
- import Head from "next/head";
49
48
  import { useRouter } from "next/router";
50
49
  import { PLASMIC } from "../plasmic-init";
51
50
 
@@ -69,7 +68,6 @@ export default function PlasmicLoaderPage(props${ifTs(
69
68
  prefetchedQueryData={queryCache}
70
69
  pageParams={pageMeta.params}
71
70
  pageQuery={router.query}
72
- Head={Head}
73
71
  >
74
72
  <PlasmicComponent component={pageMeta.displayName} />
75
73
  </PlasmicRootProvider>
@@ -94,7 +92,6 @@ export const getStaticProps${ifTs(
94
92
  loader={PLASMIC}
95
93
  prefetchedData={plasmicData}
96
94
  pageParams={pageMeta.params}
97
- Head={Head}
98
95
  >
99
96
  <PlasmicComponent component={pageMeta.displayName} />
100
97
  </PlasmicRootProvider>