@tinacms/cli 0.61.13 → 0.61.15
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/buildTina/index.d.ts +3 -1
- package/dist/cmds/compile/index.d.ts +1 -1
- package/dist/cmds/init/index.d.ts +6 -0
- package/dist/cmds/init/static.d.ts +1 -0
- package/dist/cmds/start-server/index.d.ts +2 -9
- package/dist/cmds/statusChecks/checkClientInformation.d.ts +26 -0
- package/dist/cmds/{waitForDB/index.d.ts → statusChecks/waitForIndexing.d.ts} +0 -0
- package/dist/index.js +648 -312
- package/dist/lib/getPath.d.ts +1 -3
- package/dist/server/server.d.ts +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -70,11 +70,11 @@ var init_utils = __esm({
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
// src/server/models/media.ts
|
|
73
|
-
var import_fs_extra8,
|
|
73
|
+
var import_fs_extra8, import_path11, MediaModel;
|
|
74
74
|
var init_media = __esm({
|
|
75
75
|
"src/server/models/media.ts"() {
|
|
76
76
|
import_fs_extra8 = __toModule(require("fs-extra"));
|
|
77
|
-
|
|
77
|
+
import_path11 = __toModule(require("path"));
|
|
78
78
|
init_utils();
|
|
79
79
|
MediaModel = class {
|
|
80
80
|
constructor({ publicFolder, mediaRoot }) {
|
|
@@ -83,11 +83,11 @@ var init_media = __esm({
|
|
|
83
83
|
}
|
|
84
84
|
async listMedia(args) {
|
|
85
85
|
try {
|
|
86
|
-
const folderPath = (0,
|
|
86
|
+
const folderPath = (0, import_path11.join)(this.publicFolder, this.mediaRoot, args.searchPath);
|
|
87
87
|
const searchPath = parseMediaFolder(args.searchPath);
|
|
88
88
|
const filesStr = await import_fs_extra8.default.readdir(folderPath);
|
|
89
89
|
const filesProm = filesStr.map(async (file) => {
|
|
90
|
-
const filePath = (0,
|
|
90
|
+
const filePath = (0, import_path11.join)(folderPath, file);
|
|
91
91
|
const stat = await import_fs_extra8.default.stat(filePath);
|
|
92
92
|
let src = `/${file}`;
|
|
93
93
|
const isFile = stat.isFile();
|
|
@@ -144,7 +144,7 @@ var init_media = __esm({
|
|
|
144
144
|
}
|
|
145
145
|
async deleteMedia(args) {
|
|
146
146
|
try {
|
|
147
|
-
const file = (0,
|
|
147
|
+
const file = (0, import_path11.join)(this.publicFolder, this.mediaRoot, args.searchPath);
|
|
148
148
|
await import_fs_extra8.default.stat(file);
|
|
149
149
|
await import_fs_extra8.default.remove(file);
|
|
150
150
|
return { ok: true };
|
|
@@ -158,15 +158,15 @@ var init_media = __esm({
|
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
// src/server/routes/index.ts
|
|
161
|
-
var import_express,
|
|
161
|
+
var import_express, import_path12, import_multer, createMediaRouter;
|
|
162
162
|
var init_routes = __esm({
|
|
163
163
|
"src/server/routes/index.ts"() {
|
|
164
164
|
import_express = __toModule(require("express"));
|
|
165
|
-
|
|
165
|
+
import_path12 = __toModule(require("path"));
|
|
166
166
|
import_multer = __toModule(require("multer"));
|
|
167
167
|
init_media();
|
|
168
|
-
createMediaRouter = (
|
|
169
|
-
const mediaFolder = (0,
|
|
168
|
+
createMediaRouter = (config2) => {
|
|
169
|
+
const mediaFolder = (0, import_path12.join)(process.cwd(), config2.publicFolder, config2.mediaRoot);
|
|
170
170
|
const storage = import_multer.default.diskStorage({
|
|
171
171
|
destination: function(req, file, cb) {
|
|
172
172
|
cb(null, mediaFolder);
|
|
@@ -177,7 +177,8 @@ var init_routes = __esm({
|
|
|
177
177
|
}
|
|
178
178
|
});
|
|
179
179
|
const upload = (0, import_multer.default)({ storage });
|
|
180
|
-
const
|
|
180
|
+
const uploadRoute = upload.single("file");
|
|
181
|
+
const mediaModel = new MediaModel(config2);
|
|
181
182
|
const mediaRouter = (0, import_express.Router)();
|
|
182
183
|
mediaRouter.get("/list/*", async (req, res) => {
|
|
183
184
|
const folder = req.params[0];
|
|
@@ -195,8 +196,16 @@ var init_routes = __esm({
|
|
|
195
196
|
const didDelete = await mediaModel.deleteMedia({ searchPath: file });
|
|
196
197
|
res.json(didDelete);
|
|
197
198
|
});
|
|
198
|
-
mediaRouter.post("/upload/*",
|
|
199
|
-
res
|
|
199
|
+
mediaRouter.post("/upload/*", async function(req, res) {
|
|
200
|
+
await uploadRoute(req, res, (err) => {
|
|
201
|
+
if (err instanceof import_multer.default.MulterError) {
|
|
202
|
+
res.status(500).json({ message: err.message });
|
|
203
|
+
} else if (err) {
|
|
204
|
+
res.status(500).json({ message: err.message });
|
|
205
|
+
} else {
|
|
206
|
+
res.json({ success: true });
|
|
207
|
+
}
|
|
208
|
+
});
|
|
200
209
|
});
|
|
201
210
|
return mediaRouter;
|
|
202
211
|
};
|
|
@@ -240,11 +249,11 @@ var init_server = __esm({
|
|
|
240
249
|
}));
|
|
241
250
|
app.post("/graphql", async (req, res) => {
|
|
242
251
|
const { query, variables } = req.body;
|
|
243
|
-
const
|
|
252
|
+
const config2 = {
|
|
244
253
|
useRelativeMedia: true
|
|
245
254
|
};
|
|
246
255
|
const result = await gqlPackage.resolve({
|
|
247
|
-
config,
|
|
256
|
+
config: config2,
|
|
248
257
|
database,
|
|
249
258
|
query,
|
|
250
259
|
variables,
|
|
@@ -254,7 +263,7 @@ var init_server = __esm({
|
|
|
254
263
|
});
|
|
255
264
|
const db = database;
|
|
256
265
|
const schema = await db.getSchema();
|
|
257
|
-
const mediaPaths = (
|
|
266
|
+
const mediaPaths = (_c = (_b = (_a = schema == null ? void 0 : schema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.media) == null ? void 0 : _c.tina;
|
|
258
267
|
app.use("/media", createMediaRouter({
|
|
259
268
|
publicFolder: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.publicFolder) || ""),
|
|
260
269
|
mediaRoot: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.mediaRoot) || "")
|
|
@@ -293,7 +302,7 @@ var commander = __toModule(require("commander"));
|
|
|
293
302
|
|
|
294
303
|
// package.json
|
|
295
304
|
var name = "@tinacms/cli";
|
|
296
|
-
var version = "0.61.
|
|
305
|
+
var version = "0.61.15";
|
|
297
306
|
|
|
298
307
|
// src/cmds/audit/audit.ts
|
|
299
308
|
var import_graphql = __toModule(require("@tinacms/graphql"));
|
|
@@ -506,6 +515,9 @@ var printFinalMessage = async (ctx, next, _options) => {
|
|
|
506
515
|
next();
|
|
507
516
|
};
|
|
508
517
|
|
|
518
|
+
// src/cmds/init/index.ts
|
|
519
|
+
var import_path3 = __toModule(require("path"));
|
|
520
|
+
|
|
509
521
|
// src/cmds/init/setup-files/index.ts
|
|
510
522
|
var import_chalk4 = __toModule(require("chalk"));
|
|
511
523
|
var adminPage = `import { TinaAdmin } from 'tinacms';
|
|
@@ -873,12 +885,145 @@ function extendNextScripts(scripts) {
|
|
|
873
885
|
}
|
|
874
886
|
|
|
875
887
|
// src/cmds/init/index.ts
|
|
876
|
-
var
|
|
888
|
+
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
877
889
|
var import_progress = __toModule(require("progress"));
|
|
878
890
|
var import_metrics2 = __toModule(require("@tinacms/metrics"));
|
|
879
891
|
var import_chalk5 = __toModule(require("chalk"));
|
|
880
|
-
var
|
|
892
|
+
var import_path4 = __toModule(require("path"));
|
|
881
893
|
var import_prompts2 = __toModule(require("prompts"));
|
|
894
|
+
|
|
895
|
+
// src/lib/getPath.ts
|
|
896
|
+
var import_path2 = __toModule(require("path"));
|
|
897
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
898
|
+
var fileExists = ({
|
|
899
|
+
projectDir,
|
|
900
|
+
filename,
|
|
901
|
+
allowedTypes
|
|
902
|
+
}) => {
|
|
903
|
+
if (!import_fs_extra.default.existsSync(projectDir)) {
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
|
|
907
|
+
let inputFile = void 0;
|
|
908
|
+
filePaths.every((path10) => {
|
|
909
|
+
if (import_fs_extra.default.existsSync(path10)) {
|
|
910
|
+
inputFile = path10;
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
return true;
|
|
914
|
+
});
|
|
915
|
+
return Boolean(inputFile);
|
|
916
|
+
};
|
|
917
|
+
var getPath = ({
|
|
918
|
+
projectDir,
|
|
919
|
+
filename,
|
|
920
|
+
allowedTypes,
|
|
921
|
+
errorMessage
|
|
922
|
+
}) => {
|
|
923
|
+
if (!import_fs_extra.default.existsSync(projectDir)) {
|
|
924
|
+
throw new Error(errorMessage);
|
|
925
|
+
}
|
|
926
|
+
const filePaths = allowedTypes.map((ext) => import_path2.default.join(projectDir, `${filename}.${ext}`));
|
|
927
|
+
let inputFile = void 0;
|
|
928
|
+
filePaths.every((path10) => {
|
|
929
|
+
if (import_fs_extra.default.existsSync(path10)) {
|
|
930
|
+
inputFile = path10;
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
return true;
|
|
934
|
+
});
|
|
935
|
+
if (!inputFile) {
|
|
936
|
+
throw new Error(errorMessage);
|
|
937
|
+
}
|
|
938
|
+
return inputFile;
|
|
939
|
+
};
|
|
940
|
+
var getClientPath = ({ projectDir }) => {
|
|
941
|
+
const filename = "client";
|
|
942
|
+
const allowedTypes = ["js", "ts"];
|
|
943
|
+
const errorMessage = "Must provide a `.tina/client.{ts,js}`";
|
|
944
|
+
return getPath({ projectDir, filename, allowedTypes, errorMessage });
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
// src/cmds/compile/defaultSchema.ts
|
|
948
|
+
var defaultSchema = `
|
|
949
|
+
import { defineSchema, defineConfig } from 'tinacms'
|
|
950
|
+
import { client } from './__generated__/client'
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
const branch =
|
|
954
|
+
process.env.NEXT_PUBLIC_TINA_BRANCH ||
|
|
955
|
+
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||
|
|
956
|
+
process.env.HEAD ||
|
|
957
|
+
'main'
|
|
958
|
+
const schema = defineSchema({
|
|
959
|
+
// See https://tina.io/docs/tina-cloud/connecting-site/ for more information about this config
|
|
960
|
+
config: {
|
|
961
|
+
token: '<Your Read Only Token>', // generated on app.tina.io,
|
|
962
|
+
clientId: '<Your Client ID>', // generated on app.tina.io
|
|
963
|
+
branch,
|
|
964
|
+
},
|
|
965
|
+
collections: [
|
|
966
|
+
{
|
|
967
|
+
label: 'Blog Posts',
|
|
968
|
+
name: 'post',
|
|
969
|
+
path: 'content/posts',
|
|
970
|
+
format: 'mdx',
|
|
971
|
+
ui: {
|
|
972
|
+
router: ({ document }) => {
|
|
973
|
+
// This can be used to add contextual editing to your site. See https://tina.io/docs/tinacms-context/#accessing-contextual-editing-from-the-cms for more information.
|
|
974
|
+
return \`/demo/blog/\${document._sys.filename}\`
|
|
975
|
+
},
|
|
976
|
+
},
|
|
977
|
+
fields: [
|
|
978
|
+
{
|
|
979
|
+
type: 'string',
|
|
980
|
+
label: 'Title',
|
|
981
|
+
name: 'title',
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
type: 'rich-text',
|
|
985
|
+
label: 'Blog Post Body',
|
|
986
|
+
name: 'body',
|
|
987
|
+
isBody: true,
|
|
988
|
+
templates: [
|
|
989
|
+
{
|
|
990
|
+
name: 'PageSection',
|
|
991
|
+
label: 'Page Section',
|
|
992
|
+
fields: [
|
|
993
|
+
{
|
|
994
|
+
type: 'string',
|
|
995
|
+
name: 'heading',
|
|
996
|
+
label: 'Heading',
|
|
997
|
+
},
|
|
998
|
+
{
|
|
999
|
+
type: 'string',
|
|
1000
|
+
name: 'content',
|
|
1001
|
+
label: 'Content',
|
|
1002
|
+
ui: {
|
|
1003
|
+
component: 'textarea',
|
|
1004
|
+
},
|
|
1005
|
+
},
|
|
1006
|
+
],
|
|
1007
|
+
},
|
|
1008
|
+
],
|
|
1009
|
+
},
|
|
1010
|
+
],
|
|
1011
|
+
},
|
|
1012
|
+
],
|
|
1013
|
+
})
|
|
1014
|
+
|
|
1015
|
+
export default schema
|
|
1016
|
+
|
|
1017
|
+
// Your tina config
|
|
1018
|
+
|
|
1019
|
+
export const tinaConfig = defineConfig({
|
|
1020
|
+
client,
|
|
1021
|
+
schema,
|
|
1022
|
+
})
|
|
1023
|
+
|
|
1024
|
+
`;
|
|
1025
|
+
|
|
1026
|
+
// src/cmds/init/index.ts
|
|
882
1027
|
function execShellCommand(cmd) {
|
|
883
1028
|
const exec = require("child_process").exec;
|
|
884
1029
|
return new Promise((resolve2, _reject) => {
|
|
@@ -892,22 +1037,37 @@ function execShellCommand(cmd) {
|
|
|
892
1037
|
}
|
|
893
1038
|
async function initTina(ctx, next, options) {
|
|
894
1039
|
const telemetry = new import_metrics2.Telemetry({ disabled: options.noTelemetry });
|
|
1040
|
+
const root2 = ctx.rootPath;
|
|
1041
|
+
const tsConfigPath = import_path3.default.join(root2, "tsconfig.json");
|
|
1042
|
+
const usingTs = await import_fs_extra2.default.pathExists(tsConfigPath);
|
|
1043
|
+
const schemaFileType2 = (options == null ? void 0 : options.schemaFileType) || usingTs ? "ts" : "js";
|
|
895
1044
|
await telemetry.submitRecord({
|
|
896
1045
|
event: {
|
|
897
1046
|
name: "tinacms:cli:init:invoke",
|
|
898
|
-
schemaFileType:
|
|
1047
|
+
schemaFileType: schemaFileType2
|
|
899
1048
|
}
|
|
900
1049
|
});
|
|
901
1050
|
logger.info(successText("Setting up Tina..."));
|
|
1051
|
+
const tinaPath = import_path3.default.join(root2, ".tina");
|
|
1052
|
+
const schemaExists = fileExists({
|
|
1053
|
+
projectDir: tinaPath,
|
|
1054
|
+
filename: "schema",
|
|
1055
|
+
allowedTypes: ["js", "jsx", "tsx", "ts"]
|
|
1056
|
+
});
|
|
1057
|
+
if (!schemaExists) {
|
|
1058
|
+
const file = import_path3.default.join(tinaPath, `schema.${schemaFileType2}`);
|
|
1059
|
+
await import_fs_extra2.default.ensureFile(file);
|
|
1060
|
+
await import_fs_extra2.default.writeFile(file, defaultSchema);
|
|
1061
|
+
}
|
|
902
1062
|
next();
|
|
903
1063
|
}
|
|
904
1064
|
var MIN_REACT_VERSION = ">=16.14.0";
|
|
905
1065
|
async function checkDeps(ctx, next, options) {
|
|
906
1066
|
const bar = new import_progress.default("Checking dependencies. :prog", 1);
|
|
907
|
-
if (!
|
|
1067
|
+
if (!import_fs_extra2.default.existsSync(packageJSONPath)) {
|
|
908
1068
|
throw new Error("No package.json Found. Please run tinacms init at the root of your app");
|
|
909
1069
|
}
|
|
910
|
-
const packageJSON = JSON.parse((await
|
|
1070
|
+
const packageJSON = JSON.parse((await import_fs_extra2.default.readFileSync(packageJSONPath)).toString());
|
|
911
1071
|
if (!checkPackage(packageJSON, "react") || !checkPackage(packageJSON, "react-dom")) {
|
|
912
1072
|
const message = `Unable to initialize Tina due to outdated dependencies, try upgrading the following packages:
|
|
913
1073
|
"react@${MIN_REACT_VERSION}"
|
|
@@ -976,33 +1136,33 @@ async function installDeps(ctx, next, options) {
|
|
|
976
1136
|
next();
|
|
977
1137
|
}
|
|
978
1138
|
var baseDir = process.cwd();
|
|
979
|
-
var packageJSONPath =
|
|
980
|
-
var blogContentPath =
|
|
981
|
-
var blogPostPath =
|
|
982
|
-
var TinaFolder =
|
|
983
|
-
var componentFolder =
|
|
984
|
-
var TinaProviderPath =
|
|
985
|
-
var TinaDynamicProvider =
|
|
1139
|
+
var packageJSONPath = import_path4.default.join(baseDir, "package.json");
|
|
1140
|
+
var blogContentPath = import_path4.default.join(baseDir, "content", "posts");
|
|
1141
|
+
var blogPostPath = import_path4.default.join(blogContentPath, "HelloWorld.mdx");
|
|
1142
|
+
var TinaFolder = import_path4.default.join(baseDir, ".tina");
|
|
1143
|
+
var componentFolder = import_path4.default.join(TinaFolder, "components");
|
|
1144
|
+
var TinaProviderPath = import_path4.default.join(componentFolder, "TinaProvider.js");
|
|
1145
|
+
var TinaDynamicProvider = import_path4.default.join(componentFolder, "TinaDynamicProvider.js");
|
|
986
1146
|
async function tinaSetup(_ctx, next, _options) {
|
|
987
|
-
const usingSrc = !
|
|
988
|
-
if (!
|
|
1147
|
+
const usingSrc = !import_fs_extra2.default.pathExistsSync(import_path4.default.join(baseDir, "pages"));
|
|
1148
|
+
if (!import_fs_extra2.default.pathExistsSync(blogPostPath)) {
|
|
989
1149
|
logger.info(logText("Adding a content folder..."));
|
|
990
|
-
|
|
991
|
-
|
|
1150
|
+
import_fs_extra2.default.mkdirpSync(blogContentPath);
|
|
1151
|
+
import_fs_extra2.default.writeFileSync(blogPostPath, blogPost);
|
|
992
1152
|
}
|
|
993
|
-
if (!
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1153
|
+
if (!import_fs_extra2.default.existsSync(TinaProviderPath) && !import_fs_extra2.default.existsSync(TinaDynamicProvider)) {
|
|
1154
|
+
import_fs_extra2.default.mkdirpSync(componentFolder);
|
|
1155
|
+
import_fs_extra2.default.writeFileSync(TinaProviderPath, TinaProvider.replace(/'\.\.\/schema\.ts'/, `'../schema.${_ctx.usingTs ? "ts" : "js"}'`));
|
|
1156
|
+
import_fs_extra2.default.writeFileSync(TinaDynamicProvider, TinaProviderDynamic);
|
|
997
1157
|
}
|
|
998
1158
|
logger.level = "info";
|
|
999
|
-
const pagesPath =
|
|
1000
|
-
const appPath =
|
|
1001
|
-
const appPathTS =
|
|
1002
|
-
const appExtension =
|
|
1003
|
-
if (!
|
|
1159
|
+
const pagesPath = import_path4.default.join(baseDir, usingSrc ? "src" : "", "pages");
|
|
1160
|
+
const appPath = import_path4.default.join(pagesPath, "_app.js");
|
|
1161
|
+
const appPathTS = import_path4.default.join(pagesPath, "_app.tsx");
|
|
1162
|
+
const appExtension = import_fs_extra2.default.existsSync(appPath) ? ".js" : ".tsx";
|
|
1163
|
+
if (!import_fs_extra2.default.pathExistsSync(appPath) && !import_fs_extra2.default.pathExistsSync(appPathTS)) {
|
|
1004
1164
|
logger.info(logText("Adding _app.js ... \u2705"));
|
|
1005
|
-
|
|
1165
|
+
import_fs_extra2.default.writeFileSync(appPath, AppJsContent(usingSrc));
|
|
1006
1166
|
} else {
|
|
1007
1167
|
const override = await (0, import_prompts2.default)({
|
|
1008
1168
|
name: "res",
|
|
@@ -1012,43 +1172,43 @@ async function tinaSetup(_ctx, next, _options) {
|
|
|
1012
1172
|
_ctx.overrideApp = override.res;
|
|
1013
1173
|
if (override.res) {
|
|
1014
1174
|
logger.info(logText(`Adding _app${appExtension} ... \u2705`));
|
|
1015
|
-
const appPathWithExtension =
|
|
1016
|
-
const fileContent =
|
|
1175
|
+
const appPathWithExtension = import_path4.default.join(pagesPath, `_app${appExtension}`);
|
|
1176
|
+
const fileContent = import_fs_extra2.default.pathExistsSync(appPath) ? (0, import_fs_extra2.readFileSync)(appPath) : (0, import_fs_extra2.readFileSync)(appPathTS);
|
|
1017
1177
|
const matches = [
|
|
1018
1178
|
...fileContent.toString().matchAll(/^.*import.*\.css("|').*$/gm)
|
|
1019
1179
|
];
|
|
1020
1180
|
const primaryMatches = matches.map((x) => x[0]);
|
|
1021
|
-
|
|
1181
|
+
import_fs_extra2.default.writeFileSync(appPathWithExtension, AppJsContent(usingSrc, primaryMatches.join("\n")));
|
|
1022
1182
|
}
|
|
1023
1183
|
}
|
|
1024
|
-
const tinaBlogPagePath =
|
|
1025
|
-
const tinaBlogPagePathFile =
|
|
1026
|
-
if (!
|
|
1027
|
-
|
|
1028
|
-
|
|
1184
|
+
const tinaBlogPagePath = import_path4.default.join(pagesPath, "demo", "blog");
|
|
1185
|
+
const tinaBlogPagePathFile = import_path4.default.join(tinaBlogPagePath, "[filename].js");
|
|
1186
|
+
if (!import_fs_extra2.default.pathExistsSync(tinaBlogPagePathFile)) {
|
|
1187
|
+
import_fs_extra2.default.mkdirpSync(tinaBlogPagePath);
|
|
1188
|
+
import_fs_extra2.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
|
|
1029
1189
|
}
|
|
1030
1190
|
logger.info("Adding a content folder... \u2705");
|
|
1031
|
-
if (!
|
|
1191
|
+
if (!import_fs_extra2.default.existsSync(packageJSONPath)) {
|
|
1032
1192
|
throw new Error("No package.json Found. Please run tinacms init at the root of your app");
|
|
1033
1193
|
} else {
|
|
1034
|
-
const pack = JSON.parse((0,
|
|
1194
|
+
const pack = JSON.parse((0, import_fs_extra2.readFileSync)(packageJSONPath).toString());
|
|
1035
1195
|
const oldScripts = pack.scripts || {};
|
|
1036
1196
|
const newPack = JSON.stringify(__spreadProps(__spreadValues({}, pack), {
|
|
1037
1197
|
scripts: extendNextScripts(oldScripts)
|
|
1038
1198
|
}), null, 2);
|
|
1039
|
-
(0,
|
|
1199
|
+
(0, import_fs_extra2.writeFileSync)(packageJSONPath, newPack);
|
|
1040
1200
|
}
|
|
1041
|
-
const adminPath =
|
|
1042
|
-
if (
|
|
1201
|
+
const adminPath = import_path4.default.join(pagesPath, "admin.js");
|
|
1202
|
+
if (import_fs_extra2.default.pathExistsSync(import_path4.default.join(pagesPath, "admin"))) {
|
|
1043
1203
|
logger.warn(`Unable to add /pages/admin.js, this path already exists.
|
|
1044
1204
|
Learn more about toggling edit-mode at https://tina.io/docs/tinacms-context/#manually-toggling-edit-mode`);
|
|
1045
1205
|
return next();
|
|
1046
1206
|
}
|
|
1047
|
-
(0,
|
|
1207
|
+
(0, import_fs_extra2.outputFileSync)(adminPath, adminPage);
|
|
1048
1208
|
next();
|
|
1049
1209
|
}
|
|
1050
1210
|
async function successMessage(ctx, next, options) {
|
|
1051
|
-
const usingSrc =
|
|
1211
|
+
const usingSrc = import_fs_extra2.default.pathExistsSync(import_path4.default.join(baseDir, "src"));
|
|
1052
1212
|
logger.info(`Tina setup ${import_chalk5.default.underline.green("done")} \u2705
|
|
1053
1213
|
`);
|
|
1054
1214
|
logger.info("Next Steps: \n");
|
|
@@ -1139,122 +1299,8 @@ var handleServerErrors = (e) => {
|
|
|
1139
1299
|
|
|
1140
1300
|
// src/cmds/compile/index.ts
|
|
1141
1301
|
var import_fs_extra3 = __toModule(require("fs-extra"));
|
|
1142
|
-
var
|
|
1302
|
+
var import_path5 = __toModule(require("path"));
|
|
1143
1303
|
var import_esbuild = __toModule(require("esbuild"));
|
|
1144
|
-
|
|
1145
|
-
// src/cmds/compile/defaultSchema.ts
|
|
1146
|
-
var defaultSchema = `
|
|
1147
|
-
import { defineSchema, defineConfig } from 'tinacms'
|
|
1148
|
-
import { client } from './__generated__/client'
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
const branch =
|
|
1152
|
-
process.env.NEXT_PUBLIC_TINA_BRANCH ||
|
|
1153
|
-
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ||
|
|
1154
|
-
process.env.HEAD ||
|
|
1155
|
-
'main'
|
|
1156
|
-
const schema = defineSchema({
|
|
1157
|
-
// See https://tina.io/docs/tina-cloud/connecting-site/ for more information about this config
|
|
1158
|
-
config: {
|
|
1159
|
-
token: '<Your Read Only Token>', // generated on app.tina.io,
|
|
1160
|
-
clientId: '<Your Client ID>', // generated on app.tina.io
|
|
1161
|
-
branch,
|
|
1162
|
-
},
|
|
1163
|
-
collections: [
|
|
1164
|
-
{
|
|
1165
|
-
label: 'Blog Posts',
|
|
1166
|
-
name: 'post',
|
|
1167
|
-
path: 'content/posts',
|
|
1168
|
-
format: 'mdx',
|
|
1169
|
-
ui: {
|
|
1170
|
-
router: ({ document }) => {
|
|
1171
|
-
// This can be used to add contextual editing to your site. See https://tina.io/docs/tinacms-context/#accessing-contextual-editing-from-the-cms for more information.
|
|
1172
|
-
return \`/demo/blog/\${document._sys.filename}\`
|
|
1173
|
-
},
|
|
1174
|
-
},
|
|
1175
|
-
fields: [
|
|
1176
|
-
{
|
|
1177
|
-
type: 'string',
|
|
1178
|
-
label: 'Title',
|
|
1179
|
-
name: 'title',
|
|
1180
|
-
},
|
|
1181
|
-
{
|
|
1182
|
-
type: 'rich-text',
|
|
1183
|
-
label: 'Blog Post Body',
|
|
1184
|
-
name: 'body',
|
|
1185
|
-
isBody: true,
|
|
1186
|
-
templates: [
|
|
1187
|
-
{
|
|
1188
|
-
name: 'PageSection',
|
|
1189
|
-
label: 'Page Section',
|
|
1190
|
-
fields: [
|
|
1191
|
-
{
|
|
1192
|
-
type: 'string',
|
|
1193
|
-
name: 'heading',
|
|
1194
|
-
label: 'Heading',
|
|
1195
|
-
},
|
|
1196
|
-
{
|
|
1197
|
-
type: 'string',
|
|
1198
|
-
name: 'content',
|
|
1199
|
-
label: 'Content',
|
|
1200
|
-
ui: {
|
|
1201
|
-
component: 'textarea',
|
|
1202
|
-
},
|
|
1203
|
-
},
|
|
1204
|
-
],
|
|
1205
|
-
},
|
|
1206
|
-
],
|
|
1207
|
-
},
|
|
1208
|
-
],
|
|
1209
|
-
},
|
|
1210
|
-
],
|
|
1211
|
-
})
|
|
1212
|
-
|
|
1213
|
-
export default schema
|
|
1214
|
-
|
|
1215
|
-
// Your tina config
|
|
1216
|
-
|
|
1217
|
-
export const tinaConfig = defineConfig({
|
|
1218
|
-
client,
|
|
1219
|
-
schema,
|
|
1220
|
-
})
|
|
1221
|
-
|
|
1222
|
-
`;
|
|
1223
|
-
|
|
1224
|
-
// src/lib/getPath.ts
|
|
1225
|
-
var import_path3 = __toModule(require("path"));
|
|
1226
|
-
var import_fs_extra2 = __toModule(require("fs-extra"));
|
|
1227
|
-
var getPath = ({
|
|
1228
|
-
projectDir,
|
|
1229
|
-
filename,
|
|
1230
|
-
allowedTypes,
|
|
1231
|
-
errorMessage
|
|
1232
|
-
}) => {
|
|
1233
|
-
if (!import_fs_extra2.default.existsSync(projectDir)) {
|
|
1234
|
-
throw new Error(errorMessage);
|
|
1235
|
-
}
|
|
1236
|
-
const filePaths = allowedTypes.map((ext) => import_path3.default.join(projectDir, `${filename}.${ext}`));
|
|
1237
|
-
let inputFile = void 0;
|
|
1238
|
-
filePaths.every((path8) => {
|
|
1239
|
-
if (import_fs_extra2.default.existsSync(path8)) {
|
|
1240
|
-
inputFile = path8;
|
|
1241
|
-
return false;
|
|
1242
|
-
}
|
|
1243
|
-
return true;
|
|
1244
|
-
});
|
|
1245
|
-
if (!inputFile) {
|
|
1246
|
-
throw new Error(errorMessage);
|
|
1247
|
-
}
|
|
1248
|
-
return inputFile;
|
|
1249
|
-
};
|
|
1250
|
-
var getClientPath = ({ projectDir }) => {
|
|
1251
|
-
const filename = "client";
|
|
1252
|
-
const allowedTypes = ["js", "ts"];
|
|
1253
|
-
const errorMessage = "Must provide a `.tina/client.{ts,js}`";
|
|
1254
|
-
return getPath({ projectDir, filename, allowedTypes, errorMessage });
|
|
1255
|
-
};
|
|
1256
|
-
|
|
1257
|
-
// src/cmds/compile/index.ts
|
|
1258
1304
|
var resetGeneratedFolder = async ({
|
|
1259
1305
|
tinaGeneratedPath,
|
|
1260
1306
|
usingTs
|
|
@@ -1266,14 +1312,14 @@ var resetGeneratedFolder = async ({
|
|
|
1266
1312
|
}
|
|
1267
1313
|
await import_fs_extra3.default.mkdirp(tinaGeneratedPath);
|
|
1268
1314
|
const ext = usingTs ? "ts" : "js";
|
|
1269
|
-
await import_fs_extra3.default.writeFile(
|
|
1315
|
+
await import_fs_extra3.default.writeFile(import_path5.default.join(tinaGeneratedPath, `types.${ext}`), `
|
|
1270
1316
|
export const queries = (client)=>({})
|
|
1271
1317
|
`);
|
|
1272
|
-
await import_fs_extra3.default.writeFile(
|
|
1318
|
+
await import_fs_extra3.default.writeFile(import_path5.default.join(tinaGeneratedPath, `client.${ext}`), `
|
|
1273
1319
|
export const client = ()=>{}
|
|
1274
1320
|
export default client
|
|
1275
1321
|
`);
|
|
1276
|
-
await import_fs_extra3.default.outputFile(
|
|
1322
|
+
await import_fs_extra3.default.outputFile(import_path5.default.join(tinaGeneratedPath, ".gitignore"), `db
|
|
1277
1323
|
client.ts
|
|
1278
1324
|
client.js
|
|
1279
1325
|
types.ts
|
|
@@ -1293,10 +1339,10 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1293
1339
|
if (!root2) {
|
|
1294
1340
|
throw new Error("ctx.rootPath has not been attached");
|
|
1295
1341
|
}
|
|
1296
|
-
const tinaPath =
|
|
1297
|
-
const tinaGeneratedPath =
|
|
1298
|
-
const packageJSONFilePath =
|
|
1299
|
-
const tinaTempPath =
|
|
1342
|
+
const tinaPath = import_path5.default.join(root2, ".tina");
|
|
1343
|
+
const tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
|
|
1344
|
+
const packageJSONFilePath = import_path5.default.join(root2, "package.json");
|
|
1345
|
+
const tinaTempPath = import_path5.default.join(tinaGeneratedPath, "temp_client");
|
|
1300
1346
|
if (!options.clientFileType)
|
|
1301
1347
|
options = __spreadProps(__spreadValues({}, options), { clientFileType: "ts" });
|
|
1302
1348
|
if (options.verbose) {
|
|
@@ -1311,7 +1357,7 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1311
1357
|
ctx.clientFileType = requestedClientFileType;
|
|
1312
1358
|
}
|
|
1313
1359
|
let clientExists = true;
|
|
1314
|
-
const projectDir =
|
|
1360
|
+
const projectDir = import_path5.default.join(tinaPath, "__generated__");
|
|
1315
1361
|
try {
|
|
1316
1362
|
getClientPath({ projectDir });
|
|
1317
1363
|
} catch {
|
|
@@ -1342,7 +1388,7 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1342
1388
|
}
|
|
1343
1389
|
});
|
|
1344
1390
|
try {
|
|
1345
|
-
const clientFunc = require(
|
|
1391
|
+
const clientFunc = require(import_path5.default.join(tinaTempPath, "client.js"));
|
|
1346
1392
|
const client = clientFunc.default;
|
|
1347
1393
|
ctx.client = client;
|
|
1348
1394
|
await cleanup({ tinaTempPath });
|
|
@@ -1362,11 +1408,11 @@ var compileFile = async (options, fileName) => {
|
|
|
1362
1408
|
if (!root2) {
|
|
1363
1409
|
throw new Error("ctx.rootPath has not been attached");
|
|
1364
1410
|
}
|
|
1365
|
-
const tinaPath =
|
|
1366
|
-
const tsConfigPath =
|
|
1367
|
-
const tinaGeneratedPath =
|
|
1368
|
-
const tinaTempPath =
|
|
1369
|
-
const packageJSONFilePath =
|
|
1411
|
+
const tinaPath = import_path5.default.join(root2, ".tina");
|
|
1412
|
+
const tsConfigPath = import_path5.default.join(root2, "tsconfig.json");
|
|
1413
|
+
const tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
|
|
1414
|
+
const tinaTempPath = import_path5.default.join(tinaGeneratedPath, `temp_${fileName}`);
|
|
1415
|
+
const packageJSONFilePath = import_path5.default.join(root2, "package.json");
|
|
1370
1416
|
if (!options.schemaFileType) {
|
|
1371
1417
|
const usingTs = await import_fs_extra3.default.pathExists(tsConfigPath);
|
|
1372
1418
|
options = __spreadProps(__spreadValues({}, options), { schemaFileType: usingTs ? "ts" : "js" });
|
|
@@ -1390,15 +1436,6 @@ var compileFile = async (options, fileName) => {
|
|
|
1390
1436
|
} catch {
|
|
1391
1437
|
schemaExists = false;
|
|
1392
1438
|
}
|
|
1393
|
-
if (!schemaExists && fileName === "schema") {
|
|
1394
|
-
logger.info(dangerText(`
|
|
1395
|
-
.tina/schema.${schemaFileType2} not found, Creating one for you...
|
|
1396
|
-
See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
|
|
1397
|
-
`));
|
|
1398
|
-
const file = import_path4.default.join(tinaPath, `schema.${schemaFileType2}`);
|
|
1399
|
-
await import_fs_extra3.default.ensureFile(file);
|
|
1400
|
-
await import_fs_extra3.default.writeFile(file, defaultSchema);
|
|
1401
|
-
}
|
|
1402
1439
|
try {
|
|
1403
1440
|
const define = {};
|
|
1404
1441
|
if (!process.env.NODE_ENV) {
|
|
@@ -1422,7 +1459,7 @@ var compileFile = async (options, fileName) => {
|
|
|
1422
1459
|
});
|
|
1423
1460
|
let returnObject = {};
|
|
1424
1461
|
try {
|
|
1425
|
-
const schemaFunc = require(
|
|
1462
|
+
const schemaFunc = require(import_path5.default.join(tinaTempPath, `${fileName}.js`));
|
|
1426
1463
|
returnObject = schemaFunc.default;
|
|
1427
1464
|
await cleanup({ tinaTempPath });
|
|
1428
1465
|
} catch (e) {
|
|
@@ -1438,20 +1475,35 @@ var compileFile = async (options, fileName) => {
|
|
|
1438
1475
|
};
|
|
1439
1476
|
var compileSchema = async (options) => {
|
|
1440
1477
|
const root2 = options.rootPath;
|
|
1441
|
-
const tinaPath =
|
|
1442
|
-
const tinaGeneratedPath =
|
|
1443
|
-
const tinaConfigPath =
|
|
1444
|
-
let
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1478
|
+
const tinaPath = import_path5.default.join(root2, ".tina");
|
|
1479
|
+
const tinaGeneratedPath = import_path5.default.join(tinaPath, "__generated__");
|
|
1480
|
+
const tinaConfigPath = import_path5.default.join(tinaGeneratedPath, "config");
|
|
1481
|
+
let schemaExists = fileExists({
|
|
1482
|
+
projectDir: tinaPath,
|
|
1483
|
+
filename: "schema",
|
|
1484
|
+
allowedTypes: ["js", "jsx", "tsx", "ts"]
|
|
1485
|
+
});
|
|
1486
|
+
const configExists = fileExists({
|
|
1487
|
+
projectDir: tinaPath,
|
|
1488
|
+
filename: "config",
|
|
1489
|
+
allowedTypes: ["js", "jsx", "tsx", "ts"]
|
|
1490
|
+
});
|
|
1491
|
+
if (!schemaExists && !configExists) {
|
|
1492
|
+
throw new Error("No schema or config file found in .tina folder. Please run `npx @tinacms/cli@latest init` to generate a schema file.");
|
|
1493
|
+
}
|
|
1494
|
+
let schema;
|
|
1495
|
+
if (schemaExists) {
|
|
1496
|
+
schema = await compileFile(options, "schema");
|
|
1497
|
+
}
|
|
1498
|
+
if (configExists) {
|
|
1499
|
+
const config2 = await compileFile(options, "config");
|
|
1500
|
+
const configCopy = _.cloneDeep(config2);
|
|
1448
1501
|
delete configCopy.schema;
|
|
1449
|
-
if (
|
|
1450
|
-
schema = __spreadProps(__spreadValues({},
|
|
1502
|
+
if (config2 == null ? void 0 : config2.schema) {
|
|
1503
|
+
schema = __spreadProps(__spreadValues({}, config2.schema), { config: configCopy });
|
|
1451
1504
|
}
|
|
1452
|
-
} catch (e) {
|
|
1453
1505
|
}
|
|
1454
|
-
await import_fs_extra3.default.outputFile(
|
|
1506
|
+
await import_fs_extra3.default.outputFile(import_path5.default.join(tinaConfigPath, `schema.json`), JSON.stringify(schema, null, 2));
|
|
1455
1507
|
return schema;
|
|
1456
1508
|
};
|
|
1457
1509
|
var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
|
|
@@ -1462,7 +1514,7 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
|
|
|
1462
1514
|
const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
|
|
1463
1515
|
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
1464
1516
|
const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
|
|
1465
|
-
const prebuiltInputPath =
|
|
1517
|
+
const prebuiltInputPath = import_path5.default.join(tempDir, "temp-output.jsx");
|
|
1466
1518
|
await (0, import_esbuild.build)({
|
|
1467
1519
|
bundle: true,
|
|
1468
1520
|
platform: "neutral",
|
|
@@ -1474,9 +1526,9 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
|
|
|
1474
1526
|
outfile: prebuiltInputPath,
|
|
1475
1527
|
define
|
|
1476
1528
|
});
|
|
1477
|
-
const tempTsConfigPath =
|
|
1529
|
+
const tempTsConfigPath = import_path5.default.join(tempDir, "temp-tsconfig.json");
|
|
1478
1530
|
await import_fs_extra3.default.outputFileSync(tempTsConfigPath, "{}");
|
|
1479
|
-
const outputPath =
|
|
1531
|
+
const outputPath = import_path5.default.join(tempDir, outputFile);
|
|
1480
1532
|
await (0, import_esbuild.build)({
|
|
1481
1533
|
bundle: true,
|
|
1482
1534
|
platform: "neutral",
|
|
@@ -1492,8 +1544,8 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
|
|
|
1492
1544
|
if (verbose)
|
|
1493
1545
|
logger.info(logText(`Javascript built`));
|
|
1494
1546
|
};
|
|
1495
|
-
var defineSchema = (
|
|
1496
|
-
return
|
|
1547
|
+
var defineSchema = (config2) => {
|
|
1548
|
+
return config2;
|
|
1497
1549
|
};
|
|
1498
1550
|
var loaders = {
|
|
1499
1551
|
".aac": "file",
|
|
@@ -1522,7 +1574,7 @@ var loaders = {
|
|
|
1522
1574
|
};
|
|
1523
1575
|
|
|
1524
1576
|
// src/cmds/start-server/index.ts
|
|
1525
|
-
var
|
|
1577
|
+
var import_path13 = __toModule(require("path"));
|
|
1526
1578
|
var import_chalk6 = __toModule(require("chalk"));
|
|
1527
1579
|
var import_chokidar = __toModule(require("chokidar"));
|
|
1528
1580
|
var import_metrics3 = __toModule(require("@tinacms/metrics"));
|
|
@@ -1543,12 +1595,12 @@ var AsyncLock = class {
|
|
|
1543
1595
|
var import_fs_extra7 = __toModule(require("fs-extra"));
|
|
1544
1596
|
var import_graphql9 = __toModule(require("@tinacms/graphql"));
|
|
1545
1597
|
var import_datalayer = __toModule(require("@tinacms/datalayer"));
|
|
1546
|
-
var
|
|
1598
|
+
var import_path10 = __toModule(require("path"));
|
|
1547
1599
|
|
|
1548
1600
|
// src/cmds/query-gen/genTypes.ts
|
|
1549
1601
|
var import_graphql8 = __toModule(require("graphql"));
|
|
1550
1602
|
var import_fs_extra4 = __toModule(require("fs-extra"));
|
|
1551
|
-
var
|
|
1603
|
+
var import_path7 = __toModule(require("path"));
|
|
1552
1604
|
|
|
1553
1605
|
// src/codegen/index.ts
|
|
1554
1606
|
var import_graphql7 = __toModule(require("graphql"));
|
|
@@ -1605,7 +1657,7 @@ var import_typescript = __toModule(require("@graphql-codegen/typescript"));
|
|
|
1605
1657
|
// src/codegen/sdkPlugin/index.ts
|
|
1606
1658
|
var import_graphql5 = __toModule(require("graphql"));
|
|
1607
1659
|
var import_graphql6 = __toModule(require("graphql"));
|
|
1608
|
-
var
|
|
1660
|
+
var import_path6 = __toModule(require("path"));
|
|
1609
1661
|
|
|
1610
1662
|
// src/codegen/sdkPlugin/visitor.ts
|
|
1611
1663
|
var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
|
|
@@ -1658,7 +1710,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
1658
1710
|
};
|
|
1659
1711
|
|
|
1660
1712
|
// src/codegen/sdkPlugin/index.ts
|
|
1661
|
-
var plugin = (schema, documents,
|
|
1713
|
+
var plugin = (schema, documents, config2) => {
|
|
1662
1714
|
const allAst = (0, import_graphql6.concatAST)(documents.reduce((prev, v) => {
|
|
1663
1715
|
return [...prev, v.document];
|
|
1664
1716
|
}, []));
|
|
@@ -1669,9 +1721,9 @@ var plugin = (schema, documents, config) => {
|
|
|
1669
1721
|
onType: fragmentDef.typeCondition.name.value,
|
|
1670
1722
|
isExternal: false
|
|
1671
1723
|
})),
|
|
1672
|
-
...
|
|
1724
|
+
...config2.externalFragments || []
|
|
1673
1725
|
];
|
|
1674
|
-
const visitor = new GenericSdkVisitor(schema, allFragments,
|
|
1726
|
+
const visitor = new GenericSdkVisitor(schema, allFragments, config2);
|
|
1675
1727
|
const visitorResult = (0, import_graphql5.visit)(allAst, { leave: visitor });
|
|
1676
1728
|
return {
|
|
1677
1729
|
content: [
|
|
@@ -1742,15 +1794,16 @@ var loadGraphQLDocuments = async (globPath) => {
|
|
|
1742
1794
|
var import_esbuild2 = __toModule(require("esbuild"));
|
|
1743
1795
|
var TINA_HOST = "content.tinajs.io";
|
|
1744
1796
|
var root = process.cwd();
|
|
1745
|
-
var generatedPath =
|
|
1797
|
+
var generatedPath = import_path7.default.join(root, ".tina", "__generated__");
|
|
1746
1798
|
async function genClient({
|
|
1747
1799
|
tinaSchema,
|
|
1748
1800
|
usingTs
|
|
1749
1801
|
}, options) {
|
|
1750
|
-
var _a, _b, _c;
|
|
1802
|
+
var _a, _b, _c, _d, _e;
|
|
1751
1803
|
const branch = (_a = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _a.branch;
|
|
1752
1804
|
const clientId = (_b = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _b.clientId;
|
|
1753
1805
|
const token = (_c = tinaSchema.config) == null ? void 0 : _c.token;
|
|
1806
|
+
const baseUrl = ((_e = (_d = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _d.tinaioConfig) == null ? void 0 : _e.contentApiUrlOverride) || `https://${TINA_HOST}`;
|
|
1754
1807
|
if ((!branch || !clientId || !token) && !(options == null ? void 0 : options.local)) {
|
|
1755
1808
|
const missing = [];
|
|
1756
1809
|
if (!branch)
|
|
@@ -1761,8 +1814,8 @@ async function genClient({
|
|
|
1761
1814
|
missing.push("token");
|
|
1762
1815
|
throw new Error(`Client not configured properly. Missing ${missing.join(", ")}. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information`);
|
|
1763
1816
|
}
|
|
1764
|
-
const apiURL = options.local ?
|
|
1765
|
-
const clientPath =
|
|
1817
|
+
const apiURL = options.local ? `http://localhost:${options.port || 4001}/graphql` : `${baseUrl}/content/${clientId}/github/${branch}`;
|
|
1818
|
+
const clientPath = import_path7.default.join(generatedPath, `client.${usingTs ? "ts" : "js"}`);
|
|
1766
1819
|
import_fs_extra4.default.writeFileSync(clientPath, `import { createClient } from "tinacms/dist/client";
|
|
1767
1820
|
import { queries } from "./types";
|
|
1768
1821
|
export const client = createClient({ url: '${apiURL}', token: '${token}', queries });
|
|
@@ -1814,12 +1867,12 @@ schema {
|
|
|
1814
1867
|
var import_fs_extra5 = __toModule(require("fs-extra"));
|
|
1815
1868
|
var import_ini = __toModule(require("ini"));
|
|
1816
1869
|
var import_os = __toModule(require("os"));
|
|
1817
|
-
var
|
|
1870
|
+
var import_path8 = __toModule(require("path"));
|
|
1818
1871
|
var resolveGitRoot = async () => {
|
|
1819
|
-
const pathParts = process.cwd().split(
|
|
1872
|
+
const pathParts = process.cwd().split(import_path8.default.sep);
|
|
1820
1873
|
while (true) {
|
|
1821
|
-
const pathToGit = pathParts.join(
|
|
1822
|
-
if (await import_fs_extra5.default.pathExists(
|
|
1874
|
+
const pathToGit = pathParts.join(import_path8.default.sep);
|
|
1875
|
+
if (await import_fs_extra5.default.pathExists(import_path8.default.join(pathToGit, ".git"))) {
|
|
1823
1876
|
return pathToGit;
|
|
1824
1877
|
}
|
|
1825
1878
|
if (!pathParts.length) {
|
|
@@ -1844,14 +1897,14 @@ async function makeIsomorphicOptions(fsBridge) {
|
|
|
1844
1897
|
await fsBridge.delete(filepath);
|
|
1845
1898
|
}
|
|
1846
1899
|
};
|
|
1847
|
-
const userGitConfig = `${import_os.default.homedir()}${
|
|
1900
|
+
const userGitConfig = `${import_os.default.homedir()}${import_path8.default.sep}.gitconfig`;
|
|
1848
1901
|
if (await import_fs_extra5.default.pathExists(userGitConfig)) {
|
|
1849
|
-
const
|
|
1850
|
-
if ((_a =
|
|
1851
|
-
options.author.name =
|
|
1902
|
+
const config2 = import_ini.default.parse(await import_fs_extra5.default.readFile(userGitConfig, "utf-8"));
|
|
1903
|
+
if ((_a = config2["user"]) == null ? void 0 : _a["name"]) {
|
|
1904
|
+
options.author.name = config2["user"]["name"];
|
|
1852
1905
|
}
|
|
1853
|
-
if ((_b =
|
|
1854
|
-
options.author.email =
|
|
1906
|
+
if ((_b = config2["user"]) == null ? void 0 : _b["email"]) {
|
|
1907
|
+
options.author.email = config2["user"]["email"];
|
|
1855
1908
|
}
|
|
1856
1909
|
}
|
|
1857
1910
|
let repoGitConfig = void 0;
|
|
@@ -1897,20 +1950,21 @@ async function spin({
|
|
|
1897
1950
|
spinner.start();
|
|
1898
1951
|
const res = await waitFor();
|
|
1899
1952
|
spinner.stop();
|
|
1953
|
+
console.log("");
|
|
1900
1954
|
return res;
|
|
1901
1955
|
}
|
|
1902
1956
|
|
|
1903
1957
|
// src/buildTina/attachPath.ts
|
|
1904
1958
|
var import_fs_extra6 = __toModule(require("fs-extra"));
|
|
1905
|
-
var
|
|
1959
|
+
var import_path9 = __toModule(require("path"));
|
|
1906
1960
|
var attachPath = async (ctx, next, _options) => {
|
|
1907
1961
|
ctx.rootPath = process.cwd();
|
|
1908
1962
|
ctx.usingTs = await isProjectTs(ctx.rootPath);
|
|
1909
1963
|
next();
|
|
1910
1964
|
};
|
|
1911
1965
|
var isProjectTs = async (rootPath2) => {
|
|
1912
|
-
const tinaPath =
|
|
1913
|
-
return await (0, import_fs_extra6.pathExists)(
|
|
1966
|
+
const tinaPath = import_path9.default.join(rootPath2, ".tina");
|
|
1967
|
+
return await (0, import_fs_extra6.pathExists)(import_path9.default.join(tinaPath, "schema.ts")) || await (0, import_fs_extra6.pathExists)(import_path9.default.join(tinaPath, "schema.tsx"));
|
|
1914
1968
|
};
|
|
1915
1969
|
|
|
1916
1970
|
// src/buildTina/index.ts
|
|
@@ -1939,6 +1993,7 @@ var buildSetupCmdServerStart = async (ctx, next, opts) => {
|
|
|
1939
1993
|
var buildSetupCmdAudit = async (ctx, next, options) => {
|
|
1940
1994
|
const rootPath2 = ctx.rootPath;
|
|
1941
1995
|
const bridge = options.clean ? new import_datalayer.FilesystemBridge(rootPath2) : new import_datalayer.AuditFileSystemBridge(rootPath2);
|
|
1996
|
+
await import_fs_extra7.default.ensureDirSync(import_path10.default.join(rootPath2, ".tina", "__generated__"));
|
|
1942
1997
|
const store = new import_datalayer.LevelStore(rootPath2, false);
|
|
1943
1998
|
const database = await (0, import_graphql9.createDatabase)({ store, bridge });
|
|
1944
1999
|
ctx.bridge = bridge;
|
|
@@ -1954,6 +2009,7 @@ var buildSetup = async ({
|
|
|
1954
2009
|
const fsBridge = new import_datalayer.FilesystemBridge(rootPath2);
|
|
1955
2010
|
const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
|
|
1956
2011
|
const bridge = isomorphicGitBridge2 ? new import_datalayer.IsomorphicBridge(rootPath2, isomorphicOptions) : fsBridge;
|
|
2012
|
+
await import_fs_extra7.default.ensureDirSync(import_path10.default.join(rootPath2, ".tina", "__generated__"));
|
|
1957
2013
|
const store = new import_datalayer.LevelStore(rootPath2, useMemoryStore);
|
|
1958
2014
|
const database = await (0, import_graphql9.createDatabase)({ store, bridge });
|
|
1959
2015
|
return { database, bridge, store };
|
|
@@ -1962,12 +2018,14 @@ var buildCmdBuild = async (ctx, next, options) => {
|
|
|
1962
2018
|
const { schema } = await ctx.builder.build(__spreadValues({
|
|
1963
2019
|
rootPath: ctx.rootPath
|
|
1964
2020
|
}, options));
|
|
2021
|
+
ctx.schema = schema;
|
|
1965
2022
|
const apiUrl = await ctx.builder.genTypedClient({
|
|
1966
2023
|
compiledSchema: schema,
|
|
1967
2024
|
local: options.local,
|
|
1968
2025
|
noSDK: options.noSDK,
|
|
1969
2026
|
verbose: options.verbose,
|
|
1970
|
-
usingTs: ctx.usingTs
|
|
2027
|
+
usingTs: ctx.usingTs,
|
|
2028
|
+
port: options.port
|
|
1971
2029
|
});
|
|
1972
2030
|
await buildAdmin({
|
|
1973
2031
|
local: options.local,
|
|
@@ -1983,7 +2041,12 @@ var auditCmdBuild = async (ctx, next, options) => {
|
|
|
1983
2041
|
}, options), {
|
|
1984
2042
|
verbose: true
|
|
1985
2043
|
}));
|
|
1986
|
-
await
|
|
2044
|
+
await spin({
|
|
2045
|
+
waitFor: async () => {
|
|
2046
|
+
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
2047
|
+
},
|
|
2048
|
+
text: "Indexing local files"
|
|
2049
|
+
});
|
|
1987
2050
|
next();
|
|
1988
2051
|
};
|
|
1989
2052
|
var ConfigBuilder = class {
|
|
@@ -1995,7 +2058,7 @@ var ConfigBuilder = class {
|
|
|
1995
2058
|
if (!rootPath2) {
|
|
1996
2059
|
throw new Error("Root path has not been attached");
|
|
1997
2060
|
}
|
|
1998
|
-
const tinaGeneratedPath =
|
|
2061
|
+
const tinaGeneratedPath = import_path10.default.join(rootPath2, ".tina", "__generated__");
|
|
1999
2062
|
this.database.clearCache();
|
|
2000
2063
|
await import_fs_extra7.default.mkdirp(tinaGeneratedPath);
|
|
2001
2064
|
await this.database.store.close();
|
|
@@ -2017,7 +2080,8 @@ var ConfigBuilder = class {
|
|
|
2017
2080
|
compiledSchema,
|
|
2018
2081
|
noSDK,
|
|
2019
2082
|
verbose,
|
|
2020
|
-
local
|
|
2083
|
+
local,
|
|
2084
|
+
port
|
|
2021
2085
|
}) {
|
|
2022
2086
|
const astSchema = await (0, import_graphql9.getASTSchema)(this.database);
|
|
2023
2087
|
await genTypes({ schema: astSchema, usingTs }, () => {
|
|
@@ -2026,7 +2090,8 @@ var ConfigBuilder = class {
|
|
|
2026
2090
|
verbose
|
|
2027
2091
|
});
|
|
2028
2092
|
return genClient({ tinaSchema: compiledSchema, usingTs }, {
|
|
2029
|
-
local
|
|
2093
|
+
local,
|
|
2094
|
+
port
|
|
2030
2095
|
});
|
|
2031
2096
|
}
|
|
2032
2097
|
};
|
|
@@ -2038,20 +2103,26 @@ var buildAdmin = async ({
|
|
|
2038
2103
|
}) => {
|
|
2039
2104
|
var _a;
|
|
2040
2105
|
if ((_a = schema == null ? void 0 : schema.config) == null ? void 0 : _a.build) {
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2106
|
+
const buildVite = async () => {
|
|
2107
|
+
var _a2, _b, _c, _d;
|
|
2108
|
+
await (0, import_app.viteBuild)({
|
|
2109
|
+
local,
|
|
2110
|
+
rootPath: rootPath2,
|
|
2111
|
+
outputFolder: (_b = (_a2 = schema == null ? void 0 : schema.config) == null ? void 0 : _a2.build) == null ? void 0 : _b.outputFolder,
|
|
2112
|
+
publicFolder: (_d = (_c = schema == null ? void 0 : schema.config) == null ? void 0 : _c.build) == null ? void 0 : _d.publicFolder,
|
|
2113
|
+
apiUrl
|
|
2114
|
+
});
|
|
2115
|
+
};
|
|
2116
|
+
if (local) {
|
|
2117
|
+
console.log("Starting Tina asset server");
|
|
2118
|
+
await buildVite();
|
|
2119
|
+
} else {
|
|
2120
|
+
await spin({
|
|
2121
|
+
text: "Building static site",
|
|
2122
|
+
waitFor: buildVite
|
|
2123
|
+
});
|
|
2124
|
+
console.log("\nDone building static site");
|
|
2125
|
+
}
|
|
2055
2126
|
}
|
|
2056
2127
|
};
|
|
2057
2128
|
|
|
@@ -2099,26 +2170,28 @@ async function startServer(ctx, next, {
|
|
|
2099
2170
|
try {
|
|
2100
2171
|
const s = (init_server3(), server_exports);
|
|
2101
2172
|
state.server = await s.default(database);
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2173
|
+
await new Promise((resolve2, reject) => {
|
|
2174
|
+
state.server.listen(port, () => {
|
|
2175
|
+
var _a, _b;
|
|
2176
|
+
const altairUrl = `http://localhost:${port}/altair/`;
|
|
2177
|
+
const cmsUrl = ((_b = (_a = ctx.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.build) ? `[your-development-url]/${ctx.schema.config.build.outputFolder}/index.html` : `[your-development-url]/admin`;
|
|
2178
|
+
if (verbose)
|
|
2179
|
+
logger.info(`Started Filesystem GraphQL server on port: ${port}`);
|
|
2180
|
+
logger.info(`Visit the GraphQL playground at ${import_chalk6.default.underline.blueBright(altairUrl)}
|
|
2109
2181
|
or`);
|
|
2110
|
-
|
|
2182
|
+
logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
|
|
2111
2183
|
`);
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2184
|
+
resolve2();
|
|
2185
|
+
});
|
|
2186
|
+
state.server.on("error", function(e) {
|
|
2187
|
+
if (e.code === "EADDRINUSE") {
|
|
2188
|
+
logger.error(dangerText(`Port ${port} already in use`));
|
|
2189
|
+
}
|
|
2190
|
+
reject(e);
|
|
2191
|
+
});
|
|
2192
|
+
state.server.on("connection", (socket) => {
|
|
2193
|
+
state.sockets.push(socket);
|
|
2194
|
+
});
|
|
2122
2195
|
});
|
|
2123
2196
|
} catch (error) {
|
|
2124
2197
|
throw error;
|
|
@@ -2150,14 +2223,21 @@ or`);
|
|
|
2150
2223
|
dev,
|
|
2151
2224
|
verbose
|
|
2152
2225
|
});
|
|
2226
|
+
ctx.schema = schema;
|
|
2153
2227
|
const apiUrl = await ctx.builder.genTypedClient({
|
|
2154
2228
|
compiledSchema: schema,
|
|
2155
2229
|
local: true,
|
|
2156
2230
|
noSDK,
|
|
2157
2231
|
verbose,
|
|
2158
|
-
usingTs: ctx.usingTs
|
|
2232
|
+
usingTs: ctx.usingTs,
|
|
2233
|
+
port
|
|
2234
|
+
});
|
|
2235
|
+
await spin({
|
|
2236
|
+
waitFor: async () => {
|
|
2237
|
+
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
2238
|
+
},
|
|
2239
|
+
text: "Indexing local files"
|
|
2159
2240
|
});
|
|
2160
|
-
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
2161
2241
|
await buildAdmin({
|
|
2162
2242
|
local: true,
|
|
2163
2243
|
rootPath: ctx.rootPath,
|
|
@@ -2170,7 +2250,7 @@ or`);
|
|
|
2170
2250
|
await afterBuild();
|
|
2171
2251
|
}
|
|
2172
2252
|
};
|
|
2173
|
-
const foldersToWatch = (watchFolders || []).map((x) =>
|
|
2253
|
+
const foldersToWatch = (watchFolders || []).map((x) => import_path13.default.join(rootPath2, x));
|
|
2174
2254
|
if (!noWatch && !process.env.CI) {
|
|
2175
2255
|
import_chokidar.default.watch([
|
|
2176
2256
|
...foldersToWatch,
|
|
@@ -2180,7 +2260,7 @@ or`);
|
|
|
2180
2260
|
ignored: [
|
|
2181
2261
|
"**/node_modules/**/*",
|
|
2182
2262
|
"**/.next/**/*",
|
|
2183
|
-
`${
|
|
2263
|
+
`${import_path13.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
2184
2264
|
]
|
|
2185
2265
|
}).on("ready", async () => {
|
|
2186
2266
|
if (verbose)
|
|
@@ -2195,8 +2275,7 @@ or`);
|
|
|
2195
2275
|
next();
|
|
2196
2276
|
} catch (e) {
|
|
2197
2277
|
handleServerErrors(e);
|
|
2198
|
-
|
|
2199
|
-
process.exit(0);
|
|
2278
|
+
throw e;
|
|
2200
2279
|
}
|
|
2201
2280
|
}).on("all", async () => {
|
|
2202
2281
|
if (ready) {
|
|
@@ -2235,7 +2314,8 @@ or`);
|
|
|
2235
2314
|
}
|
|
2236
2315
|
}
|
|
2237
2316
|
|
|
2238
|
-
// src/cmds/
|
|
2317
|
+
// src/cmds/statusChecks/waitForIndexing.ts
|
|
2318
|
+
var import_progress2 = __toModule(require("progress"));
|
|
2239
2319
|
var POLLING_INTERVAL = 5e3;
|
|
2240
2320
|
var STATUS_INPROGRESS = "inprogress";
|
|
2241
2321
|
var STATUS_COMPLETE = "complete";
|
|
@@ -2247,23 +2327,15 @@ var IndexFailedError = class extends Error {
|
|
|
2247
2327
|
}
|
|
2248
2328
|
};
|
|
2249
2329
|
var waitForDB = async (ctx, next, options) => {
|
|
2250
|
-
if (options.verbose) {
|
|
2251
|
-
logger.info(logText("Waiting for DB..."));
|
|
2252
|
-
}
|
|
2253
2330
|
if (!ctx.client) {
|
|
2254
|
-
|
|
2255
|
-
logger.info(logText("client is unavailable, skipping..."));
|
|
2256
|
-
}
|
|
2257
|
-
return next();
|
|
2331
|
+
throw new Error("No Tina Cloud found. For more information on how to setup the tina cloud see https://tina.io/docs/features/data-fetching/#making-requests-with-the-tina-client");
|
|
2258
2332
|
}
|
|
2259
2333
|
const client = ctx.client;
|
|
2260
2334
|
const { host, clientId, branch, isLocalClient } = client.parseURL();
|
|
2261
2335
|
if (isLocalClient) {
|
|
2262
|
-
if (options.verbose) {
|
|
2263
|
-
logger.info(logText("client is local, skipping..."));
|
|
2264
|
-
}
|
|
2265
2336
|
return next();
|
|
2266
2337
|
}
|
|
2338
|
+
const bar = new import_progress2.default("Checking indexing process in Tina Cloud... :prog", 1);
|
|
2267
2339
|
const pollForStatus = async () => {
|
|
2268
2340
|
try {
|
|
2269
2341
|
if (options.verbose) {
|
|
@@ -2279,11 +2351,11 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
2279
2351
|
headers
|
|
2280
2352
|
});
|
|
2281
2353
|
const { status, error } = await response.json();
|
|
2282
|
-
const statusMessage = `
|
|
2354
|
+
const statusMessage = `Indexing status: '${status}'`;
|
|
2283
2355
|
if (status === STATUS_COMPLETE) {
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
}
|
|
2356
|
+
bar.tick({
|
|
2357
|
+
prog: "\u2705"
|
|
2358
|
+
});
|
|
2287
2359
|
return next();
|
|
2288
2360
|
} else if (status === STATUS_INPROGRESS) {
|
|
2289
2361
|
if (options.verbose) {
|
|
@@ -2291,22 +2363,25 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
2291
2363
|
}
|
|
2292
2364
|
setTimeout(pollForStatus, POLLING_INTERVAL);
|
|
2293
2365
|
} else if (status === STATUS_FAILED) {
|
|
2294
|
-
throw new IndexFailedError(`Attempting to index
|
|
2366
|
+
throw new IndexFailedError(`Attempting to index but responded with status 'failed', ${error}`);
|
|
2295
2367
|
} else {
|
|
2296
|
-
|
|
2297
|
-
logger.info(logText(`${statusMessage}`));
|
|
2298
|
-
}
|
|
2299
|
-
return next();
|
|
2368
|
+
throw new IndexFailedError(`Attempting to index but responded with status 'unknown', ${error}`);
|
|
2300
2369
|
}
|
|
2301
2370
|
} catch (e) {
|
|
2302
2371
|
if (e instanceof IndexFailedError) {
|
|
2372
|
+
bar.tick({
|
|
2373
|
+
prog: "\u274C"
|
|
2374
|
+
});
|
|
2303
2375
|
throw e;
|
|
2304
2376
|
} else {
|
|
2305
2377
|
throw new Error(`Unable to query DB for indexing status, encountered error: ${e.message}`);
|
|
2306
2378
|
}
|
|
2307
2379
|
}
|
|
2308
2380
|
};
|
|
2309
|
-
|
|
2381
|
+
spin({
|
|
2382
|
+
text: "Checking indexing process in Tina Cloud...",
|
|
2383
|
+
waitFor: pollForStatus
|
|
2384
|
+
});
|
|
2310
2385
|
};
|
|
2311
2386
|
|
|
2312
2387
|
// src/cmds/startSubprocess/index.ts
|
|
@@ -2334,6 +2409,255 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
2334
2409
|
}
|
|
2335
2410
|
};
|
|
2336
2411
|
|
|
2412
|
+
// src/cmds/init/static.ts
|
|
2413
|
+
var import_path14 = __toModule(require("path"));
|
|
2414
|
+
var import_fs_extra9 = __toModule(require("fs-extra"));
|
|
2415
|
+
var import_prompts3 = __toModule(require("prompts"));
|
|
2416
|
+
var import_metrics4 = __toModule(require("@tinacms/metrics"));
|
|
2417
|
+
async function initStaticTina(ctx, next, options) {
|
|
2418
|
+
logger.level = "info";
|
|
2419
|
+
const packageManager = await choosePackageManager();
|
|
2420
|
+
const usingTypescript = await chooseTypescript();
|
|
2421
|
+
const publicFolder = await choosePublicFolder();
|
|
2422
|
+
await reportTelemetry(usingTypescript, options.noTelemetry);
|
|
2423
|
+
const hasPackageJSON = await import_fs_extra9.default.pathExistsSync("package.json");
|
|
2424
|
+
if (!hasPackageJSON) {
|
|
2425
|
+
await createPackageJSON();
|
|
2426
|
+
}
|
|
2427
|
+
const hasGitignore = await import_fs_extra9.default.pathExistsSync(".gitignore");
|
|
2428
|
+
if (!hasGitignore) {
|
|
2429
|
+
await createGitignore();
|
|
2430
|
+
} else {
|
|
2431
|
+
const hasNodeModulesIgnored = await checkGitignoreForNodeModules();
|
|
2432
|
+
if (!hasNodeModulesIgnored) {
|
|
2433
|
+
await addNodeModulesToGitignore();
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
await addDependencies(packageManager);
|
|
2437
|
+
await addConfigFile(publicFolder, usingTypescript);
|
|
2438
|
+
await addContentFile();
|
|
2439
|
+
logNextSteps(packageManager);
|
|
2440
|
+
}
|
|
2441
|
+
var baseDir2 = process.cwd();
|
|
2442
|
+
var choosePackageManager = async () => {
|
|
2443
|
+
const option = await (0, import_prompts3.default)({
|
|
2444
|
+
name: "selection",
|
|
2445
|
+
type: "select",
|
|
2446
|
+
message: "Choose your package manager",
|
|
2447
|
+
choices: [
|
|
2448
|
+
{ title: "PNPM", value: "pnpm" },
|
|
2449
|
+
{ title: "Yarn", value: "yarn" },
|
|
2450
|
+
{ title: "NPM", value: "npm" }
|
|
2451
|
+
]
|
|
2452
|
+
});
|
|
2453
|
+
return option["selection"];
|
|
2454
|
+
};
|
|
2455
|
+
var chooseTypescript = async () => {
|
|
2456
|
+
const option = await (0, import_prompts3.default)({
|
|
2457
|
+
name: "selection",
|
|
2458
|
+
type: "confirm",
|
|
2459
|
+
initial: true,
|
|
2460
|
+
message: "Would you like to use Typescript?"
|
|
2461
|
+
});
|
|
2462
|
+
return option["selection"];
|
|
2463
|
+
};
|
|
2464
|
+
var choosePublicFolder = async () => {
|
|
2465
|
+
const option = await (0, import_prompts3.default)({
|
|
2466
|
+
name: "selection",
|
|
2467
|
+
type: "text",
|
|
2468
|
+
message: 'Where are public assets stored? (default: "public")'
|
|
2469
|
+
});
|
|
2470
|
+
return option["selection"] || "public";
|
|
2471
|
+
};
|
|
2472
|
+
var reportTelemetry = async (usingTypescript, noTelemetry) => {
|
|
2473
|
+
if (noTelemetry) {
|
|
2474
|
+
logger.info(logText("Telemetry disabled"));
|
|
2475
|
+
}
|
|
2476
|
+
const telemetry = new import_metrics4.Telemetry({ disabled: noTelemetry });
|
|
2477
|
+
const schemaFileType2 = usingTypescript ? "ts" : "js";
|
|
2478
|
+
await telemetry.submitRecord({
|
|
2479
|
+
event: {
|
|
2480
|
+
name: "tinacms:cli:init:invoke",
|
|
2481
|
+
schemaFileType: schemaFileType2
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
};
|
|
2485
|
+
var createPackageJSON = async () => {
|
|
2486
|
+
logger.info(logText("No package.json found, creating one"));
|
|
2487
|
+
execShellCommand(`npm init --yes`);
|
|
2488
|
+
};
|
|
2489
|
+
var createGitignore = async () => {
|
|
2490
|
+
logger.info(logText("No .gitignore found, creating one"));
|
|
2491
|
+
await import_fs_extra9.default.outputFileSync(import_path14.default.join(baseDir2, ".gitignore"), "node_modules");
|
|
2492
|
+
};
|
|
2493
|
+
var checkGitignoreForNodeModules = async () => {
|
|
2494
|
+
const gitignoreContent = await import_fs_extra9.default.readFileSync(import_path14.default.join(baseDir2, ".gitignore")).toString();
|
|
2495
|
+
return gitignoreContent.split("\n").some((item) => item === "node_modules");
|
|
2496
|
+
};
|
|
2497
|
+
var addNodeModulesToGitignore = async () => {
|
|
2498
|
+
logger.info(logText("Adding node_modules to .gitignore"));
|
|
2499
|
+
const gitignoreContent = await import_fs_extra9.default.readFileSync(import_path14.default.join(baseDir2, ".gitignore")).toString();
|
|
2500
|
+
const newGitignoreContent = [
|
|
2501
|
+
...gitignoreContent.split("\n"),
|
|
2502
|
+
"node_modules"
|
|
2503
|
+
].join("\n");
|
|
2504
|
+
await import_fs_extra9.default.writeFileSync(import_path14.default.join(baseDir2, ".gitignore"), newGitignoreContent);
|
|
2505
|
+
};
|
|
2506
|
+
var addDependencies = async (packageManager) => {
|
|
2507
|
+
logger.info(logText("Adding dependencies, this might take a moment..."));
|
|
2508
|
+
const deps = ["tinacms", "@tinacms/cli"];
|
|
2509
|
+
const packageManagers = {
|
|
2510
|
+
pnpm: process.env.USE_WORKSPACE ? `pnpm add ${deps.join(" ")} --workspace` : `pnpm add ${deps.join(" ")}`,
|
|
2511
|
+
npm: `npm install ${deps.join(" ")}`,
|
|
2512
|
+
yarn: `yarn add ${deps.join(" ")}`
|
|
2513
|
+
};
|
|
2514
|
+
logger.info(` ${logText(packageManagers[packageManager])}`);
|
|
2515
|
+
await execShellCommand(packageManagers[packageManager]);
|
|
2516
|
+
};
|
|
2517
|
+
var addConfigFile = async (publicFolder, usingTypescript) => {
|
|
2518
|
+
const configPath = import_path14.default.join(".tina", `config.${usingTypescript ? "ts" : "js"}`);
|
|
2519
|
+
const fullConfigPath = import_path14.default.join(baseDir2, configPath);
|
|
2520
|
+
if (import_fs_extra9.default.pathExistsSync(fullConfigPath)) {
|
|
2521
|
+
const override = await (0, import_prompts3.default)({
|
|
2522
|
+
name: "selection",
|
|
2523
|
+
type: "confirm",
|
|
2524
|
+
message: `Found existing file at ${configPath}. Would you like to override?`
|
|
2525
|
+
});
|
|
2526
|
+
if (override["selection"]) {
|
|
2527
|
+
logger.info(logText(`Overriding file at ${configPath}.`));
|
|
2528
|
+
await import_fs_extra9.default.outputFileSync(fullConfigPath, config({ publicFolder }));
|
|
2529
|
+
} else {
|
|
2530
|
+
logger.info(logText(`Not overriding file at ${configPath}.`));
|
|
2531
|
+
}
|
|
2532
|
+
} else {
|
|
2533
|
+
logger.info(logText(`Adding config file at .tina/config.${usingTypescript ? "ts" : "js"}`));
|
|
2534
|
+
await import_fs_extra9.default.outputFileSync(fullConfigPath, config({ publicFolder }));
|
|
2535
|
+
}
|
|
2536
|
+
};
|
|
2537
|
+
var addContentFile = async () => {
|
|
2538
|
+
const contentPath = import_path14.default.join("content", "posts", "hello-world.md");
|
|
2539
|
+
const fullContentPath = import_path14.default.join(baseDir2, contentPath);
|
|
2540
|
+
if (import_fs_extra9.default.pathExistsSync(fullContentPath)) {
|
|
2541
|
+
const override = await (0, import_prompts3.default)({
|
|
2542
|
+
name: "selection",
|
|
2543
|
+
type: "confirm",
|
|
2544
|
+
message: `Found existing file at ${contentPath}. Would you like to override?`
|
|
2545
|
+
});
|
|
2546
|
+
if (override["selection"]) {
|
|
2547
|
+
logger.info(logText(`Overriding file at ${contentPath}.`));
|
|
2548
|
+
await import_fs_extra9.default.outputFileSync(fullContentPath, content);
|
|
2549
|
+
} else {
|
|
2550
|
+
logger.info(logText(`Not overriding file at ${contentPath}.`));
|
|
2551
|
+
}
|
|
2552
|
+
} else {
|
|
2553
|
+
logger.info(logText(`Adding content file at ${contentPath}`));
|
|
2554
|
+
await import_fs_extra9.default.outputFileSync(fullContentPath, content);
|
|
2555
|
+
}
|
|
2556
|
+
};
|
|
2557
|
+
var logNextSteps = (packageManager) => {
|
|
2558
|
+
const packageManagers = {
|
|
2559
|
+
pnpm: `pnpm `,
|
|
2560
|
+
npm: `npx `,
|
|
2561
|
+
yarn: `yarn `
|
|
2562
|
+
};
|
|
2563
|
+
logger.info(`
|
|
2564
|
+
${successText("TinaCMS has been initialized, to get started run:")}
|
|
2565
|
+
|
|
2566
|
+
${packageManagers[packageManager]} tinacms dev -c "<your dev command>"
|
|
2567
|
+
`);
|
|
2568
|
+
};
|
|
2569
|
+
var config = (args) => `
|
|
2570
|
+
import { defineStaticConfig } from "tinacms";
|
|
2571
|
+
|
|
2572
|
+
// Your hosting provider likely exposes this as an environment variable
|
|
2573
|
+
const branch = process.env.HEAD || process.env.VERCEL_GIT_COMMIT_REF || "main";
|
|
2574
|
+
|
|
2575
|
+
export default defineStaticConfig({
|
|
2576
|
+
branch,
|
|
2577
|
+
clientId: null, // Get this from tina.io
|
|
2578
|
+
token: null, // Get this from tina.io
|
|
2579
|
+
build: {
|
|
2580
|
+
outputFolder: "admin",
|
|
2581
|
+
publicFolder: "${args.publicFolder}",
|
|
2582
|
+
},
|
|
2583
|
+
media: {
|
|
2584
|
+
tina: {
|
|
2585
|
+
mediaRoot: "uploads",
|
|
2586
|
+
publicFolder: "${args.publicFolder}",
|
|
2587
|
+
},
|
|
2588
|
+
},
|
|
2589
|
+
schema: {
|
|
2590
|
+
collections: [
|
|
2591
|
+
{
|
|
2592
|
+
name: "post",
|
|
2593
|
+
label: "Posts",
|
|
2594
|
+
path: "content/posts",
|
|
2595
|
+
fields: [
|
|
2596
|
+
{
|
|
2597
|
+
type: "string",
|
|
2598
|
+
name: "title",
|
|
2599
|
+
label: "Title",
|
|
2600
|
+
isTitle: true,
|
|
2601
|
+
},
|
|
2602
|
+
{
|
|
2603
|
+
type: "rich-text",
|
|
2604
|
+
name: "body",
|
|
2605
|
+
label: "Body",
|
|
2606
|
+
isBody: true,
|
|
2607
|
+
},
|
|
2608
|
+
],
|
|
2609
|
+
},
|
|
2610
|
+
],
|
|
2611
|
+
},
|
|
2612
|
+
});
|
|
2613
|
+
`;
|
|
2614
|
+
var content = `---
|
|
2615
|
+
title: Hello, World!
|
|
2616
|
+
---
|
|
2617
|
+
|
|
2618
|
+
## Hello World!
|
|
2619
|
+
|
|
2620
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non lorem diam. Quisque vulputate nibh sodales eros pretium tincidunt. Aenean porttitor efficitur convallis. Nulla sagittis finibus convallis. Phasellus in fermentum quam, eu egestas tortor. Maecenas ac mollis leo. Integer maximus eu nisl vel sagittis.
|
|
2621
|
+
|
|
2622
|
+
Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a posuere eros justo nec sem. Nullam laoreet accumsan metus, sit amet tincidunt orci egestas nec. Pellentesque ut aliquet ante, at tristique nunc. Donec non massa nibh. Ut posuere lacus non aliquam laoreet. Fusce pharetra ligula a felis porttitor, at mollis ipsum maximus. Donec quam tortor, vehicula a magna sit amet, tincidunt dictum enim. In hac habitasse platea dictumst. Mauris sit amet ornare ligula, blandit consequat risus. Duis malesuada pellentesque lectus, non feugiat turpis eleifend a. Nullam tempus ante et diam pretium, ac faucibus ligula interdum.
|
|
2623
|
+
`;
|
|
2624
|
+
|
|
2625
|
+
// src/cmds/statusChecks/checkClientInformation.ts
|
|
2626
|
+
var import_progress3 = __toModule(require("progress"));
|
|
2627
|
+
var checkClientInfo = async (ctx, next, _options) => {
|
|
2628
|
+
var _a;
|
|
2629
|
+
const client = ctx.client;
|
|
2630
|
+
const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
|
|
2631
|
+
const bar = new import_progress3.default("Checking clientId, token and branch. :prog", 1);
|
|
2632
|
+
try {
|
|
2633
|
+
await client.request({
|
|
2634
|
+
query: `query {
|
|
2635
|
+
collections {
|
|
2636
|
+
name
|
|
2637
|
+
}
|
|
2638
|
+
}`
|
|
2639
|
+
});
|
|
2640
|
+
bar.tick({
|
|
2641
|
+
prog: "\u2705"
|
|
2642
|
+
});
|
|
2643
|
+
} catch (e) {
|
|
2644
|
+
bar.tick({
|
|
2645
|
+
prog: "\u274C"
|
|
2646
|
+
});
|
|
2647
|
+
console.warn(`Error when checking client information. You provided
|
|
2648
|
+
|
|
2649
|
+
${JSON.stringify({
|
|
2650
|
+
branch: config2 == null ? void 0 : config2.branch,
|
|
2651
|
+
clientId: config2 == null ? void 0 : config2.clientId,
|
|
2652
|
+
token: config2 == null ? void 0 : config2.token
|
|
2653
|
+
}, null, 2)}
|
|
2654
|
+
|
|
2655
|
+
Please check you have the correct "clientId", "branch" and "token" configured. For more information see https://tina.io/docs/tina-cloud/connecting-site/`);
|
|
2656
|
+
throw e;
|
|
2657
|
+
}
|
|
2658
|
+
next();
|
|
2659
|
+
};
|
|
2660
|
+
|
|
2337
2661
|
// src/cmds/baseCmds.ts
|
|
2338
2662
|
var CMD_START_SERVER = "server:start";
|
|
2339
2663
|
var CMD_DEV = "dev";
|
|
@@ -2372,6 +2696,10 @@ var cleanOption = {
|
|
|
2372
2696
|
name: "--clean",
|
|
2373
2697
|
description: "Updates all content files to remove any data not explicitly permitted by the current schema definition"
|
|
2374
2698
|
};
|
|
2699
|
+
var staticOption = {
|
|
2700
|
+
name: "--static",
|
|
2701
|
+
description: "Bundle Tina as a static assset"
|
|
2702
|
+
};
|
|
2375
2703
|
var useDefaultValuesOption = {
|
|
2376
2704
|
name: "--useDefaultValues",
|
|
2377
2705
|
description: "Adds default values to the graphQL mutation so that default values can be filled into existing documents (useful for adding a field with `required: true`)"
|
|
@@ -2472,6 +2800,7 @@ var baseCmds = [
|
|
|
2472
2800
|
buildSetupCmdBuild,
|
|
2473
2801
|
buildCmdBuild,
|
|
2474
2802
|
compileClient,
|
|
2803
|
+
checkClientInfo,
|
|
2475
2804
|
waitForDB
|
|
2476
2805
|
], options)
|
|
2477
2806
|
},
|
|
@@ -2481,20 +2810,27 @@ var baseCmds = [
|
|
|
2481
2810
|
experimentalDatalayer,
|
|
2482
2811
|
isomorphicGitBridge,
|
|
2483
2812
|
noTelemetryOption,
|
|
2484
|
-
schemaFileType
|
|
2813
|
+
schemaFileType,
|
|
2814
|
+
staticOption
|
|
2485
2815
|
],
|
|
2486
2816
|
description: "Add Tina Cloud to an existing project",
|
|
2487
|
-
action: (options) =>
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2817
|
+
action: (options) => {
|
|
2818
|
+
if (options.static) {
|
|
2819
|
+
chain([attachPath, checkOptions, initStaticTina], options);
|
|
2820
|
+
} else {
|
|
2821
|
+
chain([
|
|
2822
|
+
attachPath,
|
|
2823
|
+
checkOptions,
|
|
2824
|
+
checkDeps,
|
|
2825
|
+
initTina,
|
|
2826
|
+
installDeps,
|
|
2827
|
+
buildSetupCmdBuild,
|
|
2828
|
+
buildCmdBuild,
|
|
2829
|
+
tinaSetup,
|
|
2830
|
+
successMessage
|
|
2831
|
+
], options);
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2498
2834
|
},
|
|
2499
2835
|
{
|
|
2500
2836
|
options: [
|