create-plasmic-app 0.0.87 → 0.0.89
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/react/react.js +8 -3
- package/dist/utils/file-utils.d.ts +3 -2
- package/dist/utils/file-utils.js +11 -2
- package/package.json +3 -3
- package/src/react/react.ts +19 -3
- package/src/utils/file-utils.ts +17 -3
package/dist/react/react.js
CHANGED
|
@@ -19,7 +19,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
19
19
|
const cmd_utils_1 = require("../utils/cmd-utils");
|
|
20
20
|
const codegen_1 = require("../utils/codegen");
|
|
21
21
|
const file_utils_1 = require("../utils/file-utils");
|
|
22
|
-
const lang_utils_1 = require("../utils/lang-utils");
|
|
23
22
|
const npm_utils_1 = require("../utils/npm-utils");
|
|
24
23
|
exports.reactStrategy = {
|
|
25
24
|
create: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -59,12 +58,18 @@ exports.reactStrategy = {
|
|
|
59
58
|
});
|
|
60
59
|
// Pick a page for the entry point App.tsx page
|
|
61
60
|
const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "react", scheme);
|
|
62
|
-
const pagesDir = path_1.default.join(projectPath,
|
|
61
|
+
const pagesDir = path_1.default.join(projectPath, config.srcDir);
|
|
62
|
+
const projectConfig = config.projects.find((p) => p.projectId === projectId);
|
|
63
|
+
const globalContextsPath = projectConfig &&
|
|
64
|
+
projectConfig.globalContextsFilePath &&
|
|
65
|
+
config.wrapPagesWithGlobalContexts
|
|
66
|
+
? path_1.default.join(projectPath, config.srcDir, projectConfig.globalContextsFilePath)
|
|
67
|
+
: undefined;
|
|
63
68
|
const homeFilePossibilities = glob_1.default.sync(path_1.default.join(pagesDir, "**", "@(index|Home|home|Homepage).*"));
|
|
64
69
|
// Overwrite App.tsx
|
|
65
70
|
const indexPath = path_1.default.join(projectPath, "src", `App.${jsOrTs}x`);
|
|
66
71
|
const content = homeFilePossibilities.length > 0
|
|
67
|
-
? (0, file_utils_1.generateHomePage)(homeFilePossibilities[0], indexPath)
|
|
72
|
+
? (0, file_utils_1.generateHomePage)(homeFilePossibilities[0], indexPath, globalContextsPath)
|
|
68
73
|
: (0, file_utils_1.generateWelcomePage)(config, "react");
|
|
69
74
|
yield fs_1.promises.writeFile(indexPath, content);
|
|
70
75
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PlasmicConfig } from "@plasmicapp/cli/dist/utils/config-utils";
|
|
1
2
|
import { JsOrTs, PlatformType } from "../utils/types";
|
|
2
3
|
/**
|
|
3
4
|
* Runs the search pattern through `glob` and deletes all resulting files
|
|
@@ -20,7 +21,7 @@ export declare function overwriteReadme(projectPath: string, platform: PlatformT
|
|
|
20
21
|
* @param indexAbsPath - absolute path of index file to write
|
|
21
22
|
* @returns
|
|
22
23
|
*/
|
|
23
|
-
export declare function generateHomePage(componentAbsPath: string, indexAbsPath: string): string;
|
|
24
|
+
export declare function generateHomePage(componentAbsPath: string, indexAbsPath: string, globalContextsAbsPath?: string): string;
|
|
24
25
|
/**
|
|
25
26
|
* Generate a Welcome page based on a PlasmicConfig
|
|
26
27
|
* @param config - PlasmicConfig
|
|
@@ -28,6 +29,6 @@ export declare function generateHomePage(componentAbsPath: string, indexAbsPath:
|
|
|
28
29
|
* @returns
|
|
29
30
|
*/
|
|
30
31
|
export declare function generateWelcomePage(config: any, platform: string): string;
|
|
31
|
-
export declare function getPlasmicConfig(projectPath: string, platform: PlatformType, scheme: string): Promise<
|
|
32
|
+
export declare function getPlasmicConfig(projectPath: string, platform: PlatformType, scheme: string): Promise<PlasmicConfig>;
|
|
32
33
|
export declare function ensureTsconfig(projectPath: string): Promise<void>;
|
|
33
34
|
export declare function ifTs(ts: JsOrTs, str: string): string;
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -101,16 +101,25 @@ exports.overwriteReadme = overwriteReadme;
|
|
|
101
101
|
* @param indexAbsPath - absolute path of index file to write
|
|
102
102
|
* @returns
|
|
103
103
|
*/
|
|
104
|
-
function generateHomePage(componentAbsPath, indexAbsPath) {
|
|
104
|
+
function generateHomePage(componentAbsPath, indexAbsPath, globalContextsAbsPath) {
|
|
105
105
|
const componentFilename = path.basename(componentAbsPath);
|
|
106
106
|
const componentName = stripExtension(componentFilename);
|
|
107
107
|
// The relative import path from App.js to the Plasmic component
|
|
108
108
|
const componentRelativePath = path.relative(path.dirname(indexAbsPath), componentAbsPath);
|
|
109
|
+
const globalContextsImport = globalContextsAbsPath
|
|
110
|
+
? `import GlobalContextsProvider from './${stripExtension(path.relative(path.dirname(indexAbsPath), globalContextsAbsPath))}'`
|
|
111
|
+
: ``;
|
|
112
|
+
const maybeWrapInGlobalContexts = (content) => {
|
|
113
|
+
return globalContextsAbsPath
|
|
114
|
+
? `<GlobalContextsProvider>${content}</GlobalContextsProvider>`
|
|
115
|
+
: content;
|
|
116
|
+
};
|
|
109
117
|
const appjsContents = `
|
|
110
118
|
import ${componentName} from './${stripExtension(componentRelativePath)}';
|
|
119
|
+
${globalContextsImport}
|
|
111
120
|
|
|
112
121
|
function App() {
|
|
113
|
-
return (
|
|
122
|
+
return (${maybeWrapInGlobalContexts(`<${componentName} />`)});
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
export default App;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-plasmic-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.89",
|
|
4
4
|
"description": "Create Plasmic-powered React apps",
|
|
5
5
|
"main": "./dist/lib.js",
|
|
6
6
|
"types": "./dist/lib.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build": "eslint 'src/**' && tsc",
|
|
19
19
|
"run-cpa": "yarn build && ts-node run-cpa.ts",
|
|
20
20
|
"create-plasmic-app": "ts-node src/index.ts",
|
|
21
|
-
"
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/findup-sync": "^2.0.2",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"validate-npm-package-name": "^3.0.0",
|
|
55
55
|
"yargs": "^16.2.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "d6ab1d45b69aeb83b3cf3d7f585e5e011a9d80bd"
|
|
58
58
|
}
|
package/src/react/react.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
generateWelcomePage,
|
|
10
10
|
getPlasmicConfig,
|
|
11
11
|
} from "../utils/file-utils";
|
|
12
|
-
import { ensureString } from "../utils/lang-utils";
|
|
13
12
|
import { installUpgrade } from "../utils/npm-utils";
|
|
14
13
|
import { CPAStrategy } from "../utils/strategy";
|
|
15
14
|
|
|
@@ -59,7 +58,20 @@ export const reactStrategy: CPAStrategy = {
|
|
|
59
58
|
|
|
60
59
|
// Pick a page for the entry point App.tsx page
|
|
61
60
|
const config = await getPlasmicConfig(projectPath, "react", scheme);
|
|
62
|
-
const pagesDir = path.join(projectPath,
|
|
61
|
+
const pagesDir = path.join(projectPath, config.srcDir);
|
|
62
|
+
const projectConfig = config.projects.find(
|
|
63
|
+
(p) => p.projectId === projectId
|
|
64
|
+
);
|
|
65
|
+
const globalContextsPath =
|
|
66
|
+
projectConfig &&
|
|
67
|
+
projectConfig.globalContextsFilePath &&
|
|
68
|
+
config.wrapPagesWithGlobalContexts
|
|
69
|
+
? path.join(
|
|
70
|
+
projectPath,
|
|
71
|
+
config.srcDir,
|
|
72
|
+
projectConfig.globalContextsFilePath
|
|
73
|
+
)
|
|
74
|
+
: undefined;
|
|
63
75
|
const homeFilePossibilities = glob.sync(
|
|
64
76
|
path.join(pagesDir, "**", "@(index|Home|home|Homepage).*")
|
|
65
77
|
);
|
|
@@ -68,7 +80,11 @@ export const reactStrategy: CPAStrategy = {
|
|
|
68
80
|
const indexPath = path.join(projectPath, "src", `App.${jsOrTs}x`);
|
|
69
81
|
const content =
|
|
70
82
|
homeFilePossibilities.length > 0
|
|
71
|
-
? generateHomePage(
|
|
83
|
+
? generateHomePage(
|
|
84
|
+
homeFilePossibilities[0],
|
|
85
|
+
indexPath,
|
|
86
|
+
globalContextsPath
|
|
87
|
+
)
|
|
72
88
|
: generateWelcomePage(config, "react");
|
|
73
89
|
await fs.writeFile(indexPath, content);
|
|
74
90
|
}
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PlasmicConfig } from "@plasmicapp/cli/dist/utils/config-utils";
|
|
1
2
|
import { existsSync, promises as fs, unlinkSync } from "fs";
|
|
2
3
|
import glob from "glob";
|
|
3
4
|
import L from "lodash";
|
|
@@ -80,7 +81,8 @@ export async function overwriteReadme(
|
|
|
80
81
|
*/
|
|
81
82
|
export function generateHomePage(
|
|
82
83
|
componentAbsPath: string,
|
|
83
|
-
indexAbsPath: string
|
|
84
|
+
indexAbsPath: string,
|
|
85
|
+
globalContextsAbsPath?: string
|
|
84
86
|
): string {
|
|
85
87
|
const componentFilename = path.basename(componentAbsPath);
|
|
86
88
|
const componentName = stripExtension(componentFilename);
|
|
@@ -89,11 +91,23 @@ export function generateHomePage(
|
|
|
89
91
|
path.dirname(indexAbsPath),
|
|
90
92
|
componentAbsPath
|
|
91
93
|
);
|
|
94
|
+
const globalContextsImport = globalContextsAbsPath
|
|
95
|
+
? `import GlobalContextsProvider from './${stripExtension(
|
|
96
|
+
path.relative(path.dirname(indexAbsPath), globalContextsAbsPath)
|
|
97
|
+
)}'`
|
|
98
|
+
: ``;
|
|
99
|
+
const maybeWrapInGlobalContexts = (content: string) => {
|
|
100
|
+
return globalContextsAbsPath
|
|
101
|
+
? `<GlobalContextsProvider>${content}</GlobalContextsProvider>`
|
|
102
|
+
: content;
|
|
103
|
+
};
|
|
104
|
+
|
|
92
105
|
const appjsContents = `
|
|
93
106
|
import ${componentName} from './${stripExtension(componentRelativePath)}';
|
|
107
|
+
${globalContextsImport}
|
|
94
108
|
|
|
95
109
|
function App() {
|
|
96
|
-
return (
|
|
110
|
+
return (${maybeWrapInGlobalContexts(`<${componentName} />`)});
|
|
97
111
|
}
|
|
98
112
|
|
|
99
113
|
export default App;
|
|
@@ -154,7 +168,7 @@ export async function getPlasmicConfig(
|
|
|
154
168
|
projectPath: string,
|
|
155
169
|
platform: PlatformType,
|
|
156
170
|
scheme: string
|
|
157
|
-
) {
|
|
171
|
+
): Promise<PlasmicConfig> {
|
|
158
172
|
const isNextjs = platform === "nextjs";
|
|
159
173
|
const isGatsby = platform === "gatsby";
|
|
160
174
|
const isLoader = scheme === "loader";
|