@tinacms/cli 1.2.1 → 1.3.0

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.
@@ -1,9 +1,9 @@
1
1
  /**
2
2
 
3
3
  */
4
- import type { Database, TinaCloudCollection } from '@tinacms/graphql';
4
+ import type { Database, Collection } from '@tinacms/graphql';
5
5
  declare type AuditArgs = {
6
- collection: TinaCloudCollection;
6
+ collection: Collection<true>;
7
7
  database: Database;
8
8
  rootPath: string;
9
9
  documents: {
@@ -2,7 +2,7 @@
2
2
 
3
3
  */
4
4
  import { Platform } from 'esbuild';
5
- import type { TinaCloudSchema } from '@tinacms/graphql';
5
+ import type { Schema } from '@tinacms/graphql';
6
6
  export declare const resetGeneratedFolder: ({ tinaGeneratedPath, usingTs, isBuild, }: {
7
7
  tinaGeneratedPath: string;
8
8
  usingTs: boolean;
@@ -21,4 +21,4 @@ export declare const compileSchema: (options: {
21
21
  rootPath: string;
22
22
  }) => Promise<any>;
23
23
  export declare const transpile: (inputFile: any, outputFile: any, tempDir: any, verbose: any, define: any, packageJSONFilePath: string, platform?: Platform) => Promise<void>;
24
- export declare const defineSchema: (config: TinaCloudSchema) => TinaCloudSchema;
24
+ export declare const defineSchema: (config: Schema) => Schema<false>;
@@ -1,14 +1,14 @@
1
1
  /**
2
2
 
3
3
  */
4
- import type { TinaCloudCollection, TinaFieldInner } from '@tinacms/schema-tools';
4
+ import type { Collection, TinaField } from '@tinacms/schema-tools';
5
5
  export declare const generateAllCollections: ({ rootPath, }: {
6
6
  rootPath: string;
7
7
  }) => Promise<Map<string, {
8
- fields: TinaFieldInner<false>[];
8
+ fields: TinaField[];
9
9
  templateObj: any;
10
10
  }>>;
11
11
  export declare const generateCollections: ({ forestryPath, rootPath, }: {
12
12
  forestryPath: string;
13
13
  rootPath: string;
14
- }) => Promise<TinaCloudCollection<false>[]>;
14
+ }) => Promise<Collection<false>[]>;
@@ -2,8 +2,15 @@
2
2
 
3
3
  */
4
4
  import z from 'zod';
5
- import type { TinaFieldInner } from '@tinacms/schema-tools';
6
- export declare const stringifyName: (name: string, template: string) => string;
5
+ import type { TinaField } from '@tinacms/schema-tools';
6
+ export declare const getTinaFieldsFromName: (name: string) => {
7
+ name: string;
8
+ nameOverride: string;
9
+ } | {
10
+ name: string;
11
+ nameOverride?: undefined;
12
+ };
13
+ export declare const stringifyTemplateName: (name: string, template: string) => string;
7
14
  declare const forestryFieldWithoutField: z.ZodObject<{
8
15
  type: z.ZodUnion<[z.ZodLiteral<"text">, z.ZodLiteral<"datetime">, z.ZodLiteral<"list">, z.ZodLiteral<"file">, z.ZodLiteral<"image_gallery">, z.ZodLiteral<"textarea">, z.ZodLiteral<"tag_list">, z.ZodLiteral<"number">, z.ZodLiteral<"boolean">, z.ZodLiteral<"field_group">, z.ZodLiteral<"field_group_list">, z.ZodLiteral<"select">, z.ZodLiteral<"include">, z.ZodLiteral<"blocks">, z.ZodLiteral<"color">]>;
9
16
  template_types: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
@@ -114,13 +121,13 @@ export declare const transformForestryFieldsToTinaFields: ({ fields, rootPath, t
114
121
  rootPath: string;
115
122
  template: string;
116
123
  skipBlocks?: boolean;
117
- }) => TinaFieldInner<false>[];
124
+ }) => TinaField<false>[];
118
125
  export declare const getFieldsFromTemplates: (_args: {
119
126
  tem: string;
120
127
  rootPath: string;
121
128
  skipBlocks?: boolean;
122
129
  }) => {
123
- fields: TinaFieldInner<false>[];
130
+ fields: TinaField[];
124
131
  templateObj: any;
125
132
  template: {
126
133
  label?: string;
@@ -2,10 +2,10 @@
2
2
 
3
3
  */
4
4
  import { GraphQLSchema } from 'graphql';
5
- import { TinaCloudSchema } from '@tinacms/schema-tools';
5
+ import { Schema } from '@tinacms/schema-tools';
6
6
  export declare const TINA_HOST = "content.tinajs.io";
7
7
  export declare function genClient({ tinaSchema, usingTs, rootPath, }: {
8
- tinaSchema: TinaCloudSchema<false>;
8
+ tinaSchema: Schema;
9
9
  usingTs?: boolean;
10
10
  rootPath: string;
11
11
  }, options: any): Promise<string>;
@@ -4,7 +4,7 @@
4
4
  import type { Bridge } from '@tinacms/datalayer';
5
5
  import type { Database } from '@tinacms/graphql';
6
6
  import { ConfigBuilder } from '../../buildTina';
7
- import type { TinaCloudSchema } from '@tinacms/schema-tools';
7
+ import type { Schema } from '@tinacms/schema-tools';
8
8
  interface Options {
9
9
  port?: number;
10
10
  command?: string;
@@ -22,6 +22,6 @@ export declare function startServer(ctx: {
22
22
  database: Database;
23
23
  bridge: Bridge;
24
24
  usingTs: boolean;
25
- schema?: TinaCloudSchema<false>;
25
+ schema?: Schema;
26
26
  }, next: any, { port, noWatch, noSDK, noTelemetry, watchFolders, verbose, dev, }: Options): Promise<void>;
27
27
  export {};
@@ -1,9 +1,6 @@
1
- /**
2
-
3
- */
4
1
  import type { Bridge } from '@tinacms/datalayer';
5
2
  import type { Database } from '@tinacms/graphql';
6
- import type { TinaCloudSchema } from '@tinacms/schema-tools';
3
+ import type { Schema } from '@tinacms/schema-tools';
7
4
  import { ConfigBuilder } from '../../buildTina';
8
5
  export declare const checkClientInfo: (ctx: {
9
6
  builder: ConfigBuilder;
@@ -11,9 +8,25 @@ export declare const checkClientInfo: (ctx: {
11
8
  database: Database;
12
9
  bridge: Bridge;
13
10
  usingTs: boolean;
14
- schema?: TinaCloudSchema<false>;
11
+ schema?: Schema;
15
12
  apiUrl: string;
16
13
  isSelfHostedDatabase: boolean;
17
14
  }, next: any, _options: {
18
15
  verbose?: boolean;
19
16
  }) => Promise<any>;
17
+ export declare const fetchRemoteGraphqlSchema: ({ url, token, }: {
18
+ url: string;
19
+ token?: string;
20
+ }) => Promise<any>;
21
+ export declare const checkGraphqlSchema: (ctx: {
22
+ builder: ConfigBuilder;
23
+ rootPath: string;
24
+ database: Database;
25
+ bridge: Bridge;
26
+ usingTs: boolean;
27
+ schema?: Schema;
28
+ apiUrl: string;
29
+ isSelfHostedDatabase: boolean;
30
+ }, next: any, _options: {
31
+ verbose?: boolean;
32
+ }) => Promise<void>;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
 
3
3
  */
4
- import { TinaCloudSchema } from '@tinacms/schema-tools';
4
+ import { Schema } from '@tinacms/schema-tools';
5
5
  export declare const waitForDB: (ctx: {
6
- schema?: TinaCloudSchema<true>;
6
+ schema?: Schema<true>;
7
7
  apiUrl: string;
8
8
  isSelfHostedDatabase?: boolean;
9
9
  }, next: any, options: {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /**
2
-
3
- */
4
1
  export { defineSchema } from './cmds/compile';
5
- export type { TinaCloudSchema, TinaSchema, TinaCloudCollection, TinaCollection, TinaField, TinaTemplate, } from '@tinacms/graphql';
2
+ export type { Schema, TinaSchema, Collection, TinaTemplate, } from '@tinacms/graphql';
6
3
  export declare function init(args: any): Promise<void>;
package/dist/index.js CHANGED
@@ -304,7 +304,7 @@ var commander = __toModule(require("commander"));
304
304
 
305
305
  // package.json
306
306
  var name = "@tinacms/cli";
307
- var version = "1.2.1";
307
+ var version = "1.3.0";
308
308
 
309
309
  // src/cmds/audit/audit.ts
310
310
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -2065,13 +2065,27 @@ var ErrorSingleton = class {
2065
2065
 
2066
2066
  // src/cmds/forestry-migrate/util/index.ts
2067
2067
  var errorSingletonInstance = ErrorSingleton.getInstance();
2068
- var stringifyName = (name2, template) => {
2069
- const testRegex = /^[a-zA-Z0-9_]*$/;
2070
- const updateRegex = /[^a-zA-Z0-9]/g;
2071
- if (testRegex.test(name2)) {
2068
+ var NAME_TEST_REGEX = /^[a-zA-Z0-9_]*$/;
2069
+ var NAME_UPDATE_REGEX = /[^a-zA-Z0-9]/g;
2070
+ var getTinaFieldsFromName = (name2) => {
2071
+ if (name2 == "id") {
2072
+ return { name: "custom_id", nameOverride: "id" };
2073
+ } else {
2074
+ if (NAME_TEST_REGEX.test(name2)) {
2075
+ return { name: name2 };
2076
+ } else {
2077
+ return {
2078
+ name: name2.replace(NAME_UPDATE_REGEX, "_"),
2079
+ nameOverride: name2
2080
+ };
2081
+ }
2082
+ }
2083
+ };
2084
+ var stringifyTemplateName = (name2, template) => {
2085
+ if (NAME_TEST_REGEX.test(name2)) {
2072
2086
  return name2;
2073
2087
  } else {
2074
- const newName = name2.replace(updateRegex, "_");
2088
+ const newName = name2.replace(NAME_UPDATE_REGEX, "_");
2075
2089
  errorSingletonInstance.addErrorName({ name: name2, newName, template });
2076
2090
  return newName;
2077
2091
  }
@@ -2161,98 +2175,98 @@ var transformForestryFieldsToTinaFields = ({
2161
2175
  let field;
2162
2176
  switch (forestryField2.type) {
2163
2177
  case "text":
2164
- field = {
2165
- type: "string",
2166
- name: stringifyName(forestryField2.name, template),
2178
+ field = __spreadProps(__spreadValues({
2179
+ type: "string"
2180
+ }, getTinaFieldsFromName(forestryField2.name)), {
2167
2181
  label: forestryField2.label
2168
- };
2182
+ });
2169
2183
  break;
2170
2184
  case "textarea":
2171
- field = {
2172
- type: "string",
2173
- name: stringifyName(forestryField2.name, template),
2185
+ field = __spreadProps(__spreadValues({
2186
+ type: "string"
2187
+ }, getTinaFieldsFromName(forestryField2.name)), {
2174
2188
  label: forestryField2.label,
2175
2189
  ui: {
2176
2190
  component: "textarea"
2177
2191
  }
2178
- };
2192
+ });
2179
2193
  break;
2180
2194
  case "datetime":
2181
- field = {
2182
- type: forestryField2.type,
2183
- name: stringifyName(forestryField2.name, template),
2195
+ field = __spreadProps(__spreadValues({
2196
+ type: forestryField2.type
2197
+ }, getTinaFieldsFromName(forestryField2.name)), {
2184
2198
  label: forestryField2.label
2185
- };
2199
+ });
2186
2200
  break;
2187
2201
  case "number":
2188
- field = {
2189
- type: "number",
2190
- name: stringifyName(forestryField2.name, template),
2202
+ field = __spreadProps(__spreadValues({
2203
+ type: "number"
2204
+ }, getTinaFieldsFromName(forestryField2.name)), {
2191
2205
  label: forestryField2.label
2192
- };
2206
+ });
2193
2207
  break;
2194
2208
  case "boolean":
2195
- field = {
2196
- type: "boolean",
2197
- name: stringifyName(forestryField2.name, template),
2209
+ field = __spreadProps(__spreadValues({
2210
+ type: "boolean"
2211
+ }, getTinaFieldsFromName(forestryField2.name)), {
2198
2212
  label: forestryField2.label
2199
- };
2213
+ });
2200
2214
  break;
2201
2215
  case "color":
2202
- field = {
2203
- type: "string",
2204
- name: stringifyName(forestryField2.name, template),
2216
+ field = __spreadProps(__spreadValues({
2217
+ type: "string"
2218
+ }, getTinaFieldsFromName(forestryField2.name)), {
2205
2219
  label: forestryField2.label,
2206
2220
  ui: {
2207
2221
  component: "color"
2208
2222
  }
2209
- };
2223
+ });
2210
2224
  break;
2211
2225
  case "file":
2212
- field = {
2213
- type: "image",
2214
- name: stringifyName(forestryField2.name || "image", template),
2226
+ field = __spreadProps(__spreadValues({
2227
+ type: "image"
2228
+ }, getTinaFieldsFromName(forestryField2.name)), {
2215
2229
  label: forestryField2.label
2216
- };
2230
+ });
2217
2231
  break;
2218
2232
  case "select":
2219
2233
  if ((_a = forestryField2.config) == null ? void 0 : _a.options) {
2220
- field = {
2221
- type: "string",
2222
- name: stringifyName(forestryField2.name, template),
2234
+ field = __spreadProps(__spreadValues({
2235
+ type: "string"
2236
+ }, getTinaFieldsFromName(forestryField2.name)), {
2223
2237
  label: forestryField2.label,
2224
2238
  options: ((_b = forestryField2.config) == null ? void 0 : _b.options) || []
2225
- };
2239
+ });
2226
2240
  } else {
2227
2241
  logger.info(warnText(`Warning in template ${template}.yaml . "select" field migration has only been implemented for simple select. Other versions of select have not been implemented yet. To make your \`${forestryField2.name}\` field work, you will need to manually add it to your schema.`));
2228
2242
  }
2229
2243
  break;
2230
2244
  case "list":
2231
- field = {
2232
- type: "string",
2233
- name: stringifyName(forestryField2.name, template),
2245
+ field = __spreadProps(__spreadValues({
2246
+ type: "string"
2247
+ }, getTinaFieldsFromName(forestryField2.name)), {
2234
2248
  label: forestryField2.label,
2235
2249
  list: true
2236
- };
2250
+ });
2237
2251
  if ((_c = forestryField2.config) == null ? void 0 : _c.options) {
2238
2252
  field.options = forestryField2.config.options;
2239
2253
  }
2240
2254
  break;
2241
2255
  case "tag_list":
2242
- field = {
2243
- type: "string",
2244
- name: stringifyName(forestryField2.name, template),
2256
+ field = __spreadProps(__spreadValues({
2257
+ type: "string"
2258
+ }, getTinaFieldsFromName(forestryField2.name)), {
2245
2259
  label: forestryField2.label,
2246
2260
  list: true,
2247
2261
  ui: {
2248
2262
  component: "tags"
2249
2263
  }
2250
- };
2264
+ });
2251
2265
  break;
2252
2266
  case "field_group":
2253
- field = {
2254
- type: "object",
2255
- name: stringifyName(forestryField2.name, template),
2267
+ field = __spreadProps(__spreadValues({
2268
+ type: "object"
2269
+ }, getTinaFieldsFromName(forestryField2.name)), {
2256
2270
  label: forestryField2.label,
2257
2271
  fields: transformForestryFieldsToTinaFields({
2258
2272
  fields: forestryField2.fields,
@@ -2260,12 +2274,12 @@ var transformForestryFieldsToTinaFields = ({
2260
2274
  template,
2261
2275
  skipBlocks
2262
2276
  })
2263
- };
2277
+ });
2264
2278
  break;
2265
2279
  case "field_group_list":
2266
- field = {
2267
- type: "object",
2268
- name: stringifyName(forestryField2.name, template),
2280
+ field = __spreadProps(__spreadValues({
2281
+ type: "object"
2282
+ }, getTinaFieldsFromName(forestryField2.name)), {
2269
2283
  label: forestryField2.label,
2270
2284
  list: true,
2271
2285
  fields: transformForestryFieldsToTinaFields({
@@ -2274,7 +2288,7 @@ var transformForestryFieldsToTinaFields = ({
2274
2288
  rootPath: rootPath2,
2275
2289
  skipBlocks
2276
2290
  })
2277
- };
2291
+ });
2278
2292
  break;
2279
2293
  case "blocks":
2280
2294
  if (skipBlocks)
@@ -2289,17 +2303,17 @@ var transformForestryFieldsToTinaFields = ({
2289
2303
  const t = {
2290
2304
  fields: fields2,
2291
2305
  label: template2.label,
2292
- name: stringifyName(tem, tem)
2306
+ name: stringifyTemplateName(tem, tem)
2293
2307
  };
2294
2308
  templates.push(t);
2295
2309
  });
2296
- field = {
2310
+ field = __spreadProps(__spreadValues({
2297
2311
  type: "object",
2298
2312
  list: true,
2299
- label: forestryField2.label,
2300
- name: stringifyName(forestryField2.name, template),
2313
+ label: forestryField2.label
2314
+ }, getTinaFieldsFromName(forestryField2.name)), {
2301
2315
  templates
2302
- };
2316
+ });
2303
2317
  break;
2304
2318
  case "image_gallery":
2305
2319
  case "include":
@@ -2992,6 +3006,8 @@ var attachDatabase = async (ctx, next, _options) => {
2992
3006
 
2993
3007
  // src/cmds/statusChecks/checkClientInformation.ts
2994
3008
  var import_progress2 = __toModule(require("progress"));
3009
+ var import_graphql12 = __toModule(require("graphql"));
3010
+ var import_core2 = __toModule(require("@graphql-inspector/core"));
2995
3011
  var import_schema_tools2 = __toModule(require("@tinacms/schema-tools"));
2996
3012
  async function request(args) {
2997
3013
  const headers = new Headers();
@@ -3064,6 +3080,56 @@ var checkClientInfo = async (ctx, next, _options) => {
3064
3080
  }
3065
3081
  next();
3066
3082
  };
3083
+ var fetchRemoteGraphqlSchema = async ({
3084
+ url,
3085
+ token
3086
+ }) => {
3087
+ const headers = new Headers();
3088
+ if (token) {
3089
+ headers.append("X-API-KEY", token);
3090
+ }
3091
+ const body = JSON.stringify({ query: (0, import_graphql12.getIntrospectionQuery)(), variables: {} });
3092
+ headers.append("Content-Type", "application/json");
3093
+ const res = await fetch(url, {
3094
+ method: "POST",
3095
+ headers,
3096
+ body
3097
+ });
3098
+ const data = await res.json();
3099
+ return data == null ? void 0 : data.data;
3100
+ };
3101
+ var checkGraphqlSchema = async (ctx, next, _options) => {
3102
+ var _a;
3103
+ const bar = new import_progress2.default("Checking local GraphQL Schema matches server. :prog", 1);
3104
+ const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
3105
+ const token = config2.token;
3106
+ const url = ctx.apiUrl;
3107
+ const remoteSchema = await fetchRemoteGraphqlSchema({
3108
+ url,
3109
+ token
3110
+ });
3111
+ const remoteGqlSchema = (0, import_graphql12.buildClientSchema)(remoteSchema);
3112
+ const localSchemaDocument = await ctx.database.getGraphQLSchemaFromBridge();
3113
+ const localGraphqlSchema = (0, import_graphql12.buildSchema)((0, import_graphql12.print)(localSchemaDocument));
3114
+ const diffResult = await (0, import_core2.diff)(localGraphqlSchema, remoteGqlSchema);
3115
+ if (diffResult.length === 0) {
3116
+ bar.tick({
3117
+ prog: "\u2705"
3118
+ });
3119
+ } else {
3120
+ bar.tick({
3121
+ prog: "\u274C"
3122
+ });
3123
+ let errorMessage = `The local GraphQL schema doesn't match the remote GraphQL schema. Please push up your changes to Github to update your remote GraphQL schema.`;
3124
+ if (config2 == null ? void 0 : config2.branch) {
3125
+ errorMessage += `
3126
+
3127
+ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
3128
+ }
3129
+ throw new Error(errorMessage);
3130
+ }
3131
+ next();
3132
+ };
3067
3133
 
3068
3134
  // src/cmds/baseCmds.ts
3069
3135
  var CMD_START_SERVER = "server:start";
@@ -3212,6 +3278,7 @@ var baseCmds = [
3212
3278
  buildSetupCmdBuild,
3213
3279
  buildCmdBuild,
3214
3280
  checkClientInfo,
3281
+ checkGraphqlSchema,
3215
3282
  waitForDB,
3216
3283
  indexIntoSelfHostedDatabase
3217
3284
  ], options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -21,7 +21,7 @@
21
21
  ]
22
22
  },
23
23
  "devDependencies": {
24
- "@tinacms/scripts": "1.0.2",
24
+ "@tinacms/scripts": "1.0.3",
25
25
  "@types/clear": "0.1.0",
26
26
  "@types/cli-spinner": "^0.2.1",
27
27
  "@types/cors": "2.8.5",
@@ -50,13 +50,14 @@
50
50
  "@graphql-codegen/typescript-generic-sdk": "^2.1.4",
51
51
  "@graphql-codegen/typescript-operations": "^2.1.4",
52
52
  "@graphql-codegen/visitor-plugin-common": "^2.4.0",
53
+ "@graphql-inspector/core": "^4.0.0",
53
54
  "@graphql-tools/graphql-file-loader": "^7.2.0",
54
55
  "@graphql-tools/load": "^7.3.2",
55
- "@tinacms/app": "1.1.0",
56
- "@tinacms/datalayer": "1.1.2",
57
- "@tinacms/graphql": "1.3.1",
56
+ "@tinacms/app": "1.1.2",
57
+ "@tinacms/datalayer": "1.1.4",
58
+ "@tinacms/graphql": "1.3.3",
58
59
  "@tinacms/metrics": "1.0.2",
59
- "@tinacms/schema-tools": "1.3.1",
60
+ "@tinacms/schema-tools": "1.3.3",
60
61
  "ajv": "^6.12.3",
61
62
  "altair-express-middleware": "4.0.6",
62
63
  "auto-bind": "^4.0.0",
@@ -78,8 +79,8 @@
78
79
  "lodash": "^4.17.19",
79
80
  "lodash.get": "^4.4.2",
80
81
  "log4js": "^6.4.0",
81
- "memory-level": "^1.0.0",
82
82
  "many-level": "^2.0.0",
83
+ "memory-level": "^1.0.0",
83
84
  "minimatch": "^5.1.2",
84
85
  "multer": "1.4.5-lts.1",
85
86
  "normalize-path": "^3.0.0",