@tinacms/scripts 1.3.2 → 1.3.4

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.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  This package provides the `tinacms-scripts` bin with the following commands:
4
4
 
5
- | Command | Description |
6
- | --------------------- | --------------------------------------------------------------------------- |
7
- | tinacms-scripts build | Builds the package for production use (i.e. uglified and without debugging) |
8
- | tinacms-scripts watch | Watches the package for updates and rebuilds. |
9
-
5
+ | Command | Description |
6
+ | ------------------------------ | --------------------------------------------------------------------------- |
7
+ | tinacms-scripts build | Builds the package for production use (i.e. uglified and without debugging) |
8
+ | tinacms-scripts watch | Watches the package for updates and rebuilds. |
9
+ | tinacms-scripts diff-tina-lock | Generate new tina-lock in current directory and check for changes |
10
10
 
11
11
  The best way to work with this library is to run it from the root of the repository so all packages are watched in a single process. Refer to the top-level `package.json` for instructions.
@@ -4,4 +4,4 @@
4
4
 
5
5
  // __mocks__/styleMock.js
6
6
 
7
- module.exports = ''
7
+ module.exports = '';
package/dist/index.js CHANGED
@@ -18,6 +18,18 @@ var __spreadValues = (a, b) => {
18
18
  }
19
19
  return a;
20
20
  };
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
21
33
  var __export = (target, all) => {
22
34
  for (var name in all)
23
35
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -56,10 +68,12 @@ var import_node_path = __toESM(require("path"));
56
68
  var import_chokidar = __toESM(require("chokidar"));
57
69
  var import_node_child_process = require("child_process");
58
70
  var import_chalk = __toESM(require("chalk"));
71
+ var import_json_diff = __toESM(require("json-diff"));
59
72
  var commander = __toESM(require("commander"));
60
73
  var deepMerge = (target, source) => {
61
74
  for (const key in source) {
62
- if (!source.hasOwnProperty(key) || key === "__proto__" || key === "constructor") continue;
75
+ if (!source.hasOwnProperty(key) || key === "__proto__" || key === "constructor")
76
+ continue;
63
77
  if (source[key] instanceof Object && !Array.isArray(source[key]) && target.hasOwnProperty(key)) {
64
78
  target[key] = deepMerge(target[key], source[key]);
65
79
  } else if (Array.isArray(source[key]) && Array.isArray(target[key])) {
@@ -158,6 +172,64 @@ var watch = () => {
158
172
  });
159
173
  });
160
174
  };
175
+ var diffTinaLock = async () => {
176
+ if (!import_fs_extra.default.existsSync(`tina/tina-lock.json`)) {
177
+ console.error(
178
+ "No Tina lock found. Please run this command from the root of a Tina project \u274C"
179
+ );
180
+ process.exit(1);
181
+ }
182
+ const tinaLock = JSON.parse(
183
+ import_fs_extra.default.readFileSync(`tina/tina-lock.json`).toString()
184
+ );
185
+ if (!tinaLock.schema) {
186
+ console.error("No schema found in the Tina lock \u274C");
187
+ process.exit(1);
188
+ }
189
+ (0, import_node_child_process.exec)(
190
+ "pnpm exec tinacms dev --no-server",
191
+ { cwd: process.cwd() },
192
+ (error, stdout, stderr) => {
193
+ if (error) {
194
+ console.error(`exec error: ${error} \u274C`);
195
+ return;
196
+ }
197
+ if (stdout) {
198
+ console.log(
199
+ stdout.split("\n").map((line) => `> ${line}`).join("\n")
200
+ );
201
+ }
202
+ if (stderr) {
203
+ console.error(`stderr: ${stderr}`);
204
+ }
205
+ const newTinaLock = JSON.parse(
206
+ import_fs_extra.default.readFileSync(`tina/tina-lock.json`).toString()
207
+ );
208
+ if (!newTinaLock.schema) {
209
+ console.error("No schema found in the new Tina lock \u274C");
210
+ process.exit(1);
211
+ }
212
+ const _a = tinaLock.schema, { version } = _a, schema = __objRest(_a, ["version"]);
213
+ const _b = newTinaLock.schema, { version: newVersion } = _b, newSchema = __objRest(_b, ["version"]);
214
+ const schemaDiff = import_json_diff.default.diffString(schema, newSchema);
215
+ if (schemaDiff) {
216
+ console.error("Unexpected change(s) to Tina schema \u274C");
217
+ console.log(schemaDiff);
218
+ process.exit(1);
219
+ }
220
+ const graphqlDiff = import_json_diff.default.diffString(
221
+ tinaLock.graphql,
222
+ newTinaLock.graphql
223
+ );
224
+ if (graphqlDiff) {
225
+ console.error("Unexpected change(s) to Tina graphql schema \u274C");
226
+ console.log(graphqlDiff);
227
+ process.exit(1);
228
+ }
229
+ console.log("No changes found in Tina lock \u2705");
230
+ }
231
+ );
232
+ };
161
233
  async function init(args) {
162
234
  registerCommands([
163
235
  {
@@ -175,6 +247,11 @@ async function init(args) {
175
247
  command: "watch",
176
248
  description: "Watch",
177
249
  action: () => watch()
250
+ },
251
+ {
252
+ command: "diff-tina-lock",
253
+ description: "Compare the current schema for a tina project with newly generated schema",
254
+ action: () => diffTinaLock()
178
255
  }
179
256
  ]);
180
257
  program.usage("command [options]");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/scripts",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -19,6 +19,7 @@
19
19
  "commander": "^7.2.0",
20
20
  "esbuild": "^0.24.2",
21
21
  "fs-extra": "^11.3.0",
22
+ "json-diff": "^1.0.6",
22
23
  "tsup": "^8.3.6",
23
24
  "typescript": "^5.7.3",
24
25
  "vite": "^4.5.9"