create-plasmic-app 0.0.36 → 0.0.39
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.d.ts +1 -1
- package/dist/lib.js +29 -47
- package/dist/strategies/common.d.ts +8 -0
- package/dist/strategies/common.js +34 -0
- package/dist/strategies/gatsby.js +66 -38
- package/dist/strategies/nextjs.js +52 -14
- package/dist/strategies/react.js +26 -9
- package/dist/strategies/types.d.ts +14 -4
- package/dist/templates/gatsby.d.ts +6 -1
- package/dist/templates/gatsby.js +67 -9
- package/dist/templates/nextjs.d.ts +3 -1
- package/dist/templates/nextjs.js +55 -6
- package/dist/utils/file-utils.d.ts +0 -9
- package/dist/utils/file-utils.js +1 -79
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/lib.ts +33 -63
- package/src/strategies/common.ts +30 -0
- package/src/strategies/gatsby.ts +82 -43
- package/src/strategies/nextjs.ts +85 -23
- package/src/strategies/react.ts +30 -11
- package/src/strategies/types.ts +16 -4
- package/src/templates/gatsby.ts +69 -11
- package/src/templates/nextjs.ts +55 -5
- package/src/utils/file-utils.ts +0 -115
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export
|
|
2
|
+
export declare type CodeScheme = "codegen" | "loader";
|
package/dist/lib.js
CHANGED
|
@@ -37,7 +37,6 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
37
37
|
const path = __importStar(require("upath"));
|
|
38
38
|
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
39
39
|
const strategies_1 = require("./strategies");
|
|
40
|
-
const cmd_utils_1 = require("./utils/cmd-utils");
|
|
41
40
|
const file_utils_1 = require("./utils/file-utils");
|
|
42
41
|
const npm_utils_1 = require("./utils/npm-utils");
|
|
43
42
|
function toString(s) {
|
|
@@ -91,60 +90,43 @@ function create(args) {
|
|
|
91
90
|
if (useTypescript && platform !== "gatsby") {
|
|
92
91
|
yield file_utils_1.ensureTsconfig(resolvedProjectPath);
|
|
93
92
|
}
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const installResult = yield npm_utils_1.installUpgrade("@plasmicapp/cli", {
|
|
98
|
-
workingDir: resolvedProjectPath,
|
|
99
|
-
});
|
|
100
|
-
if (!installResult) {
|
|
101
|
-
throw new Error("Failed to install the Plasmic dependency");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// Trigger a sync
|
|
105
|
-
const pkgMgr = npm_utils_1.detectPackageManager(resolvedProjectPath);
|
|
106
|
-
const npmRunCmd = pkgMgr === "yarn" ? "yarn" : "npm run";
|
|
107
|
-
if (scheme === "codegen") {
|
|
108
|
-
banner("SYNCING PLASMIC COMPONENTS");
|
|
109
|
-
const project = projectApiToken
|
|
110
|
-
? `${projectId}:${projectApiToken}`
|
|
111
|
-
: projectId;
|
|
112
|
-
if (platform === "nextjs") {
|
|
113
|
-
yield file_utils_1.writeDefaultNextjsConfig(resolvedProjectPath, projectId, false);
|
|
114
|
-
}
|
|
115
|
-
yield cmd_utils_1.spawnOrFail(`npx -p @plasmicapp/cli plasmic sync --yes -p ${project}`, resolvedProjectPath);
|
|
116
|
-
}
|
|
117
|
-
else if (scheme === "loader") {
|
|
118
|
-
if (!projectApiToken) {
|
|
119
|
-
projectApiToken = yield cli_1.getProjectApiToken(projectId);
|
|
120
|
-
}
|
|
93
|
+
// Make sure we have an api token for loader
|
|
94
|
+
if (scheme === "loader" && !projectApiToken) {
|
|
95
|
+
projectApiToken = yield cli_1.getProjectApiToken(projectId);
|
|
121
96
|
if (!projectApiToken) {
|
|
122
97
|
throw new Error(`Failed to get projectApiToken for ${projectId}`);
|
|
123
98
|
}
|
|
124
|
-
yield cpaStrategy.configLoader({
|
|
125
|
-
projectPath: resolvedProjectPath,
|
|
126
|
-
projectId,
|
|
127
|
-
projectApiToken,
|
|
128
|
-
useTypescript,
|
|
129
|
-
});
|
|
130
99
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// but for codegen we still have to run it
|
|
140
|
-
// Overwrite the index file
|
|
141
|
-
yield file_utils_1.overwriteIndex(resolvedProjectPath, platform, scheme);
|
|
142
|
-
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
143
|
-
yield file_utils_1.wrapAppRoot(resolvedProjectPath, platform, scheme);
|
|
100
|
+
// Install dependency
|
|
101
|
+
banner("INSTALLING THE PLASMIC DEPENDENCY");
|
|
102
|
+
const installResult = yield cpaStrategy.installDeps({
|
|
103
|
+
scheme,
|
|
104
|
+
projectPath: resolvedProjectPath,
|
|
105
|
+
});
|
|
106
|
+
if (!installResult) {
|
|
107
|
+
throw new Error("Failed to install the Plasmic dependency");
|
|
144
108
|
}
|
|
109
|
+
// Configure
|
|
110
|
+
yield cpaStrategy.overwriteConfig({
|
|
111
|
+
projectId,
|
|
112
|
+
projectPath: resolvedProjectPath,
|
|
113
|
+
projectApiToken,
|
|
114
|
+
useTypescript,
|
|
115
|
+
scheme,
|
|
116
|
+
});
|
|
117
|
+
// Generate files
|
|
118
|
+
yield cpaStrategy.generateFiles({
|
|
119
|
+
projectPath: resolvedProjectPath,
|
|
120
|
+
useTypescript,
|
|
121
|
+
scheme,
|
|
122
|
+
projectId,
|
|
123
|
+
projectApiToken,
|
|
124
|
+
});
|
|
145
125
|
/**
|
|
146
126
|
* INSTRUCT USER ON NEXT STEPS
|
|
147
127
|
*/
|
|
128
|
+
const pkgMgr = npm_utils_1.detectPackageManager(resolvedProjectPath);
|
|
129
|
+
const npmRunCmd = pkgMgr === "yarn" ? "yarn" : "npm run";
|
|
148
130
|
const command = platform === "nextjs"
|
|
149
131
|
? `${npmRunCmd} dev`
|
|
150
132
|
: platform === "gatsby"
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runCodegenSync = exports.installCodegenDeps = void 0;
|
|
13
|
+
const lib_1 = require("../lib");
|
|
14
|
+
const cmd_utils_1 = require("../utils/cmd-utils");
|
|
15
|
+
const npm_utils_1 = require("../utils/npm-utils");
|
|
16
|
+
function installCodegenDeps(opts) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const { projectPath } = opts;
|
|
19
|
+
return ((yield npm_utils_1.installUpgrade("@plasmicapp/cli", { workingDir: projectPath })) &&
|
|
20
|
+
(yield npm_utils_1.installUpgrade("@plasmicapp/host", { workingDir: projectPath })));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.installCodegenDeps = installCodegenDeps;
|
|
24
|
+
function runCodegenSync(opts) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { projectId, projectApiToken, projectPath } = opts;
|
|
27
|
+
lib_1.banner("SYNCING PLASMIC COMPONENTS");
|
|
28
|
+
const project = projectApiToken
|
|
29
|
+
? `${projectId}:${projectApiToken}`
|
|
30
|
+
: projectId;
|
|
31
|
+
yield cmd_utils_1.spawnOrFail(`npx -p @plasmicapp/cli plasmic sync --yes -p ${project}`, projectPath);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.runCodegenSync = runCodegenSync;
|
|
@@ -44,7 +44,9 @@ const readline = __importStar(require("readline"));
|
|
|
44
44
|
const gatsby_1 = require("../templates/gatsby");
|
|
45
45
|
const cmd_utils_1 = require("../utils/cmd-utils");
|
|
46
46
|
const file_utils_1 = require("../utils/file-utils");
|
|
47
|
+
const lang_utils_1 = require("../utils/lang-utils");
|
|
47
48
|
const npm_utils_1 = require("../utils/npm-utils");
|
|
49
|
+
const common_1 = require("./common");
|
|
48
50
|
const gatsbyStrategy = {
|
|
49
51
|
create: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
52
|
const { projectPath, template } = args;
|
|
@@ -52,62 +54,88 @@ const gatsbyStrategy = {
|
|
|
52
54
|
const templateArg = template ? ` ${template}` : "";
|
|
53
55
|
yield cmd_utils_1.spawnOrFail(`${createCommand}${templateArg}`);
|
|
54
56
|
}),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
if (!installResult) {
|
|
62
|
-
throw new Error("Failed to install the Plasmic dependency");
|
|
57
|
+
installDeps: ({ projectPath, scheme }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
if (scheme === "loader") {
|
|
59
|
+
return yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
|
|
60
|
+
workingDir: projectPath,
|
|
61
|
+
});
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const rl = readline.createInterface({
|
|
67
|
-
input: fs_1.createReadStream(gatsbyConfigFile),
|
|
68
|
-
crlfDelay: Infinity,
|
|
69
|
-
});
|
|
70
|
-
let result = "";
|
|
71
|
-
try {
|
|
72
|
-
for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
|
|
73
|
-
const line = rl_1_1.value;
|
|
74
|
-
result += line + "\n";
|
|
75
|
-
// Prepend PlasmicLoader to list of plugins
|
|
76
|
-
if (line.includes("plugins:")) {
|
|
77
|
-
result += gatsby_1.GATSBY_PLUGIN_CONFIG(projectId, projectApiToken, useTypescript);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
63
|
+
else {
|
|
64
|
+
return yield common_1.installCodegenDeps({ projectPath });
|
|
80
65
|
}
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
}),
|
|
67
|
+
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
var e_1, _a;
|
|
69
|
+
const { projectId, projectPath, projectApiToken, useTypescript, scheme, } = args;
|
|
70
|
+
if (scheme === "loader") {
|
|
71
|
+
// create-gatsby will create a default gatsby-config.js that we need to modify
|
|
72
|
+
const gatsbyConfigFile = path_1.default.join(projectPath, "gatsby-config.js");
|
|
73
|
+
const rl = readline.createInterface({
|
|
74
|
+
input: fs_1.createReadStream(gatsbyConfigFile),
|
|
75
|
+
crlfDelay: Infinity,
|
|
76
|
+
});
|
|
77
|
+
let result = "";
|
|
83
78
|
try {
|
|
84
|
-
|
|
79
|
+
for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
|
|
80
|
+
const line = rl_1_1.value;
|
|
81
|
+
result += line + "\n";
|
|
82
|
+
// Prepend PlasmicLoader to list of plugins
|
|
83
|
+
if (line.includes("plugins:")) {
|
|
84
|
+
result += gatsby_1.GATSBY_PLUGIN_CONFIG(projectId, lang_utils_1.ensure(projectApiToken), useTypescript);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
89
|
+
finally {
|
|
90
|
+
try {
|
|
91
|
+
if (rl_1_1 && !rl_1_1.done && (_a = rl_1.return)) yield _a.call(rl_1);
|
|
92
|
+
}
|
|
93
|
+
finally { if (e_1) throw e_1.error; }
|
|
85
94
|
}
|
|
86
|
-
|
|
95
|
+
yield fs_1.promises.writeFile(gatsbyConfigFile, result);
|
|
87
96
|
}
|
|
88
|
-
yield fs_1.promises.writeFile(gatsbyConfigFile, result);
|
|
89
97
|
}),
|
|
90
|
-
|
|
98
|
+
generateFiles: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
99
|
// in gatsby we can delete all existing pages/components, since all pages are going
|
|
92
100
|
// to be handled by templates/defaultPlasmicPage
|
|
93
|
-
const { projectPath, useTypescript } = args;
|
|
101
|
+
const { projectId, projectApiToken, projectPath, useTypescript, scheme, } = args;
|
|
94
102
|
const extension = useTypescript ? "ts" : "js";
|
|
95
103
|
file_utils_1.deleteGlob(path_1.default.join(projectPath, "src/@(pages|components|templates)/*.*"));
|
|
96
104
|
// Create a very basic 404 page - `gatsby build` fails without it.
|
|
97
105
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/404.js`), gatsby_1.GATSBY_404);
|
|
98
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/plasmic-init.${extension}`), gatsby_1.makeGatsbyPlasmicInit(extension));
|
|
99
106
|
// Add plasmic-host page
|
|
100
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/plasmic-host.${extension}x`), gatsby_1.makeGatsbyHostPage(
|
|
107
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/plasmic-host.${extension}x`), gatsby_1.makeGatsbyHostPage({
|
|
108
|
+
useTypescript,
|
|
109
|
+
scheme,
|
|
110
|
+
}));
|
|
101
111
|
// Start with an empty gatsby-node.js
|
|
102
112
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "gatsby-node.js"), "");
|
|
103
113
|
// Updates `gatsby-ssr` to include script tag for preamble
|
|
104
114
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "gatsby-ssr.js"), gatsby_1.GATSBY_SSR_CONFIG);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
if (scheme === "loader") {
|
|
116
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/plasmic-init.${extension}`), gatsby_1.makeGatsbyPlasmicInit(extension));
|
|
117
|
+
const templatesFolder = path_1.default.join(projectPath, "src/templates");
|
|
118
|
+
if (!fs_1.existsSync(templatesFolder)) {
|
|
119
|
+
yield fs_1.promises.mkdir(templatesFolder);
|
|
120
|
+
}
|
|
121
|
+
const defaultPagePath = path_1.default.join(templatesFolder, `defaultPlasmicPage.${extension}x`);
|
|
122
|
+
yield fs_1.promises.writeFile(defaultPagePath, gatsby_1.makeGatsbyDefaultPage(extension));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
yield common_1.runCodegenSync({
|
|
126
|
+
projectId,
|
|
127
|
+
projectApiToken,
|
|
128
|
+
projectPath,
|
|
129
|
+
});
|
|
130
|
+
// Overwrite the index file
|
|
131
|
+
yield file_utils_1.overwriteIndex(projectPath, "gatsby", scheme);
|
|
132
|
+
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
133
|
+
const wrapperContent = gatsby_1.wrapAppRootForCodegen();
|
|
134
|
+
const browserFilePath = path_1.default.join(projectPath, "gatsby-browser.js");
|
|
135
|
+
yield fs_1.promises.writeFile(browserFilePath, wrapperContent);
|
|
136
|
+
const ssrFilePath = path_1.default.join(projectPath, "gatsby-ssr.js");
|
|
137
|
+
yield fs_1.promises.writeFile(ssrFilePath, wrapperContent);
|
|
109
138
|
}
|
|
110
|
-
yield fs_1.promises.writeFile(defaultPagePath, gatsby_1.makeGatsbyDefaultPage(extension));
|
|
111
139
|
}),
|
|
112
140
|
build: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
141
|
const { npmRunCmd, projectPath } = args;
|
|
@@ -12,10 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_1 = require("fs");
|
|
15
16
|
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const nextjs_1 = require("../templates/nextjs");
|
|
16
18
|
const cmd_utils_1 = require("../utils/cmd-utils");
|
|
17
19
|
const file_utils_1 = require("../utils/file-utils");
|
|
20
|
+
const lang_utils_1 = require("../utils/lang-utils");
|
|
18
21
|
const npm_utils_1 = require("../utils/npm-utils");
|
|
22
|
+
const common_1 = require("./common");
|
|
19
23
|
const nextjsStrategy = {
|
|
20
24
|
create: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
25
|
const { projectPath, template, useTypescript } = args;
|
|
@@ -25,25 +29,59 @@ const nextjsStrategy = {
|
|
|
25
29
|
// See where we `touch tsconfig.json` later on
|
|
26
30
|
yield cmd_utils_1.spawnOrFail(`${createCommand}${templateArg}`);
|
|
27
31
|
}),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
installDeps: ({ scheme, projectPath }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
if (scheme === "loader") {
|
|
34
|
+
return yield npm_utils_1.installUpgrade("@plasmicapp/loader-nextjs", {
|
|
35
|
+
workingDir: projectPath,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return yield common_1.installCodegenDeps({ projectPath });
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const { projectPath, scheme } = args;
|
|
44
|
+
if (scheme === "codegen") {
|
|
45
|
+
const nextjsConfigFile = path_1.default.join(projectPath, "next.config.js");
|
|
46
|
+
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
47
|
+
module.exports = {
|
|
48
|
+
eslint: {
|
|
49
|
+
ignoreDuringBuilds: true,
|
|
50
|
+
},
|
|
51
|
+
trailingSlash: true,
|
|
52
|
+
// Your NextJS config.
|
|
53
|
+
};
|
|
54
|
+
`);
|
|
35
55
|
}
|
|
36
|
-
yield file_utils_1.writeDefaultNextjsConfig(projectPath, projectId, true, projectApiToken, useTypescript);
|
|
37
56
|
}),
|
|
38
|
-
|
|
57
|
+
generateFiles: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
58
|
// this is supposed to be called for loader case, so we are supposed to remove
|
|
40
59
|
// all the files from pages/ since we have inserted a optional catch all
|
|
41
|
-
const { projectPath } = args;
|
|
60
|
+
const { projectPath, scheme, useTypescript, projectId, projectApiToken, } = args;
|
|
61
|
+
// Always start fresh
|
|
42
62
|
const pagesPath = path_1.default.join(projectPath, "pages");
|
|
43
|
-
file_utils_1.deleteGlob(path_1.default.join(pagesPath, `*.*`)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
file_utils_1.deleteGlob(path_1.default.join(pagesPath, `*.*`));
|
|
64
|
+
const hostPage = path_1.default.join(pagesPath, `plasmic-host.${useTypescript ? "tsx" : "jsx"}`);
|
|
65
|
+
yield fs_1.promises.writeFile(hostPage, nextjs_1.makeNextjsHostPage(scheme));
|
|
66
|
+
if (scheme === "loader") {
|
|
67
|
+
const initFile = path_1.default.join(projectPath, `plasmic-init.${useTypescript ? "ts" : "js"}`);
|
|
68
|
+
yield fs_1.promises.writeFile(initFile, nextjs_1.makeNextjsInitPage(projectId, lang_utils_1.ensure(projectApiToken)));
|
|
69
|
+
// Write catch-all page for loader
|
|
70
|
+
const loaderPage = path_1.default.join(pagesPath, `[[...catchall]].${useTypescript ? "tsx" : "jsx"}`);
|
|
71
|
+
yield fs_1.promises.writeFile(loaderPage, nextjs_1.makeNextjsCatchallPage(useTypescript ? "ts" : "js"));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
yield common_1.runCodegenSync({
|
|
75
|
+
projectId,
|
|
76
|
+
projectApiToken,
|
|
77
|
+
projectPath,
|
|
78
|
+
});
|
|
79
|
+
// Overwrite the index file
|
|
80
|
+
yield file_utils_1.overwriteIndex(projectPath, "nextjs", scheme);
|
|
81
|
+
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
82
|
+
const appFilePath = path_1.default.join(projectPath, "pages", `_app.js`);
|
|
83
|
+
yield fs_1.promises.writeFile(appFilePath, nextjs_1.wrapAppRootForCodegen());
|
|
84
|
+
}
|
|
47
85
|
}),
|
|
48
86
|
build: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
87
|
const { npmRunCmd, projectPath } = args;
|
package/dist/strategies/react.js
CHANGED
|
@@ -10,7 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const cmd_utils_1 = require("../utils/cmd-utils");
|
|
13
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
13
14
|
const npm_utils_1 = require("../utils/npm-utils");
|
|
15
|
+
const common_1 = require("./common");
|
|
14
16
|
const reactStrategy = {
|
|
15
17
|
create: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
18
|
const { projectPath, useTypescript } = args;
|
|
@@ -22,17 +24,32 @@ const reactStrategy = {
|
|
|
22
24
|
const templateArg = template ? ` --template ${template}` : "";
|
|
23
25
|
yield cmd_utils_1.spawnOrFail(`${createCommand}${templateArg}`);
|
|
24
26
|
}),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
if (!installResult) {
|
|
32
|
-
throw new Error("Failed to install the Plasmic dependency");
|
|
27
|
+
installDeps: ({ projectPath, scheme }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
if (scheme === "loader") {
|
|
29
|
+
return yield npm_utils_1.installUpgrade("@plasmicapp/loader-react", {
|
|
30
|
+
workingDir: projectPath,
|
|
31
|
+
});
|
|
33
32
|
}
|
|
33
|
+
else {
|
|
34
|
+
return yield common_1.installCodegenDeps({ projectPath });
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
// No config to overwrite
|
|
34
39
|
}),
|
|
35
|
-
|
|
40
|
+
generateFiles: ({ scheme, projectApiToken, projectId, projectPath, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
if (scheme === "loader") {
|
|
42
|
+
// Nothing to do
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
yield common_1.runCodegenSync({
|
|
46
|
+
projectId,
|
|
47
|
+
projectApiToken,
|
|
48
|
+
projectPath,
|
|
49
|
+
});
|
|
50
|
+
// Overwrite the index file
|
|
51
|
+
yield file_utils_1.overwriteIndex(projectPath, "react", scheme);
|
|
52
|
+
}
|
|
36
53
|
return;
|
|
37
54
|
}),
|
|
38
55
|
build: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodeScheme } from "..";
|
|
1
2
|
interface CreateArgs {
|
|
2
3
|
projectPath: string;
|
|
3
4
|
template?: string;
|
|
@@ -6,21 +7,30 @@ interface CreateArgs {
|
|
|
6
7
|
interface ConfigArgs {
|
|
7
8
|
projectId: string;
|
|
8
9
|
projectPath: string;
|
|
9
|
-
projectApiToken: string;
|
|
10
10
|
useTypescript: boolean;
|
|
11
|
+
scheme: CodeScheme;
|
|
12
|
+
projectApiToken: string | undefined;
|
|
11
13
|
}
|
|
12
|
-
interface
|
|
14
|
+
interface GenerateFilesArgs {
|
|
13
15
|
projectPath: string;
|
|
14
16
|
useTypescript: boolean;
|
|
17
|
+
scheme: CodeScheme;
|
|
18
|
+
projectId: string;
|
|
19
|
+
projectApiToken: string | undefined;
|
|
15
20
|
}
|
|
16
21
|
interface BuildArgs {
|
|
17
22
|
projectPath: string;
|
|
18
23
|
npmRunCmd: string;
|
|
19
24
|
}
|
|
25
|
+
interface InstallArgs {
|
|
26
|
+
scheme: CodeScheme;
|
|
27
|
+
projectPath: string;
|
|
28
|
+
}
|
|
20
29
|
export interface CPAStrategy {
|
|
21
30
|
create: (args: CreateArgs) => Promise<void>;
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
installDeps: (args: InstallArgs) => Promise<boolean>;
|
|
32
|
+
overwriteConfig: (args: ConfigArgs) => Promise<void>;
|
|
33
|
+
generateFiles: (args: GenerateFilesArgs) => Promise<void>;
|
|
24
34
|
build: (args: BuildArgs) => Promise<void>;
|
|
25
35
|
}
|
|
26
36
|
export {};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { CodeScheme } from "..";
|
|
1
2
|
export declare const makeGatsbyDefaultPage: (format: "ts" | "js") => string;
|
|
2
3
|
export declare const GATSBY_404: string;
|
|
3
4
|
export declare const GATSBY_PLUGIN_CONFIG: (projectId: string, projectApiToken: string, useTypescript: boolean) => string;
|
|
4
|
-
export declare const makeGatsbyHostPage: (
|
|
5
|
+
export declare const makeGatsbyHostPage: (opts: {
|
|
6
|
+
useTypescript: boolean;
|
|
7
|
+
scheme: CodeScheme;
|
|
8
|
+
}) => string;
|
|
5
9
|
export declare const GATSBY_SSR_CONFIG: string;
|
|
6
10
|
export declare const makeGatsbyPlasmicInit: (format: "ts" | "js") => string;
|
|
11
|
+
export declare function wrapAppRootForCodegen(): string;
|
package/dist/templates/gatsby.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeGatsbyPlasmicInit = exports.GATSBY_SSR_CONFIG = exports.makeGatsbyHostPage = exports.GATSBY_PLUGIN_CONFIG = exports.GATSBY_404 = exports.makeGatsbyDefaultPage = void 0;
|
|
3
|
+
exports.wrapAppRootForCodegen = exports.makeGatsbyPlasmicInit = exports.GATSBY_SSR_CONFIG = exports.makeGatsbyHostPage = exports.GATSBY_PLUGIN_CONFIG = exports.GATSBY_404 = exports.makeGatsbyDefaultPage = void 0;
|
|
4
4
|
const file_utils_1 = require("../utils/file-utils");
|
|
5
5
|
const makeGatsbyDefaultPage = (format) => {
|
|
6
6
|
const ts = format === "ts";
|
|
@@ -78,13 +78,13 @@ const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken, useTypescript) => `
|
|
|
78
78
|
},
|
|
79
79
|
`;
|
|
80
80
|
exports.GATSBY_PLUGIN_CONFIG = GATSBY_PLUGIN_CONFIG;
|
|
81
|
-
const makeGatsbyHostPage = (
|
|
82
|
-
const
|
|
83
|
-
|
|
81
|
+
const makeGatsbyHostPage = (opts) => {
|
|
82
|
+
const { useTypescript, scheme } = opts;
|
|
83
|
+
if (scheme === "loader") {
|
|
84
|
+
return `
|
|
84
85
|
import * as React from "react"
|
|
85
86
|
import {
|
|
86
|
-
PlasmicCanvasHost
|
|
87
|
-
InitOptions,`)}
|
|
87
|
+
PlasmicCanvasHost${file_utils_1.ifTs(useTypescript, `, InitOptions`)}
|
|
88
88
|
} from "@plasmicapp/loader-gatsby"
|
|
89
89
|
import { graphql } from "gatsby"
|
|
90
90
|
import { initPlasmicLoaderWithRegistrations } from "../plasmic-init"
|
|
@@ -95,18 +95,40 @@ export const query = graphql\`
|
|
|
95
95
|
}
|
|
96
96
|
\`
|
|
97
97
|
|
|
98
|
-
${file_utils_1.ifTs(
|
|
98
|
+
${file_utils_1.ifTs(useTypescript, `interface HostProps {
|
|
99
99
|
data: {
|
|
100
100
|
plasmicOptions: InitOptions;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
`)}
|
|
104
|
-
export default function Host({ data }${file_utils_1.ifTs(
|
|
104
|
+
export default function Host({ data }${file_utils_1.ifTs(useTypescript, ": HostProps")}) {
|
|
105
105
|
const { plasmicOptions } = data
|
|
106
106
|
initPlasmicLoaderWithRegistrations(plasmicOptions)
|
|
107
107
|
return <PlasmicCanvasHost />
|
|
108
108
|
}
|
|
109
|
-
`.trim();
|
|
109
|
+
`.trim();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return `
|
|
113
|
+
import * as React from "react"
|
|
114
|
+
import { PlasmicCanvasHost, registerComponent } from "@plasmicapp/host";
|
|
115
|
+
|
|
116
|
+
// You can register any code components that you want to use here; see
|
|
117
|
+
// https://docs.plasmic.app/learn/code-components-ref/
|
|
118
|
+
// And configure your Plasmic project to use the host url pointing at
|
|
119
|
+
// the /plasmic-host page of your nextjs app (for example,
|
|
120
|
+
// http://localhost:3000/plasmic-host). See
|
|
121
|
+
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
122
|
+
|
|
123
|
+
// registerComponent(...)
|
|
124
|
+
|
|
125
|
+
export default function PlasmicHost() {
|
|
126
|
+
return (
|
|
127
|
+
<PlasmicCanvasHost />
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
110
132
|
};
|
|
111
133
|
exports.makeGatsbyHostPage = makeGatsbyHostPage;
|
|
112
134
|
exports.GATSBY_SSR_CONFIG = `
|
|
@@ -128,6 +150,27 @@ const HeadComponents = [
|
|
|
128
150
|
key="plasmic-preamble"
|
|
129
151
|
src="https://static1.plasmic.app/preamble.js"
|
|
130
152
|
/>,
|
|
153
|
+
<script
|
|
154
|
+
key="plasmic-hmr"
|
|
155
|
+
type="text/javascript"
|
|
156
|
+
dangerouslySetInnerHTML={{
|
|
157
|
+
__html: \`
|
|
158
|
+
if (typeof window !== "undefined" && /\\\\/plasmic-host\\\\/?$/.test(window.location.pathname)) {
|
|
159
|
+
const RealEventSource = window.EventSource;
|
|
160
|
+
window.EventSource = function(url, config) {
|
|
161
|
+
if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {
|
|
162
|
+
console.warn("Plasmic: disabled EventSource request for", url);
|
|
163
|
+
return {
|
|
164
|
+
onerror() {}, onmessage() {}, onopen() {}, close() {}
|
|
165
|
+
};
|
|
166
|
+
} else {
|
|
167
|
+
return new RealEventSource(url, config);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
\`,
|
|
172
|
+
}}
|
|
173
|
+
/>
|
|
131
174
|
]
|
|
132
175
|
|
|
133
176
|
const isProduction = process.env.NODE_ENV === "production"
|
|
@@ -168,3 +211,18 @@ export function initPlasmicLoaderWithRegistrations(plasmicOptions${file_utils_1.
|
|
|
168
211
|
`.trim();
|
|
169
212
|
};
|
|
170
213
|
exports.makeGatsbyPlasmicInit = makeGatsbyPlasmicInit;
|
|
214
|
+
function wrapAppRootForCodegen() {
|
|
215
|
+
return `
|
|
216
|
+
import React from "react";
|
|
217
|
+
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
218
|
+
|
|
219
|
+
export const wrapRootElement = ({ element }) => {
|
|
220
|
+
return (
|
|
221
|
+
<PlasmicRootProvider>
|
|
222
|
+
{element}
|
|
223
|
+
</PlasmicRootProvider>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
exports.wrapAppRootForCodegen = wrapAppRootForCodegen;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodeScheme } from "..";
|
|
1
2
|
export declare const makeNextjsInitPage: (projectId: string, projectApiToken: string) => string;
|
|
2
3
|
export declare function makeNextjsCatchallPage(format: "ts" | "js"): string;
|
|
3
|
-
export declare function makeNextjsHostPage(): string;
|
|
4
|
+
export declare function makeNextjsHostPage(scheme: CodeScheme): string;
|
|
5
|
+
export declare function wrapAppRootForCodegen(): string;
|