@tinacms/cli 0.61.1 → 0.61.2

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.
@@ -20,6 +20,11 @@ export declare const compileClient: (ctx: any, next: any, options: {
20
20
  verbose?: boolean;
21
21
  dev?: boolean;
22
22
  }) => Promise<any>;
23
+ export declare const compileFile: (ctx: any, _next: any, options: {
24
+ schemaFileType?: string;
25
+ verbose?: boolean;
26
+ dev?: boolean;
27
+ }, fileName: string) => Promise<{}>;
23
28
  export declare const compileSchema: (ctx: any, _next: any, options: {
24
29
  schemaFileType?: string;
25
30
  verbose?: boolean;
package/dist/index.js CHANGED
@@ -293,7 +293,7 @@ var commander = __toModule(require("commander"));
293
293
 
294
294
  // package.json
295
295
  var name = "@tinacms/cli";
296
- var version = "0.61.1";
296
+ var version = "0.61.2";
297
297
 
298
298
  // src/cmds/audit/audit.ts
299
299
  var import_graphql = __toModule(require("@tinacms/graphql"));
@@ -1152,6 +1152,9 @@ var chain = async (cmds, options) => {
1152
1152
  // src/cmds/baseCmds.ts
1153
1153
  var import_chalk7 = __toModule(require("chalk"));
1154
1154
 
1155
+ // src/cmds/compile/index.ts
1156
+ var _ = __toModule(require("lodash"));
1157
+
1155
1158
  // src/cmds/start-server/errors/index.ts
1156
1159
  var import_graphql3 = __toModule(require("@tinacms/graphql"));
1157
1160
  var BuildSchemaError = class extends Error {
@@ -1313,12 +1316,6 @@ var getPath = ({
1313
1316
  }
1314
1317
  return inputFile;
1315
1318
  };
1316
- var getSchemaPath = ({ projectDir }) => {
1317
- const filename = "schema";
1318
- const allowedTypes = ["js", "jsx", "ts", "tsx"];
1319
- const errorMessage = "Must provide a `.tina/schema.{ts,js,tsx,jsx}`";
1320
- return getPath({ projectDir, filename, allowedTypes, errorMessage });
1321
- };
1322
1319
  var getClientPath = ({ projectDir }) => {
1323
1320
  const filename = "client";
1324
1321
  const allowedTypes = ["js", "ts"];
@@ -1342,7 +1339,8 @@ var resetGeneratedFolder = async ({
1342
1339
  export const queries = (client)=>({})
1343
1340
  `);
1344
1341
  await import_fs_extra3.default.writeFile(import_path4.default.join(tinaGeneratedPath, `client.${ext}`), `
1345
- export const client = {}
1342
+ export const client = ()=>{}
1343
+ export default client
1346
1344
  `);
1347
1345
  await import_fs_extra3.default.outputFile(import_path4.default.join(tinaGeneratedPath, ".gitignore"), `db
1348
1346
  client.ts
@@ -1427,7 +1425,7 @@ var compileClient = async (ctx, next, options) => {
1427
1425
  }
1428
1426
  return next();
1429
1427
  };
1430
- var compileSchema = async (ctx, _next, options) => {
1428
+ var compileFile = async (ctx, _next, options, fileName) => {
1431
1429
  const root2 = ctx.rootPath;
1432
1430
  if (!root2) {
1433
1431
  throw new Error("ctx.rootPath has not been attached");
@@ -1435,15 +1433,14 @@ var compileSchema = async (ctx, _next, options) => {
1435
1433
  const tinaPath = import_path4.default.join(root2, ".tina");
1436
1434
  const tsConfigPath = import_path4.default.join(root2, "tsconfig.json");
1437
1435
  const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
1438
- const tinaTempPath = import_path4.default.join(tinaGeneratedPath, "temp_schema");
1439
- const tinaConfigPath = import_path4.default.join(tinaGeneratedPath, "config");
1436
+ const tinaTempPath = import_path4.default.join(tinaGeneratedPath, `temp_${fileName}`);
1440
1437
  const packageJSONFilePath = import_path4.default.join(root2, "package.json");
1441
1438
  if (!options.schemaFileType) {
1442
1439
  const usingTs = await import_fs_extra3.default.pathExists(tsConfigPath);
1443
1440
  options = __spreadProps(__spreadValues({}, options), { schemaFileType: usingTs ? "ts" : "js" });
1444
1441
  }
1445
1442
  if (options.verbose) {
1446
- logger.info(logText("Compiling Schema..."));
1443
+ logger.info(logText(`Compiling ${fileName}...`));
1447
1444
  }
1448
1445
  const { schemaFileType: requestedSchemaFileType = "ts" } = options;
1449
1446
  const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
@@ -1455,11 +1452,16 @@ var compileSchema = async (ctx, _next, options) => {
1455
1452
  }
1456
1453
  let schemaExists = true;
1457
1454
  try {
1458
- getSchemaPath({ projectDir: tinaPath });
1455
+ getPath({
1456
+ projectDir: tinaPath,
1457
+ filename: fileName,
1458
+ allowedTypes: ["js", "jsx", "tsx", "ts"],
1459
+ errorMessage: `Must provide a ${fileName}.{js,jsx,tsx,ts}`
1460
+ });
1459
1461
  } catch {
1460
1462
  schemaExists = false;
1461
1463
  }
1462
- if (!schemaExists) {
1464
+ if (!schemaExists && fileName === "schema") {
1463
1465
  logger.info(dangerText(`
1464
1466
  .tina/schema.${schemaFileType2} not found, Creating one for you...
1465
1467
  See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
@@ -1473,8 +1475,13 @@ var compileSchema = async (ctx, _next, options) => {
1473
1475
  if (!process.env.NODE_ENV) {
1474
1476
  define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
1475
1477
  }
1476
- const inputFile = getSchemaPath({ projectDir: tinaPath });
1477
- await transpile(inputFile, "schema.js", tinaTempPath, options.verbose, define, packageJSONFilePath);
1478
+ const inputFile = getPath({
1479
+ projectDir: tinaPath,
1480
+ filename: fileName,
1481
+ allowedTypes: ["js", "jsx", "tsx", "ts"],
1482
+ errorMessage: `Must provide a ${fileName}.{js,jsx,tsx,ts}`
1483
+ });
1484
+ await transpile(inputFile, `${fileName}.js`, tinaTempPath, options.verbose, define, packageJSONFilePath);
1478
1485
  } catch (e) {
1479
1486
  await cleanup({ tinaTempPath });
1480
1487
  throw new BuildSchemaError(e);
@@ -1484,11 +1491,10 @@ var compileSchema = async (ctx, _next, options) => {
1484
1491
  delete require.cache[require.resolve(key)];
1485
1492
  }
1486
1493
  });
1494
+ let returnObject = {};
1487
1495
  try {
1488
- const schemaFunc = require(import_path4.default.join(tinaTempPath, "schema.js"));
1489
- const schemaObject = schemaFunc.default;
1490
- ctx.schema = schemaObject;
1491
- await import_fs_extra3.default.outputFile(import_path4.default.join(tinaConfigPath, "schema.json"), JSON.stringify(schemaObject, null, 2));
1496
+ const schemaFunc = require(import_path4.default.join(tinaTempPath, `${fileName}.js`));
1497
+ returnObject = schemaFunc.default;
1492
1498
  await cleanup({ tinaTempPath });
1493
1499
  } catch (e) {
1494
1500
  await cleanup({ tinaTempPath });
@@ -1499,6 +1505,25 @@ var compileSchema = async (ctx, _next, options) => {
1499
1505
  }
1500
1506
  throw new ExecuteSchemaError(e);
1501
1507
  }
1508
+ return returnObject;
1509
+ };
1510
+ var compileSchema = async (ctx, _next, options) => {
1511
+ const root2 = ctx.rootPath;
1512
+ const tinaPath = import_path4.default.join(root2, ".tina");
1513
+ const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
1514
+ const tinaConfigPath = import_path4.default.join(tinaGeneratedPath, "config");
1515
+ let schema = await compileFile(ctx, _next, options, "schema");
1516
+ try {
1517
+ const config = await compileFile(ctx, _next, options, "config");
1518
+ const configCopy = _.cloneDeep(config);
1519
+ delete configCopy.schema;
1520
+ if (config == null ? void 0 : config.schema) {
1521
+ schema = __spreadProps(__spreadValues({}, config.schema), { config: configCopy });
1522
+ }
1523
+ } catch (e) {
1524
+ }
1525
+ ctx.schema = schema;
1526
+ await import_fs_extra3.default.outputFile(import_path4.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
1502
1527
  };
1503
1528
  var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
1504
1529
  if (verbose)
@@ -1911,6 +1936,30 @@ async function makeIsomorphicOptions(fsBridge) {
1911
1936
  return options;
1912
1937
  }
1913
1938
 
1939
+ // src/buildTina/index.ts
1940
+ var import_app = __toModule(require("@tinacms/app"));
1941
+
1942
+ // src/utils/spinner.ts
1943
+ var import_cli_spinner = __toModule(require("cli-spinner"));
1944
+ async function spin({
1945
+ waitFor,
1946
+ text
1947
+ }) {
1948
+ const spinner = new import_cli_spinner.Spinner({
1949
+ text: `${text} %s`,
1950
+ stream: process.stderr,
1951
+ onTick: function(msg) {
1952
+ this.clearLine(this.stream);
1953
+ this.stream.write(msg);
1954
+ }
1955
+ });
1956
+ spinner.setSpinnerString("\u280B\u2819\u2839\u2838\u283C\u2834\u2826\u2827\u2807\u280F");
1957
+ spinner.start();
1958
+ const res = await waitFor();
1959
+ spinner.stop();
1960
+ return res;
1961
+ }
1962
+
1914
1963
  // src/buildTina/index.ts
1915
1964
  var buildSetupCmdBuild = async (ctx, next, opts) => {
1916
1965
  const rootPath2 = ctx.rootPath;
@@ -1998,6 +2047,7 @@ var build2 = async ({
1998
2047
  noSDK,
1999
2048
  skipIndex
2000
2049
  }) => {
2050
+ var _a, _b;
2001
2051
  const rootPath2 = ctx.rootPath;
2002
2052
  if (!rootPath2) {
2003
2053
  throw new Error("Root path has not been attached");
@@ -2030,6 +2080,21 @@ var build2 = async ({
2030
2080
  }, {
2031
2081
  local
2032
2082
  });
2083
+ if ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build) {
2084
+ await spin({
2085
+ text: "Building static site",
2086
+ waitFor: async () => {
2087
+ var _a2, _b2, _c, _d, _e, _f;
2088
+ await (0, import_app.viteBuild)({
2089
+ local,
2090
+ rootPath: rootPath2,
2091
+ outputFolder: (_c = (_b2 = (_a2 = ctx.schema) == null ? void 0 : _a2.config) == null ? void 0 : _b2.build) == null ? void 0 : _c.outputFolder,
2092
+ publicFolder: (_f = (_e = (_d = ctx.schema) == null ? void 0 : _d.config) == null ? void 0 : _e.build) == null ? void 0 : _f.publicFolder
2093
+ });
2094
+ }
2095
+ });
2096
+ console.log("\nDone building static site");
2097
+ }
2033
2098
  } catch (error) {
2034
2099
  throw error;
2035
2100
  } finally {
@@ -2442,7 +2507,7 @@ var baseCmds = [
2442
2507
  ],
2443
2508
  action: (options) => chain([
2444
2509
  attachPath,
2445
- async (ctx, next, _) => {
2510
+ async (ctx, next, _2) => {
2446
2511
  logger.warn(warnText("server:start will be deprecated in the future, please use `tinacms dev` instead"));
2447
2512
  next();
2448
2513
  },
@@ -10,9 +10,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
+ interface GetPathParams {
14
+ projectDir: string;
15
+ filename: string;
16
+ allowedTypes: string[];
17
+ errorMessage: string;
18
+ }
19
+ export declare const getPath: ({ projectDir, filename, allowedTypes, errorMessage, }: GetPathParams) => any;
13
20
  export declare const getSchemaPath: ({ projectDir }: {
14
21
  projectDir: string;
15
22
  }) => any;
16
23
  export declare const getClientPath: ({ projectDir }: {
17
24
  projectDir: string;
18
25
  }) => any;
26
+ export {};
@@ -10,6 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- export declare function spin<T>({ waitFor }: {
13
+ export declare function spin<T>({ waitFor, text, }: {
14
14
  waitFor: () => Promise<T>;
15
+ text: string;
15
16
  }): Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/cli",
3
- "version": "0.61.1",
3
+ "version": "0.61.2",
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": "0.50.9",
24
+ "@tinacms/scripts": "0.51.0",
25
25
  "@types/clear": "0.1.0",
26
26
  "@types/cli-spinner": "^0.2.1",
27
27
  "@types/cors": "2.8.5",
@@ -52,10 +52,11 @@
52
52
  "@graphql-codegen/visitor-plugin-common": "^2.4.0",
53
53
  "@graphql-tools/graphql-file-loader": "^7.2.0",
54
54
  "@graphql-tools/load": "^7.3.2",
55
+ "@tinacms/app": "0.0.4",
55
56
  "@tinacms/datalayer": "0.2.2",
56
- "@tinacms/graphql": "0.62.1",
57
+ "@tinacms/graphql": "0.63.0",
57
58
  "@tinacms/metrics": "0.0.3",
58
- "@tinacms/schema-tools": "0.0.9",
59
+ "@tinacms/schema-tools": "0.1.0",
59
60
  "add": "^2.0.6",
60
61
  "ajv": "^6.12.3",
61
62
  "altair-express-middleware": "4.0.6",