create-plasmic-app 0.0.63 → 0.0.64
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/README.internal.md +6 -2
- package/cpa-out/.gitignore +15 -0
- package/cpa-out/gatsby-codegen-js/gatsby-browser.jsx +11 -0
- package/cpa-out/gatsby-codegen-js/gatsby-config.js +9 -0
- package/cpa-out/gatsby-codegen-js/gatsby-node.js +0 -0
- package/cpa-out/gatsby-codegen-js/gatsby-ssr.jsx +11 -0
- package/cpa-out/gatsby-codegen-js/package.json +26 -0
- package/cpa-out/gatsby-codegen-js/plasmic.json +79 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +206 -0
- package/cpa-out/gatsby-codegen-js/src/pages/404.js +4 -0
- package/cpa-out/gatsby-codegen-js/src/pages/index.jsx +39 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-browser.tsx +11 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-config.ts +14 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-node.ts +0 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-ssr.tsx +11 -0
- package/cpa-out/gatsby-codegen-ts/package.json +34 -0
- package/cpa-out/gatsby-codegen-ts/plasmic.json +79 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +290 -0
- package/cpa-out/gatsby-codegen-ts/src/pages/404.js +4 -0
- package/cpa-out/gatsby-codegen-ts/src/pages/index.tsx +41 -0
- package/cpa-out/gatsby-codegen-ts/tsconfig.json +102 -0
- package/cpa-out/gatsby-loader-js/gatsby-config.js +25 -0
- package/cpa-out/gatsby-loader-js/gatsby-node.js +0 -0
- package/cpa-out/gatsby-loader-js/gatsby-ssr.jsx +44 -0
- package/cpa-out/gatsby-loader-js/package.json +24 -0
- package/cpa-out/gatsby-loader-js/src/pages/404.js +4 -0
- package/cpa-out/gatsby-loader-js/src/pages/plasmic-host.jsx +19 -0
- package/cpa-out/gatsby-loader-js/src/plasmic-init.js +18 -0
- package/cpa-out/gatsby-loader-js/src/templates/defaultPlasmicPage.jsx +44 -0
- package/cpa-out/gatsby-loader-ts/gatsby-config.ts +31 -0
- package/cpa-out/gatsby-loader-ts/gatsby-node.ts +0 -0
- package/cpa-out/gatsby-loader-ts/gatsby-ssr.tsx +44 -0
- package/cpa-out/gatsby-loader-ts/package.json +32 -0
- package/cpa-out/gatsby-loader-ts/src/pages/404.ts +4 -0
- package/cpa-out/gatsby-loader-ts/src/pages/plasmic-host.tsx +24 -0
- package/cpa-out/gatsby-loader-ts/src/plasmic-init.ts +19 -0
- package/cpa-out/gatsby-loader-ts/src/templates/defaultPlasmicPage.tsx +52 -0
- package/cpa-out/gatsby-loader-ts/tsconfig.json +102 -0
- package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +56 -0
- package/cpa-out/nextjs-app-loader-js/app/head.js +10 -0
- package/cpa-out/nextjs-app-loader-js/app/layout.js +14 -0
- package/cpa-out/nextjs-app-loader-js/app/plasmic-host/page.jsx +6 -0
- package/cpa-out/nextjs-app-loader-js/next.config.js +13 -0
- package/cpa-out/nextjs-app-loader-js/package.json +20 -0
- package/cpa-out/nextjs-app-loader-js/pages/api/hello.js +5 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init-client.jsx +65 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init.js +16 -0
- package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +59 -0
- package/cpa-out/nextjs-app-loader-ts/app/head.tsx +10 -0
- package/cpa-out/nextjs-app-loader-ts/app/layout.tsx +18 -0
- package/cpa-out/nextjs-app-loader-ts/app/plasmic-host/page.tsx +6 -0
- package/cpa-out/nextjs-app-loader-ts/next.config.js +13 -0
- package/cpa-out/nextjs-app-loader-ts/package.json +24 -0
- package/cpa-out/nextjs-app-loader-ts/pages/api/hello.ts +13 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init-client.tsx +65 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init.ts +16 -0
- package/cpa-out/nextjs-app-loader-ts/tsconfig.json +29 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +205 -0
- package/cpa-out/nextjs-pages-codegen-js/next.config.js +10 -0
- package/cpa-out/nextjs-pages-codegen-js/package.json +22 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/_app.jsx +11 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/api/hello.js +5 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/index.jsx +35 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/plasmic-host.jsx +15 -0
- package/cpa-out/nextjs-pages-codegen-js/plasmic.json +79 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +287 -0
- package/cpa-out/nextjs-pages-codegen-ts/next.config.js +10 -0
- package/cpa-out/nextjs-pages-codegen-ts/package.json +26 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/_app.tsx +12 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/api/hello.ts +13 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/index.tsx +37 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/plasmic-host.tsx +15 -0
- package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +79 -0
- package/cpa-out/nextjs-pages-codegen-ts/tsconfig.json +24 -0
- package/cpa-out/nextjs-pages-loader-js/next.config.js +10 -0
- package/cpa-out/nextjs-pages-loader-js/package.json +20 -0
- package/cpa-out/nextjs-pages-loader-js/pages/[[...catchall]].jsx +66 -0
- package/cpa-out/nextjs-pages-loader-js/pages/api/hello.js +5 -0
- package/cpa-out/nextjs-pages-loader-js/pages/plasmic-host.jsx +7 -0
- package/cpa-out/nextjs-pages-loader-js/plasmic-init.js +25 -0
- package/cpa-out/nextjs-pages-loader-ts/next.config.js +10 -0
- package/cpa-out/nextjs-pages-loader-ts/package.json +24 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/[[...catchall]].tsx +70 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/api/hello.ts +13 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/plasmic-host.tsx +7 -0
- package/cpa-out/nextjs-pages-loader-ts/plasmic-init.ts +25 -0
- package/cpa-out/nextjs-pages-loader-ts/tsconfig.json +24 -0
- package/cpa-out/react-codegen-js/package.json +41 -0
- package/cpa-out/react-codegen-js/plasmic.json +76 -0
- package/cpa-out/react-codegen-js/src/App.jsx +9 -0
- package/cpa-out/react-codegen-js/src/components/Homepage.jsx +26 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +196 -0
- package/cpa-out/react-codegen-js/src/index.js +17 -0
- package/cpa-out/react-codegen-js/src/reportWebVitals.js +13 -0
- package/cpa-out/react-codegen-js/src/setupTests.js +5 -0
- package/cpa-out/react-codegen-ts/package.json +46 -0
- package/cpa-out/react-codegen-ts/plasmic.json +76 -0
- package/cpa-out/react-codegen-ts/src/App.tsx +9 -0
- package/cpa-out/react-codegen-ts/src/components/Homepage.tsx +45 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +280 -0
- package/cpa-out/react-codegen-ts/src/index.tsx +19 -0
- package/cpa-out/react-codegen-ts/src/react-app-env.d.ts +1 -0
- package/cpa-out/react-codegen-ts/src/reportWebVitals.ts +15 -0
- package/cpa-out/react-codegen-ts/src/setupTests.ts +5 -0
- package/cpa-out/react-codegen-ts/tsconfig.json +26 -0
- package/cpa-out/react-loader-js/package.json +41 -0
- package/cpa-out/react-loader-js/plasmic.json +76 -0
- package/cpa-out/react-loader-js/src/App.jsx +9 -0
- package/cpa-out/react-loader-js/src/components/Homepage.jsx +26 -0
- package/cpa-out/react-loader-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/react-loader-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +196 -0
- package/cpa-out/react-loader-js/src/index.js +17 -0
- package/cpa-out/react-loader-js/src/reportWebVitals.js +13 -0
- package/cpa-out/react-loader-js/src/setupTests.js +5 -0
- package/cpa-out/react-loader-ts/package.json +46 -0
- package/cpa-out/react-loader-ts/plasmic.json +76 -0
- package/cpa-out/react-loader-ts/src/App.tsx +9 -0
- package/cpa-out/react-loader-ts/src/components/Homepage.tsx +45 -0
- package/cpa-out/react-loader-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/react-loader-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +280 -0
- package/cpa-out/react-loader-ts/src/index.tsx +19 -0
- package/cpa-out/react-loader-ts/src/react-app-env.d.ts +1 -0
- package/cpa-out/react-loader-ts/src/reportWebVitals.ts +15 -0
- package/cpa-out/react-loader-ts/src/setupTests.ts +5 -0
- package/cpa-out/react-loader-ts/tsconfig.json +26 -0
- package/dist/gatsby/gatsby.d.ts +6 -0
- package/dist/{strategies → gatsby}/gatsby.js +26 -29
- package/dist/gatsby/template.d.ts +11 -0
- package/dist/{templates/gatsby.js → gatsby/template.js} +34 -42
- package/dist/index.d.ts +1 -1
- package/dist/index.js +57 -27
- package/dist/lib.d.ts +3 -4
- package/dist/lib.js +22 -12
- package/dist/nextjs/nextjs.d.ts +2 -0
- package/dist/nextjs/nextjs.js +155 -0
- package/dist/nextjs/templates/app-loader/catchall-page.d.ts +2 -0
- package/dist/nextjs/templates/app-loader/catchall-page.js +67 -0
- package/dist/nextjs/templates/app-loader/plasmic-host.d.ts +1 -0
- package/dist/nextjs/templates/app-loader/plasmic-host.js +13 -0
- package/dist/nextjs/templates/app-loader/plasmic-init-client.d.ts +2 -0
- package/dist/nextjs/templates/app-loader/plasmic-init-client.js +73 -0
- package/dist/nextjs/templates/app-loader/plasmic-init.d.ts +1 -0
- package/dist/nextjs/templates/app-loader/plasmic-init.js +23 -0
- package/dist/nextjs/templates/pages-codegen/app.d.ts +2 -0
- package/dist/nextjs/templates/pages-codegen/app.js +20 -0
- package/dist/nextjs/templates/pages-codegen/plasmic-host.d.ts +1 -0
- package/dist/nextjs/templates/pages-codegen/plasmic-host.js +22 -0
- package/dist/nextjs/templates/pages-loader/catchall-page.d.ts +2 -0
- package/dist/nextjs/templates/pages-loader/catchall-page.js +77 -0
- package/dist/nextjs/templates/pages-loader/plasmic-host.d.ts +1 -0
- package/dist/nextjs/templates/pages-loader/plasmic-host.js +14 -0
- package/dist/nextjs/templates/pages-loader/plasmic-init.d.ts +1 -0
- package/dist/nextjs/templates/pages-loader/plasmic-init.js +32 -0
- package/dist/react/react.d.ts +2 -0
- package/dist/{strategies → react}/react.js +10 -10
- package/dist/templates/readme.d.ts +2 -2
- package/dist/templates/readme.js +5 -4
- package/dist/templates/welcomePage.d.ts +2 -2
- package/dist/templates/welcomePage.js +5 -5
- package/dist/{strategies/common.d.ts → utils/codegen.d.ts} +0 -0
- package/dist/{strategies/common.js → utils/codegen.js} +0 -0
- package/dist/utils/file-utils.d.ts +2 -2
- package/dist/utils/file-utils.js +3 -3
- package/dist/{strategies/types.d.ts → utils/strategy.d.ts} +16 -14
- package/dist/{strategies/types.js → utils/strategy.js} +0 -0
- package/dist/utils/types.d.ts +9 -0
- package/dist/utils/types.js +7 -0
- package/package.json +4 -3
- package/run-cpa.ts +151 -0
- package/src/{strategies → gatsby}/gatsby.ts +28 -46
- package/src/{templates/gatsby.ts → gatsby/template.ts} +41 -51
- package/src/index.ts +86 -56
- package/src/lib.ts +30 -15
- package/src/nextjs/nextjs.ts +180 -0
- package/src/nextjs/templates/app-loader/catchall-page.ts +71 -0
- package/src/nextjs/templates/app-loader/plasmic-host.ts +9 -0
- package/src/nextjs/templates/app-loader/plasmic-init-client.ts +74 -0
- package/src/nextjs/templates/app-loader/plasmic-init.ts +22 -0
- package/src/nextjs/templates/pages-codegen/app.ts +24 -0
- package/src/nextjs/templates/pages-codegen/plasmic-host.ts +18 -0
- package/src/nextjs/templates/pages-loader/catchall-page.ts +81 -0
- package/src/nextjs/templates/pages-loader/plasmic-host.ts +10 -0
- package/src/nextjs/templates/pages-loader/plasmic-init.ts +31 -0
- package/src/{strategies → react}/react.ts +8 -10
- package/src/templates/readme.ts +5 -5
- package/src/templates/welcomePage.ts +6 -7
- package/src/{strategies/common.ts → utils/codegen.ts} +0 -0
- package/src/utils/file-utils.ts +4 -4
- package/src/utils/strategy.ts +48 -0
- package/src/utils/types.ts +12 -0
- package/dist/strategies/gatsby.d.ts +0 -7
- package/dist/strategies/index.d.ts +0 -2
- package/dist/strategies/index.js +0 -22
- package/dist/strategies/nextjs.d.ts +0 -3
- package/dist/strategies/nextjs.js +0 -104
- package/dist/strategies/react.d.ts +0 -3
- package/dist/templates/gatsby.d.ts +0 -11
- package/dist/templates/nextjs.d.ts +0 -5
- package/dist/templates/nextjs.js +0 -162
- package/src/strategies/index.ts +0 -21
- package/src/strategies/nextjs.ts +0 -131
- package/src/strategies/types.ts +0 -42
- package/src/templates/nextjs.ts +0 -170
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-plasmic-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.64",
|
|
4
4
|
"description": "Create Plasmic-powered React apps",
|
|
5
5
|
"main": "./dist/lib.js",
|
|
6
6
|
"types": "./dist/lib.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"test": "jest --colors",
|
|
17
17
|
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
|
|
18
18
|
"build": "eslint 'src/**' && tsc",
|
|
19
|
+
"run-cpa": "yarn build && ts-node run-cpa.ts",
|
|
19
20
|
"create-plasmic-app": "ts-node src/index.ts",
|
|
20
21
|
"prepare": "if-env PREPARE_NO_BUILD=true || yarn build"
|
|
21
22
|
},
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"jest": "^26.6.3",
|
|
37
38
|
"jest-circus": "^26.6.3",
|
|
38
39
|
"ts-jest": "^26.5.3",
|
|
39
|
-
"ts-node": "^9.1
|
|
40
|
+
"ts-node": "^10.9.1",
|
|
40
41
|
"typescript": "^4.2.3"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"validate-npm-package-name": "^3.0.0",
|
|
55
56
|
"yargs": "^16.2.0"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "56c15e54ed33294aaef992171bbb1b3ab1aa6c3a"
|
|
58
59
|
}
|
package/run-cpa.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as inquirer from "inquirer";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import yargs from "yargs";
|
|
5
|
+
import { spawnOrFail } from "./src/utils/cmd-utils";
|
|
6
|
+
import { PlatformType, SchemeType } from "./src/utils/types";
|
|
7
|
+
|
|
8
|
+
// https://studio.plasmic.app/projects/47tFXWjN2C4NyHFGGpaYQ3
|
|
9
|
+
const projectId = "47tFXWjN2C4NyHFGGpaYQ3";
|
|
10
|
+
|
|
11
|
+
interface ArgSet {
|
|
12
|
+
platform: PlatformType;
|
|
13
|
+
appDir?: boolean;
|
|
14
|
+
scheme: SchemeType;
|
|
15
|
+
typescript: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function run() {
|
|
19
|
+
const allArgSets: ArgSet[] = [];
|
|
20
|
+
[false, true].forEach((typescript) => {
|
|
21
|
+
(["loader", "codegen"] as const).forEach((scheme) => {
|
|
22
|
+
allArgSets.push({
|
|
23
|
+
platform: "nextjs",
|
|
24
|
+
appDir: false,
|
|
25
|
+
scheme,
|
|
26
|
+
typescript,
|
|
27
|
+
});
|
|
28
|
+
allArgSets.push({
|
|
29
|
+
platform: "gatsby",
|
|
30
|
+
scheme,
|
|
31
|
+
typescript,
|
|
32
|
+
});
|
|
33
|
+
allArgSets.push({
|
|
34
|
+
platform: "react",
|
|
35
|
+
scheme,
|
|
36
|
+
typescript,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
allArgSets.push({
|
|
41
|
+
platform: "nextjs",
|
|
42
|
+
appDir: true,
|
|
43
|
+
scheme: "loader", // TODO: support codegen with appDir
|
|
44
|
+
typescript,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const allArgSetNames = allArgSets.map(getProjectName).sort();
|
|
48
|
+
|
|
49
|
+
let yargsCommand = yargs.command(
|
|
50
|
+
"$0 [arg-sets..]",
|
|
51
|
+
`Runs create-plasmic-app with predefined sets of args for you.
|
|
52
|
+
|
|
53
|
+
Valid arg sets:\n\tall\n\t${allArgSetNames.join("\n\t")}`,
|
|
54
|
+
(yargs) => yargs
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const cliArgSetNames = yargsCommand.strict().argv["arg-sets"] as
|
|
58
|
+
| string[]
|
|
59
|
+
| undefined;
|
|
60
|
+
|
|
61
|
+
// If arg sets were not passed in via CLI args, prompt for them.
|
|
62
|
+
const selectedArgSetNames =
|
|
63
|
+
cliArgSetNames && cliArgSetNames.length > 0
|
|
64
|
+
? cliArgSetNames
|
|
65
|
+
: ((
|
|
66
|
+
await inquirer.prompt({
|
|
67
|
+
name: "arg-sets",
|
|
68
|
+
type: "checkbox",
|
|
69
|
+
message: "Select arg sets:",
|
|
70
|
+
choices: allArgSetNames,
|
|
71
|
+
pageSize: allArgSetNames.length,
|
|
72
|
+
validate: (input) => {
|
|
73
|
+
if (input.length === 0) {
|
|
74
|
+
return "Please select at least 1 arg set.";
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
)["arg-sets"] as string[]);
|
|
80
|
+
|
|
81
|
+
let selectedArgSets: ArgSet[];
|
|
82
|
+
if (selectedArgSetNames.includes("all")) {
|
|
83
|
+
selectedArgSets = allArgSets;
|
|
84
|
+
} else {
|
|
85
|
+
const allArgSetMap = new Map(
|
|
86
|
+
allArgSets.map((argSet) => [getProjectName(argSet), argSet])
|
|
87
|
+
);
|
|
88
|
+
selectedArgSets = selectedArgSetNames.map((name) => {
|
|
89
|
+
const argSet = allArgSetMap.get(name);
|
|
90
|
+
if (argSet) {
|
|
91
|
+
return argSet;
|
|
92
|
+
} else {
|
|
93
|
+
console.error(`Invalid arg set: ${name}`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// we use /tmp to avoid plasmic CLI thinking we are in a TypeScript project all the time
|
|
100
|
+
// if everything succeeds, we move it back to this directory
|
|
101
|
+
const tmpOutDir = "/tmp/cpa-out";
|
|
102
|
+
const finalOutDir = path.resolve("cpa-out");
|
|
103
|
+
|
|
104
|
+
// delete existing projects
|
|
105
|
+
fs.rmSync(tmpOutDir, { recursive: true, force: true });
|
|
106
|
+
|
|
107
|
+
// run create-plasmic-app and build
|
|
108
|
+
for (const argSet of selectedArgSets) {
|
|
109
|
+
const projectName = getProjectName(argSet);
|
|
110
|
+
|
|
111
|
+
const options = [
|
|
112
|
+
`--platform=${argSet.platform}`,
|
|
113
|
+
`--appDir=${argSet.appDir}`,
|
|
114
|
+
`--scheme=${argSet.scheme}`,
|
|
115
|
+
`--typescript=${argSet.typescript}`,
|
|
116
|
+
`--projectId=${projectId}`,
|
|
117
|
+
].join(" ");
|
|
118
|
+
|
|
119
|
+
const cpa = path.resolve("dist/index.js");
|
|
120
|
+
// this probably only works on *nix systems, sorry :(
|
|
121
|
+
const cmd = `mkdir -p ${tmpOutDir} && cd ${tmpOutDir} && node ${cpa} ${projectName} ${options} && cd ${projectName} && yarn build`;
|
|
122
|
+
await spawnOrFail(cmd);
|
|
123
|
+
|
|
124
|
+
const tmpProjectDir = path.join(tmpOutDir, projectName);
|
|
125
|
+
const finalProjectDir = path.join(finalOutDir, projectName);
|
|
126
|
+
|
|
127
|
+
// delete any git repos
|
|
128
|
+
fs.rmSync(path.join(tmpProjectDir, ".git"), {
|
|
129
|
+
recursive: true,
|
|
130
|
+
force: true,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// move back to create-plasmic-app directory
|
|
134
|
+
fs.rmSync(finalProjectDir, { recursive: true, force: true });
|
|
135
|
+
fs.renameSync(tmpProjectDir, finalProjectDir);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
run().catch((e) => {
|
|
139
|
+
console.error(e);
|
|
140
|
+
process.exit(1);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
function getProjectName(argSet: ArgSet) {
|
|
144
|
+
const projectNameInputs = [
|
|
145
|
+
argSet.platform,
|
|
146
|
+
argSet.appDir === undefined ? undefined : argSet.appDir ? "app" : "pages",
|
|
147
|
+
argSet.scheme,
|
|
148
|
+
argSet.typescript ? "ts" : "js",
|
|
149
|
+
];
|
|
150
|
+
return projectNameInputs.filter((input) => !!input).join("-");
|
|
151
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { createReadStream, existsSync, promises as fs } from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import * as readline from "readline";
|
|
4
|
+
import { spawnOrFail } from "../utils/cmd-utils";
|
|
5
|
+
import { installCodegenDeps, runCodegenSync } from "../utils/codegen";
|
|
6
|
+
import { deleteGlob, ifTs, overwriteIndex } from "../utils/file-utils";
|
|
7
|
+
import { ensure } from "../utils/lang-utils";
|
|
8
|
+
import { installUpgrade } from "../utils/npm-utils";
|
|
9
|
+
import { CPAStrategy } from "../utils/strategy";
|
|
4
10
|
import {
|
|
5
11
|
GATSBY_404,
|
|
6
12
|
GATSBY_PLUGIN_CONFIG,
|
|
@@ -9,40 +15,34 @@ import {
|
|
|
9
15
|
makeGatsbyHostPage,
|
|
10
16
|
makeGatsbyPlasmicInit,
|
|
11
17
|
wrapAppRootForCodegen,
|
|
12
|
-
} from "
|
|
13
|
-
import { spawnOrFail } from "../utils/cmd-utils";
|
|
14
|
-
import { deleteGlob, overwriteIndex } from "../utils/file-utils";
|
|
15
|
-
import { ensure } from "../utils/lang-utils";
|
|
16
|
-
import { installUpgrade } from "../utils/npm-utils";
|
|
17
|
-
import { installCodegenDeps, runCodegenSync } from "./common";
|
|
18
|
-
import { CPAStrategy } from "./types";
|
|
18
|
+
} from "./template";
|
|
19
19
|
|
|
20
20
|
export const GATSBY_TEMPLATES = {
|
|
21
21
|
js: `https://github.com/gatsbyjs/gatsby-starter-minimal.git`,
|
|
22
22
|
ts: `https://github.com/gatsbyjs/gatsby-starter-minimal-ts.git`,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const gatsbyStrategy: CPAStrategy = {
|
|
25
|
+
export const gatsbyStrategy: CPAStrategy = {
|
|
26
26
|
create: async (args) => {
|
|
27
|
-
const { projectPath, template,
|
|
27
|
+
const { projectPath, template, jsOrTs } = args;
|
|
28
28
|
if (template) {
|
|
29
29
|
console.log(
|
|
30
30
|
`Warning: Ignoring template '${template}' (argument is not supported by Gatsby).`
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
const gatsbyTemplate = GATSBY_TEMPLATES[
|
|
33
|
+
const gatsbyTemplate = GATSBY_TEMPLATES[jsOrTs];
|
|
34
34
|
const createCommand = `git clone ${gatsbyTemplate} ${projectPath} --recursive --depth 1 --quiet`;
|
|
35
35
|
await spawnOrFail(`${createCommand}`);
|
|
36
36
|
// Remove .git and LICENSE so that we don't generate linked outputs
|
|
37
37
|
await spawnOrFail(`rm -rf ${projectPath}/.git`);
|
|
38
38
|
await spawnOrFail(`rm -rf ${projectPath}/LICENSE`);
|
|
39
39
|
},
|
|
40
|
-
installDeps: async ({ projectPath, scheme,
|
|
40
|
+
installDeps: async ({ projectPath, scheme, jsOrTs }) => {
|
|
41
41
|
const installedHelmet = await installUpgrade("react-helmet", {
|
|
42
42
|
workingDir: projectPath,
|
|
43
43
|
});
|
|
44
44
|
const installedHelmetTypes =
|
|
45
|
-
|
|
45
|
+
jsOrTs === "js" ||
|
|
46
46
|
(await installUpgrade("@types/react-helmet", {
|
|
47
47
|
workingDir: projectPath,
|
|
48
48
|
dev: true,
|
|
@@ -66,15 +66,7 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
overwriteConfig: async (args) => {
|
|
69
|
-
const {
|
|
70
|
-
projectId,
|
|
71
|
-
projectPath,
|
|
72
|
-
projectApiToken,
|
|
73
|
-
useTypescript,
|
|
74
|
-
scheme,
|
|
75
|
-
} = args;
|
|
76
|
-
const extension = useTypescript ? "ts" : "js";
|
|
77
|
-
|
|
69
|
+
const { projectId, projectPath, projectApiToken, jsOrTs, scheme } = args;
|
|
78
70
|
const packageName = path.basename(projectPath);
|
|
79
71
|
|
|
80
72
|
// Update package.json: adding name and description, removing license and author
|
|
@@ -94,7 +86,7 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
94
86
|
// create-gatsby will create a default gatsby-config that we need to modify
|
|
95
87
|
const gatsbyConfigFile = path.join(
|
|
96
88
|
projectPath,
|
|
97
|
-
`gatsby-config.${
|
|
89
|
+
`gatsby-config.${jsOrTs}`
|
|
98
90
|
);
|
|
99
91
|
const rl = readline.createInterface({
|
|
100
92
|
input: createReadStream(gatsbyConfigFile),
|
|
@@ -102,11 +94,11 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
102
94
|
});
|
|
103
95
|
// Typescript doesn't accept require.resolve
|
|
104
96
|
// https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/#requireresolve
|
|
105
|
-
let result =
|
|
97
|
+
let result = ifTs(jsOrTs, `import path from "path";\n`);
|
|
106
98
|
const pluginConfig = GATSBY_PLUGIN_CONFIG(
|
|
107
99
|
projectId,
|
|
108
100
|
ensure(projectApiToken),
|
|
109
|
-
|
|
101
|
+
jsOrTs
|
|
110
102
|
);
|
|
111
103
|
for await (const line of rl) {
|
|
112
104
|
if (line.includes("plugins: []")) {
|
|
@@ -123,46 +115,38 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
123
115
|
generateFiles: async (args) => {
|
|
124
116
|
// in gatsby we can delete all existing pages/components, since all pages are going
|
|
125
117
|
// to be handled by templates/defaultPlasmicPage
|
|
126
|
-
const {
|
|
127
|
-
projectId,
|
|
128
|
-
projectApiToken,
|
|
129
|
-
projectPath,
|
|
130
|
-
useTypescript,
|
|
131
|
-
scheme,
|
|
132
|
-
} = args;
|
|
133
|
-
|
|
134
|
-
const extension = useTypescript ? "ts" : "js";
|
|
118
|
+
const { projectId, projectApiToken, projectPath, jsOrTs, scheme } = args;
|
|
135
119
|
|
|
136
120
|
deleteGlob(path.join(projectPath, "src/@(pages|components|templates)/*.*"));
|
|
137
121
|
|
|
138
122
|
// Create a very basic 404 page - `gatsby build` fails without it.
|
|
139
123
|
await fs.writeFile(
|
|
140
|
-
path.join(projectPath, `src/pages/404.${
|
|
124
|
+
path.join(projectPath, `src/pages/404.${jsOrTs}`),
|
|
141
125
|
GATSBY_404
|
|
142
126
|
);
|
|
143
127
|
|
|
144
128
|
// Add plasmic-host page
|
|
145
129
|
await fs.writeFile(
|
|
146
|
-
path.join(projectPath, `src/pages/plasmic-host.${
|
|
130
|
+
path.join(projectPath, `src/pages/plasmic-host.${jsOrTs}x`),
|
|
147
131
|
makeGatsbyHostPage({
|
|
148
|
-
|
|
132
|
+
jsOrTs,
|
|
149
133
|
scheme,
|
|
150
134
|
})
|
|
151
135
|
);
|
|
152
136
|
|
|
153
137
|
// Start with an empty gatsby-node
|
|
154
|
-
await fs.writeFile(path.join(projectPath, `gatsby-node.${
|
|
138
|
+
await fs.writeFile(path.join(projectPath, `gatsby-node.${jsOrTs}`), "");
|
|
155
139
|
|
|
156
140
|
// Updates `gatsby-ssr` to include script tag for preamble
|
|
157
141
|
await fs.writeFile(
|
|
158
|
-
path.join(projectPath, `gatsby-ssr.${
|
|
142
|
+
path.join(projectPath, `gatsby-ssr.${jsOrTs}x`),
|
|
159
143
|
GATSBY_SSR_CONFIG
|
|
160
144
|
);
|
|
161
145
|
|
|
162
146
|
if (scheme === "loader") {
|
|
163
147
|
await fs.writeFile(
|
|
164
|
-
path.join(projectPath, `src/plasmic-init.${
|
|
165
|
-
makeGatsbyPlasmicInit(
|
|
148
|
+
path.join(projectPath, `src/plasmic-init.${jsOrTs}`),
|
|
149
|
+
makeGatsbyPlasmicInit(jsOrTs)
|
|
166
150
|
);
|
|
167
151
|
|
|
168
152
|
const templatesFolder = path.join(projectPath, "src/templates");
|
|
@@ -171,9 +155,9 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
171
155
|
}
|
|
172
156
|
const defaultPagePath = path.join(
|
|
173
157
|
templatesFolder,
|
|
174
|
-
`defaultPlasmicPage.${
|
|
158
|
+
`defaultPlasmicPage.${jsOrTs}x`
|
|
175
159
|
);
|
|
176
|
-
await fs.writeFile(defaultPagePath, makeGatsbyDefaultPage(
|
|
160
|
+
await fs.writeFile(defaultPagePath, makeGatsbyDefaultPage(jsOrTs));
|
|
177
161
|
} else {
|
|
178
162
|
await runCodegenSync({
|
|
179
163
|
projectId,
|
|
@@ -188,11 +172,11 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
188
172
|
const wrapperContent = wrapAppRootForCodegen();
|
|
189
173
|
const browserFilePath = path.join(
|
|
190
174
|
projectPath,
|
|
191
|
-
`gatsby-browser.${
|
|
175
|
+
`gatsby-browser.${jsOrTs}x`
|
|
192
176
|
);
|
|
193
177
|
await fs.writeFile(browserFilePath, wrapperContent);
|
|
194
178
|
|
|
195
|
-
const ssrFilePath = path.join(projectPath, `gatsby-ssr.${
|
|
179
|
+
const ssrFilePath = path.join(projectPath, `gatsby-ssr.${jsOrTs}x`);
|
|
196
180
|
await fs.writeFile(ssrFilePath, wrapperContent);
|
|
197
181
|
}
|
|
198
182
|
},
|
|
@@ -205,5 +189,3 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
205
189
|
await spawnOrFail(`${npmRunCmd} build`, projectPath);
|
|
206
190
|
},
|
|
207
191
|
};
|
|
208
|
-
|
|
209
|
-
export default gatsbyStrategy;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { CodeScheme } from "..";
|
|
2
1
|
import { ifTs } from "../utils/file-utils";
|
|
2
|
+
import { JsOrTs, SchemeType } from "../utils/types";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
return `
|
|
7
|
-
import React from "react";
|
|
4
|
+
export function makeGatsbyDefaultPage(jsOrTs: JsOrTs): string {
|
|
5
|
+
return `import React from "react";
|
|
8
6
|
import Helmet from "react-helmet";
|
|
9
7
|
import {
|
|
10
8
|
PlasmicComponent,
|
|
11
9
|
PlasmicRootProvider,${ifTs(
|
|
12
|
-
|
|
10
|
+
jsOrTs,
|
|
13
11
|
`
|
|
14
12
|
InitOptions,
|
|
15
13
|
ComponentRenderData,`
|
|
16
14
|
)}
|
|
17
15
|
} from "@plasmicapp/loader-gatsby";
|
|
18
|
-
import { graphql${ifTs(
|
|
16
|
+
import { graphql${ifTs(jsOrTs, ", PageProps")} } from "gatsby";
|
|
19
17
|
import { initPlasmicLoaderWithRegistrations } from "../plasmic-init";
|
|
20
18
|
|
|
21
19
|
export const query = graphql\`
|
|
@@ -26,7 +24,7 @@ export const query = graphql\`
|
|
|
26
24
|
\`;
|
|
27
25
|
|
|
28
26
|
${ifTs(
|
|
29
|
-
|
|
27
|
+
jsOrTs,
|
|
30
28
|
`interface PlasmicGatsbyPageProps extends PageProps {
|
|
31
29
|
data: {
|
|
32
30
|
plasmicOptions: InitOptions
|
|
@@ -36,7 +34,7 @@ ${ifTs(
|
|
|
36
34
|
`
|
|
37
35
|
)}
|
|
38
36
|
const PlasmicGatsbyPage = ({ data, location }${ifTs(
|
|
39
|
-
|
|
37
|
+
jsOrTs,
|
|
40
38
|
": PlasmicGatsbyPageProps"
|
|
41
39
|
)}) => {
|
|
42
40
|
const {
|
|
@@ -65,22 +63,21 @@ const PlasmicGatsbyPage = ({ data, location }${ifTs(
|
|
|
65
63
|
};
|
|
66
64
|
|
|
67
65
|
export default PlasmicGatsbyPage;
|
|
68
|
-
|
|
69
|
-
}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
70
68
|
|
|
71
|
-
export const GATSBY_404 = `
|
|
72
|
-
const NotFound = () => {
|
|
69
|
+
export const GATSBY_404 = `const NotFound = () => {
|
|
73
70
|
return "Not Found";
|
|
74
71
|
};
|
|
75
72
|
export default NotFound;
|
|
76
|
-
|
|
73
|
+
`;
|
|
77
74
|
|
|
78
|
-
export
|
|
75
|
+
export function GATSBY_PLUGIN_CONFIG(
|
|
79
76
|
projectId: string,
|
|
80
77
|
projectApiToken: string,
|
|
81
|
-
|
|
82
|
-
): string
|
|
83
|
-
{
|
|
78
|
+
jsOrTs: JsOrTs
|
|
79
|
+
): string {
|
|
80
|
+
return `{
|
|
84
81
|
resolve: "@plasmicapp/loader-gatsby",
|
|
85
82
|
options: {
|
|
86
83
|
projects: [
|
|
@@ -91,27 +88,25 @@ export const GATSBY_PLUGIN_CONFIG = (
|
|
|
91
88
|
], // An array of project ids.
|
|
92
89
|
preview: false,
|
|
93
90
|
defaultPlasmicPage: ${
|
|
94
|
-
|
|
95
|
-
}.resolve("./src/templates/defaultPlasmicPage.${
|
|
96
|
-
useTypescript ? "tsx" : "jsx"
|
|
97
|
-
}"),
|
|
91
|
+
jsOrTs === "ts" ? "path" : "require"
|
|
92
|
+
}.resolve("./src/templates/defaultPlasmicPage.${jsOrTs}x"),
|
|
98
93
|
},
|
|
99
94
|
},
|
|
100
95
|
{
|
|
101
96
|
resolve: "gatsby-plugin-react-helmet",
|
|
102
97
|
}
|
|
103
98
|
`;
|
|
99
|
+
}
|
|
104
100
|
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
scheme:
|
|
108
|
-
}): string
|
|
109
|
-
const {
|
|
101
|
+
export function makeGatsbyHostPage(opts: {
|
|
102
|
+
jsOrTs: JsOrTs;
|
|
103
|
+
scheme: SchemeType;
|
|
104
|
+
}): string {
|
|
105
|
+
const { jsOrTs, scheme } = opts;
|
|
110
106
|
if (scheme === "loader") {
|
|
111
|
-
return `
|
|
112
|
-
import * as React from "react"
|
|
107
|
+
return `import * as React from "react"
|
|
113
108
|
import {
|
|
114
|
-
PlasmicCanvasHost${ifTs(
|
|
109
|
+
PlasmicCanvasHost${ifTs(jsOrTs, `, InitOptions`)}
|
|
115
110
|
} from "@plasmicapp/loader-gatsby"
|
|
116
111
|
import { graphql } from "gatsby"
|
|
117
112
|
import { initPlasmicLoaderWithRegistrations } from "../plasmic-init"
|
|
@@ -123,7 +118,7 @@ export const query = graphql\`
|
|
|
123
118
|
\`
|
|
124
119
|
|
|
125
120
|
${ifTs(
|
|
126
|
-
|
|
121
|
+
jsOrTs,
|
|
127
122
|
`interface HostProps {
|
|
128
123
|
data: {
|
|
129
124
|
plasmicOptions: InitOptions;
|
|
@@ -131,15 +126,14 @@ ${ifTs(
|
|
|
131
126
|
}
|
|
132
127
|
`
|
|
133
128
|
)}
|
|
134
|
-
export default function Host({ data }${ifTs(
|
|
129
|
+
export default function Host({ data }${ifTs(jsOrTs, ": HostProps")}) {
|
|
135
130
|
const { plasmicOptions } = data
|
|
136
131
|
initPlasmicLoaderWithRegistrations(plasmicOptions)
|
|
137
132
|
return <PlasmicCanvasHost />
|
|
138
133
|
}
|
|
139
|
-
|
|
134
|
+
`;
|
|
140
135
|
} else {
|
|
141
|
-
return `
|
|
142
|
-
import * as React from "react"
|
|
136
|
+
return `import * as React from "react"
|
|
143
137
|
import { PlasmicCanvasHost, registerComponent } from "@plasmicapp/host";
|
|
144
138
|
|
|
145
139
|
// You can register any code components that you want to use here; see
|
|
@@ -156,12 +150,11 @@ export default function PlasmicHost() {
|
|
|
156
150
|
<PlasmicCanvasHost />
|
|
157
151
|
);
|
|
158
152
|
}
|
|
159
|
-
|
|
153
|
+
`;
|
|
160
154
|
}
|
|
161
|
-
}
|
|
155
|
+
}
|
|
162
156
|
|
|
163
|
-
export const GATSBY_SSR_CONFIG =
|
|
164
|
-
/**
|
|
157
|
+
export const GATSBY_SSR_CONFIG = `/**
|
|
165
158
|
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
|
|
166
159
|
*
|
|
167
160
|
* See: https://www.gatsbyjs.com/docs/ssr-apis/
|
|
@@ -205,21 +198,19 @@ exports.onRenderBody = ({ pathname, setHeadComponents }) => {
|
|
|
205
198
|
setHeadComponents(HeadComponents)
|
|
206
199
|
}
|
|
207
200
|
}
|
|
208
|
-
|
|
201
|
+
`;
|
|
209
202
|
|
|
210
|
-
export
|
|
211
|
-
|
|
212
|
-
return `
|
|
213
|
-
import {
|
|
203
|
+
export function makeGatsbyPlasmicInit(jsOrTs: JsOrTs): string {
|
|
204
|
+
return `import {
|
|
214
205
|
initPlasmicLoader,${ifTs(
|
|
215
|
-
|
|
206
|
+
jsOrTs,
|
|
216
207
|
`
|
|
217
208
|
InitOptions,`
|
|
218
209
|
)}
|
|
219
210
|
} from "@plasmicapp/loader-gatsby";
|
|
220
211
|
|
|
221
212
|
export function initPlasmicLoaderWithRegistrations(plasmicOptions${ifTs(
|
|
222
|
-
|
|
213
|
+
jsOrTs,
|
|
223
214
|
": InitOptions"
|
|
224
215
|
)}) {
|
|
225
216
|
const PLASMIC = initPlasmicLoader(plasmicOptions);
|
|
@@ -235,12 +226,11 @@ export function initPlasmicLoaderWithRegistrations(plasmicOptions${ifTs(
|
|
|
235
226
|
|
|
236
227
|
return PLASMIC;
|
|
237
228
|
}
|
|
238
|
-
|
|
239
|
-
}
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
240
231
|
|
|
241
232
|
export function wrapAppRootForCodegen(): string {
|
|
242
|
-
return `
|
|
243
|
-
import React from "react";
|
|
233
|
+
return `import React from "react";
|
|
244
234
|
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
245
235
|
import Helmet from "react-helmet";
|
|
246
236
|
|
|
@@ -251,5 +241,5 @@ export const wrapRootElement = ({ element }) => {
|
|
|
251
241
|
</PlasmicRootProvider>
|
|
252
242
|
);
|
|
253
243
|
}
|
|
254
|
-
|
|
244
|
+
`;
|
|
255
245
|
}
|