@plasmicapp/cli 0.1.182 → 0.1.185

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 CHANGED
@@ -1,16 +1,19 @@
1
- Public plasmic cli for syncing designs to local code.
1
+ Plasmic CLI for syncing Plasmic designs down into your local repo as generated React code.
2
2
 
3
- Install
4
- =======
3
+ Plasmic is the visual builder for React. Learn more at <https://plasmic.app>.
5
4
 
6
- `yarn global add @plasmicapp/cli`
5
+ # Install
7
6
 
8
- Usage
9
- =====
7
+ ```bash
8
+ npm install -g @plasmicapp/cli
9
+ ```
10
+
11
+ # Usage
12
+
13
+ See <https://docs.plasmic.app/learn/codegen-guide/> for the full docs to get started with Plasmic codegen.
10
14
 
11
15
  `plasmic init` creates the initial plasmic.json file, pointing to your local dev host.
12
16
 
13
17
  `plasmic sync --projects ...` allows you to sync all components in the specified projects
14
- down as code files to your current folder. Once you've run `plasmic init`, you can run
18
+ down as code files to your current folder. Once you've run `plasmic init`, you can run
15
19
  `plasmic sync` from any subfolder of the folder with the `plasmic.json` file.
16
-
@@ -42,7 +42,8 @@ const updateDirectSkeleton = (newFileContent, editedFileContent, context, compCo
42
42
  throw e;
43
43
  }
44
44
  else {
45
- throw new error_1.HandledError(e.messag);
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 !== compConfig.importSpec.modulePath &&
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
@@ -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(process.cwd(), meta.componentImportPath);
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;
@@ -27,7 +27,7 @@ function detectNextJs() {
27
27
  }
28
28
  exports.detectNextJs = detectNextJs;
29
29
  function detectGatsby() {
30
- return findup_sync_1.default("gatsby-config.js");
30
+ return findup_sync_1.default("gatsby-config.js") || findup_sync_1.default("gatsby-config.ts");
31
31
  }
32
32
  exports.detectGatsby = detectGatsby;
33
33
  function detectCreateReactApp() {
@@ -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>;
@@ -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"));
@@ -68,6 +68,34 @@ function defaultPagePath(context, fileName) {
68
68
  return fileName;
69
69
  }
70
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;
71
99
  function writeFileContent(context, srcDirFilePath, content, opts = {}) {
72
100
  return __awaiter(this, void 0, void 0, function* () {
73
101
  const path = makeFilePath(context, srcDirFilePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.182",
3
+ "version": "0.1.185",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -16,7 +16,7 @@
16
16
  "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
17
17
  "build": "bash build.sh",
18
18
  "plasmic": "ts-node src/index.ts",
19
- "prepare": "yarn build"
19
+ "prepare": "if-env PREPARE_NO_BUILD=true || yarn build"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/preset-typescript": "^7.12.1",
@@ -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
- throw new HandledError(e.messag);
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 !== compConfig.importSpec.modulePath &&
307
+ !eqPagePath(skeletonPath, compConfig.importSpec.modulePath) &&
306
308
  fileExists(context, compConfig.importSpec.modulePath)
307
309
  ) {
308
310
  if (context.cliArgs.quiet !== true) {
@@ -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(process.cwd(), meta.componentImportPath);
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;
@@ -26,7 +26,7 @@ export function detectNextJs() {
26
26
  }
27
27
 
28
28
  export function detectGatsby() {
29
- return findupSync("gatsby-config.js");
29
+ return findupSync("gatsby-config.js") || findupSync("gatsby-config.ts");
30
30
  }
31
31
 
32
32
  export function detectCreateReactApp() {
@@ -87,6 +87,37 @@ export function defaultPagePath(context: PlasmicContext, fileName: string) {
87
87
  return fileName;
88
88
  }
89
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
+
90
121
  export async function writeFileContent(
91
122
  context: PlasmicContext,
92
123
  srcDirFilePath: string,