@tinacms/cli 0.61.0 → 0.61.3

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.0";
296
+ var version = "0.61.3";
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"];
@@ -1332,19 +1329,18 @@ var resetGeneratedFolder = async ({
1332
1329
  usingTs
1333
1330
  }) => {
1334
1331
  try {
1335
- await import_fs_extra3.default.rm(tinaGeneratedPath, {
1336
- recursive: true
1337
- });
1332
+ await import_fs_extra3.default.emptyDir(tinaGeneratedPath);
1338
1333
  } catch (e) {
1339
1334
  console.log(e);
1340
1335
  }
1341
- await import_fs_extra3.default.mkdir(tinaGeneratedPath);
1336
+ await import_fs_extra3.default.mkdirp(tinaGeneratedPath);
1342
1337
  const ext = usingTs ? "ts" : "js";
1343
1338
  await import_fs_extra3.default.writeFile(import_path4.default.join(tinaGeneratedPath, `types.${ext}`), `
1344
1339
  export const queries = (client)=>({})
1345
1340
  `);
1346
1341
  await import_fs_extra3.default.writeFile(import_path4.default.join(tinaGeneratedPath, `client.${ext}`), `
1347
- export const client = {}
1342
+ export const client = ()=>{}
1343
+ export default client
1348
1344
  `);
1349
1345
  await import_fs_extra3.default.outputFile(import_path4.default.join(tinaGeneratedPath, ".gitignore"), `db
1350
1346
  client.ts
@@ -1429,7 +1425,7 @@ var compileClient = async (ctx, next, options) => {
1429
1425
  }
1430
1426
  return next();
1431
1427
  };
1432
- var compileSchema = async (ctx, _next, options) => {
1428
+ var compileFile = async (ctx, _next, options, fileName) => {
1433
1429
  const root2 = ctx.rootPath;
1434
1430
  if (!root2) {
1435
1431
  throw new Error("ctx.rootPath has not been attached");
@@ -1437,15 +1433,14 @@ var compileSchema = async (ctx, _next, options) => {
1437
1433
  const tinaPath = import_path4.default.join(root2, ".tina");
1438
1434
  const tsConfigPath = import_path4.default.join(root2, "tsconfig.json");
1439
1435
  const tinaGeneratedPath = import_path4.default.join(tinaPath, "__generated__");
1440
- const tinaTempPath = import_path4.default.join(tinaGeneratedPath, "temp_schema");
1441
- const tinaConfigPath = import_path4.default.join(tinaGeneratedPath, "config");
1436
+ const tinaTempPath = import_path4.default.join(tinaGeneratedPath, `temp_${fileName}`);
1442
1437
  const packageJSONFilePath = import_path4.default.join(root2, "package.json");
1443
1438
  if (!options.schemaFileType) {
1444
1439
  const usingTs = await import_fs_extra3.default.pathExists(tsConfigPath);
1445
1440
  options = __spreadProps(__spreadValues({}, options), { schemaFileType: usingTs ? "ts" : "js" });
1446
1441
  }
1447
1442
  if (options.verbose) {
1448
- logger.info(logText("Compiling Schema..."));
1443
+ logger.info(logText(`Compiling ${fileName}...`));
1449
1444
  }
1450
1445
  const { schemaFileType: requestedSchemaFileType = "ts" } = options;
1451
1446
  const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
@@ -1457,11 +1452,16 @@ var compileSchema = async (ctx, _next, options) => {
1457
1452
  }
1458
1453
  let schemaExists = true;
1459
1454
  try {
1460
- 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
+ });
1461
1461
  } catch {
1462
1462
  schemaExists = false;
1463
1463
  }
1464
- if (!schemaExists) {
1464
+ if (!schemaExists && fileName === "schema") {
1465
1465
  logger.info(dangerText(`
1466
1466
  .tina/schema.${schemaFileType2} not found, Creating one for you...
1467
1467
  See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
@@ -1475,8 +1475,13 @@ var compileSchema = async (ctx, _next, options) => {
1475
1475
  if (!process.env.NODE_ENV) {
1476
1476
  define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
1477
1477
  }
1478
- const inputFile = getSchemaPath({ projectDir: tinaPath });
1479
- 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);
1480
1485
  } catch (e) {
1481
1486
  await cleanup({ tinaTempPath });
1482
1487
  throw new BuildSchemaError(e);
@@ -1486,11 +1491,10 @@ var compileSchema = async (ctx, _next, options) => {
1486
1491
  delete require.cache[require.resolve(key)];
1487
1492
  }
1488
1493
  });
1494
+ let returnObject = {};
1489
1495
  try {
1490
- const schemaFunc = require(import_path4.default.join(tinaTempPath, "schema.js"));
1491
- const schemaObject = schemaFunc.default;
1492
- ctx.schema = schemaObject;
1493
- 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;
1494
1498
  await cleanup({ tinaTempPath });
1495
1499
  } catch (e) {
1496
1500
  await cleanup({ tinaTempPath });
@@ -1501,6 +1505,25 @@ var compileSchema = async (ctx, _next, options) => {
1501
1505
  }
1502
1506
  throw new ExecuteSchemaError(e);
1503
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));
1504
1527
  };
1505
1528
  var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
1506
1529
  if (verbose)
@@ -1913,6 +1936,30 @@ async function makeIsomorphicOptions(fsBridge) {
1913
1936
  return options;
1914
1937
  }
1915
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
+
1916
1963
  // src/buildTina/index.ts
1917
1964
  var buildSetupCmdBuild = async (ctx, next, opts) => {
1918
1965
  const rootPath2 = ctx.rootPath;
@@ -2000,6 +2047,7 @@ var build2 = async ({
2000
2047
  noSDK,
2001
2048
  skipIndex
2002
2049
  }) => {
2050
+ var _a, _b;
2003
2051
  const rootPath2 = ctx.rootPath;
2004
2052
  if (!rootPath2) {
2005
2053
  throw new Error("Root path has not been attached");
@@ -2032,6 +2080,21 @@ var build2 = async ({
2032
2080
  }, {
2033
2081
  local
2034
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
+ }
2035
2098
  } catch (error) {
2036
2099
  throw error;
2037
2100
  } finally {
@@ -2444,7 +2507,7 @@ var baseCmds = [
2444
2507
  ],
2445
2508
  action: (options) => chain([
2446
2509
  attachPath,
2447
- async (ctx, next, _) => {
2510
+ async (ctx, next, _2) => {
2448
2511
  logger.warn(warnText("server:start will be deprecated in the future, please use `tinacms dev` instead"));
2449
2512
  next();
2450
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.0",
3
+ "version": "0.61.3",
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.5",
55
56
  "@tinacms/datalayer": "0.2.2",
56
- "@tinacms/graphql": "0.62.0",
57
+ "@tinacms/graphql": "0.63.1",
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",