@plasmicapp/cli 0.1.181 → 0.1.184
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/actions/sync-components.js +3 -2
- package/dist/index.js +0 -0
- package/dist/utils/code-utils.js +1 -1
- package/dist/utils/file-utils.d.ts +10 -0
- package/dist/utils/file-utils.js +31 -2
- package/package.json +1 -1
- package/src/actions/sync-components.ts +4 -2
- package/src/utils/code-utils.ts +1 -1
- package/src/utils/file-utils.ts +35 -1
|
@@ -42,7 +42,8 @@ const updateDirectSkeleton = (newFileContent, editedFileContent, context, compCo
|
|
|
42
42
|
throw e;
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
|
|
45
|
+
lang_utils_1.assert(e instanceof Error);
|
|
46
|
+
throw new error_1.HandledError(e.message);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
})), () => { }, appendJsxOnMissingBase);
|
|
@@ -170,7 +171,7 @@ function syncProjectComponents(context, project, version, componentBundles, forc
|
|
|
170
171
|
}
|
|
171
172
|
if (isPage &&
|
|
172
173
|
config_utils_1.isPageAwarePlatform(context.config.platform) &&
|
|
173
|
-
skeletonPath
|
|
174
|
+
!file_utils_1.eqPagePath(skeletonPath, compConfig.importSpec.modulePath) &&
|
|
174
175
|
file_utils_1.fileExists(context, compConfig.importSpec.modulePath)) {
|
|
175
176
|
if (context.cliArgs.quiet !== true) {
|
|
176
177
|
deps_1.logger.info(`Renaming page file: ${compConfig.importSpec.modulePath} -> ${skeletonPath}\t['${project.projectName}' ${project.projectId}/${id} ${project.version}]`);
|
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/utils/code-utils.js
CHANGED
|
@@ -252,7 +252,7 @@ function replaceImports(context, code, fromPath, fixImportContext, removeImportD
|
|
|
252
252
|
const meta = fixImportContext.codeComponentMetas[uuid];
|
|
253
253
|
if (meta.componentImportPath[0] === ".") {
|
|
254
254
|
// Relative path from the project root
|
|
255
|
-
const toPath = upath_1.default.join(
|
|
255
|
+
const toPath = upath_1.default.join(context.rootDir, meta.componentImportPath);
|
|
256
256
|
lang_utils_1.assert(upath_1.default.isAbsolute(toPath));
|
|
257
257
|
const realPath = makeImportPath(context, fromPath, toPath, true, true);
|
|
258
258
|
stmt.source.value = realPath;
|
|
@@ -9,6 +9,16 @@ export declare function writeFileContentRaw(filePath: string, content: string |
|
|
|
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
11
|
export declare function defaultPagePath(context: PlasmicContext, fileName: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true iff paths `a` and `b` resolve to the same page URI. For
|
|
14
|
+
* example:
|
|
15
|
+
*
|
|
16
|
+
* - pages/about.tsx and pages/about.js resolve to the same URI (/about).
|
|
17
|
+
* - pages/about/index.tsx and pages/about.tsx resolve to the same URI (/about).
|
|
18
|
+
* - pages/index.tsx and pages/index/index.tsx do not resolve to the same URI
|
|
19
|
+
* (they resolve, respectively, to / and /index).
|
|
20
|
+
*/
|
|
21
|
+
export declare function eqPagePath(a: string, b: string): boolean;
|
|
12
22
|
export declare function writeFileContent(context: PlasmicContext, srcDirFilePath: string, content: string | Buffer, opts?: {
|
|
13
23
|
force?: boolean;
|
|
14
24
|
}): Promise<void>;
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -12,7 +12,7 @@ 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
|
-
exports.existsBuffered = exports.deleteFileBuffered = exports.renameFileBuffered = exports.readFileText = exports.writeFileText = exports.withBufferedFs = exports.assertAllPathsInRootDir = exports.findFile = exports.findSrcDirPath = exports.buildBaseNameToFiles = exports.renameFile = exports.makeFilePath = exports.fileExists = exports.deleteFile = exports.readFileContent = exports.writeFileContent = exports.defaultPagePath = exports.defaultPublicResourcePath = exports.defaultResourcePath = exports.writeFileContentRaw = exports.stripExtension = void 0;
|
|
15
|
+
exports.existsBuffered = exports.deleteFileBuffered = exports.renameFileBuffered = exports.readFileText = exports.writeFileText = exports.withBufferedFs = exports.assertAllPathsInRootDir = exports.findFile = exports.findSrcDirPath = exports.buildBaseNameToFiles = exports.renameFile = exports.makeFilePath = exports.fileExists = exports.deleteFile = exports.readFileContent = exports.writeFileContent = exports.eqPagePath = exports.defaultPagePath = exports.defaultPublicResourcePath = exports.defaultResourcePath = exports.writeFileContentRaw = exports.stripExtension = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const glob_1 = __importDefault(require("glob"));
|
|
18
18
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -23,9 +23,10 @@ const code_utils_1 = require("./code-utils");
|
|
|
23
23
|
const config_utils_1 = require("./config-utils");
|
|
24
24
|
const lang_utils_1 = require("./lang-utils");
|
|
25
25
|
const user_utils_1 = require("./user-utils");
|
|
26
|
+
const findExtension = (filename) => { var _a; return (_a = filename === null || filename === void 0 ? void 0 : filename.substring(filename.indexOf("."))) !== null && _a !== void 0 ? _a : filename; };
|
|
26
27
|
function stripExtension(filename, removeComposedPath = false) {
|
|
27
28
|
const ext = removeComposedPath
|
|
28
|
-
?
|
|
29
|
+
? findExtension(lodash_1.default.last(filename.split("/")))
|
|
29
30
|
: upath_1.default.extname(filename);
|
|
30
31
|
if (!ext || filename === ext) {
|
|
31
32
|
return filename;
|
|
@@ -67,6 +68,34 @@ function defaultPagePath(context, fileName) {
|
|
|
67
68
|
return fileName;
|
|
68
69
|
}
|
|
69
70
|
exports.defaultPagePath = defaultPagePath;
|
|
71
|
+
/**
|
|
72
|
+
* Returns true iff paths `a` and `b` resolve to the same page URI. For
|
|
73
|
+
* example:
|
|
74
|
+
*
|
|
75
|
+
* - pages/about.tsx and pages/about.js resolve to the same URI (/about).
|
|
76
|
+
* - pages/about/index.tsx and pages/about.tsx resolve to the same URI (/about).
|
|
77
|
+
* - pages/index.tsx and pages/index/index.tsx do not resolve to the same URI
|
|
78
|
+
* (they resolve, respectively, to / and /index).
|
|
79
|
+
*/
|
|
80
|
+
function eqPagePath(a, b) {
|
|
81
|
+
// Remove extension and ensure that a.length < b.length.
|
|
82
|
+
a = stripExtension(a);
|
|
83
|
+
b = stripExtension(b);
|
|
84
|
+
if (a.length > b.length) {
|
|
85
|
+
[a, b] = [b, a];
|
|
86
|
+
}
|
|
87
|
+
// pages/about.tsx and pages/about.js resolve to the same page URI.
|
|
88
|
+
if (a === b) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
// pages/about.* and pages/about/index.* resolve to the same URI, but
|
|
92
|
+
// pages/index.* and pages/index/index.* do not.
|
|
93
|
+
if (!a.endsWith("/index") && `${a}/index` === b) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
exports.eqPagePath = eqPagePath;
|
|
70
99
|
function writeFileContent(context, srcDirFilePath, content, opts = {}) {
|
|
71
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
101
|
const path = makeFilePath(context, srcDirFilePath);
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
defaultPagePath,
|
|
22
22
|
defaultResourcePath,
|
|
23
23
|
deleteFile,
|
|
24
|
+
eqPagePath,
|
|
24
25
|
fileExists,
|
|
25
26
|
readFileContent,
|
|
26
27
|
renameFile,
|
|
@@ -71,7 +72,8 @@ const updateDirectSkeleton = async (
|
|
|
71
72
|
) {
|
|
72
73
|
throw e;
|
|
73
74
|
} else {
|
|
74
|
-
|
|
75
|
+
assert(e instanceof Error);
|
|
76
|
+
throw new HandledError(e.message);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
}),
|
|
@@ -302,7 +304,7 @@ export async function syncProjectComponents(
|
|
|
302
304
|
if (
|
|
303
305
|
isPage &&
|
|
304
306
|
isPageAwarePlatform(context.config.platform) &&
|
|
305
|
-
skeletonPath
|
|
307
|
+
!eqPagePath(skeletonPath, compConfig.importSpec.modulePath) &&
|
|
306
308
|
fileExists(context, compConfig.importSpec.modulePath)
|
|
307
309
|
) {
|
|
308
310
|
if (context.cliArgs.quiet !== true) {
|
package/src/utils/code-utils.ts
CHANGED
|
@@ -330,7 +330,7 @@ export function replaceImports(
|
|
|
330
330
|
const meta = fixImportContext.codeComponentMetas[uuid];
|
|
331
331
|
if (meta.componentImportPath[0] === ".") {
|
|
332
332
|
// Relative path from the project root
|
|
333
|
-
const toPath = path.join(
|
|
333
|
+
const toPath = path.join(context.rootDir, meta.componentImportPath);
|
|
334
334
|
assert(path.isAbsolute(toPath));
|
|
335
335
|
const realPath = makeImportPath(context, fromPath, toPath, true, true);
|
|
336
336
|
stmt.source.value = realPath;
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -15,9 +15,12 @@ import {
|
|
|
15
15
|
import { ensureString } from "./lang-utils";
|
|
16
16
|
import { confirmWithUser } from "./user-utils";
|
|
17
17
|
|
|
18
|
+
const findExtension = (filename?: string) =>
|
|
19
|
+
filename?.substring(filename.indexOf(".")) ?? filename;
|
|
20
|
+
|
|
18
21
|
export function stripExtension(filename: string, removeComposedPath = false) {
|
|
19
22
|
const ext = removeComposedPath
|
|
20
|
-
?
|
|
23
|
+
? findExtension(L.last(filename.split("/")))
|
|
21
24
|
: path.extname(filename);
|
|
22
25
|
if (!ext || filename === ext) {
|
|
23
26
|
return filename;
|
|
@@ -84,6 +87,37 @@ export function defaultPagePath(context: PlasmicContext, fileName: string) {
|
|
|
84
87
|
return fileName;
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Returns true iff paths `a` and `b` resolve to the same page URI. For
|
|
92
|
+
* example:
|
|
93
|
+
*
|
|
94
|
+
* - pages/about.tsx and pages/about.js resolve to the same URI (/about).
|
|
95
|
+
* - pages/about/index.tsx and pages/about.tsx resolve to the same URI (/about).
|
|
96
|
+
* - pages/index.tsx and pages/index/index.tsx do not resolve to the same URI
|
|
97
|
+
* (they resolve, respectively, to / and /index).
|
|
98
|
+
*/
|
|
99
|
+
export function eqPagePath(a: string, b: string) {
|
|
100
|
+
// Remove extension and ensure that a.length < b.length.
|
|
101
|
+
a = stripExtension(a);
|
|
102
|
+
b = stripExtension(b);
|
|
103
|
+
if (a.length > b.length) {
|
|
104
|
+
[a, b] = [b, a];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// pages/about.tsx and pages/about.js resolve to the same page URI.
|
|
108
|
+
if (a === b) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// pages/about.* and pages/about/index.* resolve to the same URI, but
|
|
113
|
+
// pages/index.* and pages/index/index.* do not.
|
|
114
|
+
if (!a.endsWith("/index") && `${a}/index` === b) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
87
121
|
export async function writeFileContent(
|
|
88
122
|
context: PlasmicContext,
|
|
89
123
|
srcDirFilePath: string,
|