@plasmicapp/cli 0.1.293 → 0.1.295

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.
Files changed (55) hide show
  1. package/dist/__mocks__/api.js +10 -6
  2. package/dist/__tests__/code-utils-spec.js +12 -12
  3. package/dist/__tests__/file-utils.spec.js +11 -11
  4. package/dist/__tests__/ftue-spec.js +7 -7
  5. package/dist/__tests__/project-api-token-spec.js +33 -33
  6. package/dist/__tests__/versioned-sync-spec.js +20 -20
  7. package/dist/actions/auth.d.ts +1 -1
  8. package/dist/actions/auth.js +3 -3
  9. package/dist/actions/fix-imports.js +3 -3
  10. package/dist/actions/info.js +1 -1
  11. package/dist/actions/init.js +28 -28
  12. package/dist/actions/localization-strings.js +34 -26
  13. package/dist/actions/project-token.d.ts +1 -1
  14. package/dist/actions/project-token.js +6 -4
  15. package/dist/actions/sync-components.js +29 -29
  16. package/dist/actions/sync-global-contexts.js +5 -5
  17. package/dist/actions/sync-global-variants.js +9 -9
  18. package/dist/actions/sync-icons.js +10 -10
  19. package/dist/actions/sync-images.js +20 -20
  20. package/dist/actions/sync-styles.js +4 -4
  21. package/dist/actions/sync.js +52 -48
  22. package/dist/actions/upload-bundle.js +4 -4
  23. package/dist/actions/watch.js +10 -6
  24. package/dist/api.d.ts +1 -1
  25. package/dist/api.js +1 -1
  26. package/dist/deps.js +2 -0
  27. package/dist/index.js +28 -24
  28. package/dist/lib.js +1 -0
  29. package/dist/migrations/0.1.28-tsToTsx.js +3 -3
  30. package/dist/migrations/migrations.d.ts +2 -2
  31. package/dist/migrations/migrations.js +12 -12
  32. package/dist/plasmic.schema.json +3 -2
  33. package/dist/utils/auth-utils.d.ts +2 -2
  34. package/dist/utils/auth-utils.js +8 -8
  35. package/dist/utils/checksum.js +2 -2
  36. package/dist/utils/code-utils.js +40 -32
  37. package/dist/utils/config-utils.d.ts +3 -3
  38. package/dist/utils/config-utils.js +5 -5
  39. package/dist/utils/envdetect.js +8 -8
  40. package/dist/utils/error.js +3 -2
  41. package/dist/utils/file-utils.js +3 -3
  42. package/dist/utils/get-context.js +20 -16
  43. package/dist/utils/help.js +2 -2
  44. package/dist/utils/lang-utils.d.ts +1 -1
  45. package/dist/utils/lang-utils.js +2 -1
  46. package/dist/utils/npm-utils.js +18 -16
  47. package/dist/utils/resolve-utils.js +11 -7
  48. package/dist/utils/semver.d.ts +2 -2
  49. package/dist/utils/semver.js +64 -35
  50. package/dist/utils/test-utils.js +9 -5
  51. package/package.json +5 -5
  52. package/src/actions/init.ts +2 -2
  53. package/src/actions/localization-strings.ts +34 -21
  54. package/src/index.ts +1 -1
  55. package/src/utils/config-utils.ts +3 -3
package/dist/index.js CHANGED
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -15,7 +19,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
19
  var __importStar = (this && this.__importStar) || function (mod) {
16
20
  if (mod && mod.__esModule) return mod;
17
21
  var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
23
  __setModuleDefault(result, mod);
20
24
  return result;
21
25
  };
@@ -42,7 +46,7 @@ if (process.env.DEBUG_CHDIR) {
42
46
  }
43
47
  // Check once an hour
44
48
  const pkg = require("../package.json");
45
- const notifier = update_notifier_1.default({ pkg, updateCheckInterval: 1000 * 60 * 60 });
49
+ const notifier = (0, update_notifier_1.default)({ pkg, updateCheckInterval: 1000 * 60 * 60 });
46
50
  // Workaround for this bug
47
51
  // https://github.com/yeoman/update-notifier/issues/181
48
52
  if (!!notifier.update &&
@@ -69,23 +73,23 @@ yargs_1.default
69
73
  type: "boolean",
70
74
  default: false,
71
75
  })
72
- .option("host", init_1.getYargsOption("host", "https://studio.plasmic.app"))
73
- .option("platform", init_1.getYargsOption("platform"))
74
- .option("code-lang", init_1.getYargsOption("codeLang"))
75
- .option("code-scheme", init_1.getYargsOption("codeScheme"))
76
+ .option("host", (0, init_1.getYargsOption)("host", "https://studio.plasmic.app"))
77
+ .option("platform", (0, init_1.getYargsOption)("platform"))
78
+ .option("code-lang", (0, init_1.getYargsOption)("codeLang"))
79
+ .option("code-scheme", (0, init_1.getYargsOption)("codeScheme"))
76
80
  .option("react-runtime", {
77
81
  describe: "React runtime to use; either classic or automatic",
78
82
  choices: ["classic", "automatic"],
79
83
  default: "classic",
80
84
  })
