@diagonal-hq/cli 0.42.4 → 0.42.5

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 (2) hide show
  1. package/dist/cli.mjs +63 -2
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -7160,6 +7160,46 @@ function writeWholePageFile(path, file, options, resources, keep = [], { branchP
7160
7160
  return { ok: false, diagnostic: diagnosticFromError(path, error) };
7161
7161
  }
7162
7162
  }
7163
+ function writePagePaused(path, source, paused, resources, { branchPaths = null, permissions = [] } = {}) {
7164
+ try {
7165
+ const ast = parseSource(source, { jsx: true });
7166
+ const exportStatement = ast.program.body.find(
7167
+ (statement) => statement.type === "ExportDefaultDeclaration"
7168
+ );
7169
+ if (exportStatement === void 0) {
7170
+ throw new SourceError(
7171
+ "A page file must export default definePage(options, function Page() { ... })",
7172
+ ast.program
7173
+ );
7174
+ }
7175
+ const [optionsNode] = expectDefineCall(exportStatement.declaration, "definePage", 2);
7176
+ if (optionsNode.type !== "ObjectExpression") {
7177
+ throw new SourceError(
7178
+ "The options of definePage must be an object literal to pause the page in the app. Edit the file in Files.",
7179
+ optionsNode
7180
+ );
7181
+ }
7182
+ const written = applySourceEdits(
7183
+ source,
7184
+ objectPatchEdits(
7185
+ source,
7186
+ optionsNode,
7187
+ { paused: paused ? true : null },
7188
+ "definePage options",
7189
+ 0
7190
+ )
7191
+ );
7192
+ return checkedPage(
7193
+ path,
7194
+ written,
7195
+ branchResourceNames(resources),
7196
+ branchPaths,
7197
+ declaredPermissionEntries(permissions)
7198
+ );
7199
+ } catch (error) {
7200
+ return { ok: false, diagnostic: diagnosticFromError(path, error) };
7201
+ }
7202
+ }
7163
7203
  function writeParts(path, options, parts, { previous, readPath: readPath2, names, permissionEntries, keep, branchPaths, sourceOptions, addsCodeImports }) {
7164
7204
  options = migrateOptionValues(options);
7165
7205
  if (options.layout !== void 0 && !keep.includes("layout")) {
@@ -7601,6 +7641,24 @@ function writeFile({ path, data, context }) {
7601
7641
  })
7602
7642
  ).source;
7603
7643
  }
7644
+ function writePaused({ path, source, data, context }) {
7645
+ if (typeof data.paused !== "boolean") {
7646
+ throw new SourceTransformRequestError("paused must be a boolean.");
7647
+ }
7648
+ if (data.options !== void 0 || data.code !== void 0 || data.file !== void 0) {
7649
+ throw new SourceTransformRequestError("A pause write sends only paused.");
7650
+ }
7651
+ if (typeof source !== "string") {
7652
+ throw new SourceTransformRequestError("A pause write edits an existing page file.");
7653
+ }
7654
+ const { resources, branchPaths, permissions } = contextOf(context);
7655
+ return checked(
7656
+ writePagePaused(path, source, data.paused, resources, {
7657
+ branchPaths,
7658
+ permissions
7659
+ })
7660
+ ).source;
7661
+ }
7604
7662
  function checked(result) {
7605
7663
  if (!result.ok) {
7606
7664
  throw new SourceTransformDiagnostic(result.diagnostic);
@@ -7611,8 +7669,8 @@ var pageAdapter = Object.freeze({
7611
7669
  contextFields: ["resources", "resource_slugs", "branch_paths", "permissions", "keep", "previous_path"],
7612
7670
  // `code` is the factory body of the page function, with `options`. `file` is
7613
7671
  // the whole file, as the page builder edits it: it is written as it is, or
7614
- // with `options` in place of its own.
7615
- writeFields: ["options", "code", "file"],
7672
+ // with `options` in place of its own. `paused` alone writes only that option.
7673
+ writeFields: ["options", "code", "file", "paused"],
7616
7674
  accepts: (path) => /^pages\/.+\.tsx$/.test(path),
7617
7675
  read({ path, source, context }) {
7618
7676
  const { resources, branchPaths, permissions } = contextOf(context);
@@ -7620,6 +7678,9 @@ var pageAdapter = Object.freeze({
7620
7678
  return { options, code, imports };
7621
7679
  },
7622
7680
  write({ path, source, data, context }) {
7681
+ if (data.paused !== void 0) {
7682
+ return writePaused({ path, source, data, context });
7683
+ }
7623
7684
  if (data.file !== void 0) {
7624
7685
  return writeFile({ path, data, context });
7625
7686
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.42.4",
3
+ "version": "0.42.5",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {