@tinacms/cli 2.2.3 → 2.2.5
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/index.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
import { Cli, Builtins } from "clipanion";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "2.2.
|
|
5
|
+
var version = "2.2.5";
|
|
6
6
|
|
|
7
7
|
// src/next/commands/dev-command/index.ts
|
|
8
|
-
import
|
|
8
|
+
import path9 from "path";
|
|
9
9
|
import { FilesystemBridge as FilesystemBridge2, buildSchema } from "@tinacms/graphql";
|
|
10
10
|
import { LocalSearchIndexClient, SearchIndexer } from "@tinacms/search";
|
|
11
11
|
import AsyncLock from "async-lock";
|
|
12
12
|
import chokidar from "chokidar";
|
|
13
13
|
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
14
|
-
import
|
|
14
|
+
import fs8 from "fs-extra";
|
|
15
15
|
|
|
16
16
|
// src/logger/index.ts
|
|
17
17
|
import chalk from "chalk";
|
|
@@ -472,22 +472,28 @@ var Codegen = class {
|
|
|
472
472
|
localUrl;
|
|
473
473
|
// production url
|
|
474
474
|
productionUrl;
|
|
475
|
+
// URL for the local GraphQL server used during --content=local builds
|
|
476
|
+
localBuildUrl;
|
|
475
477
|
graphqlSchemaDoc;
|
|
476
478
|
tinaSchema;
|
|
477
479
|
lookup;
|
|
478
480
|
noClientBuildCache;
|
|
481
|
+
// When true, queries run locally but the generated client points to TinaCloud
|
|
482
|
+
localContentBuild;
|
|
479
483
|
constructor({
|
|
480
484
|
configManager,
|
|
481
485
|
port,
|
|
482
486
|
queryDoc,
|
|
483
487
|
fragDoc,
|
|
484
488
|
isLocal,
|
|
489
|
+
localContentBuild,
|
|
485
490
|
graphqlSchemaDoc,
|
|
486
491
|
tinaSchema,
|
|
487
492
|
lookup,
|
|
488
493
|
noClientBuildCache
|
|
489
494
|
}) {
|
|
490
495
|
this.isLocal = isLocal;
|
|
496
|
+
this.localContentBuild = localContentBuild || false;
|
|
491
497
|
this.graphqlSchemaDoc = graphqlSchemaDoc;
|
|
492
498
|
this.configManager = configManager;
|
|
493
499
|
this.port = port;
|
|
@@ -536,10 +542,11 @@ var Codegen = class {
|
|
|
536
542
|
JSON.stringify(this.tinaSchema.schema)
|
|
537
543
|
);
|
|
538
544
|
await this.writeConfigFile("_lookup.json", JSON.stringify(this.lookup));
|
|
539
|
-
const { apiURL, localUrl, tinaCloudUrl } = this._createApiUrl();
|
|
545
|
+
const { apiURL, localUrl, tinaCloudUrl, localBuildUrl } = this._createApiUrl();
|
|
540
546
|
this.apiURL = apiURL;
|
|
541
547
|
this.localUrl = localUrl;
|
|
542
548
|
this.productionUrl = tinaCloudUrl;
|
|
549
|
+
this.localBuildUrl = localBuildUrl;
|
|
543
550
|
if (this.configManager.shouldSkipSDK()) {
|
|
544
551
|
await this.removeGeneratedFilesIfExists();
|
|
545
552
|
return apiURL;
|
|
@@ -638,13 +645,19 @@ var Codegen = class {
|
|
|
638
645
|
}
|
|
639
646
|
let localUrl = `http://localhost:${this.port}/graphql`;
|
|
640
647
|
let tinaCloudUrl = `${baseUrl}/${version2}/content/${clientId}/github/${branch}`;
|
|
641
|
-
let apiURL
|
|
648
|
+
let apiURL;
|
|
649
|
+
if (this.isLocal && !this.localContentBuild) {
|
|
650
|
+
apiURL = `http://localhost:${this.port}/graphql`;
|
|
651
|
+
} else {
|
|
652
|
+
apiURL = `${baseUrl}/${version2}/content/${clientId}/github/${branch}`;
|
|
653
|
+
}
|
|
642
654
|
if (this.configManager.config.contentApiUrlOverride) {
|
|
643
655
|
apiURL = this.configManager.config.contentApiUrlOverride;
|
|
644
656
|
localUrl = apiURL;
|
|
645
657
|
tinaCloudUrl = apiURL;
|
|
646
658
|
}
|
|
647
|
-
|
|
659
|
+
const localBuildUrl = this.port ? `http://localhost:${this.port}/graphql` : void 0;
|
|
660
|
+
return { apiURL, localUrl, tinaCloudUrl, localBuildUrl };
|
|
648
661
|
}
|
|
649
662
|
getApiURL() {
|
|
650
663
|
if (!this.apiURL)
|
|
@@ -747,7 +760,7 @@ export default databaseClient;
|
|
|
747
760
|
import { queries } from "./types";
|
|
748
761
|
export const client = createClient({ ${this.noClientBuildCache === false ? `cacheDir: '${normalizePath(
|
|
749
762
|
this.configManager.generatedCachePath
|
|
750
|
-
)}', ` : ""}url: '${apiURL}', token: '${token}', queries, ${errorPolicy ? `errorPolicy: '${errorPolicy}'` : ""} });
|
|
763
|
+
)}', ` : ""}url: ${this.localContentBuild ? `process.env.TINA_LOCAL_URL || '${apiURL}'` : `'${apiURL}'`}, token: '${token}', queries, ${errorPolicy ? `errorPolicy: '${errorPolicy}'` : ""} });
|
|
751
764
|
export default client;
|
|
752
765
|
`;
|
|
753
766
|
return { apiURL, clientString };
|
|
@@ -806,16 +819,22 @@ var unlinkIfExists = async (filepath) => {
|
|
|
806
819
|
};
|
|
807
820
|
|
|
808
821
|
// src/next/config-manager.ts
|
|
809
|
-
import
|
|
810
|
-
import
|
|
822
|
+
import fs3 from "fs-extra";
|
|
823
|
+
import path4 from "path";
|
|
811
824
|
import os from "os";
|
|
812
825
|
import { pathToFileURL } from "url";
|
|
813
826
|
import * as esbuild from "esbuild";
|
|
814
827
|
import * as dotenv from "dotenv";
|
|
815
828
|
import normalizePath2 from "normalize-path";
|
|
816
|
-
import
|
|
829
|
+
import chalk4 from "chalk";
|
|
817
830
|
import { createRequire } from "module";
|
|
818
831
|
|
|
832
|
+
// src/next/resolve-content-root.ts
|
|
833
|
+
import fs2 from "fs-extra";
|
|
834
|
+
import path3 from "path";
|
|
835
|
+
import chalk3 from "chalk";
|
|
836
|
+
import { z } from "zod";
|
|
837
|
+
|
|
819
838
|
// src/utils/path.ts
|
|
820
839
|
import path2 from "path";
|
|
821
840
|
function stripNativeTrailingSlash(p) {
|
|
@@ -835,6 +854,33 @@ var PathTraversalError = class extends Error {
|
|
|
835
854
|
}
|
|
836
855
|
};
|
|
837
856
|
|
|
857
|
+
// src/next/resolve-content-root.ts
|
|
858
|
+
var localContentPathSchema = z.string().min(1).optional();
|
|
859
|
+
async function resolveContentRootPath(params) {
|
|
860
|
+
const localContentPath = localContentPathSchema.parse(
|
|
861
|
+
params.localContentPath
|
|
862
|
+
);
|
|
863
|
+
if (!localContentPath) {
|
|
864
|
+
return params.rootPath;
|
|
865
|
+
}
|
|
866
|
+
const fullLocalContentPath = stripNativeTrailingSlash(
|
|
867
|
+
path3.join(params.tinaFolderPath, localContentPath)
|
|
868
|
+
);
|
|
869
|
+
const exists = await fs2.pathExists(fullLocalContentPath);
|
|
870
|
+
if (exists) {
|
|
871
|
+
logger.info(`Using separate content repo at ${fullLocalContentPath}`);
|
|
872
|
+
return fullLocalContentPath;
|
|
873
|
+
}
|
|
874
|
+
logger.warn(
|
|
875
|
+
`${chalk3.yellow("Warning:")} The localContentPath ${chalk3.cyan(
|
|
876
|
+
fullLocalContentPath
|
|
877
|
+
)} does not exist. Please create it or remove the localContentPath from your config file at ${chalk3.cyan(
|
|
878
|
+
params.tinaConfigFilePath
|
|
879
|
+
)}`
|
|
880
|
+
);
|
|
881
|
+
return params.rootPath;
|
|
882
|
+
}
|
|
883
|
+
|
|
838
884
|
// src/next/config-manager.ts
|
|
839
885
|
var TINA_FOLDER = "tina";
|
|
840
886
|
var LEGACY_TINA_FOLDER = ".tina";
|
|
@@ -894,7 +940,7 @@ var ConfigManager = class {
|
|
|
894
940
|
this.legacyNoSDK = legacyNoSDK;
|
|
895
941
|
}
|
|
896
942
|
isUsingTs() {
|
|
897
|
-
return [".ts", ".tsx"].includes(
|
|
943
|
+
return [".ts", ".tsx"].includes(path4.extname(this.tinaConfigFilePath));
|
|
898
944
|
}
|
|
899
945
|
hasSelfHostedConfig() {
|
|
900
946
|
return !!this.selfHostedDatabaseFilePath;
|
|
@@ -911,12 +957,12 @@ var ConfigManager = class {
|
|
|
911
957
|
async processConfig() {
|
|
912
958
|
const require2 = createRequire(import.meta.url);
|
|
913
959
|
this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
|
|
914
|
-
this.envFilePath =
|
|
915
|
-
|
|
960
|
+
this.envFilePath = path4.resolve(
|
|
961
|
+
path4.join(this.tinaFolderPath, "..", ".env")
|
|
916
962
|
);
|
|
917
963
|
dotenv.config({ path: this.envFilePath });
|
|
918
964
|
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
919
|
-
|
|
965
|
+
path4.join(this.tinaFolderPath, "config")
|
|
920
966
|
);
|
|
921
967
|
if (!this.tinaConfigFilePath) {
|
|
922
968
|
throw new Error(
|
|
@@ -924,89 +970,89 @@ var ConfigManager = class {
|
|
|
924
970
|
);
|
|
925
971
|
}
|
|
926
972
|
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
927
|
-
|
|
973
|
+
path4.join(this.tinaFolderPath, "database")
|
|
928
974
|
);
|
|
929
|
-
this.generatedFolderPath =
|
|
930
|
-
this.generatedCachePath =
|
|
975
|
+
this.generatedFolderPath = path4.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
976
|
+
this.generatedCachePath = path4.join(
|
|
931
977
|
this.generatedFolderPath,
|
|
932
978
|
".cache",
|
|
933
979
|
String((/* @__PURE__ */ new Date()).getTime())
|
|
934
980
|
);
|
|
935
|
-
this.generatedGraphQLGQLPath =
|
|
981
|
+
this.generatedGraphQLGQLPath = path4.join(
|
|
936
982
|
this.generatedFolderPath,
|
|
937
983
|
GRAPHQL_GQL_FILE
|
|
938
984
|
);
|
|
939
|
-
this.generatedGraphQLJSONPath =
|
|
985
|
+
this.generatedGraphQLJSONPath = path4.join(
|
|
940
986
|
this.generatedFolderPath,
|
|
941
987
|
GRAPHQL_JSON_FILE
|
|
942
988
|
);
|
|
943
|
-
this.generatedSchemaJSONPath =
|
|
989
|
+
this.generatedSchemaJSONPath = path4.join(
|
|
944
990
|
this.generatedFolderPath,
|
|
945
991
|
SCHEMA_JSON_FILE
|
|
946
992
|
);
|
|
947
|
-
this.generatedLookupJSONPath =
|
|
993
|
+
this.generatedLookupJSONPath = path4.join(
|
|
948
994
|
this.generatedFolderPath,
|
|
949
995
|
LOOKUP_JSON_FILE
|
|
950
996
|
);
|
|
951
|
-
this.generatedQueriesFilePath =
|
|
997
|
+
this.generatedQueriesFilePath = path4.join(
|
|
952
998
|
this.generatedFolderPath,
|
|
953
999
|
"queries.gql"
|
|
954
1000
|
);
|
|
955
|
-
this.generatedFragmentsFilePath =
|
|
1001
|
+
this.generatedFragmentsFilePath = path4.join(
|
|
956
1002
|
this.generatedFolderPath,
|
|
957
1003
|
"frags.gql"
|
|
958
1004
|
);
|
|
959
|
-
this.generatedTypesTSFilePath =
|
|
1005
|
+
this.generatedTypesTSFilePath = path4.join(
|
|
960
1006
|
this.generatedFolderPath,
|
|
961
1007
|
"types.ts"
|
|
962
1008
|
);
|
|
963
|
-
this.generatedTypesJSFilePath =
|
|
1009
|
+
this.generatedTypesJSFilePath = path4.join(
|
|
964
1010
|
this.generatedFolderPath,
|
|
965
1011
|
"types.js"
|
|
966
1012
|
);
|
|
967
|
-
this.generatedTypesDFilePath =
|
|
1013
|
+
this.generatedTypesDFilePath = path4.join(
|
|
968
1014
|
this.generatedFolderPath,
|
|
969
1015
|
"types.d.ts"
|
|
970
1016
|
);
|
|
971
|
-
this.userQueriesAndFragmentsGlob =
|
|
1017
|
+
this.userQueriesAndFragmentsGlob = path4.join(
|
|
972
1018
|
this.tinaFolderPath,
|
|
973
1019
|
"queries/**/*.{graphql,gql}"
|
|
974
1020
|
);
|
|
975
|
-
this.generatedQueriesAndFragmentsGlob =
|
|
1021
|
+
this.generatedQueriesAndFragmentsGlob = path4.join(
|
|
976
1022
|
this.generatedFolderPath,
|
|
977
1023
|
"*.{graphql,gql}"
|
|
978
1024
|
);
|
|
979
|
-
this.generatedClientTSFilePath =
|
|
1025
|
+
this.generatedClientTSFilePath = path4.join(
|
|
980
1026
|
this.generatedFolderPath,
|
|
981
1027
|
"client.ts"
|
|
982
1028
|
);
|
|
983
|
-
this.generatedClientJSFilePath =
|
|
1029
|
+
this.generatedClientJSFilePath = path4.join(
|
|
984
1030
|
this.generatedFolderPath,
|
|
985
1031
|
"client.js"
|
|
986
1032
|
);
|
|
987
|
-
this.generatedClientDFilePath =
|
|
1033
|
+
this.generatedClientDFilePath = path4.join(
|
|
988
1034
|
this.generatedFolderPath,
|
|
989
1035
|
"client.d.ts"
|
|
990
1036
|
);
|
|
991
|
-
this.generatedDatabaseClientDFilePath =
|
|
1037
|
+
this.generatedDatabaseClientDFilePath = path4.join(
|
|
992
1038
|
this.generatedFolderPath,
|
|
993
1039
|
"databaseClient.d.ts"
|
|
994
1040
|
);
|
|
995
|
-
this.generatedDatabaseClientTSFilePath =
|
|
1041
|
+
this.generatedDatabaseClientTSFilePath = path4.join(
|
|
996
1042
|
this.generatedFolderPath,
|
|
997
1043
|
"databaseClient.ts"
|
|
998
1044
|
);
|
|
999
|
-
this.generatedDatabaseClientJSFilePath =
|
|
1045
|
+
this.generatedDatabaseClientJSFilePath = path4.join(
|
|
1000
1046
|
this.generatedFolderPath,
|
|
1001
1047
|
"databaseClient.js"
|
|
1002
1048
|
);
|
|
1003
|
-
const clientExists = this.isUsingTs() ? await
|
|
1049
|
+
const clientExists = this.isUsingTs() ? await fs3.pathExists(this.generatedClientTSFilePath) : await fs3.pathExists(this.generatedClientJSFilePath);
|
|
1004
1050
|
if (!clientExists) {
|
|
1005
1051
|
const file = "export default ()=>({})\nexport const client = ()=>({})";
|
|
1006
1052
|
if (this.isUsingTs()) {
|
|
1007
|
-
await
|
|
1053
|
+
await fs3.outputFile(this.generatedClientTSFilePath, file);
|
|
1008
1054
|
} else {
|
|
1009
|
-
await
|
|
1055
|
+
await fs3.outputFile(this.generatedClientJSFilePath, file);
|
|
1010
1056
|
}
|
|
1011
1057
|
}
|
|
1012
1058
|
const { config: config2, prebuildPath, watchList } = await this.loadConfigFile(
|
|
@@ -1016,62 +1062,47 @@ var ConfigManager = class {
|
|
|
1016
1062
|
this.watchList = watchList;
|
|
1017
1063
|
this.config = config2;
|
|
1018
1064
|
this.prebuildFilePath = prebuildPath;
|
|
1019
|
-
this.publicFolderPath =
|
|
1065
|
+
this.publicFolderPath = path4.join(
|
|
1020
1066
|
this.rootPath,
|
|
1021
1067
|
this.config.build.publicFolder
|
|
1022
1068
|
);
|
|
1023
|
-
this.outputFolderPath =
|
|
1069
|
+
this.outputFolderPath = path4.join(
|
|
1024
1070
|
this.publicFolderPath,
|
|
1025
1071
|
this.config.build.outputFolder
|
|
1026
1072
|
);
|
|
1027
|
-
this.outputHTMLFilePath =
|
|
1028
|
-
this.outputGitignorePath =
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
this.contentRootPath = fullLocalContentPath;
|
|
1037
|
-
} else {
|
|
1038
|
-
logger.warn(
|
|
1039
|
-
`${chalk3.yellow("Warning:")} The localContentPath ${chalk3.cyan(
|
|
1040
|
-
fullLocalContentPath
|
|
1041
|
-
)} does not exist. Please create it or remove the localContentPath from your config file at ${chalk3.cyan(
|
|
1042
|
-
this.tinaConfigFilePath
|
|
1043
|
-
)}`
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
if (!this.contentRootPath) {
|
|
1048
|
-
this.contentRootPath = this.rootPath;
|
|
1049
|
-
}
|
|
1050
|
-
this.generatedFolderPathContentRepo = path3.join(
|
|
1073
|
+
this.outputHTMLFilePath = path4.join(this.outputFolderPath, "index.html");
|
|
1074
|
+
this.outputGitignorePath = path4.join(this.outputFolderPath, ".gitignore");
|
|
1075
|
+
this.contentRootPath = await resolveContentRootPath({
|
|
1076
|
+
rootPath: this.rootPath,
|
|
1077
|
+
tinaFolderPath: this.tinaFolderPath,
|
|
1078
|
+
tinaConfigFilePath: this.tinaConfigFilePath,
|
|
1079
|
+
localContentPath: this.config.localContentPath
|
|
1080
|
+
});
|
|
1081
|
+
this.generatedFolderPathContentRepo = path4.join(
|
|
1051
1082
|
await this.getTinaFolderPath(this.contentRootPath, {
|
|
1052
1083
|
isContentRoot: this.hasSeparateContentRoot()
|
|
1053
1084
|
}),
|
|
1054
1085
|
GENERATED_FOLDER
|
|
1055
1086
|
);
|
|
1056
1087
|
this.spaMainPath = require2.resolve("@tinacms/app");
|
|
1057
|
-
this.spaRootPath =
|
|
1088
|
+
this.spaRootPath = path4.join(this.spaMainPath, "..", "..");
|
|
1058
1089
|
}
|
|
1059
1090
|
async getTinaFolderPath(rootPath, { isContentRoot } = {}) {
|
|
1060
|
-
const tinaFolderPath =
|
|
1061
|
-
const tinaFolderExists = await
|
|
1091
|
+
const tinaFolderPath = path4.join(rootPath, TINA_FOLDER);
|
|
1092
|
+
const tinaFolderExists = await fs3.pathExists(tinaFolderPath);
|
|
1062
1093
|
if (tinaFolderExists) {
|
|
1063
1094
|
this.isUsingLegacyFolder = false;
|
|
1064
1095
|
return tinaFolderPath;
|
|
1065
1096
|
}
|
|
1066
|
-
const legacyFolderPath =
|
|
1067
|
-
const legacyFolderExists = await
|
|
1097
|
+
const legacyFolderPath = path4.join(rootPath, LEGACY_TINA_FOLDER);
|
|
1098
|
+
const legacyFolderExists = await fs3.pathExists(legacyFolderPath);
|
|
1068
1099
|
if (legacyFolderExists) {
|
|
1069
1100
|
this.isUsingLegacyFolder = true;
|
|
1070
1101
|
return legacyFolderPath;
|
|
1071
1102
|
}
|
|
1072
1103
|
if (isContentRoot) {
|
|
1073
1104
|
throw new Error(
|
|
1074
|
-
`Unable to find a ${
|
|
1105
|
+
`Unable to find a ${chalk4.cyan("tina/")} folder in your content root at ${chalk4.cyan(rootPath)}. When using localContentPath, the content directory must contain a ${chalk4.cyan("tina/")} folder for generated files. Create one with: mkdir ${path4.join(rootPath, TINA_FOLDER)}`
|
|
1075
1106
|
);
|
|
1076
1107
|
}
|
|
1077
1108
|
throw new Error(
|
|
@@ -1088,7 +1119,7 @@ var ConfigManager = class {
|
|
|
1088
1119
|
patch: version2[2] || "x"
|
|
1089
1120
|
};
|
|
1090
1121
|
}
|
|
1091
|
-
const generatedSchema =
|
|
1122
|
+
const generatedSchema = fs3.readJSONSync(this.generatedSchemaJSONPath);
|
|
1092
1123
|
if (!generatedSchema || !(typeof generatedSchema?.version !== "undefined")) {
|
|
1093
1124
|
throw new Error(
|
|
1094
1125
|
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
@@ -1135,7 +1166,7 @@ var ConfigManager = class {
|
|
|
1135
1166
|
return;
|
|
1136
1167
|
}
|
|
1137
1168
|
const filepathWithExtension = `${filepath}.${ext}`;
|
|
1138
|
-
const exists =
|
|
1169
|
+
const exists = fs3.existsSync(filepathWithExtension);
|
|
1139
1170
|
if (exists) {
|
|
1140
1171
|
result = filepathWithExtension;
|
|
1141
1172
|
}
|
|
@@ -1144,8 +1175,8 @@ var ConfigManager = class {
|
|
|
1144
1175
|
return result;
|
|
1145
1176
|
}
|
|
1146
1177
|
async loadDatabaseFile() {
|
|
1147
|
-
const tmpdir =
|
|
1148
|
-
const outfile =
|
|
1178
|
+
const tmpdir = path4.join(os.tmpdir(), Date.now().toString());
|
|
1179
|
+
const outfile = path4.join(tmpdir, "database.build.mjs");
|
|
1149
1180
|
await esbuild.build({
|
|
1150
1181
|
entryPoints: [this.selfHostedDatabaseFilePath],
|
|
1151
1182
|
bundle: true,
|
|
@@ -1163,22 +1194,22 @@ var ConfigManager = class {
|
|
|
1163
1194
|
}
|
|
1164
1195
|
});
|
|
1165
1196
|
const result = await import(pathToFileURL(outfile).href);
|
|
1166
|
-
|
|
1197
|
+
fs3.removeSync(outfile);
|
|
1167
1198
|
return result.default;
|
|
1168
1199
|
}
|
|
1169
1200
|
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
1170
|
-
const tmpdir =
|
|
1171
|
-
const preBuildConfigPath =
|
|
1201
|
+
const tmpdir = path4.join(os.tmpdir(), Date.now().toString());
|
|
1202
|
+
const preBuildConfigPath = path4.join(
|
|
1172
1203
|
this.generatedFolderPath,
|
|
1173
1204
|
"config.prebuild.jsx"
|
|
1174
1205
|
);
|
|
1175
|
-
const outfile =
|
|
1176
|
-
const outfile2 =
|
|
1177
|
-
const tempTSConfigFile =
|
|
1206
|
+
const outfile = path4.join(tmpdir, "config.build.jsx");
|
|
1207
|
+
const outfile2 = path4.join(tmpdir, "config.build.mjs");
|
|
1208
|
+
const tempTSConfigFile = path4.join(tmpdir, "tsconfig.json");
|
|
1178
1209
|
const esmRequireBanner = {
|
|
1179
1210
|
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
1180
1211
|
};
|
|
1181
|
-
|
|
1212
|
+
fs3.outputFileSync(tempTSConfigFile, "{}");
|
|
1182
1213
|
const result2 = await esbuild.build({
|
|
1183
1214
|
entryPoints: [configFilePath],
|
|
1184
1215
|
bundle: true,
|
|
@@ -1228,8 +1259,8 @@ var ConfigManager = class {
|
|
|
1228
1259
|
console.error(e);
|
|
1229
1260
|
throw e;
|
|
1230
1261
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1262
|
+
fs3.removeSync(outfile);
|
|
1263
|
+
fs3.removeSync(outfile2);
|
|
1233
1264
|
return {
|
|
1234
1265
|
config: result.default,
|
|
1235
1266
|
prebuildPath: preBuildConfigPath,
|
|
@@ -1320,7 +1351,7 @@ async function createAndInitializeDatabase(configManager, datalayerPort, bridgeO
|
|
|
1320
1351
|
|
|
1321
1352
|
// src/next/commands/baseCommands.ts
|
|
1322
1353
|
import { Command, Option } from "clipanion";
|
|
1323
|
-
import
|
|
1354
|
+
import chalk5 from "chalk";
|
|
1324
1355
|
|
|
1325
1356
|
// src/utils/start-subprocess.ts
|
|
1326
1357
|
import childProcess from "child_process";
|
|
@@ -1354,7 +1385,7 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
1354
1385
|
|
|
1355
1386
|
// src/next/commands/baseCommands.ts
|
|
1356
1387
|
import { getChangedFiles, getSha, shaExists } from "@tinacms/graphql";
|
|
1357
|
-
import
|
|
1388
|
+
import fs4 from "fs-extra";
|
|
1358
1389
|
var BaseCommand = class extends Command {
|
|
1359
1390
|
experimentalDataLayer = Option.Boolean("--experimentalData", {
|
|
1360
1391
|
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
@@ -1388,7 +1419,7 @@ var BaseCommand = class extends Command {
|
|
|
1388
1419
|
if (this.subCommand) {
|
|
1389
1420
|
subProc = await startSubprocess2({ command: this.subCommand });
|
|
1390
1421
|
logger.info(
|
|
1391
|
-
`Running web application with command: ${
|
|
1422
|
+
`Running web application with command: ${chalk5.cyan(this.subCommand)}`
|
|
1392
1423
|
);
|
|
1393
1424
|
}
|
|
1394
1425
|
function exitHandler(options, exitCode) {
|
|
@@ -1436,7 +1467,7 @@ var BaseCommand = class extends Command {
|
|
|
1436
1467
|
const rootPath = configManager.rootPath;
|
|
1437
1468
|
let sha;
|
|
1438
1469
|
try {
|
|
1439
|
-
sha = await getSha({ fs:
|
|
1470
|
+
sha = await getSha({ fs: fs4, dir: rootPath });
|
|
1440
1471
|
} catch (e) {
|
|
1441
1472
|
if (partialReindex) {
|
|
1442
1473
|
console.error(
|
|
@@ -1446,7 +1477,7 @@ var BaseCommand = class extends Command {
|
|
|
1446
1477
|
}
|
|
1447
1478
|
}
|
|
1448
1479
|
const lastSha = await database.getMetadata("lastSha");
|
|
1449
|
-
const exists = lastSha && await shaExists({ fs:
|
|
1480
|
+
const exists = lastSha && await shaExists({ fs: fs4, dir: rootPath, sha: lastSha });
|
|
1450
1481
|
let res;
|
|
1451
1482
|
if (partialReindex && lastSha && exists && sha) {
|
|
1452
1483
|
const pathFilter = {};
|
|
@@ -1461,14 +1492,14 @@ var BaseCommand = class extends Command {
|
|
|
1461
1492
|
};
|
|
1462
1493
|
}
|
|
1463
1494
|
const { added, modified, deleted } = await getChangedFiles({
|
|
1464
|
-
fs:
|
|
1495
|
+
fs: fs4,
|
|
1465
1496
|
dir: rootPath,
|
|
1466
1497
|
from: lastSha,
|
|
1467
1498
|
to: sha,
|
|
1468
1499
|
pathFilter
|
|
1469
1500
|
});
|
|
1470
1501
|
const tinaPathUpdates = modified.filter(
|
|
1471
|
-
(
|
|
1502
|
+
(path16) => path16.startsWith(".tina/__generated__/_schema.json") || path16.startsWith("tina/tina-lock.json")
|
|
1472
1503
|
);
|
|
1473
1504
|
if (tinaPathUpdates.length > 0) {
|
|
1474
1505
|
res = await database.indexContent({
|
|
@@ -1587,9 +1618,9 @@ var devHTML = (port) => `<!DOCTYPE html>
|
|
|
1587
1618
|
import { createServer as createViteServer } from "vite";
|
|
1588
1619
|
|
|
1589
1620
|
// src/next/vite/index.ts
|
|
1590
|
-
import
|
|
1621
|
+
import path6 from "node:path";
|
|
1591
1622
|
import react from "@vitejs/plugin-react";
|
|
1592
|
-
import
|
|
1623
|
+
import fs5 from "fs-extra";
|
|
1593
1624
|
import normalizePath3 from "normalize-path";
|
|
1594
1625
|
import {
|
|
1595
1626
|
splitVendorChunkPlugin
|
|
@@ -1656,7 +1687,7 @@ function filterPublicEnv(env = process.env) {
|
|
|
1656
1687
|
}
|
|
1657
1688
|
|
|
1658
1689
|
// src/next/vite/tailwind.ts
|
|
1659
|
-
import
|
|
1690
|
+
import path5 from "node:path";
|
|
1660
1691
|
import aspectRatio from "@tailwindcss/aspect-ratio";
|
|
1661
1692
|
import containerQueries from "@tailwindcss/container-queries";
|
|
1662
1693
|
import twTypography from "@tailwindcss/typography";
|
|
@@ -1671,7 +1702,7 @@ var tinaTailwind = (spaPath, prebuildFilePath) => {
|
|
|
1671
1702
|
const require2 = createRequire2(import.meta.url);
|
|
1672
1703
|
const plugins = [];
|
|
1673
1704
|
const content = [
|
|
1674
|
-
|
|
1705
|
+
path5.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
1675
1706
|
prebuildFilePath,
|
|
1676
1707
|
require2.resolve("tinacms")
|
|
1677
1708
|
];
|
|
@@ -1935,35 +1966,35 @@ async function listFilesRecursively({
|
|
|
1935
1966
|
config: config2,
|
|
1936
1967
|
roothPath
|
|
1937
1968
|
}) {
|
|
1938
|
-
const fullDirectoryPath =
|
|
1969
|
+
const fullDirectoryPath = path6.join(
|
|
1939
1970
|
roothPath,
|
|
1940
1971
|
config2.publicFolder,
|
|
1941
1972
|
directoryPath
|
|
1942
1973
|
);
|
|
1943
|
-
const exists = await
|
|
1974
|
+
const exists = await fs5.pathExists(fullDirectoryPath);
|
|
1944
1975
|
if (!exists) {
|
|
1945
1976
|
return { "0": [] };
|
|
1946
1977
|
}
|
|
1947
|
-
const items = await
|
|
1978
|
+
const items = await fs5.readdir(fullDirectoryPath);
|
|
1948
1979
|
const staticMediaItems = [];
|
|
1949
1980
|
for (const item of items) {
|
|
1950
|
-
const itemPath =
|
|
1951
|
-
const stats = await
|
|
1981
|
+
const itemPath = path6.join(fullDirectoryPath, item);
|
|
1982
|
+
const stats = await fs5.promises.lstat(itemPath);
|
|
1952
1983
|
const staticMediaItem = {
|
|
1953
1984
|
id: item,
|
|
1954
1985
|
filename: item,
|
|
1955
1986
|
type: stats.isDirectory() ? "dir" : "file",
|
|
1956
1987
|
directory: `${directoryPath.replace(config2.mediaRoot, "")}`,
|
|
1957
|
-
src: `/${
|
|
1988
|
+
src: `/${path6.join(directoryPath, item)}`,
|
|
1958
1989
|
thumbnails: {
|
|
1959
|
-
"75x75": `/${
|
|
1960
|
-
"400x400": `/${
|
|
1961
|
-
"1000x1000": `/${
|
|
1990
|
+
"75x75": `/${path6.join(directoryPath, item)}`,
|
|
1991
|
+
"400x400": `/${path6.join(directoryPath, item)}`,
|
|
1992
|
+
"1000x1000": `/${path6.join(directoryPath, item)}`
|
|
1962
1993
|
}
|
|
1963
1994
|
};
|
|
1964
1995
|
if (stats.isDirectory()) {
|
|
1965
1996
|
staticMediaItem.children = await listFilesRecursively({
|
|
1966
|
-
directoryPath:
|
|
1997
|
+
directoryPath: path6.join(directoryPath, item),
|
|
1967
1998
|
config: config2,
|
|
1968
1999
|
roothPath
|
|
1969
2000
|
});
|
|
@@ -1988,7 +2019,7 @@ var createConfig = async ({
|
|
|
1988
2019
|
rollupOptions
|
|
1989
2020
|
}) => {
|
|
1990
2021
|
const publicEnv = filterPublicEnv();
|
|
1991
|
-
const staticMediaPath =
|
|
2022
|
+
const staticMediaPath = path6.join(
|
|
1992
2023
|
configManager.generatedFolderPath,
|
|
1993
2024
|
"static-media.json"
|
|
1994
2025
|
);
|
|
@@ -1998,21 +2029,21 @@ var createConfig = async ({
|
|
|
1998
2029
|
config: configManager.config.media.tina,
|
|
1999
2030
|
roothPath: configManager.rootPath
|
|
2000
2031
|
});
|
|
2001
|
-
await
|
|
2032
|
+
await fs5.outputFile(staticMediaPath, JSON.stringify(staticMedia, null, 2));
|
|
2002
2033
|
} else {
|
|
2003
|
-
await
|
|
2034
|
+
await fs5.outputFile(staticMediaPath, `[]`);
|
|
2004
2035
|
}
|
|
2005
2036
|
const alias = {
|
|
2006
2037
|
TINA_IMPORT: configManager.prebuildFilePath,
|
|
2007
2038
|
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath,
|
|
2008
2039
|
STATIC_MEDIA_IMPORT: staticMediaPath,
|
|
2009
|
-
crypto:
|
|
2010
|
-
fs:
|
|
2011
|
-
os:
|
|
2012
|
-
path:
|
|
2040
|
+
crypto: path6.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
2041
|
+
fs: path6.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
2042
|
+
os: path6.join(configManager.spaRootPath, "src", "dummy-client.ts"),
|
|
2043
|
+
path: path6.join(configManager.spaRootPath, "src", "dummy-client.ts")
|
|
2013
2044
|
};
|
|
2014
2045
|
if (configManager.shouldSkipSDK()) {
|
|
2015
|
-
alias["CLIENT_IMPORT"] =
|
|
2046
|
+
alias["CLIENT_IMPORT"] = path6.join(
|
|
2016
2047
|
configManager.spaRootPath,
|
|
2017
2048
|
"src",
|
|
2018
2049
|
"dummy-client.ts"
|
|
@@ -2122,8 +2153,8 @@ var createConfig = async ({
|
|
|
2122
2153
|
};
|
|
2123
2154
|
|
|
2124
2155
|
// src/next/vite/plugins.ts
|
|
2125
|
-
import
|
|
2126
|
-
import
|
|
2156
|
+
import fs7 from "fs";
|
|
2157
|
+
import path8 from "path";
|
|
2127
2158
|
import { createFilter } from "@rollup/pluginutils";
|
|
2128
2159
|
import { resolve as gqlResolve } from "@tinacms/graphql";
|
|
2129
2160
|
import bodyParser from "body-parser";
|
|
@@ -2132,11 +2163,11 @@ import { transform as esbuildTransform } from "esbuild";
|
|
|
2132
2163
|
import { transformWithEsbuild } from "vite";
|
|
2133
2164
|
|
|
2134
2165
|
// src/next/commands/dev-command/server/media.ts
|
|
2135
|
-
import
|
|
2166
|
+
import path7, { join } from "path";
|
|
2136
2167
|
import busboy from "busboy";
|
|
2137
|
-
import
|
|
2168
|
+
import fs6 from "fs-extra";
|
|
2138
2169
|
var createMediaRouter = (config2) => {
|
|
2139
|
-
const mediaFolder =
|
|
2170
|
+
const mediaFolder = path7.join(
|
|
2140
2171
|
config2.rootPath,
|
|
2141
2172
|
config2.publicFolder,
|
|
2142
2173
|
config2.mediaRoot
|
|
@@ -2200,8 +2231,8 @@ var createMediaRouter = (config2) => {
|
|
|
2200
2231
|
);
|
|
2201
2232
|
return;
|
|
2202
2233
|
}
|
|
2203
|
-
await
|
|
2204
|
-
file.pipe(
|
|
2234
|
+
await fs6.ensureDir(path7.dirname(saveTo));
|
|
2235
|
+
file.pipe(fs6.createWriteStream(saveTo));
|
|
2205
2236
|
});
|
|
2206
2237
|
bb.on("error", (error) => {
|
|
2207
2238
|
responded = true;
|
|
@@ -2231,18 +2262,18 @@ var parseMediaFolder = (str) => {
|
|
|
2231
2262
|
var ENCODED_TRAVERSAL_RE = /%2e%2e|%2f|%5c/i;
|
|
2232
2263
|
function resolveRealPath(candidate) {
|
|
2233
2264
|
try {
|
|
2234
|
-
return
|
|
2265
|
+
return fs6.realpathSync(candidate);
|
|
2235
2266
|
} catch {
|
|
2236
|
-
const parent =
|
|
2267
|
+
const parent = path7.dirname(candidate);
|
|
2237
2268
|
if (parent === candidate) return candidate;
|
|
2238
|
-
return
|
|
2269
|
+
return path7.join(resolveRealPath(parent), path7.basename(candidate));
|
|
2239
2270
|
}
|
|
2240
2271
|
}
|
|
2241
2272
|
function assertSymlinkWithinBase(resolved, resolvedBase, userPath) {
|
|
2242
2273
|
try {
|
|
2243
|
-
const realBase =
|
|
2274
|
+
const realBase = fs6.realpathSync(resolvedBase);
|
|
2244
2275
|
const realResolved = resolveRealPath(resolved);
|
|
2245
|
-
if (realResolved !== realBase && !realResolved.startsWith(realBase +
|
|
2276
|
+
if (realResolved !== realBase && !realResolved.startsWith(realBase + path7.sep)) {
|
|
2246
2277
|
throw new PathTraversalError(userPath);
|
|
2247
2278
|
}
|
|
2248
2279
|
} catch (err) {
|
|
@@ -2253,13 +2284,13 @@ function resolveWithinBase(userPath, baseDir) {
|
|
|
2253
2284
|
if (ENCODED_TRAVERSAL_RE.test(userPath)) {
|
|
2254
2285
|
throw new PathTraversalError(userPath);
|
|
2255
2286
|
}
|
|
2256
|
-
const resolvedBase =
|
|
2257
|
-
const resolved =
|
|
2287
|
+
const resolvedBase = path7.resolve(baseDir);
|
|
2288
|
+
const resolved = path7.resolve(path7.join(baseDir, userPath));
|
|
2258
2289
|
if (resolved === resolvedBase) {
|
|
2259
2290
|
assertSymlinkWithinBase(resolved, resolvedBase, userPath);
|
|
2260
2291
|
return resolvedBase;
|
|
2261
2292
|
}
|
|
2262
|
-
if (resolved.startsWith(resolvedBase +
|
|
2293
|
+
if (resolved.startsWith(resolvedBase + path7.sep)) {
|
|
2263
2294
|
assertSymlinkWithinBase(resolved, resolvedBase, userPath);
|
|
2264
2295
|
return resolved;
|
|
2265
2296
|
}
|
|
@@ -2269,12 +2300,12 @@ function resolveStrictlyWithinBase(userPath, baseDir) {
|
|
|
2269
2300
|
if (ENCODED_TRAVERSAL_RE.test(userPath)) {
|
|
2270
2301
|
throw new PathTraversalError(userPath);
|
|
2271
2302
|
}
|
|
2272
|
-
const resolvedBase =
|
|
2273
|
-
const resolved =
|
|
2303
|
+
const resolvedBase = path7.resolve(baseDir) + path7.sep;
|
|
2304
|
+
const resolved = path7.resolve(path7.join(baseDir, userPath));
|
|
2274
2305
|
if (!resolved.startsWith(resolvedBase)) {
|
|
2275
2306
|
throw new PathTraversalError(userPath);
|
|
2276
2307
|
}
|
|
2277
|
-
assertSymlinkWithinBase(resolved,
|
|
2308
|
+
assertSymlinkWithinBase(resolved, path7.resolve(baseDir), userPath);
|
|
2278
2309
|
return resolved;
|
|
2279
2310
|
}
|
|
2280
2311
|
var MediaModel = class {
|
|
@@ -2291,16 +2322,16 @@ var MediaModel = class {
|
|
|
2291
2322
|
const mediaBase = join(this.rootPath, this.publicFolder, this.mediaRoot);
|
|
2292
2323
|
const validatedPath = resolveWithinBase(args.searchPath, mediaBase);
|
|
2293
2324
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
2294
|
-
if (!await
|
|
2325
|
+
if (!await fs6.pathExists(validatedPath)) {
|
|
2295
2326
|
return {
|
|
2296
2327
|
files: [],
|
|
2297
2328
|
directories: []
|
|
2298
2329
|
};
|
|
2299
2330
|
}
|
|
2300
|
-
const filesStr = await
|
|
2331
|
+
const filesStr = await fs6.readdir(validatedPath);
|
|
2301
2332
|
const filesProm = filesStr.map(async (file) => {
|
|
2302
2333
|
const filePath = join(validatedPath, file);
|
|
2303
|
-
const stat = await
|
|
2334
|
+
const stat = await fs6.stat(filePath);
|
|
2304
2335
|
let src = `/${file}`;
|
|
2305
2336
|
const isFile = stat.isFile();
|
|
2306
2337
|
if (!isFile) {
|
|
@@ -2359,8 +2390,8 @@ var MediaModel = class {
|
|
|
2359
2390
|
try {
|
|
2360
2391
|
const mediaBase = join(this.rootPath, this.publicFolder, this.mediaRoot);
|
|
2361
2392
|
const file = resolveStrictlyWithinBase(args.searchPath, mediaBase);
|
|
2362
|
-
await
|
|
2363
|
-
await
|
|
2393
|
+
await fs6.stat(file);
|
|
2394
|
+
await fs6.remove(file);
|
|
2364
2395
|
return { ok: true };
|
|
2365
2396
|
} catch (error) {
|
|
2366
2397
|
if (error instanceof PathTraversalError) throw error;
|
|
@@ -2468,7 +2499,7 @@ var transformTsxPlugin = ({
|
|
|
2468
2499
|
const plug = {
|
|
2469
2500
|
name: "transform-tsx",
|
|
2470
2501
|
async transform(code, id) {
|
|
2471
|
-
const extName =
|
|
2502
|
+
const extName = path8.extname(id);
|
|
2472
2503
|
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
2473
2504
|
const result = await esbuildTransform(code, { loader: "tsx" });
|
|
2474
2505
|
return {
|
|
@@ -2579,7 +2610,7 @@ function viteTransformExtension({
|
|
|
2579
2610
|
async transform(code, id) {
|
|
2580
2611
|
if (filter(id)) {
|
|
2581
2612
|
const { transform: transform2 } = await import("@svgr/core");
|
|
2582
|
-
const svgCode = await
|
|
2613
|
+
const svgCode = await fs7.promises.readFile(
|
|
2583
2614
|
id.replace(/\?.*$/, ""),
|
|
2584
2615
|
"utf8"
|
|
2585
2616
|
);
|
|
@@ -2720,13 +2751,13 @@ var DevCommand = class extends BaseCommand {
|
|
|
2720
2751
|
});
|
|
2721
2752
|
const apiURL2 = await codegen2.execute();
|
|
2722
2753
|
if (!configManager.isUsingLegacyFolder) {
|
|
2723
|
-
const schemaObject = await
|
|
2754
|
+
const schemaObject = await fs8.readJSON(
|
|
2724
2755
|
configManager.generatedSchemaJSONPath
|
|
2725
2756
|
);
|
|
2726
|
-
const lookupObject = await
|
|
2757
|
+
const lookupObject = await fs8.readJSON(
|
|
2727
2758
|
configManager.generatedLookupJSONPath
|
|
2728
2759
|
);
|
|
2729
|
-
const graphqlSchemaObject = await
|
|
2760
|
+
const graphqlSchemaObject = await fs8.readJSON(
|
|
2730
2761
|
configManager.generatedGraphQLJSONPath
|
|
2731
2762
|
);
|
|
2732
2763
|
const tinaLockFilename = "tina-lock.json";
|
|
@@ -2735,8 +2766,8 @@ var DevCommand = class extends BaseCommand {
|
|
|
2735
2766
|
lookup: lookupObject,
|
|
2736
2767
|
graphql: graphqlSchemaObject
|
|
2737
2768
|
});
|
|
2738
|
-
|
|
2739
|
-
|
|
2769
|
+
fs8.writeFileSync(
|
|
2770
|
+
path9.join(configManager.tinaFolderPath, tinaLockFilename),
|
|
2740
2771
|
tinaLockContent
|
|
2741
2772
|
);
|
|
2742
2773
|
if (configManager.hasSeparateContentRoot()) {
|
|
@@ -2744,9 +2775,9 @@ var DevCommand = class extends BaseCommand {
|
|
|
2744
2775
|
configManager.contentRootPath,
|
|
2745
2776
|
{ isContentRoot: true }
|
|
2746
2777
|
);
|
|
2747
|
-
const filePath =
|
|
2748
|
-
await
|
|
2749
|
-
await
|
|
2778
|
+
const filePath = path9.join(rootPath, tinaLockFilename);
|
|
2779
|
+
await fs8.ensureFile(filePath);
|
|
2780
|
+
await fs8.outputFile(filePath, tinaLockContent);
|
|
2750
2781
|
}
|
|
2751
2782
|
}
|
|
2752
2783
|
await this.indexContentWithSpinner({
|
|
@@ -2789,8 +2820,8 @@ ${dangerText(e.message)}
|
|
|
2789
2820
|
const { apiURL, graphQLSchema, tinaSchema } = await setup({
|
|
2790
2821
|
firstTime: true
|
|
2791
2822
|
});
|
|
2792
|
-
await
|
|
2793
|
-
await
|
|
2823
|
+
await fs8.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
2824
|
+
await fs8.outputFile(
|
|
2794
2825
|
configManager.outputGitignorePath,
|
|
2795
2826
|
"index.html\nassets/"
|
|
2796
2827
|
);
|
|
@@ -2935,7 +2966,7 @@ ${dangerText(e.message)}
|
|
|
2935
2966
|
watchContentFiles(configManager, database, databaseLock, searchIndexer) {
|
|
2936
2967
|
const collectionContentFiles = [];
|
|
2937
2968
|
configManager.config.schema.collections.forEach((collection) => {
|
|
2938
|
-
const collectionGlob = `${
|
|
2969
|
+
const collectionGlob = `${path9.join(
|
|
2939
2970
|
configManager.contentRootPath,
|
|
2940
2971
|
collection.path
|
|
2941
2972
|
)}/**/*.${collection.format || "md"}`;
|
|
@@ -2985,7 +3016,7 @@ ${dangerText(e.message)}
|
|
|
2985
3016
|
|
|
2986
3017
|
// src/next/commands/build-command/index.ts
|
|
2987
3018
|
import crypto from "crypto";
|
|
2988
|
-
import
|
|
3019
|
+
import path10 from "path";
|
|
2989
3020
|
import { diff } from "@graphql-inspector/core";
|
|
2990
3021
|
import { FilesystemBridge as FilesystemBridge3, buildSchema as buildSchema2 } from "@tinacms/graphql";
|
|
2991
3022
|
import { parseURL as parseURL2 } from "@tinacms/schema-tools";
|
|
@@ -2994,7 +3025,7 @@ import {
|
|
|
2994
3025
|
TinaCMSSearchIndexClient
|
|
2995
3026
|
} from "@tinacms/search";
|
|
2996
3027
|
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
2997
|
-
import
|
|
3028
|
+
import fs9 from "fs-extra";
|
|
2998
3029
|
import {
|
|
2999
3030
|
buildASTSchema as buildASTSchema2,
|
|
3000
3031
|
buildClientSchema,
|
|
@@ -3137,6 +3168,9 @@ var BuildCommand = class extends BaseCommand {
|
|
|
3137
3168
|
localOption = Option3.Boolean("--local", {
|
|
3138
3169
|
description: "Starts local Graphql server and builds the local client instead of production client"
|
|
3139
3170
|
});
|
|
3171
|
+
contentOption = Option3.String("--content", {
|
|
3172
|
+
description: "Source for content during the build. Use `--content=local` to build from local content for fast builds while still generating a production client that connects to TinaCloud when deployed."
|
|
3173
|
+
});
|
|
3140
3174
|
skipIndexing = Option3.Boolean("--skip-indexing", false, {
|
|
3141
3175
|
description: "Skips indexing the content. This can be used for building the site without indexing the content (defaults to false)"
|
|
3142
3176
|
});
|
|
@@ -3199,6 +3233,15 @@ var BuildCommand = class extends BaseCommand {
|
|
|
3199
3233
|
);
|
|
3200
3234
|
process.exit(1);
|
|
3201
3235
|
}
|
|
3236
|
+
if (this.contentOption !== void 0 && this.contentOption !== "local") {
|
|
3237
|
+
logger.error(
|
|
3238
|
+
`${dangerText(
|
|
3239
|
+
`ERROR: --content only accepts 'local'. Received '${this.contentOption}'.`
|
|
3240
|
+
)}`
|
|
3241
|
+
);
|
|
3242
|
+
process.exit(1);
|
|
3243
|
+
}
|
|
3244
|
+
const localContentOnly = this.contentOption === "local";
|
|
3202
3245
|
try {
|
|
3203
3246
|
await configManager.processConfig();
|
|
3204
3247
|
} catch (e) {
|
|
@@ -3209,6 +3252,21 @@ ${dangerText(e.message)}`);
|
|
|
3209
3252
|
);
|
|
3210
3253
|
process.exit(1);
|
|
3211
3254
|
}
|
|
3255
|
+
if (localContentOnly && !this.localOption) {
|
|
3256
|
+
const config2 = configManager.config;
|
|
3257
|
+
const missing = [];
|
|
3258
|
+
if (!config2.branch) missing.push("branch");
|
|
3259
|
+
if (!config2.clientId) missing.push("clientId");
|
|
3260
|
+
if (!config2.token) missing.push("token");
|
|
3261
|
+
if (missing.length > 0) {
|
|
3262
|
+
logger.error(
|
|
3263
|
+
`${dangerText(
|
|
3264
|
+
`ERROR: --content=local requires ${missing.join(", ")} to be configured, since the generated client must point to TinaCloud.`
|
|
3265
|
+
)}`
|
|
3266
|
+
);
|
|
3267
|
+
process.exit(1);
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3212
3270
|
let server;
|
|
3213
3271
|
createDBServer(Number(this.datalayerPort));
|
|
3214
3272
|
const database = await createAndInitializeDatabase(
|
|
@@ -3216,10 +3274,12 @@ ${dangerText(e.message)}`);
|
|
|
3216
3274
|
Number(this.datalayerPort)
|
|
3217
3275
|
);
|
|
3218
3276
|
const { queryDoc, fragDoc, graphQLSchema, tinaSchema, lookup } = await buildSchema2(configManager.config);
|
|
3277
|
+
const useLocalServer = this.localOption || localContentOnly;
|
|
3219
3278
|
const codegen2 = new Codegen({
|
|
3220
3279
|
configManager,
|
|
3221
|
-
port:
|
|
3222
|
-
isLocal:
|
|
3280
|
+
port: useLocalServer ? Number(this.port) : void 0,
|
|
3281
|
+
isLocal: useLocalServer,
|
|
3282
|
+
localContentBuild: localContentOnly && !this.localOption,
|
|
3223
3283
|
queryDoc,
|
|
3224
3284
|
fragDoc,
|
|
3225
3285
|
graphqlSchemaDoc: graphQLSchema,
|
|
@@ -3228,8 +3288,8 @@ ${dangerText(e.message)}`);
|
|
|
3228
3288
|
noClientBuildCache: this.noClientBuildCache
|
|
3229
3289
|
});
|
|
3230
3290
|
const apiURL = await codegen2.execute();
|
|
3231
|
-
if ((configManager.hasSelfHostedConfig() || this.localOption) && !this.skipIndexing) {
|
|
3232
|
-
const text = this.localOption ? void 0 : "Indexing to self-hosted data layer";
|
|
3291
|
+
if ((configManager.hasSelfHostedConfig() || this.localOption || localContentOnly) && !this.skipIndexing) {
|
|
3292
|
+
const text = this.localOption || localContentOnly ? void 0 : "Indexing to self-hosted data layer";
|
|
3233
3293
|
try {
|
|
3234
3294
|
await this.indexContentWithSpinner({
|
|
3235
3295
|
text,
|
|
@@ -3250,12 +3310,13 @@ ${dangerText(e.message)}
|
|
|
3250
3310
|
process.exit(1);
|
|
3251
3311
|
}
|
|
3252
3312
|
}
|
|
3253
|
-
if (this.localOption) {
|
|
3313
|
+
if (this.localOption || localContentOnly) {
|
|
3314
|
+
const serverUrl = codegen2.localBuildUrl || apiURL;
|
|
3254
3315
|
server = await createDevServer(
|
|
3255
3316
|
configManager,
|
|
3256
3317
|
database,
|
|
3257
3318
|
null,
|
|
3258
|
-
|
|
3319
|
+
serverUrl,
|
|
3259
3320
|
true,
|
|
3260
3321
|
(lockedFn) => lockedFn()
|
|
3261
3322
|
);
|
|
@@ -3323,11 +3384,16 @@ ${dangerText(e.message)}
|
|
|
3323
3384
|
}
|
|
3324
3385
|
}
|
|
3325
3386
|
await buildProductionSpa(configManager, database, codegen2.productionUrl);
|
|
3326
|
-
await
|
|
3387
|
+
await fs9.outputFile(
|
|
3327
3388
|
configManager.outputGitignorePath,
|
|
3328
3389
|
"index.html\nassets/"
|
|
3329
3390
|
);
|
|
3330
|
-
if (configManager.config.search && !this.skipSearchIndex
|
|
3391
|
+
if (localContentOnly && configManager.config.search && !this.skipSearchIndex) {
|
|
3392
|
+
logger.warn(
|
|
3393
|
+
`${warnText("WARN: Search indexing skipped when building with --content=local. The search index on TinaCloud was not updated.")}`
|
|
3394
|
+
);
|
|
3395
|
+
}
|
|
3396
|
+
if (configManager.config.search && !this.skipSearchIndex && !this.localOption && !localContentOnly) {
|
|
3331
3397
|
let client;
|
|
3332
3398
|
const hasTinaSearch = Boolean(configManager.config?.search?.tina);
|
|
3333
3399
|
if (hasTinaSearch) {
|
|
@@ -3426,6 +3492,12 @@ ${dangerText(e.message)}
|
|
|
3426
3492
|
...summaryItems
|
|
3427
3493
|
]
|
|
3428
3494
|
});
|
|
3495
|
+
if (localContentOnly && codegen2.localBuildUrl) {
|
|
3496
|
+
process.env.TINA_LOCAL_URL = codegen2.localBuildUrl;
|
|
3497
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV !== "production") {
|
|
3498
|
+
process.env.NODE_ENV = "production";
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3429
3501
|
if (this.subCommand) {
|
|
3430
3502
|
await this.startSubCommand();
|
|
3431
3503
|
} else {
|
|
@@ -3690,7 +3762,7 @@ Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
|
3690
3762
|
}
|
|
3691
3763
|
const localTinaSchema = JSON.parse(
|
|
3692
3764
|
await database.bridge.get(
|
|
3693
|
-
|
|
3765
|
+
path10.join(database.tinaDirectory, "__generated__", "_schema.json")
|
|
3694
3766
|
)
|
|
3695
3767
|
);
|
|
3696
3768
|
localTinaSchema.version = void 0;
|
|
@@ -3812,7 +3884,7 @@ import { buildSchema as buildSchema3 } from "@tinacms/graphql";
|
|
|
3812
3884
|
import prompts from "prompts";
|
|
3813
3885
|
import { Telemetry } from "@tinacms/metrics";
|
|
3814
3886
|
import { resolve } from "@tinacms/graphql";
|
|
3815
|
-
import
|
|
3887
|
+
import chalk6 from "chalk";
|
|
3816
3888
|
var audit = async ({
|
|
3817
3889
|
database,
|
|
3818
3890
|
clean,
|
|
@@ -3830,7 +3902,7 @@ var audit = async ({
|
|
|
3830
3902
|
});
|
|
3831
3903
|
if (clean) {
|
|
3832
3904
|
logger.info(
|
|
3833
|
-
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${
|
|
3905
|
+
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${chalk6.bold(
|
|
3834
3906
|
"clean git tree"
|
|
3835
3907
|
)} so unwanted changes can be undone.
|
|
3836
3908
|
|
|
@@ -3842,13 +3914,13 @@ var audit = async ({
|
|
|
3842
3914
|
message: `Do you want to continue?`
|
|
3843
3915
|
});
|
|
3844
3916
|
if (!res.useClean) {
|
|
3845
|
-
logger.warn(
|
|
3917
|
+
logger.warn(chalk6.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
3846
3918
|
process.exit(0);
|
|
3847
3919
|
}
|
|
3848
3920
|
}
|
|
3849
3921
|
if (useDefaultValues && !clean) {
|
|
3850
3922
|
logger.warn(
|
|
3851
|
-
|
|
3923
|
+
chalk6.yellowBright(
|
|
3852
3924
|
"WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"
|
|
3853
3925
|
)
|
|
3854
3926
|
);
|
|
@@ -3876,10 +3948,10 @@ var audit = async ({
|
|
|
3876
3948
|
}
|
|
3877
3949
|
if (error) {
|
|
3878
3950
|
logger.error(
|
|
3879
|
-
|
|
3951
|
+
chalk6.redBright(`\u203C\uFE0F Audit ${chalk6.bold("failed")} with errors`)
|
|
3880
3952
|
);
|
|
3881
3953
|
} else {
|
|
3882
|
-
logger.info(
|
|
3954
|
+
logger.info(chalk6.greenBright("\u2705 Audit passed"));
|
|
3883
3955
|
}
|
|
3884
3956
|
};
|
|
3885
3957
|
var auditDocuments = async (args) => {
|
|
@@ -3907,11 +3979,11 @@ var auditDocuments = async (args) => {
|
|
|
3907
3979
|
if (docResult.errors) {
|
|
3908
3980
|
error = true;
|
|
3909
3981
|
docResult.errors.forEach((err) => {
|
|
3910
|
-
logger.error(
|
|
3982
|
+
logger.error(chalk6.red(err.message));
|
|
3911
3983
|
if (err.originalError.originalError) {
|
|
3912
3984
|
logger.error(
|
|
3913
3985
|
// @ts-ignore FIXME: this doesn't seem right
|
|
3914
|
-
|
|
3986
|
+
chalk6.red(` ${err.originalError.originalError.message}`)
|
|
3915
3987
|
);
|
|
3916
3988
|
}
|
|
3917
3989
|
});
|
|
@@ -3953,7 +4025,7 @@ var auditDocuments = async (args) => {
|
|
|
3953
4025
|
if (mutationRes.errors) {
|
|
3954
4026
|
mutationRes.errors.forEach((err) => {
|
|
3955
4027
|
error = true;
|
|
3956
|
-
logger.error(
|
|
4028
|
+
logger.error(chalk6.red(err.message));
|
|
3957
4029
|
});
|
|
3958
4030
|
}
|
|
3959
4031
|
}
|
|
@@ -4053,26 +4125,26 @@ var AuditCommand = class extends Command4 {
|
|
|
4053
4125
|
import { Command as Command6, Option as Option6 } from "clipanion";
|
|
4054
4126
|
|
|
4055
4127
|
// src/cmds/init/detectEnvironment.ts
|
|
4056
|
-
import
|
|
4057
|
-
import
|
|
4128
|
+
import fs10 from "fs-extra";
|
|
4129
|
+
import path11 from "path";
|
|
4058
4130
|
var checkGitignoreForItem = async ({
|
|
4059
4131
|
baseDir,
|
|
4060
4132
|
line
|
|
4061
4133
|
}) => {
|
|
4062
|
-
const gitignoreContent =
|
|
4134
|
+
const gitignoreContent = fs10.readFileSync(path11.join(baseDir, ".gitignore")).toString();
|
|
4063
4135
|
return gitignoreContent.split("\n").some((item) => item === line);
|
|
4064
4136
|
};
|
|
4065
4137
|
var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
4066
4138
|
const result = {
|
|
4067
|
-
fullPathTS:
|
|
4139
|
+
fullPathTS: path11.join(
|
|
4068
4140
|
parentPath,
|
|
4069
4141
|
`${name2}.${opts?.typescriptSuffix || opts?.extensionOverride || "ts"}`
|
|
4070
4142
|
),
|
|
4071
|
-
fullPathJS:
|
|
4143
|
+
fullPathJS: path11.join(
|
|
4072
4144
|
parentPath,
|
|
4073
4145
|
`${name2}.${opts?.extensionOverride || "js"}`
|
|
4074
4146
|
),
|
|
4075
|
-
fullPathOverride: opts?.extensionOverride ?
|
|
4147
|
+
fullPathOverride: opts?.extensionOverride ? path11.join(parentPath, `${name2}.${opts?.extensionOverride}`) : "",
|
|
4076
4148
|
generatedFileType,
|
|
4077
4149
|
name: name2,
|
|
4078
4150
|
parentPath,
|
|
@@ -4090,8 +4162,8 @@ var makeGeneratedFile = async (name2, generatedFileType, parentPath, opts) => {
|
|
|
4090
4162
|
};
|
|
4091
4163
|
}
|
|
4092
4164
|
};
|
|
4093
|
-
result.typescriptExists = await
|
|
4094
|
-
result.javascriptExists = await
|
|
4165
|
+
result.typescriptExists = await fs10.pathExists(result.fullPathTS);
|
|
4166
|
+
result.javascriptExists = await fs10.pathExists(result.fullPathJS);
|
|
4095
4167
|
return result;
|
|
4096
4168
|
};
|
|
4097
4169
|
var detectEnvironment = async ({
|
|
@@ -4100,21 +4172,21 @@ var detectEnvironment = async ({
|
|
|
4100
4172
|
rootPath,
|
|
4101
4173
|
debug = false
|
|
4102
4174
|
}) => {
|
|
4103
|
-
const hasForestryConfig = await
|
|
4104
|
-
|
|
4175
|
+
const hasForestryConfig = await fs10.pathExists(
|
|
4176
|
+
path11.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
4105
4177
|
);
|
|
4106
|
-
const sampleContentPath =
|
|
4178
|
+
const sampleContentPath = path11.join(
|
|
4107
4179
|
baseDir,
|
|
4108
4180
|
"content",
|
|
4109
4181
|
"posts",
|
|
4110
4182
|
"hello-world.md"
|
|
4111
4183
|
);
|
|
4112
|
-
const usingSrc =
|
|
4113
|
-
const tinaFolder =
|
|
4184
|
+
const usingSrc = fs10.pathExistsSync(path11.join(baseDir, "src")) && (fs10.pathExistsSync(path11.join(baseDir, "src", "app")) || fs10.pathExistsSync(path11.join(baseDir, "src", "pages")));
|
|
4185
|
+
const tinaFolder = path11.join(baseDir, "tina");
|
|
4114
4186
|
const tinaConfigExists = Boolean(
|
|
4115
4187
|
// Does the tina folder exist?
|
|
4116
|
-
await
|
|
4117
|
-
(await
|
|
4188
|
+
await fs10.pathExists(tinaFolder) && // Does the tina folder contain a config file?
|
|
4189
|
+
(await fs10.readdir(tinaFolder)).find((x) => x.includes("config"))
|
|
4118
4190
|
);
|
|
4119
4191
|
const pagesDir = [baseDir, usingSrc ? "src" : false, "pages"].filter(
|
|
4120
4192
|
Boolean
|
|
@@ -4126,12 +4198,12 @@ var detectEnvironment = async ({
|
|
|
4126
4198
|
"next-api-handler": await makeGeneratedFile(
|
|
4127
4199
|
"[...routes]",
|
|
4128
4200
|
"next-api-handler",
|
|
4129
|
-
|
|
4201
|
+
path11.join(...pagesDir, "api", "tina")
|
|
4130
4202
|
),
|
|
4131
4203
|
"reactive-example": await makeGeneratedFile(
|
|
4132
4204
|
"[filename]",
|
|
4133
4205
|
"reactive-example",
|
|
4134
|
-
|
|
4206
|
+
path11.join(...pagesDir, "demo", "blog"),
|
|
4135
4207
|
{
|
|
4136
4208
|
typescriptSuffix: "tsx"
|
|
4137
4209
|
}
|
|
@@ -4139,22 +4211,22 @@ var detectEnvironment = async ({
|
|
|
4139
4211
|
"users-json": await makeGeneratedFile(
|
|
4140
4212
|
"index",
|
|
4141
4213
|
"users-json",
|
|
4142
|
-
|
|
4214
|
+
path11.join(baseDir, "content", "users"),
|
|
4143
4215
|
{ extensionOverride: "json" }
|
|
4144
4216
|
),
|
|
4145
4217
|
"sample-content": await makeGeneratedFile(
|
|
4146
4218
|
"hello-world",
|
|
4147
4219
|
"sample-content",
|
|
4148
|
-
|
|
4220
|
+
path11.join(baseDir, "content", "posts"),
|
|
4149
4221
|
{ extensionOverride: "md" }
|
|
4150
4222
|
)
|
|
4151
4223
|
};
|
|
4152
|
-
const hasSampleContent = await
|
|
4153
|
-
const hasPackageJSON = await
|
|
4224
|
+
const hasSampleContent = await fs10.pathExists(sampleContentPath);
|
|
4225
|
+
const hasPackageJSON = await fs10.pathExists("package.json");
|
|
4154
4226
|
let hasTinaDeps = false;
|
|
4155
4227
|
if (hasPackageJSON) {
|
|
4156
4228
|
try {
|
|
4157
|
-
const packageJSON = await
|
|
4229
|
+
const packageJSON = await fs10.readJSON("package.json");
|
|
4158
4230
|
const deps = [];
|
|
4159
4231
|
if (packageJSON?.dependencies) {
|
|
4160
4232
|
deps.push(...Object.keys(packageJSON.dependencies));
|
|
@@ -4171,15 +4243,15 @@ var detectEnvironment = async ({
|
|
|
4171
4243
|
);
|
|
4172
4244
|
}
|
|
4173
4245
|
}
|
|
4174
|
-
const hasGitIgnore = await
|
|
4246
|
+
const hasGitIgnore = await fs10.pathExists(path11.join(".gitignore"));
|
|
4175
4247
|
const hasGitIgnoreNodeModules = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: "node_modules" });
|
|
4176
4248
|
const hasEnvTina = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env.tina" });
|
|
4177
4249
|
const hasGitIgnoreEnv = hasGitIgnore && await checkGitignoreForItem({ baseDir, line: ".env" });
|
|
4178
4250
|
let frontMatterFormat;
|
|
4179
4251
|
if (hasForestryConfig) {
|
|
4180
|
-
const hugoConfigPath =
|
|
4181
|
-
if (await
|
|
4182
|
-
const hugoConfig = await
|
|
4252
|
+
const hugoConfigPath = path11.join(rootPath, "config.toml");
|
|
4253
|
+
if (await fs10.pathExists(hugoConfigPath)) {
|
|
4254
|
+
const hugoConfig = await fs10.readFile(hugoConfigPath, "utf8");
|
|
4183
4255
|
const metaDataFormat = hugoConfig.toString().match(/metaDataFormat = "(.*)"/)?.[1];
|
|
4184
4256
|
if (metaDataFormat && (metaDataFormat === "yaml" || metaDataFormat === "toml" || metaDataFormat === "json")) {
|
|
4185
4257
|
frontMatterFormat = metaDataFormat;
|
|
@@ -4792,21 +4864,21 @@ var CLICommand = class {
|
|
|
4792
4864
|
};
|
|
4793
4865
|
|
|
4794
4866
|
// src/cmds/init/apply.ts
|
|
4795
|
-
import
|
|
4867
|
+
import path15 from "path";
|
|
4796
4868
|
|
|
4797
4869
|
// src/cmds/forestry-migrate/index.ts
|
|
4798
|
-
import
|
|
4799
|
-
import
|
|
4870
|
+
import fs12 from "fs-extra";
|
|
4871
|
+
import path13 from "path";
|
|
4800
4872
|
import yaml2 from "js-yaml";
|
|
4801
4873
|
import pkg from "minimatch";
|
|
4802
4874
|
import { parseFile, stringifyFile } from "@tinacms/graphql";
|
|
4803
4875
|
import { CONTENT_FORMATS } from "@tinacms/schema-tools";
|
|
4804
4876
|
|
|
4805
4877
|
// src/cmds/forestry-migrate/util/index.ts
|
|
4806
|
-
import
|
|
4807
|
-
import
|
|
4878
|
+
import fs11 from "fs-extra";
|
|
4879
|
+
import path12 from "path";
|
|
4808
4880
|
import yaml from "js-yaml";
|
|
4809
|
-
import
|
|
4881
|
+
import z2 from "zod";
|
|
4810
4882
|
|
|
4811
4883
|
// src/cmds/forestry-migrate/util/errorSingleton.ts
|
|
4812
4884
|
var ErrorSingleton = class _ErrorSingleton {
|
|
@@ -4845,7 +4917,7 @@ var ErrorSingleton = class _ErrorSingleton {
|
|
|
4845
4917
|
});
|
|
4846
4918
|
logger.error(
|
|
4847
4919
|
`If you wish to edit any of the following templates, you will have to update your content and code to use the new name. See ${linkText(
|
|
4848
|
-
"https://tina.io/docs/forestry
|
|
4920
|
+
"https://tina.io/docs/r/forestry-common-errors#migrating-fields-with-non-alphanumeric-characters"
|
|
4849
4921
|
)} for more information.`
|
|
4850
4922
|
);
|
|
4851
4923
|
}
|
|
@@ -4933,82 +5005,82 @@ var stringifyTemplateName = (name2, template) => {
|
|
|
4933
5005
|
return newName;
|
|
4934
5006
|
}
|
|
4935
5007
|
};
|
|
4936
|
-
var forestryConfigSchema =
|
|
4937
|
-
sections:
|
|
4938
|
-
|
|
4939
|
-
type:
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
5008
|
+
var forestryConfigSchema = z2.object({
|
|
5009
|
+
sections: z2.array(
|
|
5010
|
+
z2.object({
|
|
5011
|
+
type: z2.union([
|
|
5012
|
+
z2.literal("directory"),
|
|
5013
|
+
z2.literal("document"),
|
|
5014
|
+
z2.literal("heading"),
|
|
5015
|
+
z2.literal("jekyll-pages"),
|
|
5016
|
+
z2.literal("jekyll-posts")
|
|
4945
5017
|
]),
|
|
4946
|
-
label:
|
|
4947
|
-
path:
|
|
4948
|
-
match:
|
|
4949
|
-
exclude:
|
|
4950
|
-
create:
|
|
4951
|
-
templates:
|
|
4952
|
-
new_doc_ext:
|
|
4953
|
-
read_only:
|
|
5018
|
+
label: z2.string(),
|
|
5019
|
+
path: z2.string().optional().nullable(),
|
|
5020
|
+
match: z2.string().optional().nullable(),
|
|
5021
|
+
exclude: z2.string().optional().nullable(),
|
|
5022
|
+
create: z2.union([z2.literal("all"), z2.literal("documents"), z2.literal("none")]).optional(),
|
|
5023
|
+
templates: z2.array(z2.string()).optional().nullable(),
|
|
5024
|
+
new_doc_ext: z2.string().optional().nullable(),
|
|
5025
|
+
read_only: z2.boolean().optional().nullable()
|
|
4954
5026
|
})
|
|
4955
5027
|
)
|
|
4956
5028
|
});
|
|
4957
|
-
var forestryFieldWithoutField =
|
|
5029
|
+
var forestryFieldWithoutField = z2.object({
|
|
4958
5030
|
// TODO: maybe better type this?
|
|
4959
|
-
type:
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
5031
|
+
type: z2.union([
|
|
5032
|
+
z2.literal("text"),
|
|
5033
|
+
z2.literal("datetime"),
|
|
5034
|
+
z2.literal("list"),
|
|
5035
|
+
z2.literal("file"),
|
|
5036
|
+
z2.literal("image_gallery"),
|
|
5037
|
+
z2.literal("textarea"),
|
|
5038
|
+
z2.literal("tag_list"),
|
|
5039
|
+
z2.literal("number"),
|
|
5040
|
+
z2.literal("boolean"),
|
|
5041
|
+
z2.literal("field_group"),
|
|
5042
|
+
z2.literal("field_group_list"),
|
|
5043
|
+
z2.literal("select"),
|
|
5044
|
+
z2.literal("include"),
|
|
5045
|
+
z2.literal("blocks"),
|
|
5046
|
+
z2.literal("color")
|
|
4975
5047
|
]),
|
|
4976
|
-
template_types:
|
|
4977
|
-
name:
|
|
4978
|
-
label:
|
|
4979
|
-
default:
|
|
4980
|
-
template:
|
|
4981
|
-
config:
|
|
5048
|
+
template_types: z2.array(z2.string()).optional().nullable(),
|
|
5049
|
+
name: z2.string(),
|
|
5050
|
+
label: z2.string(),
|
|
5051
|
+
default: z2.any().optional(),
|
|
5052
|
+
template: z2.string().optional(),
|
|
5053
|
+
config: z2.object({
|
|
4982
5054
|
// min and max are used for lists
|
|
4983
|
-
min:
|
|
4984
|
-
max:
|
|
4985
|
-
required:
|
|
4986
|
-
use_select:
|
|
4987
|
-
date_format:
|
|
4988
|
-
time_format:
|
|
4989
|
-
options:
|
|
4990
|
-
source:
|
|
4991
|
-
type:
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
5055
|
+
min: z2.number().optional().nullable(),
|
|
5056
|
+
max: z2.number().optional().nullable(),
|
|
5057
|
+
required: z2.boolean().optional().nullable(),
|
|
5058
|
+
use_select: z2.boolean().optional().nullable(),
|
|
5059
|
+
date_format: z2.string().optional().nullable(),
|
|
5060
|
+
time_format: z2.string().optional().nullable(),
|
|
5061
|
+
options: z2.array(z2.string()).optional().nullable(),
|
|
5062
|
+
source: z2.object({
|
|
5063
|
+
type: z2.union([
|
|
5064
|
+
z2.literal("custom"),
|
|
5065
|
+
z2.literal("pages"),
|
|
5066
|
+
z2.literal("documents"),
|
|
5067
|
+
z2.literal("simple"),
|
|
4996
5068
|
// TODO: I want to ignore this key if its invalid
|
|
4997
|
-
|
|
5069
|
+
z2.string()
|
|
4998
5070
|
]).optional().nullable(),
|
|
4999
|
-
section:
|
|
5071
|
+
section: z2.string().optional().nullable()
|
|
5000
5072
|
}).optional()
|
|
5001
5073
|
}).optional()
|
|
5002
5074
|
});
|
|
5003
|
-
var forestryField =
|
|
5075
|
+
var forestryField = z2.lazy(
|
|
5004
5076
|
() => forestryFieldWithoutField.extend({
|
|
5005
|
-
fields:
|
|
5077
|
+
fields: z2.array(forestryField).optional()
|
|
5006
5078
|
})
|
|
5007
5079
|
);
|
|
5008
|
-
var FrontmatterTemplateSchema =
|
|
5009
|
-
label:
|
|
5010
|
-
hide_body:
|
|
5011
|
-
fields:
|
|
5080
|
+
var FrontmatterTemplateSchema = z2.object({
|
|
5081
|
+
label: z2.string(),
|
|
5082
|
+
hide_body: z2.boolean().optional(),
|
|
5083
|
+
fields: z2.array(forestryField).optional()
|
|
5012
5084
|
});
|
|
5013
5085
|
var transformForestryFieldsToTinaFields = ({
|
|
5014
5086
|
fields,
|
|
@@ -5231,7 +5303,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
5231
5303
|
return tinaFields;
|
|
5232
5304
|
};
|
|
5233
5305
|
var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false }) => {
|
|
5234
|
-
const templatePath =
|
|
5306
|
+
const templatePath = path12.join(
|
|
5235
5307
|
pathToForestryConfig,
|
|
5236
5308
|
".forestry",
|
|
5237
5309
|
"front_matter",
|
|
@@ -5240,7 +5312,7 @@ var getFieldsFromTemplates = ({ tem, pathToForestryConfig, skipBlocks = false })
|
|
|
5240
5312
|
);
|
|
5241
5313
|
let templateString = "";
|
|
5242
5314
|
try {
|
|
5243
|
-
templateString =
|
|
5315
|
+
templateString = fs11.readFileSync(templatePath).toString();
|
|
5244
5316
|
} catch {
|
|
5245
5317
|
throw new Error(
|
|
5246
5318
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -5289,7 +5361,7 @@ var transformForestryMatchToTinaMatch = (match) => {
|
|
|
5289
5361
|
if (match !== newMatch) {
|
|
5290
5362
|
logger.info(
|
|
5291
5363
|
`Info: Match ${match} was transformed to ${newMatch}. See ${linkText(
|
|
5292
|
-
"https://tina.io/docs/forestry
|
|
5364
|
+
"https://tina.io/docs/r/forestry-common-errors#info-match-match-was-transformed-to-newmatch"
|
|
5293
5365
|
)}`
|
|
5294
5366
|
);
|
|
5295
5367
|
}
|
|
@@ -5306,9 +5378,9 @@ function checkExt(ext) {
|
|
|
5306
5378
|
var generateAllTemplates = async ({
|
|
5307
5379
|
pathToForestryConfig
|
|
5308
5380
|
}) => {
|
|
5309
|
-
const allTemplates = (await
|
|
5310
|
-
|
|
5311
|
-
)).map((tem) =>
|
|
5381
|
+
const allTemplates = (await fs12.readdir(
|
|
5382
|
+
path13.join(pathToForestryConfig, ".forestry", "front_matter", "templates")
|
|
5383
|
+
)).map((tem) => path13.basename(tem, ".yml"));
|
|
5312
5384
|
const templateMap = /* @__PURE__ */ new Map();
|
|
5313
5385
|
const proms = allTemplates.map(async (tem) => {
|
|
5314
5386
|
try {
|
|
@@ -5433,7 +5505,7 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5433
5505
|
logger.warn(
|
|
5434
5506
|
warnText(
|
|
5435
5507
|
`No templates found for section ${section.label}. Please see ${linkText(
|
|
5436
|
-
"https://tina.io/docs/forestry
|
|
5508
|
+
"https://tina.io/docs/r/forestry-content-modelling"
|
|
5437
5509
|
)} for more information`
|
|
5438
5510
|
)
|
|
5439
5511
|
);
|
|
@@ -5453,9 +5525,9 @@ var generateCollectionFromForestrySection = (args) => {
|
|
|
5453
5525
|
return c;
|
|
5454
5526
|
} else if (section.type === "document") {
|
|
5455
5527
|
const filePath = section.path;
|
|
5456
|
-
const extname =
|
|
5457
|
-
const fileName =
|
|
5458
|
-
const dir =
|
|
5528
|
+
const extname = path13.extname(filePath);
|
|
5529
|
+
const fileName = path13.basename(filePath, extname);
|
|
5530
|
+
const dir = path13.dirname(filePath);
|
|
5459
5531
|
const ext = checkExt(extname);
|
|
5460
5532
|
if (ext) {
|
|
5461
5533
|
const fields = [];
|
|
@@ -5517,8 +5589,8 @@ var generateCollections = async ({
|
|
|
5517
5589
|
templateMap,
|
|
5518
5590
|
usingTypescript
|
|
5519
5591
|
});
|
|
5520
|
-
const forestryConfig = await
|
|
5521
|
-
|
|
5592
|
+
const forestryConfig = await fs12.readFile(
|
|
5593
|
+
path13.join(pathToForestryConfig, ".forestry", "settings.yml")
|
|
5522
5594
|
);
|
|
5523
5595
|
rewriteTemplateKeysInDocs({
|
|
5524
5596
|
templateMap,
|
|
@@ -5548,12 +5620,12 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5548
5620
|
const { templateObj } = templateMap.get(templateKey);
|
|
5549
5621
|
templateObj?.pages?.forEach((page) => {
|
|
5550
5622
|
try {
|
|
5551
|
-
const filePath =
|
|
5552
|
-
if (
|
|
5623
|
+
const filePath = path13.join(page);
|
|
5624
|
+
if (fs12.lstatSync(filePath).isDirectory()) {
|
|
5553
5625
|
return;
|
|
5554
5626
|
}
|
|
5555
|
-
const extname =
|
|
5556
|
-
const fileContent =
|
|
5627
|
+
const extname = path13.extname(filePath);
|
|
5628
|
+
const fileContent = fs12.readFileSync(filePath).toString();
|
|
5557
5629
|
const content = parseFile(
|
|
5558
5630
|
fileContent,
|
|
5559
5631
|
extname,
|
|
@@ -5564,7 +5636,7 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5564
5636
|
_template: stringifyLabel(templateKey),
|
|
5565
5637
|
...content
|
|
5566
5638
|
};
|
|
5567
|
-
|
|
5639
|
+
fs12.writeFileSync(
|
|
5568
5640
|
filePath,
|
|
5569
5641
|
stringifyFile(newContent, extname, true, markdownParseConfig)
|
|
5570
5642
|
);
|
|
@@ -5579,12 +5651,12 @@ var rewriteTemplateKeysInDocs = (args) => {
|
|
|
5579
5651
|
|
|
5580
5652
|
// src/cmds/init/apply.ts
|
|
5581
5653
|
import { Telemetry as Telemetry2 } from "@tinacms/metrics";
|
|
5582
|
-
import
|
|
5654
|
+
import fs15 from "fs-extra";
|
|
5583
5655
|
|
|
5584
5656
|
// src/next/commands/codemod-command/index.ts
|
|
5585
5657
|
import { Command as Command5, Option as Option5 } from "clipanion";
|
|
5586
|
-
import
|
|
5587
|
-
import
|
|
5658
|
+
import fs13 from "fs-extra";
|
|
5659
|
+
import path14 from "path";
|
|
5588
5660
|
var CodemodCommand = class extends Command5 {
|
|
5589
5661
|
static paths = [["codemod"], ["codemod", "move-tina-folder"]];
|
|
5590
5662
|
rootPath = Option5.String("--rootPath", {
|
|
@@ -5625,13 +5697,13 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5625
5697
|
logger.error(e.message);
|
|
5626
5698
|
process.exit(1);
|
|
5627
5699
|
}
|
|
5628
|
-
const tinaDestination =
|
|
5629
|
-
if (await
|
|
5700
|
+
const tinaDestination = path14.join(configManager.rootPath, "tina");
|
|
5701
|
+
if (await fs13.existsSync(tinaDestination)) {
|
|
5630
5702
|
logger.info(
|
|
5631
5703
|
`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.`
|
|
5632
5704
|
);
|
|
5633
5705
|
} else {
|
|
5634
|
-
await
|
|
5706
|
+
await fs13.moveSync(configManager.tinaFolderPath, tinaDestination);
|
|
5635
5707
|
await writeGitignore(configManager.rootPath);
|
|
5636
5708
|
logger.info(
|
|
5637
5709
|
"Move to 'tina' folder complete. Be sure to update any imports of the autogenerated client!"
|
|
@@ -5639,8 +5711,8 @@ var moveTinaFolder = async (rootPath = process.cwd()) => {
|
|
|
5639
5711
|
}
|
|
5640
5712
|
};
|
|
5641
5713
|
var writeGitignore = async (rootPath) => {
|
|
5642
|
-
await
|
|
5643
|
-
|
|
5714
|
+
await fs13.outputFileSync(
|
|
5715
|
+
path14.join(rootPath, "tina", ".gitignore"),
|
|
5644
5716
|
"__generated__"
|
|
5645
5717
|
);
|
|
5646
5718
|
};
|
|
@@ -6078,7 +6150,7 @@ function extendNextScripts(scripts, opts) {
|
|
|
6078
6150
|
|
|
6079
6151
|
// src/cmds/init/codegen/index.ts
|
|
6080
6152
|
import ts2 from "typescript";
|
|
6081
|
-
import
|
|
6153
|
+
import fs14 from "fs-extra";
|
|
6082
6154
|
|
|
6083
6155
|
// src/cmds/init/codegen/util.ts
|
|
6084
6156
|
import ts from "typescript";
|
|
@@ -6315,7 +6387,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6315
6387
|
const pathToConfig = configFile.resolve(config2.typescript).path;
|
|
6316
6388
|
const sourceFile = ts2.createSourceFile(
|
|
6317
6389
|
pathToConfig,
|
|
6318
|
-
|
|
6390
|
+
fs14.readFileSync(pathToConfig, "utf8"),
|
|
6319
6391
|
config2.typescript ? ts2.ScriptTarget.Latest : ts2.ScriptTarget.ESNext
|
|
6320
6392
|
);
|
|
6321
6393
|
const { configImports, configAuthProviderClass, extraTinaCollections } = config2.authProvider;
|
|
@@ -6365,7 +6437,7 @@ var addSelfHostedTinaAuthToConfig = async (config2, configFile) => {
|
|
|
6365
6437
|
)
|
|
6366
6438
|
].map((visitor) => makeTransformer(visitor))
|
|
6367
6439
|
);
|
|
6368
|
-
return
|
|
6440
|
+
return fs14.writeFile(
|
|
6369
6441
|
pathToConfig,
|
|
6370
6442
|
ts2.createPrinter({ omitTrailingSemicolon: true }).printFile(transformedSourceFileResult.transformed[0])
|
|
6371
6443
|
);
|
|
@@ -6381,7 +6453,7 @@ async function apply({
|
|
|
6381
6453
|
if (config2.framework.name === "other" && config2.hosting === "self-host") {
|
|
6382
6454
|
logger.error(
|
|
6383
6455
|
logText(
|
|
6384
|
-
"Self-hosted Tina requires init setup only works with next.js right now. Please check out the docs for info on how to setup Tina on another framework: https://tina.io/docs/self-
|
|
6456
|
+
"Self-hosted Tina requires init setup only works with next.js right now. Please check out the docs for info on how to setup Tina on another framework: https://tina.io/docs/r/self-hosting-nextjs"
|
|
6385
6457
|
)
|
|
6386
6458
|
);
|
|
6387
6459
|
return;
|
|
@@ -6483,8 +6555,8 @@ async function apply({
|
|
|
6483
6555
|
await addConfigFile({
|
|
6484
6556
|
configArgs: {
|
|
6485
6557
|
config: config2,
|
|
6486
|
-
publicFolder:
|
|
6487
|
-
|
|
6558
|
+
publicFolder: path15.join(
|
|
6559
|
+
path15.relative(process.cwd(), pathToForestryConfig),
|
|
6488
6560
|
config2.publicFolder
|
|
6489
6561
|
),
|
|
6490
6562
|
collections,
|
|
@@ -6557,18 +6629,18 @@ var createPackageJSON = async () => {
|
|
|
6557
6629
|
};
|
|
6558
6630
|
var createGitignore = async ({ baseDir }) => {
|
|
6559
6631
|
logger.info(logText("No .gitignore found, creating one"));
|
|
6560
|
-
|
|
6632
|
+
fs15.outputFileSync(path15.join(baseDir, ".gitignore"), "node_modules");
|
|
6561
6633
|
};
|
|
6562
6634
|
var updateGitIgnore = async ({
|
|
6563
6635
|
baseDir,
|
|
6564
6636
|
items
|
|
6565
6637
|
}) => {
|
|
6566
6638
|
logger.info(logText(`Adding ${items.join(",")} to .gitignore`));
|
|
6567
|
-
const gitignoreContent =
|
|
6639
|
+
const gitignoreContent = fs15.readFileSync(path15.join(baseDir, ".gitignore")).toString();
|
|
6568
6640
|
const newGitignoreContent = [...gitignoreContent.split("\n"), ...items].join(
|
|
6569
6641
|
"\n"
|
|
6570
6642
|
);
|
|
6571
|
-
await
|
|
6643
|
+
await fs15.writeFile(path15.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
6572
6644
|
};
|
|
6573
6645
|
var addDependencies = async (config2, env, params) => {
|
|
6574
6646
|
const { packageManager } = config2;
|
|
@@ -6639,22 +6711,22 @@ var writeGeneratedFile = async ({
|
|
|
6639
6711
|
content,
|
|
6640
6712
|
typescript
|
|
6641
6713
|
}) => {
|
|
6642
|
-
const { exists, path:
|
|
6714
|
+
const { exists, path: path16, parentPath } = generatedFile.resolve(typescript);
|
|
6643
6715
|
if (exists) {
|
|
6644
6716
|
if (overwrite) {
|
|
6645
|
-
logger.info(`Overwriting file at ${
|
|
6646
|
-
|
|
6717
|
+
logger.info(`Overwriting file at ${path16}... \u2705`);
|
|
6718
|
+
fs15.outputFileSync(path16, content);
|
|
6647
6719
|
} else {
|
|
6648
|
-
logger.info(`Not overwriting file at ${
|
|
6720
|
+
logger.info(`Not overwriting file at ${path16}.`);
|
|
6649
6721
|
logger.info(
|
|
6650
|
-
logText(`Please add the following to ${
|
|
6722
|
+
logText(`Please add the following to ${path16}:
|
|
6651
6723
|
${indentText(content)}}`)
|
|
6652
6724
|
);
|
|
6653
6725
|
}
|
|
6654
6726
|
} else {
|
|
6655
|
-
logger.info(`Adding file at ${
|
|
6656
|
-
await
|
|
6657
|
-
|
|
6727
|
+
logger.info(`Adding file at ${path16}... \u2705`);
|
|
6728
|
+
await fs15.ensureDir(parentPath);
|
|
6729
|
+
fs15.outputFileSync(path16, content);
|
|
6658
6730
|
}
|
|
6659
6731
|
};
|
|
6660
6732
|
var addConfigFile = async ({
|
|
@@ -6732,7 +6804,7 @@ var addContentFile = async ({
|
|
|
6732
6804
|
return () => ({
|
|
6733
6805
|
exists: env.sampleContentExists,
|
|
6734
6806
|
path: env.sampleContentPath,
|
|
6735
|
-
parentPath:
|
|
6807
|
+
parentPath: path15.dirname(env.sampleContentPath)
|
|
6736
6808
|
});
|
|
6737
6809
|
}
|
|
6738
6810
|
},
|
|
@@ -6755,10 +6827,10 @@ ${titleText(" TinaCMS ")} backend initialized!`));
|
|
|
6755
6827
|
return `${x.key}=${x.value || "***"}`;
|
|
6756
6828
|
}).join("\n") + `
|
|
6757
6829
|
TINA_PUBLIC_IS_LOCAL=true`;
|
|
6758
|
-
const envFile =
|
|
6759
|
-
if (!
|
|
6830
|
+
const envFile = path15.join(process.cwd(), ".env");
|
|
6831
|
+
if (!fs15.existsSync(envFile)) {
|
|
6760
6832
|
logger.info(`Adding .env file to your project... \u2705`);
|
|
6761
|
-
|
|
6833
|
+
fs15.writeFileSync(envFile, envFileText);
|
|
6762
6834
|
} else {
|
|
6763
6835
|
logger.info(
|
|
6764
6836
|
"Please add the following environment variables to your .env file"
|
|
@@ -6766,7 +6838,7 @@ TINA_PUBLIC_IS_LOCAL=true`;
|
|
|
6766
6838
|
logger.info(indentText(envFileText));
|
|
6767
6839
|
}
|
|
6768
6840
|
logger.info(
|
|
6769
|
-
"Before you can run your site you will need to update it to use the backend client.\nSee docs for more info: https://tina.io/docs/self-hosted
|
|
6841
|
+
"Before you can run your site you will need to update it to use the backend client.\nSee docs for more info: https://tina.io/docs/r/self-hosted-querying-data"
|
|
6770
6842
|
);
|
|
6771
6843
|
logger.info(
|
|
6772
6844
|
"If you are deploying to vercel make sure to add the environment variables to your project."
|
|
@@ -6827,7 +6899,7 @@ var addReactiveFile = {
|
|
|
6827
6899
|
baseDir,
|
|
6828
6900
|
dataLayer
|
|
6829
6901
|
}) => {
|
|
6830
|
-
const packageJsonPath =
|
|
6902
|
+
const packageJsonPath = path15.join(baseDir, "package.json");
|
|
6831
6903
|
await writeGeneratedFile({
|
|
6832
6904
|
generatedFile,
|
|
6833
6905
|
typescript: config2.typescript,
|
|
@@ -6840,7 +6912,7 @@ var addReactiveFile = {
|
|
|
6840
6912
|
})
|
|
6841
6913
|
});
|
|
6842
6914
|
logger.info("Adding a nextjs example... \u2705");
|
|
6843
|
-
const packageJson = JSON.parse(
|
|
6915
|
+
const packageJson = JSON.parse(fs15.readFileSync(packageJsonPath).toString());
|
|
6844
6916
|
const scripts = packageJson.scripts || {};
|
|
6845
6917
|
const updatedPackageJson = JSON.stringify(
|
|
6846
6918
|
{
|
|
@@ -6853,7 +6925,7 @@ var addReactiveFile = {
|
|
|
6853
6925
|
null,
|
|
6854
6926
|
2
|
|
6855
6927
|
);
|
|
6856
|
-
|
|
6928
|
+
fs15.writeFileSync(packageJsonPath, updatedPackageJson);
|
|
6857
6929
|
}
|
|
6858
6930
|
};
|
|
6859
6931
|
function execShellCommand(cmd) {
|