81
- .option("src-dir", init_1.getYargsOption("srcDir"))
82
- .option("plasmic-dir", init_1.getYargsOption("plasmicDir"))
83
- .option("pages-dir", init_1.getYargsOption("pagesDir"))
84
- .option("style-scheme", init_1.getYargsOption("styleScheme"))
85
- .option("images-scheme", init_1.getYargsOption("imagesScheme"))
86
- .option("images-public-dir", init_1.getYargsOption("imagesPublicDir"))
87
- .option("images-public-url-prefix", init_1.getYargsOption("imagesPublicUrlPrefix"));
88
- }, (argv) => error_1.handleError(init_1.initPlasmic(argv)))
85
+ .option("src-dir", (0, init_1.getYargsOption)("srcDir"))
86
+ .option("plasmic-dir", (0, init_1.getYargsOption)("plasmicDir"))
87
+ .option("pages-dir", (0, init_1.getYargsOption)("pagesDir"))
88
+ .option("style-scheme", (0, init_1.getYargsOption)("styleScheme"))
89
+ .option("images-scheme", (0, init_1.getYargsOption)("imagesScheme"))
90
+ .option("images-public-dir", (0, init_1.getYargsOption)("imagesPublicDir"))
91
+ .option("images-public-url-prefix", (0, init_1.getYargsOption)("imagesPublicUrlPrefix"));
92
+ }, (argv) => (0, error_1.handleError)((0, init_1.initPlasmic)(argv)))
89
93
  .command("auth", "Authenticates you to plasmic.", (yags) => {
90
94
  yags
91
95
  .option("host", {
@@ -103,30 +107,30 @@ yargs_1.default
103
107
  type: "boolean",
104
108
  });
105
109
  }, (argv) => {
106
- error_1.handleError(auth.auth(argv));
110
+ (0, error_1.handleError)(auth.auth(argv));
107
111
  })
108
112
  .command("sync", "Syncs designs from Plasmic to local files.", (yags) => configureSyncArgs(yags), (argv) => {
109
- error_1.handleError(sync_1.sync(argv, {
113
+ (0, error_1.handleError)((0, sync_1.sync)(argv, {
110
114
  source: "cli",
111
115
  scheme: "codegen",
112
116
  command: "sync",
113
117
  }));
114
118
  })
115
119
  .command("watch", "Watches for updates to projects, and syncs them automatically to local files.", (yags) => configureSyncArgs(yags, false), (argv) => {
116
- error_1.handleError(watch_1.watchProjects(argv, {
120
+ (0, error_1.handleError)((0, watch_1.watchProjects)(argv, {
117
121
  source: "cli",
118
122
  scheme: "codegen",
119
123
  command: "watch",
120
124
  }));
121
125
  })
122
- .command("fix-imports", "Fixes import paths after you've moved around Plasmic blackbox files", (yags) => 0, (argv) => error_1.handleError(fix_imports_1.fixImports(argv)))
126
+ .command("fix-imports", "Fixes import paths after you've moved around Plasmic blackbox files", (yags) => 0, (argv) => (0, error_1.handleError)((0, fix_imports_1.fixImports)(argv)))
123
127
  .command("info", "Fetches metadata for projects", (yags) => yags.option("projects", {
124
128
  alias: "p",
125
129
  describe: "ID of plasmic project to check",
126
130
  type: "array",
127
131
  default: [],
128
132
  }), (argv) => {
129
- error_1.handleError(info_1.printProjectInfo(argv));
133
+ (0, error_1.handleError)((0, info_1.printProjectInfo)(argv));
130
134
  })
131
135
  .command("upload-bundle", false, (yargs) => yargs
132
136
  .option("project", {
@@ -176,7 +180,7 @@ yargs_1.default
176
180
  describe: "the list of css paths to import in generate code whenever a component in this bundle is used",
177
181
  type: "array",
178
182
  default: [],
179
- }), (argv) => error_1.handleError(upload_bundle_1.uploadJsBundle(argv)))
183
+ }), (argv) => (0, error_1.handleError)((0, upload_bundle_1.uploadJsBundle)(argv)))
180
184
  .command("project-token <projectId>", "Get projectApiToken for a given project", (yargs) => yargs
181
185
  .positional("projectId", {
182
186
  describe: "projectId",
@@ -186,11 +190,11 @@ yargs_1.default
186
190
  describe: "Plasmic host to use",
187
191
  type: "string",
188
192
  default: "https://studio.plasmic.app",
189
- }), (argv) => error_1.handleError(projectToken.projectToken(argv)))
193
+ }), (argv) => (0, error_1.handleError)(projectToken.projectToken(argv)))
190
194
  .command("localization-strings", false, (yargs) => yargs
191
195
  .option("projects", {
192
196
  alias: "p",
193
- describe: "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
197
+ describe: "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version. If not specified, will be derived from plasmic.json if you are using codegen.",
194
198
  type: "array",
195
199
  })
196
200
  .option("host", {
@@ -232,7 +236,7 @@ yargs_1.default
232
236
  type: "array",
233
237
  default: [],
234
238
  describe: "(Optional) List of project API tokens to be used for auth, in the format PROJECT_ID:PROJECT_API_TOKEN (the pairs should be separated by comma)",
235
- }), (argv) => error_1.handleError(localization_strings_1.localizationStrings(argv)))
239
+ }), (argv) => (0, error_1.handleError)((0, localization_strings_1.localizationStrings)(argv)))
236
240
  .demandCommand()
