@tinacms/cli 2.3.1 → 2.4.1
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/dist/cmds/forestry-migrate/util/index.d.ts +2 -2
- package/dist/cmds/init/index.d.ts +1 -0
- package/dist/index.js +440 -267
- package/dist/next/build-database-esbuild-config.d.ts +38 -0
- package/dist/next/cache-manager.d.ts +51 -0
- package/dist/next/commands/build-command/index.d.ts +3 -0
- package/dist/next/external-resolver.d.ts +23 -0
- package/dist/utils/fetchPostHogConfig.d.ts +5 -0
- package/dist/utils/posthog.d.ts +21 -0
- package/package.json +8 -6
package/dist/index.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import { Cli, Builtins } from "clipanion";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "2.
|
|
5
|
+
var version = "2.4.1";
|
|
6
6
|
|
|
7
7
|
// src/next/commands/dev-command/index.ts
|
|
8
|
-
import
|
|
8
|
+
import path10 from "path";
|
|
9
9
|
import { FilesystemBridge as FilesystemBridge2, buildSchema } from "@tinacms/graphql";
|
|
10
10
|
import { Telemetry } from "@tinacms/metrics";
|
|
11
11
|
import { LocalSearchIndexClient, SearchIndexer } from "@tinacms/search";
|
|
12
12
|
import AsyncLock from "async-lock";
|
|
13
13
|
import chokidar from "chokidar";
|
|
14
14
|
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
15
|
-
import
|
|
15
|
+
import fs9 from "fs-extra";
|
|
16
16
|
|
|
17
17
|
// src/logger/index.ts
|
|
18
18
|
import chalk from "chalk";
|
|
@@ -816,9 +816,8 @@ var unlinkIfExists = async (filepath) => {
|
|
|
816
816
|
};
|
|
817
817
|
|
|
818
818
|
// src/next/config-manager.ts
|
|
819
|
-
import
|
|
820
|
-
import
|
|
821
|
-
import os from "os";
|
|
819
|
+
import fs4 from "fs-extra";
|
|
820
|
+
import path5 from "path";
|
|
822
821
|
import { pathToFileURL } from "url";
|
|
823
822
|
import * as esbuild from "esbuild";
|
|
824
823
|
import * as dotenv from "dotenv";
|
|
@@ -877,6 +876,76 @@ async function resolveContentRootPath(params) {
|
|
|
877
876
|
return params.rootPath;
|
|
878
877
|
}
|
|
879
878
|
|
|
879
|
+
// src/next/external-resolver.ts
|
|
880
|
+
var EXTERNAL_BASELINE = ["better-sqlite3"];
|
|
881
|
+
var resolveDatabaseExternals = (config2) => {
|
|
882
|
+
const userExternals = config2?.build?.externalDependencies ?? [];
|
|
883
|
+
return [...EXTERNAL_BASELINE, ...userExternals];
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
// src/next/cache-manager.ts
|
|
887
|
+
import fs3 from "fs-extra";
|
|
888
|
+
import path4 from "path";
|
|
889
|
+
var buildReadOnlyMountErrorMessage = (cacheParentPath, underlyingError) => `TinaCMS cannot write to ${cacheParentPath}.
|
|
890
|
+
|
|
891
|
+
Tina v3 needs write access to your project's tina/__generated__/.cache/ directory at build time. This usually means your project directory is read-only \u2014 common in some Docker setups (\`:ro\` volumes), AWS Lambda's \`/var/task\`, sandboxed CI runners, or restricted file permissions.
|
|
892
|
+
|
|
893
|
+
To resolve, either:
|
|
894
|
+
- Make the project directory writable (e.g. remount with read-write access, or copy the project to a writable location), or
|
|
895
|
+
- Run \`tinacms build\` against a writable copy of your project and deploy the resulting artifacts.
|
|
896
|
+
|
|
897
|
+
Underlying error: ${underlyingError.code} ${underlyingError.message}`;
|
|
898
|
+
var READONLY_ERROR_CODES = /* @__PURE__ */ new Set(["EACCES", "EROFS", "EPERM"]);
|
|
899
|
+
var prepareCacheLocation = async (generatedFolderPath, now = Date.now()) => {
|
|
900
|
+
const parentPath = path4.join(generatedFolderPath, ".cache");
|
|
901
|
+
try {
|
|
902
|
+
if (await fs3.pathExists(parentPath)) {
|
|
903
|
+
await fs3.remove(parentPath);
|
|
904
|
+
}
|
|
905
|
+
await fs3.ensureDir(parentPath);
|
|
906
|
+
} catch (err) {
|
|
907
|
+
const code = err?.code;
|
|
908
|
+
if (code && READONLY_ERROR_CODES.has(code)) {
|
|
909
|
+
throw new Error(
|
|
910
|
+
buildReadOnlyMountErrorMessage(parentPath, err)
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
throw err;
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
parentPath,
|
|
917
|
+
buildPath: path4.join(parentPath, String(now))
|
|
918
|
+
};
|
|
919
|
+
};
|
|
920
|
+
var reapBuildSubdir = (buildSubdirPath, buildParentPath) => {
|
|
921
|
+
fs3.removeSync(buildSubdirPath);
|
|
922
|
+
try {
|
|
923
|
+
fs3.rmdirSync(buildParentPath);
|
|
924
|
+
} catch (err) {
|
|
925
|
+
if (err?.code !== "ENOTEMPTY") throw err;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
// src/next/build-database-esbuild-config.ts
|
|
930
|
+
var buildDatabaseEsbuildConfig = (opts) => ({
|
|
931
|
+
entryPoints: [opts.entryPoint],
|
|
932
|
+
bundle: true,
|
|
933
|
+
platform: "node",
|
|
934
|
+
format: "esm",
|
|
935
|
+
outfile: opts.outfile,
|
|
936
|
+
loader: opts.loader,
|
|
937
|
+
external: opts.external,
|
|
938
|
+
// Provide a require() polyfill for ESM bundles containing CommonJS packages.
|
|
939
|
+
// Some bundled packages (e.g., 'scmp' used by 'mongodb-level') use
|
|
940
|
+
// require('crypto'). When esbuild inlines these CommonJS packages, it keeps
|
|
941
|
+
// the require() calls, but ESM doesn't have a global require. This banner
|
|
942
|
+
// creates one using Node.js's official createRequire API, allowing the
|
|
943
|
+
// bundled CommonJS code to work in ESM.
|
|
944
|
+
banner: {
|
|
945
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
|
|
880
949
|
// src/next/config-manager.ts
|
|
881
950
|
var TINA_FOLDER = "tina";
|
|
882
951
|
var LEGACY_TINA_FOLDER = ".tina";
|
|
@@ -936,7 +1005,7 @@ var ConfigManager = class {
|
|
|
936
1005
|
this.legacyNoSDK = legacyNoSDK;
|
|
937
1006
|
}
|
|
938
1007
|
isUsingTs() {
|
|
939
|
-
return [".ts", ".tsx"].includes(
|
|
1008
|
+
return [".ts", ".tsx"].includes(path5.extname(this.tinaConfigFilePath));
|
|
940
1009
|
}
|
|
941
1010
|
hasSelfHostedConfig() {
|
|
942
1011
|
return !!this.selfHostedDatabaseFilePath;
|
|
@@ -961,12 +1030,12 @@ var ConfigManager = class {
|
|
|
961
1030
|
)
|
|
962
1031
|
);
|
|
963
1032
|
}
|
|
964
|
-
this.envFilePath =
|
|
965
|
-
|
|
1033
|
+
this.envFilePath = path5.resolve(
|
|
1034
|
+
path5.join(this.tinaFolderPath, "..", ".env")
|
|
966
1035
|
);
|
|
967
1036
|
dotenv.config({ path: this.envFilePath });
|
|
968
1037
|
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
969
|
-
|
|
1038
|
+
path5.join(this.tinaFolderPath, "config")
|
|
970
1039
|
);
|
|
971
1040
|
if (!this.tinaConfigFilePath) {
|
|
972
1041
|
throw new Error(
|
|
@@ -974,89 +1043,86 @@ var ConfigManager = class {
|
|
|
974
1043
|
);
|
|
975
1044
|
}
|
|
976
1045
|
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
977
|
-
|
|
978
|
-
);
|
|
979
|
-
this.generatedFolderPath = path4.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
980
|
-
this.generatedCachePath = path4.join(
|
|
981
|
-
this.generatedFolderPath,
|
|
982
|
-
".cache",
|
|
983
|
-
String((/* @__PURE__ */ new Date()).getTime())
|
|
1046
|
+
path5.join(this.tinaFolderPath, "database")
|
|
984
1047
|
);
|
|
985
|
-
this.
|
|
1048
|
+
this.generatedFolderPath = path5.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
1049
|
+
const cacheLocation = await prepareCacheLocation(this.generatedFolderPath);
|
|
1050
|
+
this.generatedCachePath = cacheLocation.buildPath;
|
|
1051
|
+
this.generatedGraphQLGQLPath = path5.join(
|
|
986
1052
|
this.generatedFolderPath,
|
|
987
1053
|
GRAPHQL_GQL_FILE
|
|
988
1054
|
);
|
|
989
|
-
this.generatedGraphQLJSONPath =
|
|
1055
|
+
this.generatedGraphQLJSONPath = path5.join(
|
|
990
1056
|
this.generatedFolderPath,
|
|
991
1057
|
GRAPHQL_JSON_FILE
|
|
992
1058
|
);
|
|
993
|
-
this.generatedSchemaJSONPath =
|
|
1059
|
+
this.generatedSchemaJSONPath = path5.join(
|
|
994
1060
|
this.generatedFolderPath,
|
|
995
1061
|
SCHEMA_JSON_FILE
|
|
996
1062
|
);
|
|
997
|
-
this.generatedLookupJSONPath =
|
|
1063
|
+
this.generatedLookupJSONPath = path5.join(
|
|
998
1064
|
this.generatedFolderPath,
|
|
999
1065
|
LOOKUP_JSON_FILE
|
|
1000
1066
|
);
|
|
1001
|
-
this.generatedQueriesFilePath =
|
|
1067
|
+
this.generatedQueriesFilePath = path5.join(
|
|
1002
1068
|
this.generatedFolderPath,
|
|
1003
1069
|
"queries.gql"
|
|
1004
1070
|
);
|
|
1005
|
-
this.generatedFragmentsFilePath =
|
|
1071
|
+
this.generatedFragmentsFilePath = path5.join(
|
|
1006
1072
|
this.generatedFolderPath,
|
|
1007
1073
|
"frags.gql"
|
|
1008
1074
|
);
|
|
1009
|
-
this.generatedTypesTSFilePath =
|
|
1075
|
+
this.generatedTypesTSFilePath = path5.join(
|
|
1010
1076
|
this.generatedFolderPath,
|
|
1011
1077
|
"types.ts"
|
|
1012
1078
|
);
|
|
1013
|
-
this.generatedTypesJSFilePath =
|
|
1079
|
+
this.generatedTypesJSFilePath = path5.join(
|
|
1014
1080
|
this.generatedFolderPath,
|
|
1015
1081
|
"types.js"
|
|
1016
1082
|
);
|
|
1017
|
-
this.generatedTypesDFilePath =
|
|
1083
|
+
this.generatedTypesDFilePath = path5.join(
|
|
1018
1084
|
this.generatedFolderPath,
|
|
1019
1085
|
"types.d.ts"
|
|
1020
1086
|
);
|
|
1021
|
-
this.userQueriesAndFragmentsGlob =
|
|
1087
|
+
this.userQueriesAndFragmentsGlob = path5.join(
|
|
1022
1088
|
this.tinaFolderPath,
|
|
1023
1089
|
"queries/**/*.{graphql,gql}"
|
|
1024
1090
|
);
|
|
1025
|
-
this.generatedQueriesAndFragmentsGlob =
|
|
1091
|
+
this.generatedQueriesAndFragmentsGlob = path5.join(
|
|
1026
1092
|
this.generatedFolderPath,
|
|
1027
1093
|
"*.{graphql,gql}"
|
|
1028
1094
|
);
|
|
1029
|
-
this.generatedClientTSFilePath =
|
|
1095
|
+
this.generatedClientTSFilePath = path5.join(
|
|
1030
1096
|
this.generatedFolderPath,
|
|
1031
1097
|
"client.ts"
|
|
1032
1098
|
);
|
|
1033
|
-
this.generatedClientJSFilePath =
|
|
1099
|
+
this.generatedClientJSFilePath = path5.join(
|
|
1034
1100
|
this.generatedFolderPath,
|
|
1035
1101
|
"client.js"
|
|
1036
1102
|
);
|
|
1037
|
-
this.generatedClientDFilePath =
|
|
1103
|
+
this.generatedClientDFilePath = path5.join(
|
|
1038
1104
|
this.generatedFolderPath,
|
|
1039
1105
|
"client.d.ts"
|
|
1040
1106
|
);
|
|
1041
|
-
this.generatedDatabaseClientDFilePath =
|
|
1107
|
+
this.generatedDatabaseClientDFilePath = path5.join(
|
|
1042
1108
|
this.generatedFolderPath,
|
|
1043
1109
|
"databaseClient.d.ts"
|
|
1044
1110
|
);
|
|
1045
|
-
this.generatedDatabaseClientTSFilePath =
|
|
1111
|
+
this.generatedDatabaseClientTSFilePath = path5.join(
|
|
1046
1112
|
this.generatedFolderPath,
|
|
1047
1113
|
"databaseClient.ts"
|
|
1048
1114
|
);
|
|
1049
|
-
this.generatedDatabaseClientJSFilePath =
|
|
1115
|
+
this.generatedDatabaseClientJSFilePath = path5.join(
|
|
1050
1116
|
this.generatedFolderPath,
|
|
1051
1117
|
"databaseClient.js"
|
|
1052
1118
|
);
|
|
1053
|
-
const clientExists = this.isUsingTs() ? await
|
|
1119
|
+
const clientExists = this.isUsingTs() ? await fs4.pathExists(this.generatedClientTSFilePath) : await fs4.pathExists(this.generatedClientJSFilePath);
|
|
1054
1120
|
if (!clientExists) {
|
|
1055
1121
|
const file = "export default ()=>({})\nexport const client = ()=>({})";
|
|
1056
1122
|
if (this.isUsingTs()) {
|
|
1057
|
-
await
|
|
1123
|
+
await fs4.outputFile(this.generatedClientTSFilePath, file);
|
|
1058
1124
|
} else {
|
|
1059
|
-
await
|
|
1125
|
+
await fs4.outputFile(this.generatedClientJSFilePath, file);
|
|
1060
1126
|
}
|
|
1061
1127
|
}
|
|
1062
1128
|
const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
|
|
@@ -1066,16 +1132,16 @@ var ConfigManager = class {
|
|
|
1066
1132
|
this.watchList = watchList;
|
|
1067
1133
|
this.config = config2;
|
|
1068
1134
|
this.prebuildFilePath = prebuildPath;
|
|
1069
|
-
this.publicFolderPath =
|
|
1135
|
+
this.publicFolderPath = path5.join(
|
|
1070
1136
|
this.rootPath,
|
|
1071
1137
|
this.config.build.publicFolder
|
|
1072
1138
|
);
|
|
1073
|
-
this.outputFolderPath =
|
|
1139
|
+
this.outputFolderPath = path5.join(
|
|
1074
1140
|
this.publicFolderPath,
|
|
1075
1141
|
this.config.build.outputFolder
|
|
1076
1142
|
);
|
|
1077
|
-
this.outputHTMLFilePath =
|
|
1078
|
-
this.outputGitignorePath =
|
|
1143
|
+
this.outputHTMLFilePath = path5.join(this.outputFolderPath, "index.html");
|
|
1144
|
+
this.outputGitignorePath = path5.join(this.outputFolderPath, ".gitignore");
|
|
1079
1145
|
this.contentRootPath = await resolveContentRootPath({
|
|
1080
1146
|
rootPath: this.rootPath,
|
|
1081
1147
|
tinaFolderPath: this.tinaFolderPath,
|
|
@@ -1083,17 +1149,17 @@ var ConfigManager = class {
|
|
|
1083
1149
|
localContentPath: this.config.localContentPath
|
|
1084
1150
|
});
|
|
1085
1151
|
this.spaMainPath = require2.resolve("@tinacms/app");
|
|
1086
|
-
this.spaRootPath =
|
|
1152
|
+
this.spaRootPath = path5.join(this.spaMainPath, "..", "..");
|
|
1087
1153
|
}
|
|
1088
1154
|
async getTinaFolderPath(rootPath) {
|
|
1089
|
-
const tinaFolderPath =
|
|
1090
|
-
const tinaFolderExists = await
|
|
1155
|
+
const tinaFolderPath = path5.join(rootPath, TINA_FOLDER);
|
|
1156
|
+
const tinaFolderExists = await fs4.pathExists(tinaFolderPath);
|
|
1091
1157
|
if (tinaFolderExists) {
|
|
1092
1158
|
this.isUsingLegacyFolder = false;
|
|
1093
1159
|
return tinaFolderPath;
|
|
1094
1160
|
}
|
|
1095
|
-
const legacyFolderPath =
|
|
1096
|
-
const legacyFolderExists = await
|
|
1161
|
+
const legacyFolderPath = path5.join(rootPath, LEGACY_TINA_FOLDER);
|
|
1162
|
+
const legacyFolderExists = await fs4.pathExists(legacyFolderPath);
|
|
1097
1163
|
if (legacyFolderExists) {
|
|
1098
1164
|
this.isUsingLegacyFolder = true;
|
|
1099
1165
|
return legacyFolderPath;
|
|
@@ -1112,7 +1178,7 @@ var ConfigManager = class {
|
|
|
1112
1178
|
patch: version2[2] || "x"
|
|
1113
1179
|
};
|
|
1114
1180
|
}
|
|
1115
|
-
const generatedSchema =
|
|
1181
|
+
const generatedSchema = fs4.readJSONSync(this.generatedSchemaJSONPath);
|
|
1116
1182
|
if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
|
|
1117
1183
|
throw new Error(
|
|
1118
1184
|
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
@@ -1123,40 +1189,40 @@ var ConfigManager = class {
|
|
|
1123
1189
|
printGeneratedClientFilePath() {
|
|
1124
1190
|
if (this.isUsingTs()) {
|
|
1125
1191
|
return normalizePath2(
|
|
1126
|
-
|
|
1192
|
+
path5.relative(this.rootPath, this.generatedClientTSFilePath)
|
|
1127
1193
|
);
|
|
1128
1194
|
}
|
|
1129
1195
|
return normalizePath2(
|
|
1130
|
-
|
|
1196
|
+
path5.relative(this.rootPath, this.generatedClientJSFilePath)
|
|
1131
1197
|
);
|
|
1132
1198
|
}
|
|
1133
1199
|
printGeneratedTypesFilePath() {
|
|
1134
1200
|
return normalizePath2(
|
|
1135
|
-
|
|
1201
|
+
path5.relative(this.rootPath, this.generatedTypesTSFilePath)
|
|
1136
1202
|
);
|
|
1137
1203
|
}
|
|
1138
1204
|
printoutputHTMLFilePath() {
|
|
1139
1205
|
return normalizePath2(
|
|
1140
|
-
|
|
1206
|
+
path5.relative(this.publicFolderPath, this.outputHTMLFilePath)
|
|
1141
1207
|
);
|
|
1142
1208
|
}
|
|
1143
1209
|
printRelativePath(filename) {
|
|
1144
1210
|
if (filename) {
|
|
1145
|
-
return normalizePath2(
|
|
1211
|
+
return normalizePath2(path5.relative(this.rootPath, filename));
|
|
1146
1212
|
}
|
|
1147
1213
|
throw `No path provided to print`;
|
|
1148
1214
|
}
|
|
1149
1215
|
printPrebuildFilePath() {
|
|
1150
1216
|
return normalizePath2(
|
|
1151
|
-
|
|
1152
|
-
|
|
1217
|
+
path5.relative(
|
|
1218
|
+
path5.join(this.rootPath, this.tinaFolderPath),
|
|
1153
1219
|
this.prebuildFilePath
|
|
1154
1220
|
)
|
|
1155
1221
|
);
|
|
1156
1222
|
}
|
|
1157
1223
|
printContentRelativePath(filename) {
|
|
1158
1224
|
if (filename) {
|
|
1159
|
-
return normalizePath2(
|
|
1225
|
+
return normalizePath2(path5.relative(this.contentRootPath, filename));
|
|
1160
1226
|
}
|
|
1161
1227
|
throw `No path provided to print`;
|
|
1162
1228
|
}
|
|
@@ -1172,7 +1238,7 @@ var ConfigManager = class {
|
|
|
1172
1238
|
return;
|
|
1173
1239
|
}
|
|
1174
1240
|
const filepathWithExtension = `${filepath}.${ext}`;
|
|
1175
|
-
const exists =
|
|
1241
|
+
const exists = fs4.existsSync(filepathWithExtension);
|
|
1176
1242
|
if (exists) {
|
|
1177
1243
|
result = filepathWithExtension;
|
|
1178
1244
|
}
|
|
@@ -1181,41 +1247,34 @@ var ConfigManager = class {
|
|
|
1181
1247
|
return result;
|
|
1182
1248
|
}
|
|
1183
1249
|
async loadDatabaseFile() {
|
|
1184
|
-
const
|
|
1185
|
-
const outfile =
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
// When esbuild inlines these CommonJS packages, it keeps the require() calls,
|
|
1196
|
-
// but ESM doesn't have a global require. This banner creates one using Node.js's
|
|
1197
|
-
// official createRequire API, allowing the bundled CommonJS code to work in ESM.
|
|
1198
|
-
banner: {
|
|
1199
|
-
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1250
|
+
const buildDir = path5.join(this.generatedCachePath, "database");
|
|
1251
|
+
const outfile = path5.join(buildDir, "database.build.mjs");
|
|
1252
|
+
const external = resolveDatabaseExternals(this.config);
|
|
1253
|
+
await esbuild.build(
|
|
1254
|
+
buildDatabaseEsbuildConfig({
|
|
1255
|
+
entryPoint: this.selfHostedDatabaseFilePath,
|
|
1256
|
+
outfile,
|
|
1257
|
+
external,
|
|
1258
|
+
loader: loaders
|
|
1259
|
+
})
|
|
1260
|
+
);
|
|
1202
1261
|
const result = await import(pathToFileURL(outfile).href);
|
|
1203
|
-
|
|
1262
|
+
reapBuildSubdir(buildDir, this.generatedCachePath);
|
|
1204
1263
|
return result.default;
|
|
1205
1264
|
}
|
|
1206
1265
|
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
1207
|
-
const
|
|
1208
|
-
const preBuildConfigPath =
|
|
1266
|
+
const buildDir = path5.join(this.generatedCachePath, "config");
|
|
1267
|
+
const preBuildConfigPath = path5.join(
|
|
1209
1268
|
this.generatedFolderPath,
|
|
1210
1269
|
"config.prebuild.jsx"
|
|
1211
1270
|
);
|
|
1212
|
-
const outfile =
|
|
1213
|
-
const outfile2 =
|
|
1214
|
-
const tempTSConfigFile =
|
|
1271
|
+
const outfile = path5.join(buildDir, "config.build.jsx");
|
|
1272
|
+
const outfile2 = path5.join(buildDir, "config.build.mjs");
|
|
1273
|
+
const tempTSConfigFile = path5.join(buildDir, "tsconfig.json");
|
|
1215
1274
|
const esmRequireBanner = {
|
|
1216
1275
|
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
1217
1276
|
};
|
|
1218
|
-
|
|
1277
|
+
fs4.outputFileSync(tempTSConfigFile, "{}");
|
|
1219
1278
|
const result2 = await esbuild.build({
|
|
1220
1279
|
entryPoints: [configFilePath],
|
|
1221
1280
|
bundle: true,
|
|
@@ -1265,8 +1324,7 @@ var ConfigManager = class {
|
|
|
1265
1324
|
console.error(e);
|
|
1266
1325
|
throw e;
|
|
1267
1326
|
}
|
|
1268
|
-
|
|
1269
|
-
fs3.removeSync(outfile2);
|
|
1327
|
+
reapBuildSubdir(buildDir, this.generatedCachePath);
|
|
1270
1328
|
return {
|
|
1271
1329
|
config: result.default,
|
|
1272
1330
|
prebuildPath: preBuildConfigPath,
|
|
@@ -1391,7 +1449,7 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
1391
1449
|
|
|
1392
1450
|
// src/next/commands/baseCommands.ts
|
|
1393
1451
|
import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
|
|
1394
|
-
import
|
|
1452
|
+
import fs5 from "fs-extra";
|
|
1395
1453
|
var BaseCommand = class extends Command {
|
|
1396
1454
|
experimentalDataLayer = Option.Boolean("--experimentalData", {
|
|
1397
1455
|
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
@@ -1473,7 +1531,7 @@ var BaseCommand = class extends Command {
|
|
|
1473
1531
|
const rootPath = configManager.rootPath;
|
|
1474
1532
|
let sha;
|
|
1475
1533
|
try {
|
|
1476
|
-
sha = await getSha({ fs:
|
|
1534
|
+
sha = await getSha({ fs: fs5, dir: rootPath });
|
|
1477
1535
|
} catch (e) {
|
|
1478
1536
|
if (partialReindex) {
|
|
1479
1537
|
console.error(
|
|
@@ -1483,7 +1541,7 @@ var BaseCommand = class extends Command {
|
|
|
1483
1541
|
}
|
|
1484
1542
|
}
|
|
1485
1543
|
const lastSha = await database.getMetadata("lastSha");
|
|
1486
|
-
const exists = lastSha && await shaExists({ fs:
|
|
1544
|
+
const exists = lastSha && await shaExists({ fs: fs5, dir: rootPath, sha: lastSha });
|
|
1487
1545
|
let res;
|
|
1488
1546
|
if (partialReindex && lastSha && exists && sha) {
|
|
1489
1547
|
const pathFilter = {};
|
|
@@ -1498,14 +1556,14 @@ var BaseCommand = class extends Command {
|
|
|
1498
1556
|
};
|
|
1499
1557
|
}
|
|
1500
1558
|
const { added, modified, deleted } = await getChangedFiles({
|
|
1501
|
-
fs:
|
|
1559
|
+
fs: fs5,
|
|
1502
1560
|
dir: rootPath,
|
|
1503
1561
|
from: lastSha,
|
|
1504
1562
|
to: sha,
|
|
1505
1563
|
pathFilter
|
|
1506
1564
|
});
|
|
1507
1565
|
const tinaPathUpdates = modified.filter(
|
|
1508
|
-
(
|
|
1566
|
+
(path18) => path18.startsWith(".tina/__generated__/_schema.json") || path18.startsWith("tina/tina-lock.json")
|
|
1509
1567
|
);
|
|
1510
1568
|
if (tinaPathUpdates.length > 0) {
|
|
1511
1569
|
res = await database.indexContent({
|
|
@@ -1624,9 +1682,9 @@ var devHTML = (port) => `<!DOCTYPE html>
|
|
|
1624
1682
|
import { createServer as createViteServer } from "vite";
|
|
1625
1683
|
|
|
1626
1684
|
// src/next/vite/index.ts
|
|
1627
|
-
import
|
|
1685
|
+
import path7 from "node:path";
|
|
1628
1686
|
import react from "@vitejs/plugin-react";
|
|
1629
|
-
import
|
|
1687
|
+
import fs6 from "fs-extra";
|
|
1630
1688
|
import normalizePath3 from "normalize-path";
|
|
1631
1689
|
import {
|
|
1632
1690
|
splitVendorChunkPlugin
|
|
@@ -1693,7 +1751,7 @@ function filterPublicEnv(env = process.env) {
|
|
|
1693
1751
|
}
|
|
1694
1752
|
|
|
1695
1753
|
// src/next/vite/tailwind.ts
|
|
1696
|
-
import
|
|
1754
|
+
import path6 from "node:path";
|
|
1697
1755
|
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
1698
1756
|
import containerQueries from "@tailwindcss/container-queries";
|
|
1699
1757
|
import twTypography from "@tailwindcss/typography";
|
|
@@ -1708,7 +1766,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1708
1766
|
const require2 = createRequire2(import.meta.url);
|
|
1709
1767
|
const plugins = [];
|
|
1710
1768
|
const content = [
|
|
1711
|
-
|
|
1769
|
+
path6.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
1712
1770
|
prebuildFilePath,
|
|
1713
1771
|
require2.resolve("tinacms")
|
|
1714
1772
|
];
|
|
@@ -1972,35 +2030,35 @@ async function listFilesRecursively({
|
|
|
1972
2030
|
config: config2,
|
|
1973
2031
|
roothPath
|
|
1974
2032
|
}) {
|
|
1975
|
-
const fullDirectoryPath =
|
|
2033
|
+
const fullDirectoryPath = path7.join(
|
|
1976
2034
|
roothPath,
|
|
1977
2035
|
config2.publicFolder,
|
|
1978
2036
|
directoryPath
|
|
1979
2037
|
);
|
|
1980
|
-
const exists = await
|
|
2038
|
+
const exists = await fs6.pathExists(fullDirectoryPath);
|
|
1981
2039
|
if (!exists) {
|
|
1982
2040
|
return { "0": [] };
|
|
1983
2041
|
}
|
|
1984
|
-
const items = await
|
|
2042
|
+
const items = await fs6.readdir(fullDirectoryPath);
|
|
1985
2043
|
const staticMediaItems = [];
|
|
1986
2044
|
for (const item of items) {
|
|
1987
|
-
const itemPath =
|
|
1988
|
-
const stats = await
|
|
2045
|
+
const itemPath = path7.join(fullDirectoryPath, item);
|
|
2046
|
+
const stats = await fs6.promises.lstat(itemPath);
|
|
1989
2047
|
const staticMediaItem = {
|
|
1990
2048
|
id: item,
|
|
1991
2049
|
filename: item,
|
|
1992
2050
|
type: stats.isDirectory() ? "dir" : "file",
|
|
1993
2051
|
directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
|
|
1994
|
-
src: `/${
|
|
2052
|
+
src: `/${path7.join(directoryPath, item)}`,
|
|
1995
2053
|
thumbnails: {
|
|
1996
|
-
"75x75": `/${
|
|
1997
|
-
"400x400": `/${
|
|
1998
|
-
"1000x1000": `/${
|
|
2054
|
+
"75x75": `/${path7.join(directoryPath, item)}`,
|
|
2055
|
+
"400x400": `/${path7.join(directoryPath, item)}`,
|
|
2056
|
+
"1000x1000": `/${path7.join(directoryPath, item)}`
|
|
1999
2057
|
}
|
|
2000
2058
|
};
|
|
2001
2059
|
if (stats.isDirectory()) {
|
|
2002
2060
|
staticMediaItem.children = await listFilesRecursively({
|
|
2003
|
-
directoryPath:
|
|
2061
|
+
directoryPath: path7.join(directoryPath, item),
|
|
2004
2062
|
config: config2,
|
|
2005
2063
|
roothPath
|
|
2006
2064
|
});
|
|
@@ -2025,7 +2083,7 @@ var createConfig = async ({
|
|
|
2025
2083
|
rollupOptions
|
|
2026
2084
|
}) => {
|
|
2027
2085
|
const publicEnv = filterPublicEnv();
|
|
2028
|
-
const staticMediaPath =
|
|
2086
|
+
const staticMediaPath = path7.join(
|
|
2029
2087
|
configManager.generatedFolderPath,
|
|
2030
2088
|
"static-media.json"
|
|
2031
2089
|
);
|
|
@@ -2035,21 +2093,21 @@ var createConfig = async ({
|
|
|
2035
2093
|
config: configManager.config.media.tina,
|
|
2036
2094
|
roothPath: configManager.rootPath
|
|
2037
2095
|
});
|
|
2038
|
-
await
|
|
2096
|
+
await fs6.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
|
|
2039
2097
|
} else {
|
|
2040
|
-
await
|
|
2098
|
+
await fs6.outputFile(staticMediaPath, `[]`);
|
|
2041
2099
|
}
|
|
2042
2100
|
const alias = {
|
|
2043
2101
|
TINA_IMPORT: configManager.prebuildFilePath,
|
|
2044
2102
|
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
|
|
2045
2103
|
STATIC_MEDIA_IMPORT: staticMediaPath,
|
|
2046
|
-
crypto:
|
|
2047
|
-
fs:
|
|
2048
|
-
os:
|
|
2049
|
-
path:
|
|
2104
|
+
crypto: path7.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
2105
|
+
fs: path7.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
2106
|
+
os: path7.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
2107
|
+
path: path7.join(configManager.spaRootPath, "src", "dummy-client.ts")
|
|
2050
2108
|
};
|
|
2051
2109
|
if (configManager.shouldSkipSDK()) {
|
|
2052
|
-
alias["CLIENT_IMPORT"] =
|
|
2110
|
+
alias["CLIENT_IMPORT"] = path7.join(
|
|
2053
2111
|
configManager.spaRootPath,
|
|
2054
2112
|
"src",
|
|
2055
2113
|
"dummy-client.ts"
|
|
@@ -2159,8 +2217,8 @@ var createConfig = async ({
|
|
|
2159
2217
|
};
|
|
2160
2218
|
|
|
2161
2219
|
// src/next/vite/plugins.ts
|
|
2162
|
-
import
|
|
2163
|
-
import
|
|
2220
|
+
import fs8 from "fs";
|
|
2221
|
+
import path9 from "path";
|
|
2164
2222
|
import { createFilter } from "@rollup/pluginutils";
|
|
2165
2223
|
import { resolve as gqlResolve } from "@tinacms/graphql";
|
|
2166
2224
|
import bodyParser from "body-parser";
|
|
@@ -2169,11 +2227,11 @@ import { transform as esbuildTransform } from "esbuild";
|
|
|
2169
2227
|
import { transformWithEsbuild } from "vite";
|
|
2170
2228
|
|
|
2171
2229
|
// src/next/commands/dev-command/server/media.ts
|
|
2172
|
-
import
|
|
2230
|
+
import path8, { join } from "path";
|
|
2173
2231
|
import busboy from "busboy";
|
|
2174
|
-
import
|
|
2232
|
+
import fs7 from "fs-extra";
|
|
2175
2233
|
var createMediaRouter = (config2) => {
|
|
2176
|
-
const mediaFolder =
|
|
2234
|
+
const mediaFolder = path8.join(
|
|
2177
2235
|
config2.rootPath,
|
|
2178
2236
|
config2.publicFolder,
|
|
2179
2237
|
config2.mediaRoot
|
|
@@ -2237,8 +2295,8 @@ var createMediaRouter = (config2) => {
|
|
|
2237
2295
|
);
|
|
2238
2296
|
return;
|
|
2239
2297
|
}
|
|
2240
|
-
await
|
|
2241
|
-
file.pipe(
|
|
2298
|
+
await fs7.ensureDir(path8.dirname(saveTo));
|
|
2299
|
+
file.pipe(fs7.createWriteStream(saveTo));
|
|
2242
2300
|
});
|
|
2243
2301
|
bb.on("error", (error) => {
|
|
2244
2302
|
responded = true;
|
|
@@ -2268,18 +2326,18 @@ var parseMediaFolder = (str) => {
|
|
|
2268
2326
|
var ENCODED_TRAVERSAL_RE = /%2e%2e|%2f|%5c/i;
|
|
2269
2327
|
function resolveRealPath(candidate) {
|
|
2270
2328
|
try {
|
|
2271
|
-
return
|
|
2329
|
+
return fs7.realpathSync(candidate);
|
|
2272
2330
|
} catch {
|
|
2273
|
-
const parent =
|
|
2331
|
+
const parent = path8.dirname(candidate);
|
|
2274
2332
|
if (parent === candidate) return candidate;
|
|
2275
|
-
return
|
|
2333
|
+
return path8.join(resolveRealPath(parent), path8.basename(candidate));
|
|
2276
2334
|
}
|
|
2277
2335
|
}
|
|
2278
2336
|
function assertSymlinkWithinBase(resolved, resolvedBase, userPath) {
|
|
2279
2337
|
try {
|
|
2280
|
-
const realBase =
|
|
2338
|
+
const realBase = fs7.realpathSync(resolvedBase);
|
|
2281
2339
|
const realResolved = resolveRealPath(resolved);
|
|
2282
|
-
if (realResolved !== realBase && !realResolved.startsWith(realBase +
|
|
2340
|
+
if (realResolved !== realBase && !realResolved.startsWith(realBase + path8.sep)) {
|
|
2283
2341
|
throw new PathTraversalError(userPath);
|
|
2284
2342
|
}
|
|
2285
2343
|
} catch (err) {
|
|
@@ -2290,13 +2348,13 @@ function resolveWithinBase(userPath, baseDir) {
|
|
|
2290
2348
|
if (ENCODED_TRAVERSAL_RE.test(userPath)) {
|
|
2291
2349
|
throw new PathTraversalError(userPath);
|
|
2292
2350
|
}
|
|
2293
|
-
const resolvedBase =
|
|
2294
|
-
const resolved =
|
|
2351
|
+
const resolvedBase = path8.resolve(baseDir);
|
|
2352
|
+
const resolved = path8.resolve(path8.join(baseDir, userPath));
|
|
2295
2353
|
if (resolved === resolvedBase) {
|
|
2296
2354
|
assertSymlinkWithinBase(resolved, resolvedBase, userPath);
|
|
2297
2355
|
return resolvedBase;
|
|
2298
2356
|
}
|
|
2299
|
-
if (resolved.startsWith(resolvedBase +
|
|
2357
|
+
if (resolved.startsWith(resolvedBase + path8.sep)) {
|
|
2300
2358
|
assertSymlinkWithinBase(resolved, resolvedBase, userPath);
|
|
2301
2359
|
return resolved;
|
|
2302
2360
|
}
|
|
@@ -2306,12 +2364,12 @@ function resolveStrictlyWithinBase(userPath, baseDir) {
|
|
|
2306
2364
|
if (ENCODED_TRAVERSAL_RE.test(userPath)) {
|
|
2307
2365
|
throw new PathTraversalError(userPath);
|
|
2308
2366
|
}
|
|
2309
|
-
const resolvedBase =
|
|
2310
|
-
const resolved =
|
|
2367
|
+
const resolvedBase = path8.resolve(baseDir) + path8.sep;
|
|
2368
|
+
const resolved = path8.resolve(path8.join(baseDir, userPath));
|
|
2311
2369
|
if (!resolved.startsWith(resolvedBase)) {
|
|
2312
2370
|
throw new PathTraversalError(userPath);
|
|
2313
2371
|
}
|
|
2314
|
-
assertSymlinkWithinBase(resolved,
|
|
2372
|
+
assertSymlinkWithinBase(resolved, path8.resolve(baseDir), userPath);
|
|
2315
2373
|
return resolved;
|
|
2316
2374
|
}
|
|
2317
2375
|
var MediaModel = class {
|
|
@@ -2328,16 +2386,16 @@ var MediaModel = class {
|
|
|
2328
2386
|
const mediaBase = join(this.rootPath, this.publicFolder, this.mediaRoot);
|
|
2329
2387
|
const validatedPath = resolveWithinBase(args.searchPath, mediaBase);
|
|
2330
2388
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
2331
|
-
if (!await
|
|
2389
|
+
if (!await fs7.pathExists(validatedPath)) {
|
|
2332
2390
|
return {
|
|
2333
2391
|
files: [],
|
|
2334
2392
|
directories: []
|
|
2335
2393
|
};
|
|
2336
2394
|
}
|
|
2337
|
-
const filesStr = await
|
|
2395
|
+
const filesStr = await fs7.readdir(validatedPath);
|
|
2338
2396
|
const filesProm = filesStr.map(async (file) => {
|
|
2339
2397
|
const filePath = join(validatedPath, file);
|
|
2340
|
-
const stat = await
|
|
2398
|
+
const stat = await fs7.stat(filePath);
|
|
2341
2399
|
let src = `/${file}`;
|
|
2342
2400
|
const isFile = stat.isFile();
|
|
2343
2401
|
if (!isFile) {
|
|
@@ -2396,8 +2454,8 @@ var MediaModel = class {
|
|
|
2396
2454
|
try {
|
|
2397
2455
|
const mediaBase = join(this.rootPath, this.publicFolder, this.mediaRoot);
|
|
2398
2456
|
const file = resolveStrictlyWithinBase(args.searchPath, mediaBase);
|
|
2399
|
-
await
|
|
2400
|
-
await
|
|
2457
|
+
await fs7.stat(file);
|
|
2458
|
+
await fs7.remove(file);
|
|
2401
2459
|
return { ok: true };
|
|
2402
2460
|
} catch (error) {
|
|
2403
2461
|
if (error instanceof PathTraversalError) throw error;
|
|
@@ -2505,7 +2563,7 @@ var transformTsxPlugin = ({
|
|
|
2505
2563
|
const plug = {
|
|
2506
2564
|
name: "transform-tsx",
|
|
2507
2565
|
async transform(code, id) {
|
|
2508
|
-
const extName =
|
|
2566
|
+
const extName = path9.extname(id);
|
|
2509
2567
|
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
2510
2568
|
const result = await esbuildTransform(code, { loader: "tsx" });
|
|
2511
2569
|
return {
|
|
@@ -2616,7 +2674,7 @@ function viteTransformExtension({
|
|
|
2616
2674
|
async transform(code, id) {
|
|
2617
2675
|
if (filter(id)) {
|
|
2618
2676
|
const { transform: transform2 } = await import("@svgr/core");
|
|
2619
|
-
const svgCode = await
|
|
2677
|
+
const svgCode = await fs8.promises.readFile(
|
|
2620
2678
|
id.replace(/\?.*$/, ""),
|
|
2621
2679
|
"utf8"
|
|
2622
2680
|
);
|
|
@@ -2708,7 +2766,7 @@ var DevCommand = class extends BaseCommand {
|
|
|
2708
2766
|
]
|
|
2709
2767
|
});
|
|
2710
2768
|
async catch(error) {
|
|
2711
|
-
logger.error("Error
|
|
2769
|
+
logger.error("Error occurred during tinacms dev");
|
|
2712
2770
|
console.error(error);
|
|
2713
2771
|
process.exit(1);
|
|
2714
2772
|
}
|
|
@@ -2766,13 +2824,13 @@ var DevCommand = class extends BaseCommand {
|
|
|
2766
2824
|
});
|
|
2767
2825
|
const apiURL2 = await codegen2.execute();
|
|
2768
2826
|
if (!configManager.isUsingLegacyFolder) {
|
|
2769
|
-
const schemaObject = await
|
|
2827
|
+
const schemaObject = await fs9.readJSON(
|
|
2770
2828
|
configManager.generatedSchemaJSONPath
|
|
2771
2829
|
);
|
|
2772
|
-
const lookupObject = await
|
|
2830
|
+
const lookupObject = await fs9.readJSON(
|
|
2773
2831
|
configManager.generatedLookupJSONPath
|
|
2774
2832
|
);
|
|
2775
|
-
const graphqlSchemaObject = await
|
|
2833
|
+
const graphqlSchemaObject = await fs9.readJSON(
|
|
2776
2834
|
configManager.generatedGraphQLJSONPath
|
|
2777
2835
|
);
|
|
2778
2836
|
const tinaLockFilename = "tina-lock.json";
|
|
@@ -2781,8 +2839,8 @@ var DevCommand = class extends BaseCommand {
|
|
|
2781
2839
|
lookup: lookupObject,
|
|
2782
2840
|
graphql: graphqlSchemaObject
|
|
2783
2841
|
});
|
|
2784
|
-
|
|
2785
|
-
|
|
2842
|
+
fs9.writeFileSync(
|
|
2843
|
+
path10.join(configManager.tinaFolderPath, tinaLockFilename),
|
|
2786
2844
|
tinaLockContent
|
|
2787
2845
|
);
|
|
2788
2846
|
}
|
|
@@ -2826,8 +2884,8 @@ ${dangerText(e.message)}
|
|
|
2826
2884
|
const { apiURL, graphQLSchema, tinaSchema } = await setup({
|
|
2827
2885
|
firstTime: true
|
|
2828
2886
|
});
|
|
2829
|
-
await
|
|
2830
|
-
await
|
|
2887
|
+
await fs9.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
2888
|
+
await fs9.outputFile(
|
|
2831
2889
|
configManager.outputGitignorePath,
|
|
2832
2890
|
"index.html\nassets/"
|
|
2833
2891
|
);
|
|
@@ -2972,7 +3030,7 @@ ${dangerText(e.message)}
|
|
|
2972
3030
|
watchContentFiles(configManager, database, databaseLock, searchIndexer) {
|
|
2973
3031
|
const collectionContentFiles = [];
|
|
2974
3032
|
configManager.config.schema.collections.forEach((collection) => {
|
|
2975
|
-
const collectionGlob = `${
|
|
3033
|
+
const collectionGlob = `${path10.join(
|
|
2976
3034
|
configManager.contentRootPath,
|
|
2977
3035
|
collection.path
|
|
2978
3036
|
)}/**/*.${collection.format || "md"}`;
|
|
@@ -3022,17 +3080,16 @@ ${dangerText(e.message)}
|
|
|
3022
3080
|
|
|
3023
3081
|
// src/next/commands/build-command/index.ts
|
|
3024
3082
|
import crypto from "crypto";
|
|
3025
|
-
import
|
|
3083
|
+
import path11 from "path";
|
|
3026
3084
|
import { diff } from "@graphql-inspector/core";
|
|
3027
3085
|
import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
|
|
3028
|
-
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
3029
3086
|
import { parseURL as parseURL2 } from "@tinacms/schema-tools";
|
|
3030
3087
|
import {
|
|
3031
3088
|
SearchIndexer as SearchIndexer2,
|
|
3032
3089
|
TinaCMSSearchIndexClient
|
|
3033
3090
|
} from "@tinacms/search";
|
|
3034
3091
|
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
3035
|
-
import
|
|
3092
|
+
import fs10 from "fs-extra";
|
|
3036
3093
|
import {
|
|
3037
3094
|
buildASTSchema as buildASTSchema2,
|
|
3038
3095
|
buildClientSchema,
|
|
@@ -3169,6 +3226,75 @@ var waitForDB = async (config2, apiUrl, previewName, verbose) => {
|
|
|
3169
3226
|
});
|
|
3170
3227
|
};
|
|
3171
3228
|
|
|
3229
|
+
// src/utils/posthog.ts
|
|
3230
|
+
import { randomUUID } from "node:crypto";
|
|
3231
|
+
import { PostHog } from "posthog-node";
|
|
3232
|
+
|
|
3233
|
+
// src/utils/fetchPostHogConfig.ts
|
|
3234
|
+
async function fetchPostHogConfig(endpointUrl) {
|
|
3235
|
+
try {
|
|
3236
|
+
const response = await fetch(endpointUrl, {
|
|
3237
|
+
method: "GET",
|
|
3238
|
+
headers: {
|
|
3239
|
+
"Content-Type": "application/json"
|
|
3240
|
+
},
|
|
3241
|
+
// Cap latency for offline / firewalled developers. Endpoint is
|
|
3242
|
+
// typically single-digit ms when reachable; a timeout returns {}
|
|
3243
|
+
// and disables telemetry for this run, which is the right behavior.
|
|
3244
|
+
signal: AbortSignal.timeout(2e3)
|
|
3245
|
+
});
|
|
3246
|
+
if (!response.ok) {
|
|
3247
|
+
throw new Error(`Failed to fetch PostHog config: ${response.statusText}`);
|
|
3248
|
+
}
|
|
3249
|
+
const config2 = await response.json();
|
|
3250
|
+
return {
|
|
3251
|
+
POSTHOG_API_KEY: config2.api_key,
|
|
3252
|
+
POSTHOG_ENDPOINT: config2.host
|
|
3253
|
+
};
|
|
3254
|
+
} catch {
|
|
3255
|
+
return {};
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
// src/utils/posthog.ts
|
|
3260
|
+
function generateSessionId() {
|
|
3261
|
+
return randomUUID();
|
|
3262
|
+
}
|
|
3263
|
+
var BuildInvokeEvent = "tinacms-cli-build-invoke";
|
|
3264
|
+
var BuildFinishedEvent = "tinacms-cli-build-finished";
|
|
3265
|
+
async function initializePostHog(configEndpoint, disableGeoip) {
|
|
3266
|
+
if (process.env.TINA_DEV === "true") return null;
|
|
3267
|
+
let apiKey;
|
|
3268
|
+
let endpoint;
|
|
3269
|
+
if (configEndpoint) {
|
|
3270
|
+
const config2 = await fetchPostHogConfig(configEndpoint);
|
|
3271
|
+
apiKey = config2.POSTHOG_API_KEY;
|
|
3272
|
+
endpoint = config2.POSTHOG_ENDPOINT;
|
|
3273
|
+
}
|
|
3274
|
+
if (!apiKey) return null;
|
|
3275
|
+
return new PostHog(apiKey, {
|
|
3276
|
+
host: endpoint,
|
|
3277
|
+
disableGeoip: disableGeoip ?? true
|
|
3278
|
+
});
|
|
3279
|
+
}
|
|
3280
|
+
function postHogCapture(client, distinctId, event, properties) {
|
|
3281
|
+
if (!client) {
|
|
3282
|
+
return;
|
|
3283
|
+
}
|
|
3284
|
+
try {
|
|
3285
|
+
client.capture({
|
|
3286
|
+
distinctId,
|
|
3287
|
+
event,
|
|
3288
|
+
properties: {
|
|
3289
|
+
...properties,
|
|
3290
|
+
system: "tinacms/cli"
|
|
3291
|
+
}
|
|
3292
|
+
});
|
|
3293
|
+
} catch (error) {
|
|
3294
|
+
console.error("Error capturing event:", error);
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
|
|
3172
3298
|
// src/next/commands/build-command/index.ts
|
|
3173
3299
|
var BuildCommand = class extends BaseCommand {
|
|
3174
3300
|
static paths = [["build"]];
|
|
@@ -3212,7 +3338,17 @@ var BuildCommand = class extends BaseCommand {
|
|
|
3212
3338
|
category: `Commands`,
|
|
3213
3339
|
description: `Build the CMS and autogenerated modules for usage with TinaCloud`
|
|
3214
3340
|
});
|
|
3341
|
+
posthogClient = null;
|
|
3342
|
+
buildStartedAt = 0;
|
|
3343
|
+
buildRunId = generateSessionId();
|
|
3215
3344
|
async catch(error) {
|
|
3345
|
+
const errorCode = error?.errorCode ?? "ERR_BUILD_FAILED";
|
|
3346
|
+
postHogCapture(this.posthogClient, this.buildRunId, BuildFinishedEvent, {
|
|
3347
|
+
success: false,
|
|
3348
|
+
durationMs: Date.now() - this.buildStartedAt,
|
|
3349
|
+
errorCode
|
|
3350
|
+
});
|
|
3351
|
+
if (this.posthogClient) await this.posthogClient.shutdown();
|
|
3216
3352
|
console.error(error);
|
|
3217
3353
|
process.exit(1);
|
|
3218
3354
|
}
|
|
@@ -3249,6 +3385,27 @@ var BuildCommand = class extends BaseCommand {
|
|
|
3249
3385
|
process.exit(1);
|
|
3250
3386
|
}
|
|
3251
3387
|
const localContentOnly = this.contentOption === "local";
|
|
3388
|
+
this.posthogClient = this.noTelemetry ? null : await initializePostHog(
|
|
3389
|
+
"https://identity-v2.tinajs.io/v2/posthog-token",
|
|
3390
|
+
false
|
|
3391
|
+
);
|
|
3392
|
+
const buildInvokeEventPayload = {
|
|
3393
|
+
hasLocalOption: Boolean(this.localOption),
|
|
3394
|
+
hasContentLocal: localContentOnly,
|
|
3395
|
+
skipIndexing: Boolean(this.skipIndexing),
|
|
3396
|
+
partialReindex: Boolean(this.partialReindex),
|
|
3397
|
+
hasPreviewName: Boolean(this.previewName),
|
|
3398
|
+
specifiesTinaGraphQLVersions: Boolean(this.tinaGraphQLVersion),
|
|
3399
|
+
skipCloudChecks: Boolean(this.skipCloudChecks),
|
|
3400
|
+
skipSearchIndex: Boolean(this.skipSearchIndex)
|
|
3401
|
+
};
|
|
3402
|
+
this.buildStartedAt = Date.now();
|
|
3403
|
+
postHogCapture(
|
|
3404
|
+
this.posthogClient,
|
|
3405
|
+
this.buildRunId,
|
|
3406
|
+
BuildInvokeEvent,
|
|
3407
|
+
buildInvokeEventPayload
|
|
3408
|
+
);
|
|
3252
3409
|
try {
|
|
3253
3410
|
await configManager.processConfig();
|
|
3254
3411
|
} catch (e) {
|
|
@@ -3257,15 +3414,10 @@ ${dangerText(e.message)}`);
|
|
|
3257
3414
|
logger.error(
|
|
3258
3415
|
dangerText("Unable to build, please fix your Tina config and try again")
|
|
3259
3416
|
);
|
|
3260
|
-
|
|
3417
|
+
throw Object.assign(new Error(e.message), {
|
|
3418
|
+
errorCode: "ERR_CONFIG_LOAD_FAILED"
|
|
3419
|
+
});
|
|
3261
3420
|
}
|
|
3262
|
-
const telemetry = new Telemetry2({ disabled: this.noTelemetry });
|
|
3263
|
-
await telemetry.submitRecord({
|
|
3264
|
-
event: {
|
|
3265
|
-
name: "tinacms:cli:build:invoke",
|
|
3266
|
-
hasLocalContentPath: Boolean(configManager.config.localContentPath)
|
|
3267
|
-
}
|
|
3268
|
-
});
|
|
3269
3421
|
if (localContentOnly && !this.localOption) {
|
|
3270
3422
|
const config2 = configManager.config;
|
|
3271
3423
|
const missing = [];
|
|
@@ -3273,12 +3425,11 @@ ${dangerText(e.message)}`);
|
|
|
3273
3425
|
if (!config2.clientId) missing.push("clientId");
|
|
3274
3426
|
if (!config2.token) missing.push("token");
|
|
3275
3427
|
if (missing.length > 0) {
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
);
|
|
3281
|
-
process.exit(1);
|
|
3428
|
+
const message = `--content=local requires ${missing.join(", ")} to be configured, since the generated client must point to TinaCloud.`;
|
|
3429
|
+
logger.error(`${dangerText(`ERROR: ${message}`)}`);
|
|
3430
|
+
throw Object.assign(new Error(message), {
|
|
3431
|
+
errorCode: "ERR_MISSING_CLOUD_CREDS"
|
|
3432
|
+
});
|
|
3282
3433
|
}
|
|
3283
3434
|
}
|
|
3284
3435
|
let server;
|
|
@@ -3321,7 +3472,9 @@ ${dangerText(e.message)}
|
|
|
3321
3472
|
if (this.verbose) {
|
|
3322
3473
|
console.error(e);
|
|
3323
3474
|
}
|
|
3324
|
-
|
|
3475
|
+
throw Object.assign(new Error(e.message), {
|
|
3476
|
+
errorCode: "ERR_INDEXING_FAILED"
|
|
3477
|
+
});
|
|
3325
3478
|
}
|
|
3326
3479
|
}
|
|
3327
3480
|
if (this.localOption || localContentOnly) {
|
|
@@ -3394,11 +3547,13 @@ ${dangerText(e.message)}
|
|
|
3394
3547
|
if (this.verbose) {
|
|
3395
3548
|
console.error(e);
|
|
3396
3549
|
}
|
|
3397
|
-
|
|
3550
|
+
throw Object.assign(new Error(e.message), {
|
|
3551
|
+
errorCode: "ERR_CLOUD_CHECK_FAILED"
|
|
3552
|
+
});
|
|
3398
3553
|
}
|
|
3399
3554
|
}
|
|
3400
3555
|
await buildProductionSpa(configManager, database, codegen2.productionUrl);
|
|
3401
|
-
await
|
|
3556
|
+
await fs10.outputFile(
|
|
3402
3557
|
configManager.outputGitignorePath,
|
|
3403
3558
|
"index.html\nassets/"
|
|
3404
3559
|
);
|
|
@@ -3466,7 +3621,9 @@ ${dangerText(e.message)}
|
|
|
3466
3621
|
});
|
|
3467
3622
|
if (err) {
|
|
3468
3623
|
logger.error(`${dangerText(`ERROR: ${err.message}`)}`);
|
|
3469
|
-
|
|
3624
|
+
throw Object.assign(new Error(err.message), {
|
|
3625
|
+
errorCode: "ERR_SEARCH_INDEX_FAILED"
|
|
3626
|
+
});
|
|
3470
3627
|
}
|
|
3471
3628
|
}
|
|
3472
3629
|
const summaryItems = [];
|
|
@@ -3512,6 +3669,11 @@ ${dangerText(e.message)}
|
|
|
3512
3669
|
process.env.NODE_ENV = "production";
|
|
3513
3670
|
}
|
|
3514
3671
|
}
|
|
3672
|
+
postHogCapture(this.posthogClient, this.buildRunId, BuildFinishedEvent, {
|
|
3673
|
+
success: true,
|
|
3674
|
+
durationMs: Date.now() - this.buildStartedAt
|
|
3675
|
+
});
|
|
3676
|
+
if (this.posthogClient) await this.posthogClient.shutdown();
|
|
3515
3677
|
if (this.subCommand) {
|
|
3516
3678
|
await this.startSubCommand();
|
|
3517
3679
|
} else {
|
|
@@ -3776,7 +3938,7 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3776
3938
|
}
|
|
3777
3939
|
const localTinaSchema = JSON.parse(
|
|
3778
3940
|
await database.bridge.get(
|
|
3779
|
-
|
|
3941
|
+
path11.join(database.tinaDirectory, "__generated__", "_schema.json")
|
|
3780
3942
|
)
|
|
3781
3943
|
);
|
|
3782
3944
|
localTinaSchema.version = void 0;
|
|
@@ -3896,7 +4058,7 @@ import { buildSchema as buildSchema3 } from "@tinacms/graphql";
|
|
|
3896
4058
|
|
|
3897
4059
|
// src/next/commands/audit-command/audit.ts
|
|
3898
4060
|
import prompts from "prompts";
|
|
3899
|
-
import { Telemetry as
|
|
4061
|
+
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
3900
4062
|
import { resolve } from "@tinacms/graphql";
|
|
3901
4063
|
import chalk5 from "chalk";
|
|
3902
4064
|
var audit = async ({
|
|
@@ -3906,7 +4068,7 @@ var audit = async ({
|
|
|
3906
4068
|
noTelemetry,
|
|
3907
4069
|
verbose
|
|
3908
4070
|
}) => {
|
|
3909
|
-
const telemetry = new
|
|
4071
|
+
const telemetry = new Telemetry2({ disabled: noTelemetry });
|
|
3910
4072
|
await telemetry.submitRecord({
|
|
3911
4073
|
event: {
|
|
3912
4074
|
name: "tinacms:cli:audit:invoke",
|
|
@@ -4082,7 +4244,7 @@ var AuditCommand = class extends Command4 {
|
|
|
4082
4244
|
description: `Audit config and content files`
|
|
4083
4245
|
});
|
|
4084
4246
|
async catch(error) {
|
|
4085
|
-
logger.error("Error
|
|
4247
|
+
logger.error("Error occurred during tinacms audit");
|
|
4086
4248
|
if (this.verbose) {
|
|
4087
4249
|
console.error(error);
|
|
4088
4250
|
}
|
|
@@ -4139,26 +4301,26 @@ var AuditCommand = class extends Command4 {
|
|
|
4139
4301
|
import { Command as Command6, Option as Option6 } from "clipanion";
|
|
4140
4302
|
|
|
4141
4303
|
// src/cmds/init/detectEnvironment.ts
|
|
4142
|
-
import
|
|
4143
|
-
import
|
|
4304
|
+
import fs11 from "fs-extra";
|
|
4305
|
+
import path12 from "path";
|
|
4144
4306
|
var checkGitignoreForItem = async ({
|
|
4145
4307
|
baseDir,
|
|
4146
4308
|
line
|
|
4147
4309
|
}) => {
|
|
4148
|
-
const gitignoreContent =
|
|
4310
|
+
const gitignoreContent = fs11.readFileSync(path12.join(baseDir, ".gitignore")).toString();
|
|
4149
4311
|
return gitignoreContent.split("\n").some((item) => item === line);
|
|
4150
4312
|
};
|
|
4151
4313
|
var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
4152
4314
|
const result = {
|
|
4153
|
-
fullPathTS:
|
|
4315
|
+
fullPathTS: path12.join(
|
|
4154
4316
|
parentPath,
|
|
4155
4317
|
`${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
|
|
4156
4318
|
),
|
|
4157
|
-
fullPathJS:
|
|
4319
|
+
fullPathJS: path12.join(
|
|
4158
4320
|
parentPath,
|
|
4159
4321
|
`${name2}.${opts?.extensionOverride || "js"}`
|
|
4160
4322
|
),
|
|
4161
|
-
fullPathOverride: opts?.extensionOverride ?
|
|
4323
|
+
fullPathOverride: opts?.extensionOverride ? path12.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
|
|
4162
4324
|
generatedFileType,
|
|
4163
4325
|
name: name2,
|
|
4164
4326
|
parentPath,
|
|
@@ -4176,8 +4338,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
|
4176
4338
|
};
|
|
4177
4339
|
}
|
|
4178
4340
|
};
|
|
4179
|
-
result.typescriptExists = await
|
|
4180
|
-
result.javascriptExists = await
|
|
4341
|
+
result.typescriptExists = await fs11.pathExists(result.fullPathTS);
|
|
4342
|
+
result.javascriptExists = await fs11.pathExists(result.fullPathJS);
|
|
4181
4343
|
return result;
|
|
4182
4344
|
};
|
|
4183
4345
|
var detectEnvironment = async ({
|
|
@@ -4186,21 +4348,21 @@ var detectEnvironment = async ({
|
|
|
4186
4348
|
rootPath,
|
|
4187
4349
|
debug = false
|
|
4188
4350
|
}) => {
|
|
4189
|
-
const hasForestryConfig = await
|
|
4190
|
-
|
|
4351
|
+
const hasForestryConfig = await fs11.pathExists(
|
|
4352
|
+
path12.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
4191
4353
|
);
|
|
4192
|
-
const sampleContentPath =
|
|
4354
|
+
const sampleContentPath = path12.join(
|
|
4193
4355
|
baseDir,
|
|
4194
4356
|
"content",
|
|
4195
4357
|
"posts",
|
|
4196
4358
|
"hello-world.md"
|
|
4197
4359
|
);
|
|
4198
|
-
const usingSrc =
|
|
4199
|
-
const tinaFolder =
|
|
4360
|
+
const usingSrc = fs11.pathExistsSync(path12.join(baseDir, "src")) && (fs11.pathExistsSync(path12.join(baseDir, "src", "app")) || fs11.pathExistsSync(path12.join(baseDir, "src", "pages")));
|
|
4361
|
+
const tinaFolder = path12.join(baseDir, "tina");
|
|
4200
4362
|
const tinaConfigExists = Boolean(
|
|
4201
4363
|
// Does the tina folder exist?
|
|
4202
|
-
await
|
|
4203
|
-
(await
|
|
4364
|
+
await fs11.pathExists(tinaFolder) && // Does the tina folder contain a config file?
|
|
4365
|
+
(await fs11.readdir(tinaFolder)).find((x) => x.includes("config"))
|
|
4204
4366
|
);
|
|
4205
4367
|
const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
|
|
4206
4368
|
Boolean
|
|
@@ -4212,12 +4374,12 @@ var detectEnvironment = async ({
|
|
|
4212
4374
|
"next-api-handler": await makeGeneratedFile(
|
|
4213
4375
|
"[...routes]",
|
|
4214
4376
|
"next-api-handler",
|
|
4215
|
-
|
|
4377
|
+
path12.join(...pagesDir, "api", "tina")
|
|
4216
4378
|
),
|
|
4217
4379
|
"reactive-example": await makeGeneratedFile(
|
|
4218
4380
|
"[filename]",
|
|
4219
4381
|
"reactive-example",
|
|
4220
|
-
|
|
4382
|
+
path12.join(...pagesDir, "demo", "blog"),
|
|
4221
4383
|
{
|
|
4222
4384
|
typescriptSuffix: "tsx"
|
|
4223
4385
|
}
|
|
@@ -4225,22 +4387,22 @@ var detectEnvironment = async ({
|
|
|
4225
4387
|
"users-json": await makeGeneratedFile(
|
|
4226
4388
|
"index",
|
|
4227
4389
|
"users-json",
|
|
4228
|
-
|
|
4390
|
+
path12.join(baseDir, "content", "users"),
|
|
4229
4391
|
{ extensionOverride: "json" }
|
|
4230
4392
|
),
|
|
4231
4393
|
"sample-content": await makeGeneratedFile(
|
|
4232
4394
|
"hello-world",
|
|
4233
4395
|
"sample-content",
|
|
4234
|
-
|
|
4396
|
+
path12.join(baseDir, "content", "posts"),
|
|
4235
4397
|
{ extensionOverride: "md" }
|
|
4236
4398
|
)
|
|
4237
4399
|
};
|
|
4238
|
-
const hasSampleContent = await
|
|
4239
|
-
const hasPackageJSON = await
|
|
4400
|
+
const hasSampleContent = await fs11.pathExists(sampleContentPath);
|
|
4401
|
+
const hasPackageJSON = await fs11.pathExists("package.json");
|
|
4240
4402
|
let hasTinaDeps = false;
|
|
4241
4403
|
if (hasPackageJSON) {
|
|
4242
4404
|
try {
|
|
4243
|
-
const packageJSON = await
|
|
4405
|
+
const packageJSON = await fs11.readJSON("package.json");
|
|
4244
4406
|
const deps = [];
|
|
4245
4407
|
if (packageJSON?.dependencies) {
|
|
4246
4408
|
deps.push(...Object.keys(packageJSON.dependencies));
|
|
@@ -4257,15 +4419,19 @@ var detectEnvironment = async ({
|
|
|
4257
4419
|
);
|
|
4258
4420
|
}
|
|
4259
4421
|
}
|
|
4260
|
-
const hasGitIgnore = await
|
|
4422
|
+
const hasGitIgnore = await fs11.pathExists(path12.join(".gitignore"));
|
|
4261
4423
|
const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
|
|
4262
4424
|
const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
|
|
4263
4425
|
const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
|
|
4426
|
+
const hasGitIgnoreTinaGenerated = hasGitIgnore && await checkGitignoreForItem({
|
|
4427
|
+
baseDir,
|
|
4428
|
+
line: "tina/__generated__"
|
|
4429
|
+
});
|
|
4264
4430
|
let frontMatterFormat;
|
|
4265
4431
|
if (hasForestryConfig) {
|
|
4266
|
-
const hugoConfigPath =
|
|
4267
|
-
if (await
|
|
4268
|
-
const hugoConfig = await
|
|
4432
|
+
const hugoConfigPath = path12.join(rootPath, "config.toml");
|
|
4433
|
+
if (await fs11.pathExists(hugoConfigPath)) {
|
|
4434
|
+
const hugoConfig = await fs11.readFile(hugoConfigPath, "utf8");
|
|
4269
4435
|
const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
|
|
4270
4436
|
if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
|
|
4271
4437
|
frontMatterFormat = metaDataFormat;
|
|
@@ -4279,6 +4445,7 @@ var detectEnvironment = async ({
|
|
|
4279
4445
|
gitIgnoreNodeModulesExists: hasGitIgnoreNodeModules,
|
|
4280
4446
|
gitIgnoreEnvExists: hasGitIgnoreEnv,
|
|
4281
4447
|
gitIgnoreTinaEnvExists: hasEnvTina,
|
|
4448
|
+
gitIgnoreTinaGeneratedExists: hasGitIgnoreTinaGenerated,
|
|
4282
4449
|
packageJSONExists: hasPackageJSON,
|
|
4283
4450
|
sampleContentExists: hasSampleContent,
|
|
4284
4451
|
sampleContentPath,
|
|
@@ -4878,19 +5045,19 @@ var CLICommand = class {
|
|
|
4878
5045
|
};
|
|
4879
5046
|
|
|
4880
5047
|
// src/cmds/init/apply.ts
|
|
4881
|
-
import
|
|
5048
|
+
import path16 from "path";
|
|
4882
5049
|
|
|
4883
5050
|
// src/cmds/forestry-migrate/index.ts
|
|
4884
|
-
import
|
|
4885
|
-
import
|
|
5051
|
+
import fs13 from "fs-extra";
|
|
5052
|
+
import path14 from "path";
|
|
4886
5053
|
import yaml2 from "js-yaml";
|
|
4887
5054
|
import pkg from "minimatch";
|
|
4888
5055
|
import { parseFile, stringifyFile } from "@tinacms/graphql";
|
|
4889
5056
|
import { CONTENT_FORMATS } from "@tinacms/schema-tools";
|
|
4890
5057
|
|
|
4891
5058
|
// src/cmds/forestry-migrate/util/index.ts
|
|
4892
|
-
import
|
|
4893
|
-
import
|
|
5059
|
+
import fs12 from "fs-extra";
|
|
5060
|
+
import path13 from "path";
|
|
4894
5061
|
import yaml from "js-yaml";
|
|
4895
5062
|
import z2 from "zod";
|
|
4896
5063
|
|
|
@@ -5317,7 +5484,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
5317
5484
|
return tinaFields;
|
|
5318
5485
|
};
|
|
5319
5486
|
var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
|
|
5320
|
-
const templatePath =
|
|
5487
|
+
const templatePath = path13.join(
|
|
5321
5488
|
pathToForestryConfig,
|
|
5322
5489
|
".forestry",
|
|
5323
5490
|
"front_matter",
|
|
@@ -5326,7 +5493,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
5326
5493
|
);
|
|
5327
5494
|
let templateString = "";
|
|
5328
5495
|
try {
|
|
5329
|
-
templateString =
|
|
5496
|
+
templateString = fs12.readFileSync(templatePath).toString();
|
|
5330
5497
|
} catch {
|
|
5331
5498
|
throw new Error(
|
|
5332
5499
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -5392,9 +5559,9 @@ function checkExt(ext) {
|
|
|
5392
5559
|
var generateAllTemplates = async ({
|
|
5393
5560
|
pathToForestryConfig
|
|
5394
5561
|
}) => {
|
|
5395
|
-
const allTemplates = (await
|
|
5396
|
-
|
|
5397
|
-
)).map((tem) =>
|
|
5562
|
+
const allTemplates = (await fs13.readdir(
|
|
5563
|
+
path14.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
|
|
5564
|
+
)).map((tem) => path14.basename(tem, ".yml"));
|
|
5398
5565
|
const templateMap = /* @__PURE__ */ new Map();
|
|
5399
5566
|
const proms = allTemplates.map(async (tem) => {
|
|
5400
5567
|
try {
|
|
@@ -5539,9 +5706,9 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5539
5706
|
return c;
|
|
5540
5707
|
} else if (section.type === "document") {
|
|
5541
5708
|
const filePath = section.path;
|
|
5542
|
-
const extname =
|
|
5543
|
-
const fileName =
|
|
5544
|
-
const dir =
|
|
5709
|
+
const extname = path14.extname(filePath);
|
|
5710
|
+
const fileName = path14.basename(filePath, extname);
|
|
5711
|
+
const dir = path14.dirname(filePath);
|
|
5545
5712
|
const ext = checkExt(extname);
|
|
5546
5713
|
if (ext) {
|
|
5547
5714
|
const fields = [];
|
|
@@ -5603,8 +5770,8 @@ var generateCollections = async ({
|
|
|
5603
5770
|
templateMap,
|
|
5604
5771
|
usingTypescript
|
|
5605
5772
|
});
|
|
5606
|
-
const forestryConfig = await
|
|
5607
|
-
|
|
5773
|
+
const forestryConfig = await fs13.readFile(
|
|
5774
|
+
path14.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
5608
5775
|
);
|
|
5609
5776
|
rewriteTemplateKeysInDocs({
|
|
5610
5777
|
templateMap,
|
|
@@ -5634,12 +5801,12 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5634
5801
|
const { templateObj } = templateMap.get(templateKey);
|
|
5635
5802
|
templateObj?.pages?.forEach((page) => {
|
|
5636
5803
|
try {
|
|
5637
|
-
const filePath =
|
|
5638
|
-
if (
|
|
5804
|
+
const filePath = path14.join(page);
|
|
5805
|
+
if (fs13.lstatSync(filePath).isDirectory()) {
|
|
5639
5806
|
return;
|
|
5640
5807
|
}
|
|
5641
|
-
const extname =
|
|
5642
|
-
const fileContent =
|
|
5808
|
+
const extname = path14.extname(filePath);
|
|
5809
|
+
const fileContent = fs13.readFileSync(filePath).toString();
|
|
5643
5810
|
const content = parseFile(
|
|
5644
5811
|
fileContent,
|
|
5645
5812
|
extname,
|
|
@@ -5650,7 +5817,7 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5650
5817
|
_template: stringifyLabel(templateKey),
|
|
5651
5818
|
...content
|
|
5652
5819
|
};
|
|
5653
|
-
|
|
5820
|
+
fs13.writeFileSync(
|
|
5654
5821
|
filePath,
|
|
5655
5822
|
stringifyFile(newContent, extname, true, markdownParseConfig)
|
|
5656
5823
|
);
|
|
@@ -5664,13 +5831,13 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5664
5831
|
};
|
|
5665
5832
|
|
|
5666
5833
|
// src/cmds/init/apply.ts
|
|
5667
|
-
import { Telemetry as
|
|
5668
|
-
import
|
|
5834
|
+
import { Telemetry as Telemetry3 } from "@tinacms/metrics";
|
|
5835
|
+
import fs16 from "fs-extra";
|
|
5669
5836
|
|
|
5670
5837
|
// src/next/commands/codemod-command/index.ts
|
|
5671
5838
|
import { Command as Command5, Option as Option5 } from "clipanion";
|
|
5672
|
-
import
|
|
5673
|
-
import
|
|
5839
|
+
import fs14 from "fs-extra";
|
|
5840
|
+
import path15 from "path";
|
|
5674
5841
|
var CodemodCommand = class extends Command5 {
|
|
5675
5842
|
static paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5676
5843
|
rootPath = Option5.String("--rootPath", {
|
|
@@ -5711,13 +5878,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5711
5878
|
logger.error(e.message);
|
|
5712
5879
|
process.exit(1);
|
|
5713
5880
|
}
|
|
5714
|
-
const tinaDestination =
|
|
5715
|
-
if (await
|
|
5881
|
+
const tinaDestination = path15.join(configManager.rootPath, "tina");
|
|
5882
|
+
if (await fs14.existsSync(tinaDestination)) {
|
|
5716
5883
|
logger.info(
|
|
5717
5884
|
`Folder already exists at ${tinaDestination}. Either delete this folder to complete the codemod, or ensure you have properly copied your config from the ".tina" folder.`
|
|
5718
5885
|
);
|
|
5719
5886
|
} else {
|
|
5720
|
-
await
|
|
5887
|
+
await fs14.moveSync(configManager.tinaFolderPath, tinaDestination);
|
|
5721
5888
|
await writeGitignore(configManager.rootPath);
|
|
5722
5889
|
logger.info(
|
|
5723
5890
|
"Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
|
|
@@ -5725,8 +5892,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5725
5892
|
}
|
|
5726
5893
|
};
|
|
5727
5894
|
var writeGitignore = async (rootPath) => {
|
|
5728
|
-
await
|
|
5729
|
-
|
|
5895
|
+
await fs14.outputFileSync(
|
|
5896
|
+
path15.join(rootPath, "tina", ".gitignore"),
|
|
5730
5897
|
"__generated__"
|
|
5731
5898
|
);
|
|
5732
5899
|
};
|
|
@@ -6164,7 +6331,7 @@ function extendNextScripts(scripts, opts) {
|
|
|
6164
6331
|
|
|
6165
6332
|
// src/cmds/init/codegen/index.ts
|
|
6166
6333
|
import ts2 from "typescript";
|
|
6167
|
-
import
|
|
6334
|
+
import fs15 from "fs-extra";
|
|
6168
6335
|
|
|
6169
6336
|
// src/cmds/init/codegen/util.ts
|
|
6170
6337
|
import ts from "typescript";
|
|
@@ -6401,7 +6568,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6401
6568
|
const pathToConfig = configFile.resolve(config2.typescript).path;
|
|
6402
6569
|
const sourceFile = ts2.createSourceFile(
|
|
6403
6570
|
pathToConfig,
|
|
6404
|
-
|
|
6571
|
+
fs15.readFileSync(pathToConfig, "utf8"),
|
|
6405
6572
|
config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
|
|
6406
6573
|
);
|
|
6407
6574
|
const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
|
|
@@ -6451,7 +6618,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6451
6618
|
)
|
|
6452
6619
|
].map((visitor) => makeTransformer(visitor))
|
|
6453
6620
|
);
|
|
6454
|
-
return
|
|
6621
|
+
return fs15.writeFile(
|
|
6455
6622
|
pathToConfig,
|
|
6456
6623
|
ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
|
|
6457
6624
|
);
|
|
@@ -6508,6 +6675,9 @@ async function apply({
|
|
|
6508
6675
|
if (!env.gitIgnoreEnvExists) {
|
|
6509
6676
|
itemsToAdd.push(".env");
|
|
6510
6677
|
}
|
|
6678
|
+
if (!env.gitIgnoreTinaGeneratedExists) {
|
|
6679
|
+
itemsToAdd.push("tina/__generated__");
|
|
6680
|
+
}
|
|
6511
6681
|
if (itemsToAdd.length > 0) {
|
|
6512
6682
|
await updateGitIgnore({ baseDir, items: itemsToAdd });
|
|
6513
6683
|
}
|
|
@@ -6569,8 +6739,8 @@ async function apply({
|
|
|
6569
6739
|
await addConfigFile({
|
|
6570
6740
|
configArgs: {
|
|
6571
6741
|
config: config2,
|
|
6572
|
-
publicFolder:
|
|
6573
|
-
|
|
6742
|
+
publicFolder: path16.join(
|
|
6743
|
+
path16.relative(process.cwd(), pathToForestryConfig),
|
|
6574
6744
|
config2.publicFolder
|
|
6575
6745
|
),
|
|
6576
6746
|
collections,
|
|
@@ -6627,7 +6797,7 @@ var reportTelemetry = async ({
|
|
|
6627
6797
|
if (noTelemetry) {
|
|
6628
6798
|
logger.info(logText("Telemetry disabled"));
|
|
6629
6799
|
}
|
|
6630
|
-
const telemetry = new
|
|
6800
|
+
const telemetry = new Telemetry3({ disabled: noTelemetry });
|
|
6631
6801
|
const schemaFileType = usingTypescript ? "ts" : "js";
|
|
6632
6802
|
await telemetry.submitRecord({
|
|
6633
6803
|
event: {
|
|
@@ -6643,18 +6813,21 @@ var createPackageJSON = async () => {
|
|
|
6643
6813
|
};
|
|
6644
6814
|
var createGitignore = async ({ baseDir }) => {
|
|
6645
6815
|
logger.info(logText("No .gitignore found, creating one"));
|
|
6646
|
-
|
|
6816
|
+
fs16.outputFileSync(
|
|
6817
|
+
path16.join(baseDir, ".gitignore"),
|
|
6818
|
+
"node_modules\ntina/__generated__\n"
|
|
6819
|
+
);
|
|
6647
6820
|
};
|
|
6648
6821
|
var updateGitIgnore = async ({
|
|
6649
6822
|
baseDir,
|
|
6650
6823
|
items
|
|
6651
6824
|
}) => {
|
|
6652
6825
|
logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
|
|
6653
|
-
const gitignoreContent =
|
|
6826
|
+
const gitignoreContent = fs16.readFileSync(path16.join(baseDir, ".gitignore")).toString();
|
|
6654
6827
|
const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
|
|
6655
6828
|
"\n"
|
|
6656
6829
|
);
|
|
6657
|
-
await
|
|
6830
|
+
await fs16.writeFile(path16.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
6658
6831
|
};
|
|
6659
6832
|
var addDependencies = async (config2, env, params) => {
|
|
6660
6833
|
const { packageManager } = config2;
|
|
@@ -6725,22 +6898,22 @@ var writeGeneratedFile = async ({
|
|
|
6725
6898
|
content,
|
|
6726
6899
|
typescript
|
|
6727
6900
|
}) => {
|
|
6728
|
-
const { exists, path:
|
|
6901
|
+
const { exists, path: path18, parentPath } = generatedFile.resolve(typescript);
|
|
6729
6902
|
if (exists) {
|
|
6730
6903
|
if (overwrite) {
|
|
6731
|
-
logger.info(`Overwriting file at ${
|
|
6732
|
-
|
|
6904
|
+
logger.info(`Overwriting file at ${path18}... \u2705`);
|
|
6905
|
+
fs16.outputFileSync(path18, content);
|
|
6733
6906
|
} else {
|
|
6734
|
-
logger.info(`Not overwriting file at ${
|
|
6907
|
+
logger.info(`Not overwriting file at ${path18}.`);
|
|
6735
6908
|
logger.info(
|
|
6736
|
-
logText(`Please add the following to ${
|
|
6909
|
+
logText(`Please add the following to ${path18}:
|
|
6737
6910
|
${indentText(content)}}`)
|
|
6738
6911
|
);
|
|
6739
6912
|
}
|
|
6740
6913
|
} else {
|
|
6741
|
-
logger.info(`Adding file at ${
|
|
6742
|
-
await
|
|
6743
|
-
|
|
6914
|
+
logger.info(`Adding file at ${path18}... \u2705`);
|
|
6915
|
+
await fs16.ensureDir(parentPath);
|
|
6916
|
+
fs16.outputFileSync(path18, content);
|
|
6744
6917
|
}
|
|
6745
6918
|
};
|
|
6746
6919
|
var addConfigFile = async ({
|
|
@@ -6818,7 +6991,7 @@ var addContentFile = async ({
|
|
|
6818
6991
|
return () => ({
|
|
6819
6992
|
exists: env.sampleContentExists,
|
|
6820
6993
|
path: env.sampleContentPath,
|
|
6821
|
-
parentPath:
|
|
6994
|
+
parentPath: path16.dirname(env.sampleContentPath)
|
|
6822
6995
|
});
|
|
6823
6996
|
}
|
|
6824
6997
|
},
|
|
@@ -6841,10 +7014,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
|
|
|
6841
7014
|
return `${x.key}=${x.value || "***"}`;
|
|
6842
7015
|
}).join("\n") + `
|
|
6843
7016
|
TINA_PUBLIC_IS_LOCAL=true`;
|
|
6844
|
-
const envFile =
|
|
6845
|
-
if (!
|
|
7017
|
+
const envFile = path16.join(process.cwd(), ".env");
|
|
7018
|
+
if (!fs16.existsSync(envFile)) {
|
|
6846
7019
|
logger.info(`Adding .env file to your project... \u2705`);
|
|
6847
|
-
|
|
7020
|
+
fs16.writeFileSync(envFile, envFileText);
|
|
6848
7021
|
} else {
|
|
6849
7022
|
logger.info(
|
|
6850
7023
|
"Please add the following environment variables to your .env file"
|
|
@@ -6913,7 +7086,7 @@ var addReactiveFile = {
|
|
|
6913
7086
|
baseDir,
|
|
6914
7087
|
dataLayer
|
|
6915
7088
|
}) => {
|
|
6916
|
-
const packageJsonPath =
|
|
7089
|
+
const packageJsonPath = path16.join(baseDir, "package.json");
|
|
6917
7090
|
await writeGeneratedFile({
|
|
6918
7091
|
generatedFile,
|
|
6919
7092
|
typescript: config2.typescript,
|
|
@@ -6926,7 +7099,7 @@ var addReactiveFile = {
|
|
|
6926
7099
|
})
|
|
6927
7100
|
});
|
|
6928
7101
|
logger.info("Adding a nextjs example... \u2705");
|
|
6929
|
-
const packageJson = JSON.parse(
|
|
7102
|
+
const packageJson = JSON.parse(fs16.readFileSync(packageJsonPath).toString());
|
|
6930
7103
|
const scripts = packageJson.scripts || {};
|
|
6931
7104
|
const updatedPackageJson = JSON.stringify(
|
|
6932
7105
|
{
|
|
@@ -6939,7 +7112,7 @@ var addReactiveFile = {
|
|
|
6939
7112
|
null,
|
|
6940
7113
|
2
|
|
6941
7114
|
);
|
|
6942
|
-
|
|
7115
|
+
fs16.writeFileSync(packageJsonPath, updatedPackageJson);
|
|
6943
7116
|
}
|
|
6944
7117
|
};
|
|
6945
7118
|
function execShellCommand(cmd) {
|
|
@@ -7010,7 +7183,7 @@ var InitCommand = class extends Command6 {
|
|
|
7010
7183
|
description: `Add Tina to an existing project`
|
|
7011
7184
|
});
|
|
7012
7185
|
async catch(error) {
|
|
7013
|
-
logger.error("Error
|
|
7186
|
+
logger.error("Error occurred during tinacms init");
|
|
7014
7187
|
console.error(error);
|
|
7015
7188
|
process.exit(1);
|
|
7016
7189
|
}
|
|
@@ -7049,7 +7222,7 @@ var SearchIndexCommand = class extends Command7 {
|
|
|
7049
7222
|
description: `Index the site for search`
|
|
7050
7223
|
});
|
|
7051
7224
|
async catch(error) {
|
|
7052
|
-
logger.error("Error
|
|
7225
|
+
logger.error("Error occurred during tinacms search-index");
|
|
7053
7226
|
console.error(error);
|
|
7054
7227
|
process.exit(1);
|
|
7055
7228
|
}
|
|
@@ -7139,8 +7312,8 @@ var SearchIndexCommand = class extends Command7 {
|
|
|
7139
7312
|
import { Command as Command8, Option as Option8 } from "clipanion";
|
|
7140
7313
|
|
|
7141
7314
|
// src/next/commands/doctor-command/doctor.ts
|
|
7142
|
-
import
|
|
7143
|
-
import
|
|
7315
|
+
import path17 from "path";
|
|
7316
|
+
import fs17 from "fs-extra";
|
|
7144
7317
|
import yaml3 from "js-yaml";
|
|
7145
7318
|
var DEPENDENCY_TYPES = [
|
|
7146
7319
|
"dependencies",
|
|
@@ -7173,11 +7346,11 @@ function getTinaDependencies(packageJson) {
|
|
|
7173
7346
|
);
|
|
7174
7347
|
}
|
|
7175
7348
|
async function readProjectPackageJson(rootPath) {
|
|
7176
|
-
const packageJsonPath =
|
|
7177
|
-
if (!await
|
|
7349
|
+
const packageJsonPath = path17.join(rootPath, "package.json");
|
|
7350
|
+
if (!await fs17.pathExists(packageJsonPath)) {
|
|
7178
7351
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
7179
7352
|
}
|
|
7180
|
-
return
|
|
7353
|
+
return fs17.readJSON(packageJsonPath);
|
|
7181
7354
|
}
|
|
7182
7355
|
async function resolveInstalledVersions({
|
|
7183
7356
|
rootPath,
|
|
@@ -7300,14 +7473,14 @@ function isLocalReference(version2) {
|
|
|
7300
7473
|
);
|
|
7301
7474
|
}
|
|
7302
7475
|
async function readNodeModulesVersion(rootPath, packageName) {
|
|
7303
|
-
const packageJsonPath =
|
|
7476
|
+
const packageJsonPath = path17.join(
|
|
7304
7477
|
rootPath,
|
|
7305
7478
|
"node_modules",
|
|
7306
7479
|
...packageName.split("/"),
|
|
7307
7480
|
"package.json"
|
|
7308
7481
|
);
|
|
7309
|
-
if (!await
|
|
7310
|
-
const packageJson = await
|
|
7482
|
+
if (!await fs17.pathExists(packageJsonPath)) return void 0;
|
|
7483
|
+
const packageJson = await fs17.readJSON(packageJsonPath);
|
|
7311
7484
|
return typeof packageJson.version === "string" ? packageJson.version : void 0;
|
|
7312
7485
|
}
|
|
7313
7486
|
async function readLockfileVersions(rootPath) {
|
|
@@ -7323,10 +7496,10 @@ async function readLockfileVersions(rootPath) {
|
|
|
7323
7496
|
return /* @__PURE__ */ new Map();
|
|
7324
7497
|
}
|
|
7325
7498
|
async function readPackageLockVersions(rootPath) {
|
|
7326
|
-
const lockfilePath =
|
|
7499
|
+
const lockfilePath = path17.join(rootPath, "package-lock.json");
|
|
7327
7500
|
const versions = /* @__PURE__ */ new Map();
|
|
7328
|
-
if (!await
|
|
7329
|
-
const lockfile = await
|
|
7501
|
+
if (!await fs17.pathExists(lockfilePath)) return versions;
|
|
7502
|
+
const lockfile = await fs17.readJSON(lockfilePath);
|
|
7330
7503
|
for (const [key, value] of Object.entries(lockfile.packages || {})) {
|
|
7331
7504
|
if (!key.startsWith("node_modules/")) continue;
|
|
7332
7505
|
const name2 = key.replace(/^node_modules\//, "");
|
|
@@ -7344,10 +7517,10 @@ async function readPackageLockVersions(rootPath) {
|
|
|
7344
7517
|
return versions;
|
|
7345
7518
|
}
|
|
7346
7519
|
async function readPnpmLockVersions(rootPath) {
|
|
7347
|
-
const lockfilePath =
|
|
7520
|
+
const lockfilePath = path17.join(rootPath, "pnpm-lock.yaml");
|
|
7348
7521
|
const versions = /* @__PURE__ */ new Map();
|
|
7349
|
-
if (!await
|
|
7350
|
-
const lockfile = yaml3.load(await
|
|
7522
|
+
if (!await fs17.pathExists(lockfilePath)) return versions;
|
|
7523
|
+
const lockfile = yaml3.load(await fs17.readFile(lockfilePath, "utf8"));
|
|
7351
7524
|
const rootImporter = lockfile?.importers?.["."];
|
|
7352
7525
|
for (const dependencyType of DEPENDENCY_TYPES) {
|
|
7353
7526
|
for (const [name2, value] of Object.entries(
|
|
@@ -7367,10 +7540,10 @@ async function readPnpmLockVersions(rootPath) {
|
|
|
7367
7540
|
return versions;
|
|
7368
7541
|
}
|
|
7369
7542
|
async function readYarnLockVersions(rootPath) {
|
|
7370
|
-
const lockfilePath =
|
|
7543
|
+
const lockfilePath = path17.join(rootPath, "yarn.lock");
|
|
7371
7544
|
const versions = /* @__PURE__ */ new Map();
|
|
7372
|
-
if (!await
|
|
7373
|
-
const contents = await
|
|
7545
|
+
if (!await fs17.pathExists(lockfilePath)) return versions;
|
|
7546
|
+
const contents = await fs17.readFile(lockfilePath, "utf8");
|
|
7374
7547
|
if (contents.includes("__metadata:")) {
|
|
7375
7548
|
return readYarnBerryLockVersions(contents);
|
|
7376
7549
|
}
|