@plasmicapp/cli 0.1.230 → 0.1.232
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/__tests__/file-utils.spec.d.ts +1 -0
- package/dist/__tests__/file-utils.spec.js +48 -0
- package/dist/actions/init.js +14 -6
- package/dist/actions/sync.js +9 -1
- package/dist/api.d.ts +5 -0
- package/dist/utils/envdetect.d.ts +1 -0
- package/dist/utils/envdetect.js +10 -1
- package/dist/utils/file-utils.d.ts +4 -2
- package/dist/utils/file-utils.js +19 -5
- package/package.json +3 -3
- package/src/__tests__/file-utils.spec.ts +86 -0
- package/src/actions/init.ts +17 -6
- package/src/actions/sync.ts +10 -0
- package/src/api.ts +5 -0
- package/src/utils/envdetect.ts +9 -0
- package/src/utils/file-utils.ts +27 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
4
|
+
describe("defaultPagePath", () => {
|
|
5
|
+
it("does nothing for react", () => {
|
|
6
|
+
expect(file_utils_1.defaultPagePath({ config: { platform: "react" } }, "/index.tsx")).toBe("/index.tsx");
|
|
7
|
+
expect(file_utils_1.defaultPagePath({ config: { platform: "react" } }, "/nested/index.tsx")).toBe("/nested/index.tsx");
|
|
8
|
+
});
|
|
9
|
+
it("handles gatsby pagesDir", () => {
|
|
10
|
+
expect(file_utils_1.defaultPagePath({
|
|
11
|
+
config: {
|
|
12
|
+
platform: "gatsby",
|
|
13
|
+
gatsbyConfig: { pagesDir: "../pages" },
|
|
14
|
+
},
|
|
15
|
+
}, "/index.tsx")).toBe("../pages/index.tsx");
|
|
16
|
+
expect(file_utils_1.defaultPagePath({
|
|
17
|
+
config: {
|
|
18
|
+
platform: "gatsby",
|
|
19
|
+
gatsbyConfig: { pagesDir: "../pages" },
|
|
20
|
+
},
|
|
21
|
+
}, "/nested/index.tsx")).toBe("../pages/nested/index.tsx");
|
|
22
|
+
});
|
|
23
|
+
it("handles nextjs pagesDir", () => {
|
|
24
|
+
expect(file_utils_1.defaultPagePath({
|
|
25
|
+
config: {
|
|
26
|
+
platform: "nextjs",
|
|
27
|
+
nextjsConfig: { pagesDir: "../pages" },
|
|
28
|
+
},
|
|
29
|
+
}, "/index.tsx")).toBe("../pages/index.tsx");
|
|
30
|
+
expect(file_utils_1.defaultPagePath({
|
|
31
|
+
config: {
|
|
32
|
+
platform: "nextjs",
|
|
33
|
+
nextjsConfig: { pagesDir: "../pages" },
|
|
34
|
+
},
|
|
35
|
+
}, "/nested/index.tsx")).toBe("../pages/nested/index.tsx");
|
|
36
|
+
});
|
|
37
|
+
it("handles nextjs pagesDir using app/ directory ", () => {
|
|
38
|
+
expect(file_utils_1.defaultPagePath({
|
|
39
|
+
config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
|
|
40
|
+
}, "/index.tsx")).toBe("../app/page.tsx");
|
|
41
|
+
expect(file_utils_1.defaultPagePath({
|
|
42
|
+
config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
|
|
43
|
+
}, "/nested/index.tsx")).toBe("../app/nested/page.tsx");
|
|
44
|
+
expect(file_utils_1.defaultPagePath({
|
|
45
|
+
config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
|
|
46
|
+
}, "/not-index.tsx")).toBe("../app/not-index/page.tsx");
|
|
47
|
+
});
|
|
48
|
+
});
|
package/dist/actions/init.js
CHANGED
|
@@ -81,14 +81,22 @@ function deriveInitAnswers(opts) {
|
|
|
81
81
|
? "nextjs"
|
|
82
82
|
: envdetect_1.detectGatsby()
|
|
83
83
|
? "gatsby"
|
|
84
|
-
:
|
|
85
|
-
|
|
84
|
+
: envdetect_1.detectCreateReactApp()
|
|
85
|
+
? "react"
|
|
86
|
+
: "";
|
|
87
|
+
const isCra = platform === "react";
|
|
86
88
|
const isNext = platform === "nextjs";
|
|
89
|
+
const isNextAppDir = isNext && envdetect_1.detectNextJsAppDir();
|
|
87
90
|
const isGatsby = platform === "gatsby";
|
|
88
91
|
const isGeneric = !isCra && !isNext && !isGatsby;
|
|
89
92
|
const isTypescript = envdetect_1.detectTypescript();
|
|
90
93
|
if (isNext) {
|
|
91
|
-
|
|
94
|
+
if (isNextAppDir) {
|
|
95
|
+
deps_1.logger.info("Detected Next.js with app/ directory (experimental)...");
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
deps_1.logger.info("Detected Next.js...");
|
|
99
|
+
}
|
|
92
100
|
}
|
|
93
101
|
else if (isGatsby) {
|
|
94
102
|
deps_1.logger.info("Detected Gatsby...");
|
|
@@ -98,7 +106,7 @@ function deriveInitAnswers(opts) {
|
|
|
98
106
|
}
|
|
99
107
|
// Platform-specific defaults that take precedent
|
|
100
108
|
const deriver = isNext
|
|
101
|
-
? getNextDefaults(plasmicRootDir)
|
|
109
|
+
? getNextDefaults(plasmicRootDir, isNextAppDir)
|
|
102
110
|
: isGatsby
|
|
103
111
|
? getGatsbyDefaults(plasmicRootDir)
|
|
104
112
|
: isCra
|
|
@@ -276,12 +284,12 @@ function deriveInitAnswers(opts) {
|
|
|
276
284
|
return answers;
|
|
277
285
|
});
|
|
278
286
|
}
|
|
279
|
-
function getNextDefaults(plasmicRootDir) {
|
|
287
|
+
function getNextDefaults(plasmicRootDir, appDir) {
|
|
280
288
|
var _a;
|
|
281
289
|
const projectRootDir = (_a = npm_utils_1.findPackageJsonDir(plasmicRootDir)) !== null && _a !== void 0 ? _a : plasmicRootDir;
|
|
282
290
|
return {
|
|
283
291
|
srcDir: upath_1.default.relative(plasmicRootDir, upath_1.default.join(projectRootDir, "components")),
|
|
284
|
-
pagesDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, "pages")),
|
|
292
|
+
pagesDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, appDir ? "app" : "pages")),
|
|
285
293
|
styleScheme: "css-modules",
|
|
286
294
|
imagesScheme: "public-files",
|
|
287
295
|
imagesPublicDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, "public")),
|
package/dist/actions/sync.js
CHANGED
|
@@ -330,7 +330,7 @@ function fixFileExtension(context) {
|
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
function syncProject(context, opts, projectIdsAndTokens, projectId, branchName, componentIds, projectVersion, dependencies, summary, indirect, externalNpmPackages, externalCssImports, metadataDefaults) {
|
|
333
|
-
var _a;
|
|
333
|
+
var _a, _b, _c;
|
|
334
334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
335
335
|
const existingProject = context.config.projects.find((p) => p.projectId === projectId);
|
|
336
336
|
const existingCompScheme = ((existingProject === null || existingProject === void 0 ? void 0 : existingProject.components) || []).map((c) => [c.id, c.scheme]);
|
|
@@ -339,6 +339,14 @@ function syncProject(context, opts, projectIdsAndTokens, projectId, branchName,
|
|
|
339
339
|
// Server-side code-gen
|
|
340
340
|
const projectBundle = yield context.api.projectComponents(projectId, branchName, {
|
|
341
341
|
platform: context.config.platform,
|
|
342
|
+
platformOptions: context.config.platform === "nextjs"
|
|
343
|
+
? {
|
|
344
|
+
nextjs: {
|
|
345
|
+
appDir: ((_c = (_b = context.config.nextjsConfig) === null || _b === void 0 ? void 0 : _b.pagesDir) === null || _c === void 0 ? void 0 : _c.endsWith("app")) ||
|
|
346
|
+
false,
|
|
347
|
+
},
|
|
348
|
+
}
|
|
349
|
+
: {},
|
|
342
350
|
componentIdOrNames: componentIds,
|
|
343
351
|
version: projectVersion,
|
|
344
352
|
imageOpts: context.config.images,
|
package/dist/api.d.ts
CHANGED
|
@@ -178,6 +178,11 @@ export declare class PlasmicApi {
|
|
|
178
178
|
*/
|
|
179
179
|
projectComponents(projectId: string, branchName: string, opts: {
|
|
180
180
|
platform: string;
|
|
181
|
+
platformOptions: {
|
|
182
|
+
nextjs?: {
|
|
183
|
+
appDir: boolean;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
181
186
|
componentIdOrNames: readonly string[] | undefined;
|
|
182
187
|
version: string;
|
|
183
188
|
imageOpts: ImagesConfig;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function detectTypescript(): string | null;
|
|
2
2
|
export declare function detectNextJs(): boolean;
|
|
3
|
+
export declare function detectNextJsAppDir(): any;
|
|
3
4
|
export declare function detectGatsby(): string | null;
|
|
4
5
|
export declare function detectCreateReactApp(): boolean;
|
package/dist/utils/envdetect.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.detectCreateReactApp = exports.detectGatsby = exports.detectNextJs = exports.detectTypescript = void 0;
|
|
6
|
+
exports.detectCreateReactApp = exports.detectGatsby = exports.detectNextJsAppDir = exports.detectNextJs = exports.detectTypescript = void 0;
|
|
7
7
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
8
|
const npm_utils_1 = require("./npm-utils");
|
|
9
9
|
function detectTypescript() {
|
|
@@ -26,6 +26,15 @@ function detectNextJs() {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.detectNextJs = detectNextJs;
|
|
29
|
+
function detectNextJsAppDir() {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const nextConfigPath = findup_sync_1.default("next.config.js");
|
|
32
|
+
if (!nextConfigPath) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return ((_b = (_a = require(nextConfigPath)) === null || _a === void 0 ? void 0 : _a.experimental) === null || _b === void 0 ? void 0 : _b.appDir) || false;
|
|
36
|
+
}
|
|
37
|
+
exports.detectNextJsAppDir = detectNextJsAppDir;
|
|
29
38
|
function detectGatsby() {
|
|
30
39
|
return findup_sync_1.default("gatsby-config.js") || findup_sync_1.default("gatsby-config.ts");
|
|
31
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ProjectMetaBundle } from "../api";
|
|
3
|
-
import { PlasmicContext, ProjectConfig } from "./config-utils";
|
|
3
|
+
import { PlasmicConfig, PlasmicContext, ProjectConfig } from "./config-utils";
|
|
4
4
|
export declare function stripExtension(filename: string, removeComposedPath?: boolean): string;
|
|
5
5
|
export declare function writeFileContentRaw(filePath: string, content: string | Buffer, opts?: {
|
|
6
6
|
force?: boolean;
|
|
@@ -8,7 +8,9 @@ export declare function writeFileContentRaw(filePath: string, content: string |
|
|
|
8
8
|
}): Promise<void>;
|
|
9
9
|
export declare function defaultResourcePath(context: PlasmicContext, project: ProjectConfig | ProjectMetaBundle | string, ...subpaths: string[]): string;
|
|
10
10
|
export declare function defaultPublicResourcePath(context: PlasmicContext, project: ProjectConfig, ...subpaths: string[]): string;
|
|
11
|
-
export declare function defaultPagePath(context:
|
|
11
|
+
export declare function defaultPagePath(context: {
|
|
12
|
+
config: Pick<PlasmicConfig, "platform" | "gatsbyConfig" | "nextjsConfig">;
|
|
13
|
+
}, fileName: string): string;
|
|
12
14
|
/**
|
|
13
15
|
* Returns true iff paths `a` and `b` resolve to the same page URI. For
|
|
14
16
|
* example:
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -58,14 +58,28 @@ function defaultPublicResourcePath(context, project, ...subpaths) {
|
|
|
58
58
|
}
|
|
59
59
|
exports.defaultPublicResourcePath = defaultPublicResourcePath;
|
|
60
60
|
function defaultPagePath(context, fileName) {
|
|
61
|
-
var _a, _b;
|
|
61
|
+
var _a, _b, _c, _d;
|
|
62
62
|
if (context.config.platform === "nextjs") {
|
|
63
|
-
|
|
63
|
+
if ((_b = (_a = context.config.nextjsConfig) === null || _a === void 0 ? void 0 : _a.pagesDir) === null || _b === void 0 ? void 0 : _b.endsWith("app")) {
|
|
64
|
+
if (fileName.endsWith("/index.tsx")) {
|
|
65
|
+
// convert "/foo/index.tsx" to "/foo/page.tsx"
|
|
66
|
+
return upath_1.default.join(context.config.nextjsConfig.pagesDir, fileName.replace(/\/index\.tsx$/, "/page.tsx"));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// convert "/foo/bar.tsx" to "/foo/bar/page.tsx"
|
|
70
|
+
return upath_1.default.join(context.config.nextjsConfig.pagesDir, fileName.replace(/\.tsx$/, "/page.tsx"));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return upath_1.default.join(((_c = context.config.nextjsConfig) === null || _c === void 0 ? void 0 : _c.pagesDir) || "", fileName);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (context.config.platform === "gatsby") {
|
|
78
|
+
return upath_1.default.join(((_d = context.config.gatsbyConfig) === null || _d === void 0 ? void 0 : _d.pagesDir) || "", fileName);
|
|
64
79
|
}
|
|
65
|
-
|
|
66
|
-
return
|
|
80
|
+
else {
|
|
81
|
+
return fileName;
|
|
67
82
|
}
|
|
68
|
-
return fileName;
|
|
69
83
|
}
|
|
70
84
|
exports.defaultPagePath = defaultPagePath;
|
|
71
85
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.232",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-typescript": "^7.12.1",
|
|
23
|
-
"@plasmicapp/react-web": "0.2.
|
|
23
|
+
"@plasmicapp/react-web": "0.2.175",
|
|
24
24
|
"@types/findup-sync": "^2.0.2",
|
|
25
25
|
"@types/glob": "^7.1.3",
|
|
26
26
|
"@types/inquirer": "^6.5.0",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"wrap-ansi": "^7.0.0",
|
|
78
78
|
"yargs": "^15.4.1"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "1d9e46447dea9fe47ae76c2e1a39e14dcab687e6"
|
|
81
81
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { defaultPagePath } from "../utils/file-utils";
|
|
2
|
+
|
|
3
|
+
describe("defaultPagePath", () => {
|
|
4
|
+
it("does nothing for react", () => {
|
|
5
|
+
expect(
|
|
6
|
+
defaultPagePath({ config: { platform: "react" } }, "/index.tsx")
|
|
7
|
+
).toBe("/index.tsx");
|
|
8
|
+
expect(
|
|
9
|
+
defaultPagePath({ config: { platform: "react" } }, "/nested/index.tsx")
|
|
10
|
+
).toBe("/nested/index.tsx");
|
|
11
|
+
});
|
|
12
|
+
it("handles gatsby pagesDir", () => {
|
|
13
|
+
expect(
|
|
14
|
+
defaultPagePath(
|
|
15
|
+
{
|
|
16
|
+
config: {
|
|
17
|
+
platform: "gatsby",
|
|
18
|
+
gatsbyConfig: { pagesDir: "../pages" },
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
"/index.tsx"
|
|
22
|
+
)
|
|
23
|
+
).toBe("../pages/index.tsx");
|
|
24
|
+
expect(
|
|
25
|
+
defaultPagePath(
|
|
26
|
+
{
|
|
27
|
+
config: {
|
|
28
|
+
platform: "gatsby",
|
|
29
|
+
gatsbyConfig: { pagesDir: "../pages" },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
"/nested/index.tsx"
|
|
33
|
+
)
|
|
34
|
+
).toBe("../pages/nested/index.tsx");
|
|
35
|
+
});
|
|
36
|
+
it("handles nextjs pagesDir", () => {
|
|
37
|
+
expect(
|
|
38
|
+
defaultPagePath(
|
|
39
|
+
{
|
|
40
|
+
config: {
|
|
41
|
+
platform: "nextjs",
|
|
42
|
+
nextjsConfig: { pagesDir: "../pages" },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"/index.tsx"
|
|
46
|
+
)
|
|
47
|
+
).toBe("../pages/index.tsx");
|
|
48
|
+
expect(
|
|
49
|
+
defaultPagePath(
|
|
50
|
+
{
|
|
51
|
+
config: {
|
|
52
|
+
platform: "nextjs",
|
|
53
|
+
nextjsConfig: { pagesDir: "../pages" },
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
"/nested/index.tsx"
|
|
57
|
+
)
|
|
58
|
+
).toBe("../pages/nested/index.tsx");
|
|
59
|
+
});
|
|
60
|
+
it("handles nextjs pagesDir using app/ directory ", () => {
|
|
61
|
+
expect(
|
|
62
|
+
defaultPagePath(
|
|
63
|
+
{
|
|
64
|
+
config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
|
|
65
|
+
},
|
|
66
|
+
"/index.tsx"
|
|
67
|
+
)
|
|
68
|
+
).toBe("../app/page.tsx");
|
|
69
|
+
expect(
|
|
70
|
+
defaultPagePath(
|
|
71
|
+
{
|
|
72
|
+
config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
|
|
73
|
+
},
|
|
74
|
+
"/nested/index.tsx"
|
|
75
|
+
)
|
|
76
|
+
).toBe("../app/nested/page.tsx");
|
|
77
|
+
expect(
|
|
78
|
+
defaultPagePath(
|
|
79
|
+
{
|
|
80
|
+
config: { platform: "nextjs", nextjsConfig: { pagesDir: "../app" } },
|
|
81
|
+
},
|
|
82
|
+
"/not-index.tsx"
|
|
83
|
+
)
|
|
84
|
+
).toBe("../app/not-index/page.tsx");
|
|
85
|
+
});
|
|
86
|
+
});
|
package/src/actions/init.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
detectCreateReactApp,
|
|
20
20
|
detectGatsby,
|
|
21
21
|
detectNextJs,
|
|
22
|
+
detectNextJsAppDir,
|
|
22
23
|
detectTypescript,
|
|
23
24
|
} from "../utils/envdetect";
|
|
24
25
|
import { existsBuffered } from "../utils/file-utils";
|
|
@@ -163,15 +164,22 @@ async function deriveInitAnswers(
|
|
|
163
164
|
? "nextjs"
|
|
164
165
|
: detectGatsby()
|
|
165
166
|
? "gatsby"
|
|
166
|
-
:
|
|
167
|
-
|
|
167
|
+
: detectCreateReactApp()
|
|
168
|
+
? "react"
|
|
169
|
+
: "";
|
|
170
|
+
const isCra = platform === "react";
|
|
168
171
|
const isNext = platform === "nextjs";
|
|
172
|
+
const isNextAppDir = isNext && detectNextJsAppDir();
|
|
169
173
|
const isGatsby = platform === "gatsby";
|
|
170
174
|
const isGeneric = !isCra && !isNext && !isGatsby;
|
|
171
175
|
const isTypescript = detectTypescript();
|
|
172
176
|
|
|
173
177
|
if (isNext) {
|
|
174
|
-
|
|
178
|
+
if (isNextAppDir) {
|
|
179
|
+
logger.info("Detected Next.js with app/ directory (experimental)...");
|
|
180
|
+
} else {
|
|
181
|
+
logger.info("Detected Next.js...");
|
|
182
|
+
}
|
|
175
183
|
} else if (isGatsby) {
|
|
176
184
|
logger.info("Detected Gatsby...");
|
|
177
185
|
} else if (isCra) {
|
|
@@ -180,7 +188,7 @@ async function deriveInitAnswers(
|
|
|
180
188
|
|
|
181
189
|
// Platform-specific defaults that take precedent
|
|
182
190
|
const deriver = isNext
|
|
183
|
-
? getNextDefaults(plasmicRootDir)
|
|
191
|
+
? getNextDefaults(plasmicRootDir, isNextAppDir)
|
|
184
192
|
: isGatsby
|
|
185
193
|
? getGatsbyDefaults(plasmicRootDir)
|
|
186
194
|
: isCra
|
|
@@ -407,7 +415,10 @@ async function deriveInitAnswers(
|
|
|
407
415
|
return answers as InitArgs;
|
|
408
416
|
}
|
|
409
417
|
|
|
410
|
-
function getNextDefaults(
|
|
418
|
+
function getNextDefaults(
|
|
419
|
+
plasmicRootDir: string,
|
|
420
|
+
appDir: boolean
|
|
421
|
+
): DefaultDeriver {
|
|
411
422
|
const projectRootDir = findPackageJsonDir(plasmicRootDir) ?? plasmicRootDir;
|
|
412
423
|
return {
|
|
413
424
|
srcDir: path.relative(
|
|
@@ -417,7 +428,7 @@ function getNextDefaults(plasmicRootDir: string): DefaultDeriver {
|
|
|
417
428
|
pagesDir: (srcDir: string) =>
|
|
418
429
|
path.relative(
|
|
419
430
|
path.join(plasmicRootDir, srcDir),
|
|
420
|
-
path.join(projectRootDir, "pages")
|
|
431
|
+
path.join(projectRootDir, appDir ? "app" : "pages")
|
|
421
432
|
),
|
|
422
433
|
styleScheme: "css-modules",
|
|
423
434
|
imagesScheme: "public-files",
|
package/src/actions/sync.ts
CHANGED
|
@@ -555,6 +555,16 @@ async function syncProject(
|
|
|
555
555
|
branchName,
|
|
556
556
|
{
|
|
557
557
|
platform: context.config.platform,
|
|
558
|
+
platformOptions:
|
|
559
|
+
context.config.platform === "nextjs"
|
|
560
|
+
? {
|
|
561
|
+
nextjs: {
|
|
562
|
+
appDir:
|
|
563
|
+
context.config.nextjsConfig?.pagesDir?.endsWith("app") ||
|
|
564
|
+
false,
|
|
565
|
+
},
|
|
566
|
+
}
|
|
567
|
+
: {},
|
|
558
568
|
componentIdOrNames: componentIds,
|
|
559
569
|
version: projectVersion,
|
|
560
570
|
imageOpts: context.config.images,
|
package/src/api.ts
CHANGED
|
@@ -261,6 +261,11 @@ export class PlasmicApi {
|
|
|
261
261
|
branchName: string,
|
|
262
262
|
opts: {
|
|
263
263
|
platform: string;
|
|
264
|
+
platformOptions: {
|
|
265
|
+
nextjs?: {
|
|
266
|
+
appDir: boolean;
|
|
267
|
+
};
|
|
268
|
+
};
|
|
264
269
|
componentIdOrNames: readonly string[] | undefined;
|
|
265
270
|
version: string;
|
|
266
271
|
imageOpts: ImagesConfig;
|
package/src/utils/envdetect.ts
CHANGED
|
@@ -25,6 +25,15 @@ export function detectNextJs() {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export function detectNextJsAppDir() {
|
|
29
|
+
const nextConfigPath = findupSync("next.config.js");
|
|
30
|
+
if (!nextConfigPath) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return require(nextConfigPath)?.experimental?.appDir || false;
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
export function detectGatsby() {
|
|
29
38
|
return findupSync("gatsby-config.js") || findupSync("gatsby-config.ts");
|
|
30
39
|
}
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { isLocalModulePath } from "./code-utils";
|
|
|
9
9
|
import {
|
|
10
10
|
ComponentConfig,
|
|
11
11
|
CONFIG_FILE_NAME,
|
|
12
|
+
PlasmicConfig,
|
|
12
13
|
PlasmicContext,
|
|
13
14
|
ProjectConfig,
|
|
14
15
|
} from "./config-utils";
|
|
@@ -77,14 +78,35 @@ export function defaultPublicResourcePath(
|
|
|
77
78
|
);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
export function defaultPagePath(
|
|
81
|
+
export function defaultPagePath(
|
|
82
|
+
context: {
|
|
83
|
+
config: Pick<PlasmicConfig, "platform" | "gatsbyConfig" | "nextjsConfig">;
|
|
84
|
+
},
|
|
85
|
+
fileName: string
|
|
86
|
+
) {
|
|
81
87
|
if (context.config.platform === "nextjs") {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
if (context.config.nextjsConfig?.pagesDir?.endsWith("app")) {
|
|
89
|
+
if (fileName.endsWith("/index.tsx")) {
|
|
90
|
+
// convert "/foo/index.tsx" to "/foo/page.tsx"
|
|
91
|
+
return path.join(
|
|
92
|
+
context.config.nextjsConfig.pagesDir,
|
|
93
|
+
fileName.replace(/\/index\.tsx$/, "/page.tsx")
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
// convert "/foo/bar.tsx" to "/foo/bar/page.tsx"
|
|
97
|
+
return path.join(
|
|
98
|
+
context.config.nextjsConfig.pagesDir,
|
|
99
|
+
fileName.replace(/\.tsx$/, "/page.tsx")
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
return path.join(context.config.nextjsConfig?.pagesDir || "", fileName);
|
|
104
|
+
}
|
|
105
|
+
} else if (context.config.platform === "gatsby") {
|
|
85
106
|
return path.join(context.config.gatsbyConfig?.pagesDir || "", fileName);
|
|
107
|
+
} else {
|
|
108
|
+
return fileName;
|
|
86
109
|
}
|
|
87
|
-
return fileName;
|
|
88
110
|
}
|
|
89
111
|
|
|
90
112
|
/**
|