237
241
  .strict()
238
242
  .help("h")
package/dist/lib.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setMetadataEnv = exports.handleError = exports.HandledError = exports.logger = exports.watchProjects = exports.uploadJsBundle = exports.sync = exports.getProjectApiToken = exports.initPlasmic = exports.fixImports = exports.auth = void 0;
3
4
  var auth_1 = require("./actions/auth");
4
5
  Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_1.auth; } });
5
6
  var fix_imports_1 = require("./actions/fix-imports");
@@ -18,11 +18,11 @@ function tsToTsx(config, context) {
18
18
  config.projects.forEach((project) => {
19
19
  project.components.forEach((c) => {
20
20
  if (c.renderModuleFilePath.endsWith("ts")) {
21
- const relFilePath = file_utils_1.findSrcDirPath(context.absoluteSrcDir, c.renderModuleFilePath, existingFiles);
21
+ const relFilePath = (0, file_utils_1.findSrcDirPath)(context.absoluteSrcDir, c.renderModuleFilePath, existingFiles);
22
22
  const absFilePath = upath_1.default.join(context.absoluteSrcDir, relFilePath);
23
- if (file_utils_1.existsBuffered(absFilePath)) {
23
+ if ((0, file_utils_1.existsBuffered)(absFilePath)) {
24
24
  deps_1.logger.info(`rename file from ${absFilePath} to ${absFilePath}x`);
25
- file_utils_1.renameFileBuffered(absFilePath, `${absFilePath}x`);
25
+ (0, file_utils_1.renameFileBuffered)(absFilePath, `${absFilePath}x`);
26
26
  }
27
27
  c.renderModuleFilePath = `${c.renderModuleFilePath}x`;
28
28
  }
@@ -2,8 +2,8 @@ import { PlasmicConfig, PlasmicLock } from "../utils/config-utils";
2
2
  export interface MigrateContext {
3
3
  absoluteSrcDir: string;
4
4
  }
5
- declare type MigrateConfigFunc = (prev: PlasmicConfig, context: MigrateContext) => PlasmicConfig;
6
- declare type MigrateLockFunc = (prev: PlasmicLock, context: MigrateContext) => PlasmicLock;
5
+ type MigrateConfigFunc = (prev: PlasmicConfig, context: MigrateContext) => PlasmicConfig;
6
+ type MigrateLockFunc = (prev: PlasmicLock, context: MigrateContext) => PlasmicLock;
7
7
  export declare const MIGRATIONS: Record<string, MigrateConfigFunc>;
8
8
  export declare const LOCK_MIGRATIONS: Record<string, MigrateLockFunc>;
9
9
  export declare function runNecessaryMigrations(configFile: string, lockFile: string, baseDir: string, yes?: boolean): Promise<void>;
@@ -64,23 +64,23 @@ exports.LOCK_MIGRATIONS = {
64
64
  };
65
65
  function runNecessaryMigrations(configFile, lockFile, baseDir, yes) {
66
66
  return __awaiter(this, void 0, void 0, function* () {
67
- const cliVersion = npm_utils_1.getCliVersion();
67
+ const cliVersion = (0, npm_utils_1.getCliVersion)();
68
68
  // If we don't have a lock file, we don't need to run migrations on it!
69
69
  const maybeReadLock = () => {
70
- if (file_utils_1.existsBuffered(lockFile)) {
71
- return JSON.parse(file_utils_1.readFileText(lockFile));
70
+ if ((0, file_utils_1.existsBuffered)(lockFile)) {
71
+ return JSON.parse((0, file_utils_1.readFileText)(lockFile));
72
72
  }
73
73
  return undefined;
74
74
  };
75
- const cur = config_utils_1.readConfig(configFile, false);
75
+ const cur = (0, config_utils_1.readConfig)(configFile, false);
76
76
  const curVersion = cur.cliVersion;
77
77
  if (!!curVersion && semver_1.default.lt(cliVersion, curVersion)) {
78
- const confirm = yield user_utils_1.confirmWithUser(`Project requires @plasmicapp/cli>=${curVersion} (You currently have ${cliVersion}). Would you like to upgrade it?`, yes);
78
+ const confirm = yield (0, user_utils_1.confirmWithUser)(`Project requires @plasmicapp/cli>=${curVersion} (You currently have ${cliVersion}). Would you like to upgrade it?`, yes);
79
79
  if (!confirm) {
80
80
  throw new error_1.HandledError("Upgrading is required to continue.");
81
81
  }
82
- const success = npm_utils_1.installUpgrade(cur, "@plasmicapp/cli", baseDir, {
83
- global: npm_utils_1.isCliGloballyInstalled(upath_1.default.dirname(configFile)),
82
+ const success = (0, npm_utils_1.installUpgrade)(cur, "@plasmicapp/cli", baseDir, {
83
+ global: (0, npm_utils_1.isCliGloballyInstalled)(upath_1.default.dirname(configFile)),
84
84
  dev: true,
85
85
  });
86
86
  deps_1.logger.info(chalk_1.default.bold("@plasmicapp/cli has been upgraded; please try again!"));
@@ -96,25 +96,25 @@ function runNecessaryMigrations(configFile, lockFile, baseDir, yes) {
96
96
  deps_1.logger.info(`Migrating to plasmic.json version ${version}`);
97
97
  const migrationFunc = exports.MIGRATIONS[version];
98
98
  if (migrationFunc !== undefined) {
99
- const prev = config_utils_1.readConfig(configFile, false);
99
+ const prev = (0, config_utils_1.readConfig)(configFile, false);
100
100
  const next = migrationFunc(prev, context);
101
101
  next.cliVersion = version;
102
- yield config_utils_1.writeConfig(configFile, next, baseDir);
102
+ yield (0, config_utils_1.writeConfig)(configFile, next, baseDir);
103
103
  }
104
104
  const lockMigrationFunc = exports.LOCK_MIGRATIONS[version];
105
105
  if (lockMigrationFunc !== undefined) {
106
106
  const prev = maybeReadLock();
107
107
  if (prev) {
108
108
  const next = lockMigrationFunc(prev, context);
109
- yield config_utils_1.writeLock(lockFile, next, baseDir);
109
+ yield (0, config_utils_1.writeLock)(lockFile, next, baseDir);
110
110
  }
111
111
  }
112
112
  }
113
113
  // Finally, stamp the latest version
114
- const latestConfig = config_utils_1.readConfig(configFile, false);
114
+ const latestConfig = (0, config_utils_1.readConfig)(configFile, false);
115
115
  if (latestConfig.cliVersion !== cliVersion) {
116
116
  latestConfig.cliVersion = cliVersion;
117
- yield config_utils_1.writeConfig(configFile, latestConfig, baseDir);
117
+ yield (0, config_utils_1.writeConfig)(configFile, latestConfig, baseDir);
118
118
  }
119
119
  });
120
120
  }
@@ -182,10 +182,11 @@
182
182
  "I18NConfig": {
183
183
  "properties": {
184
184
  "keyScheme": {
185
- "description": "For localization, whether the extracted strings are keyed by its content\nor by a hash of its content",
185
+ "description": "For localization, whether the extracted strings are keyed by its content,\nor by a hash of its content, or by where the string is found (\"path\")",
186
186
  "enum": [
187
187
  "content",
188
- "hash"
188
+ "hash",
189
+ "path"
189
190
  ],
190
191
  "type": "string"
191
192
  },
@@ -1,10 +1,10 @@
1
1
  import { CommonArgs } from "../index";
2
2
  import { AuthConfig } from "./config-utils";
3
- export declare type AuthData = {
3
+ export type AuthData = {
4
4
  user: string;
5
5
  token: string;
6
6
  };
7
- export declare type CancellablePromise<T> = {
7
+ export type CancellablePromise<T> = {
8
8
  promise: Promise<T>;
9
9
  cancel: () => void;
10
10
  };
@@ -26,7 +26,7 @@ const error_1 = require("../utils/error");
26
26
  const config_utils_1 = require("./config-utils");
27
27
  const file_utils_1 = require("./file-utils");
28
28
  function authByPolling(host, initToken) {
29
- const socket = socket_io_client_1.default(host, {
29
+ const socket = (0, socket_io_client_1.default)(host, {
30
30
  path: `/api/v1/init-token`,
31
31
  transportOptions: {
32
32
  polling: {
@@ -79,9 +79,9 @@ function startAuth(opts) {
79
79
  }
80
80
  const auth = yield new Promise((resolve, reject) => {
81
81
  let prompt;
82
- const initToken = uuid_1.v4();
82
+ const initToken = (0, uuid_1.v4)();
83
83
  const url = `${opts.host}/auth/plasmic-init/${initToken}`;
84
- open_1.default(url);
84
+ (0, open_1.default)(url);
85
85
  deps_1.logger.info(`\nIf your browser doesn't automatically open, enter the following URL:\n${url}\n`);
86
86
  deps_1.logger.info(`Please log in and authorize Plasmic CLI.`);
87
87
  const polling = authByPolling(opts.host, initToken);
@@ -125,11 +125,11 @@ function startAuth(opts) {
125
125
  }
126
126
  exports.startAuth = startAuth;
127
127
  function readAuth(authFile) {
128
- if (!file_utils_1.existsBuffered(authFile)) {
128
+ if (!(0, file_utils_1.existsBuffered)(authFile)) {
129
129
  throw new error_1.HandledError(`No Plasmic auth file found at ${authFile}`);
130
130
  }
131
131
  try {
132
- const parsed = JSON.parse(file_utils_1.readFileText(authFile));
132
+ const parsed = JSON.parse((0, file_utils_1.readFileText)(authFile));
133
133
  // Strip trailing slashes.
134
134
  return Object.assign(Object.assign({}, parsed), { host: parsed.host.replace(/\/+$/, "") });
135
135
  }
@@ -216,9 +216,9 @@ function getOrStartAuth(opts) {
216
216
  }
217
217
  exports.getOrStartAuth = getOrStartAuth;
218
218
  function findAuthFile(dir, opts) {
219
- let file = file_utils_1.findFile(dir, (f) => f === config_utils_1.AUTH_FILE_NAME, opts);
219
+ let file = (0, file_utils_1.findFile)(dir, (f) => f === config_utils_1.AUTH_FILE_NAME, opts);
220
220
  if (!file) {
221
- file = file_utils_1.findFile(os_1.default.homedir(), (f) => f === config_utils_1.AUTH_FILE_NAME, {
221
+ file = (0, file_utils_1.findFile)(os_1.default.homedir(), (f) => f === config_utils_1.AUTH_FILE_NAME, {
222
222
  traverseParents: false,
223
223
  });
224
224
  }
@@ -227,7 +227,7 @@ function findAuthFile(dir, opts) {
227
227
  exports.findAuthFile = findAuthFile;
228
228
  function writeAuth(authFile, config) {
229
229
  return __awaiter(this, void 0, void 0, function* () {
230
- yield file_utils_1.writeFileContentRaw(authFile, JSON.stringify(config, undefined, 2), {
230
+ yield (0, file_utils_1.writeFileContentRaw)(authFile, JSON.stringify(config, undefined, 2), {
231
231
  force: true,
232
232
  });
233
233
  fs_1.default.chmodSync(authFile, "600");
@@ -50,10 +50,10 @@ function getChecksums(context, opts, projectId, componentIds) {
50
50
  knownGlobalVariants.has(fileLock.assetId))
51
51
  .map((fileLock) => [fileLock.assetId, fileLock.checksum]);
52
52
  const projectCssChecksums = fileLocks.filter((fileLock) => fileLock.type === "projectCss");
53
- lang_utils_1.assert(projectCssChecksums.length < 2);
53
+ (0, lang_utils_1.assert)(projectCssChecksums.length < 2);
54
54
  const projectCssChecksum = projectCssChecksums.length > 0 ? projectCssChecksums[0].checksum : "";
55
55
  const globalContextsChecksums = fileLocks.filter((fileLock) => fileLock.type === "globalContexts" && fileLock.assetId === projectId);
56
- lang_utils_1.assert(globalContextsChecksums.length < 2);
56
+ (0, lang_utils_1.assert)(globalContextsChecksums.length < 2);
57
57
  const globalContextsChecksum = globalContextsChecksums.length > 0
58
58
  ? globalContextsChecksums[0].checksum
59
59
  : "";
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -14,7 +18,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
18
  var __importStar = (this && this.__importStar) || function (mod) {
15
19
  if (mod && mod.__esModule) return mod;
16
20
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
22
  __setModuleDefault(result, mod);
19
23
  return result;
20
24
  };
@@ -48,7 +52,7 @@ const error_1 = require("../utils/error");
48
52
  const config_utils_1 = require("./config-utils");
49
53
  const file_utils_1 = require("./file-utils");
50
54
  const lang_utils_1 = require("./lang-utils");
51
- exports.formatAsLocal = (content, filePath, baseDir, defaultOpts = {}) => {
55
+ const formatAsLocal = (content, filePath, baseDir, defaultOpts = {}) => {
52
56
  const opts = prettier_1.resolveConfig.sync(baseDir) || defaultOpts;
53
57
  opts.filepath = filePath;
54
58
  // Running Prettier multiple times may actually yield different results!
@@ -57,14 +61,15 @@ exports.formatAsLocal = (content, filePath, baseDir, defaultOpts = {}) => {
57
61
  const res2 = Prettier.format(res, opts);
58
62
  return res2;
59
63
  };
64
+ exports.formatAsLocal = formatAsLocal;
60
65
  const nodeToFormattedCode = (n, baseDir, unformatted, commentsToRemove) => {
61
- const c = generator_1.default(n, {
66
+ const c = (0, generator_1.default)(n, {
62
67
  retainLines: true,
63
68
  shouldPrintComment: (c) => !commentsToRemove || !commentsToRemove.has(c),
64
69
  }).code;
65
70
  return unformatted
66
71
  ? c
67
- : exports.formatAsLocal(c, "/tmp/x.tsx", baseDir, {
72
+ : (0, exports.formatAsLocal)(c, "/tmp/x.tsx", baseDir, {
68
73
  trailingComma: "none",
69
74
  arrowParens: "avoid",
70
75
  });
@@ -256,7 +261,7 @@ function replaceImports(context, code, fromPath, fixImportContext, removeImportD
256
261
  if (meta.componentImportPath[0] === ".") {
257
262
  // Relative path from the project root
258
263
  const toPath = upath_1.default.join(context.rootDir, meta.componentImportPath);
259
- lang_utils_1.assert(upath_1.default.isAbsolute(toPath));
264
+ (0, lang_utils_1.assert)(upath_1.default.isAbsolute(toPath));
260
265
  const realPath = makeImportPath(context, fromPath, toPath, true, true);
261
266
  stmt.source.value = realPath;
262
267
  }
@@ -273,7 +278,7 @@ function replaceImports(context, code, fromPath, fixImportContext, removeImportD
273
278
  if (meta.helper.importPath[0] === ".") {
274
279
  // Relative path from the project root
275
280
  const toPath = upath_1.default.join(context.rootDir, meta.helper.importPath);
276
- lang_utils_1.assert(upath_1.default.isAbsolute(toPath));
281
+ (0, lang_utils_1.assert)(upath_1.default.isAbsolute(toPath));
277
282
  const realPath = makeImportPath(context, fromPath, toPath, true, true);
278
283
  stmt.source.value = realPath;
279
284
  }
@@ -310,13 +315,13 @@ function throwMissingReference(context, itemType, uuid, fromPath) {
310
315
  function makeImportPath(context, fromPath, toPath, stripExt, forceRelative = false) {
311
316
  let result = toPath;
312
317
  if (forceRelative || isLocalModulePath(toPath)) {
313
- result = upath_1.default.relative(file_utils_1.makeFilePath(context, upath_1.default.dirname(fromPath)), file_utils_1.makeFilePath(context, toPath));
318
+ result = upath_1.default.relative((0, file_utils_1.makeFilePath)(context, upath_1.default.dirname(fromPath)), (0, file_utils_1.makeFilePath)(context, toPath));
314
319
  if (!result.startsWith(".")) {
315
320
  result = `./${result}`;
316
321
  }
317
322
  }
318
323
  if (stripExt) {
319
- result = file_utils_1.stripExtension(result);
324
+ result = (0, file_utils_1.stripExtension)(result);
320
325
  }
321
326
  return result;
322
327
  }
@@ -331,14 +336,14 @@ function isLocalModulePath(modulePath) {
331
336
  return !!upath_1.default.extname(modulePath) && !modulePath.startsWith("@");
332
337
  }
333
338
  exports.isLocalModulePath = isLocalModulePath;
334
- exports.mkFixImportContext = (config) => {
335
- const allComponents = lang_utils_1.flatMap(config.projects, (p) => p.components);
339
+ const mkFixImportContext = (config) => {
340
+ const allComponents = (0, lang_utils_1.flatMap)(config.projects, (p) => p.components);
336
341
  const components = lodash_1.default.keyBy(allComponents, (c) => c.id);
337
- const allCodeComponents = lang_utils_1.flatMap(config.projects, (p) => p.codeComponents || []);
342
+ const allCodeComponents = (0, lang_utils_1.flatMap)(config.projects, (p) => p.codeComponents || []);
338
343
  const codeComponentMetas = lodash_1.default.keyBy(allCodeComponents, (c) => c.id);
339
344
  const globalVariants = lodash_1.default.keyBy(config.globalVariants.variantGroups, (c) => c.id);
340
- const icons = lodash_1.default.keyBy(lang_utils_1.flatMap(config.projects, (p) => p.icons), (c) => c.id);
341
- const images = lodash_1.default.keyBy(lang_utils_1.flatMap(config.projects, (p) => p.images), (c) => c.id);
345
+ const icons = lodash_1.default.keyBy((0, lang_utils_1.flatMap)(config.projects, (p) => p.icons), (c) => c.id);
346
+ const images = lodash_1.default.keyBy((0, lang_utils_1.flatMap)(config.projects, (p) => p.images), (c) => c.id);
342
347
  const projects = lodash_1.default.keyBy(config.projects, (p) => p.projectId);
343
348
  return {
344
349
  config,
@@ -350,6 +355,7 @@ exports.mkFixImportContext = (config) => {
350
355
  projects,
351
356
  };
352
357
  };
358
+ exports.mkFixImportContext = mkFixImportContext;
353
359
  /**
354
360
  * Assuming that all the files referenced in PlasmicConfig are correct, fixes import statements using PlasmicConfig
355
361
  * file locations as the source of truth.
@@ -358,7 +364,7 @@ function fixAllImportStatements(context, baseDir, summary) {
358
364
  return __awaiter(this, void 0, void 0, function* () {
359
365
  deps_1.logger.info("Fixing import statements...");
360
366
  const config = context.config;
361
- const fixImportContext = exports.mkFixImportContext(config);
367
+ const fixImportContext = (0, exports.mkFixImportContext)(config);
362
368
  for (const project of config.projects) {
363
369
  for (const compConfig of project.components) {
364
370
  const compSummary = summary === null || summary === void 0 ? void 0 : summary.get(compConfig.id);
@@ -387,9 +393,9 @@ function fixComponentImportStatements(context, compConfig, fixImportContext, fix
387
393
  }
388
394
  let renderModuleChanged = false;
389
395
  if (["files", "public-files"].includes(context.config.images.scheme)) {
390
- yield sync_images_1.fixComponentCssReferences(context, fixImportContext, compConfig.cssFilePath);
396
+ yield (0, sync_images_1.fixComponentCssReferences)(context, fixImportContext, compConfig.cssFilePath);
391
397
  if (context.config.images.scheme === "public-files") {
392
- renderModuleChanged = yield sync_images_1.fixComponentImagesReferences(context, fixImportContext, compConfig.renderModuleFilePath);
398
+ renderModuleChanged = yield (0, sync_images_1.fixComponentImagesReferences)(context, fixImportContext, compConfig.renderModuleFilePath);
393
399
  }
394
400
  }
395
401
  // Fix file imports and run prettier just after fixing image references
@@ -398,15 +404,15 @@ function fixComponentImportStatements(context, compConfig, fixImportContext, fix
398
404
  }
399
405
  function fixFileImportStatements(context, srcDirFilePath, fixImportContext, removeImportDirective, baseDir, fileHasChanged = false) {
400
406
  return __awaiter(this, void 0, void 0, function* () {
401
- const filePath = file_utils_1.makeFilePath(context, srcDirFilePath);
402
- if (!file_utils_1.existsBuffered(filePath)) {
407
+ const filePath = (0, file_utils_1.makeFilePath)(context, srcDirFilePath);
408
+ if (!(0, file_utils_1.existsBuffered)(filePath)) {
403
409
  deps_1.logger.warn(`Cannot fix imports in non-existing file ${srcDirFilePath}. Check your plasmic.json file for invalid entries.`);
404
410
  return;
405
411
  }
406
- const prevContent = file_utils_1.readFileText(filePath).toString();
412
+ const prevContent = (0, file_utils_1.readFileText)(filePath).toString();
407
413
  const newContent = replaceImports(context, prevContent, srcDirFilePath, fixImportContext, removeImportDirective, baseDir, fileHasChanged);
408
414
  if (prevContent !== newContent) {
409
- yield file_utils_1.writeFileContent(context, srcDirFilePath, newContent, {
415
+ yield (0, file_utils_1.writeFileContent)(context, srcDirFilePath, newContent, {
410
416
  force: true,
411
417
  });
412
418
  }
@@ -420,15 +426,15 @@ class CompilerOptions {
420
426
  do {
421
427
  curDir = upath_1.default.join(curDir, "..");
422
428
  configPath = upath_1.default.join(curDir, "tsconfig-transform.json");
423
- } while (!file_utils_1.existsBuffered(configPath));
424
- const c = ts.readConfigFile(configPath, (path) => file_utils_1.readFileText(path));
429
+ } while (!(0, file_utils_1.existsBuffered)(configPath));
430
+ const c = ts.readConfigFile(configPath, (path) => (0, file_utils_1.readFileText)(path));
425
431
  this.opts = ts.convertCompilerOptionsFromJson(c.config.compilerOptions, ".").options;
426
432
  }
427
433
  return this.opts;
428
434
  }
429
435
  }
430
436
  CompilerOptions.opts = undefined;
431
- exports.tsxToJsx = (code) => {
437
+ const tsxToJsx = (code) => {
432
438
  // when the code has jsx pragma, typescript will remove comments, and remove
433
439
  // "import React from 'React'" if React is unused. So we first invalidate it.
434
440
  // We also need to add the usageMagic to prevent typescript from remove the
@@ -453,16 +459,17 @@ exports.tsxToJsx = (code) => {
453
459
  });
454
460
  return fixPostTranspile(result.outputText);
455
461
  };
462
+ exports.tsxToJsx = tsxToJsx;
456
463
  function maybeConvertTsxToJsx(fileName, content, baseDir) {
457
464
  if (fileName.endsWith("tsx")) {
458
- const jsFileName = file_utils_1.stripExtension(fileName) + ".jsx";
459
- const jsContent = exports.formatScript(exports.tsxToJsx(content), baseDir);
465
+ const jsFileName = (0, file_utils_1.stripExtension)(fileName) + ".jsx";
466
+ const jsContent = (0, exports.formatScript)((0, exports.tsxToJsx)(content), baseDir);
460
467
  return [jsFileName, jsContent];
461
468
  }
462
469
  return [fileName, content];
463
470
  }
464
471
  exports.maybeConvertTsxToJsx = maybeConvertTsxToJsx;
465
- exports.formatScript = (code, baseDir) => {
472
+ const formatScript = (code, baseDir) => {
466
473
  const file = parser.parse(code, {
467
474
  strictMode: true,
468
475
  sourceType: "module",
@@ -472,7 +479,7 @@ exports.formatScript = (code, baseDir) => {
472
479
  while (code.includes(newLineMarker)) {
473
480
  newLineMarker = newLineMarker + "_REALLY";
474
481
  }
475
- traverse_1.default(file, {
482
+ (0, traverse_1.default)(file, {
476
483
  Statement: function (path) {
477
484
  if (file.program.body.includes(path.node) &&
478
485
  path.node.type !== "ImportDeclaration") {
@@ -483,21 +490,22 @@ exports.formatScript = (code, baseDir) => {
483
490
  });
484
491
  const withmarkers = nodeToFormattedCode(file, baseDir, true);
485
492
  const withNewLines = withmarkers.replace(new RegExp(`"${newLineMarker}"`, "g"), "\n");
486
- return exports.formatAsLocal(withNewLines, "/tmp/x.tsx", baseDir, {
493
+ return (0, exports.formatAsLocal)(withNewLines, "/tmp/x.tsx", baseDir, {
487
494
  printWidth: 80,
488
495
  tabWidth: 2,
489
496
  useTabs: false,
490
497
  });
491
498
  };
499
+ exports.formatScript = formatScript;
492
500
  function fixGlobalContextImportStatements(context, fixImportContext, baseDir) {
493
501
  return __awaiter(this, void 0, void 0, function* () {
494
502
  for (const project of context.config.projects) {
495
503
  if (!project.globalContextsFilePath)
496
504
  continue;
497
- const resourcePath = sync_global_contexts_1.getGlobalContextsResourcePath(context, project);
505
+ const resourcePath = (0, sync_global_contexts_1.getGlobalContextsResourcePath)(context, project);
498
506
  let prevContent;
499
507
  try {
500
- prevContent = file_utils_1.readFileText(file_utils_1.makeFilePath(context, resourcePath)).toString();
508
+ prevContent = (0, file_utils_1.readFileText)((0, file_utils_1.makeFilePath)(context, resourcePath)).toString();
501
509
  }
502
510
  catch (e) {
503
511
  deps_1.logger.warn(`${resourcePath} is missing. If you deleted this component, remember to remove the component from ${config_utils_1.CONFIG_FILE_NAME}`);
@@ -505,7 +513,7 @@ function fixGlobalContextImportStatements(context, fixImportContext, baseDir) {
505
513
  }
506
514
  const newContent = replaceImports(context, prevContent, resourcePath, fixImportContext, false, baseDir, true);
507
515
  if (prevContent !== newContent) {
508
- yield file_utils_1.writeFileContent(context, resourcePath, newContent, {
516
+ yield (0, file_utils_1.writeFileContent)(context, resourcePath, newContent, {
509
517
  force: true,
510
518
  });
511
519
  }
@@ -250,10 +250,10 @@ export interface ProjectLock {
250
250
  }
251
251
  export interface I18NConfig {
252
252
  /**
253
- * For localization, whether the extracted strings are keyed by its content
254
- * or by a hash of its content
253
+ * For localization, whether the extracted strings are keyed by its content,
254
+ * or by a hash of its content, or by where the string is found ("path")
255
255
  */
256
- keyScheme: "content" | "hash";
256
+ keyScheme: "content" | "hash" | "path";
257
257
  /**
258
258
  * For localization, rich text with embedded tags are exported as
259
259
  * "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like
@@ -84,7 +84,7 @@ exports.DEFAULT_PUBLIC_FILES_CONFIG = {
84
84
  * returns undefined.
85
85
  */
86
86
  function findConfigFile(dir, opts) {
87
- return file_utils_1.findFile(dir, (f) => f === exports.CONFIG_FILE_NAME, opts);
87
+ return (0, file_utils_1.findFile)(dir, (f) => f === exports.CONFIG_FILE_NAME, opts);
88
88
  }
89
89
  exports.findConfigFile = findConfigFile;
90
90
  /**
@@ -96,12 +96,12 @@ function fillDefaults(config) {
96
96
  }
97
97
  exports.fillDefaults = fillDefaults;
98
98
  function readConfig(configFile, autoFillDefaults) {
99
- if (!file_utils_1.existsBuffered(configFile)) {
99
+ if (!(0, file_utils_1.existsBuffered)(configFile)) {
100
100
  const err = new error_1.HandledError(`No Plasmic config file found at ${configFile}`);
101
101
  throw err;
102
102
  }
103
103
  try {
104
- const result = JSON.parse(file_utils_1.readFileText(configFile));
104
+ const result = JSON.parse((0, file_utils_1.readFileText)(configFile));
105
105
  return autoFillDefaults ? fillDefaults(result) : result;
106
106
  }
107
107
  catch (e) {
@@ -112,7 +112,7 @@ function readConfig(configFile, autoFillDefaults) {
112
112
  exports.readConfig = readConfig;
113
113
  function writeConfig(configFile, config, baseDir) {
114
114
  return __awaiter(this, void 0, void 0, function* () {
115
- yield file_utils_1.writeFileContentRaw(configFile, code_utils_1.formatAsLocal(JSON.stringify(Object.assign(Object.assign({}, config), { $schema: `https://unpkg.com/@plasmicapp/cli@${config.cliVersion}/dist/plasmic.schema.json` }), undefined, 2), configFile, baseDir), {
115
+ yield (0, file_utils_1.writeFileContentRaw)(configFile, (0, code_utils_1.formatAsLocal)(JSON.stringify(Object.assign(Object.assign({}, config), { $schema: `https://unpkg.com/@plasmicapp/cli@${config.cliVersion}/dist/plasmic.schema.json` }), undefined, 2), configFile, baseDir), {
116
116
  force: true,
117
117
  });
118
118
  });
@@ -120,7 +120,7 @@ function writeConfig(configFile, config, baseDir) {
120
120
  exports.writeConfig = writeConfig;
121
121
  function writeLock(lockFile, lock, baseDir) {
122
122
  return __awaiter(this, void 0, void 0, function* () {
123
- yield file_utils_1.writeFileContentRaw(lockFile, code_utils_1.formatAsLocal(JSON.stringify(lock, undefined, 2), "/tmp/x.json", baseDir), {
123
+ yield (0, file_utils_1.writeFileContentRaw)(lockFile, (0, code_utils_1.formatAsLocal)(JSON.stringify(lock, undefined, 2), "/tmp/x.json", baseDir), {
124
124
  force: true,
125
125
  });
126
126
  });