@tinacms/cli 0.61.12 → 0.61.14
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 +6 -3
- 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/query-gen/genTypes.d.ts +1 -1
- package/dist/cmds/start-server/index.d.ts +2 -0
- 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 +657 -319
- 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.14";
|
|
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
|
|
@@ -1282,6 +1328,7 @@ types.d.ts
|
|
|
1282
1328
|
frags.gql
|
|
1283
1329
|
queries.gql
|
|
1284
1330
|
schema.gql
|
|
1331
|
+
out.jsx
|
|
1285
1332
|
`);
|
|
1286
1333
|
};
|
|
1287
1334
|
var cleanup = async ({ tinaTempPath }) => {
|
|
@@ -1292,10 +1339,10 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1292
1339
|
if (!root2) {
|
|
1293
1340
|
throw new Error("ctx.rootPath has not been attached");
|
|
1294
1341
|
}
|
|
1295
|
-
const tinaPath =
|
|
1296
|
-
const tinaGeneratedPath =
|
|
1297
|
-
const packageJSONFilePath =
|
|
1298
|
-
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");
|
|
1299
1346
|
if (!options.clientFileType)
|
|
1300
1347
|
options = __spreadProps(__spreadValues({}, options), { clientFileType: "ts" });
|
|
1301
1348
|
if (options.verbose) {
|
|
@@ -1310,7 +1357,7 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1310
1357
|
ctx.clientFileType = requestedClientFileType;
|
|
1311
1358
|
}
|
|
1312
1359
|
let clientExists = true;
|
|
1313
|
-
const projectDir =
|
|
1360
|
+
const projectDir = import_path5.default.join(tinaPath, "__generated__");
|
|
1314
1361
|
try {
|
|
1315
1362
|
getClientPath({ projectDir });
|
|
1316
1363
|
} catch {
|
|
@@ -1341,7 +1388,7 @@ var compileClient = async (ctx, next, options) => {
|
|
|
1341
1388
|
}
|
|
1342
1389
|
});
|
|
1343
1390
|
try {
|
|
1344
|
-
const clientFunc = require(
|
|
1391
|
+
const clientFunc = require(import_path5.default.join(tinaTempPath, "client.js"));
|
|
1345
1392
|
const client = clientFunc.default;
|
|
1346
1393
|
ctx.client = client;
|
|
1347
1394
|
await cleanup({ tinaTempPath });
|
|
@@ -1361,11 +1408,11 @@ var compileFile = async (options, fileName) => {
|
|
|
1361
1408
|
if (!root2) {
|
|
1362
1409
|
throw new Error("ctx.rootPath has not been attached");
|
|
1363
1410
|
}
|
|
1364
|
-
const tinaPath =
|
|
1365
|
-
const tsConfigPath =
|
|
1366
|
-
const tinaGeneratedPath =
|
|
1367
|
-
const tinaTempPath =
|
|
1368
|
-
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");
|
|
1369
1416
|
if (!options.schemaFileType) {
|
|
1370
1417
|
const usingTs = await import_fs_extra3.default.pathExists(tsConfigPath);
|
|
1371
1418
|
options = __spreadProps(__spreadValues({}, options), { schemaFileType: usingTs ? "ts" : "js" });
|
|
@@ -1389,15 +1436,6 @@ var compileFile = async (options, fileName) => {
|
|
|
1389
1436
|
} catch {
|
|
1390
1437
|
schemaExists = false;
|
|
1391
1438
|
}
|
|
1392
|
-
if (!schemaExists && fileName === "schema") {
|
|
1393
|
-
logger.info(dangerText(`
|
|
1394
|
-
.tina/schema.${schemaFileType2} not found, Creating one for you...
|
|
1395
|
-
See Documentation: https://tina.io/docs/tina-cloud/cli/#getting-started"
|
|
1396
|
-
`));
|
|
1397
|
-
const file = import_path4.default.join(tinaPath, `schema.${schemaFileType2}`);
|
|
1398
|
-
await import_fs_extra3.default.ensureFile(file);
|
|
1399
|
-
await import_fs_extra3.default.writeFile(file, defaultSchema);
|
|
1400
|
-
}
|
|
1401
1439
|
try {
|
|
1402
1440
|
const define = {};
|
|
1403
1441
|
if (!process.env.NODE_ENV) {
|
|
@@ -1421,7 +1459,7 @@ var compileFile = async (options, fileName) => {
|
|
|
1421
1459
|
});
|
|
1422
1460
|
let returnObject = {};
|
|
1423
1461
|
try {
|
|
1424
|
-
const schemaFunc = require(
|
|
1462
|
+
const schemaFunc = require(import_path5.default.join(tinaTempPath, `${fileName}.js`));
|
|
1425
1463
|
returnObject = schemaFunc.default;
|
|
1426
1464
|
await cleanup({ tinaTempPath });
|
|
1427
1465
|
} catch (e) {
|
|
@@ -1437,20 +1475,35 @@ var compileFile = async (options, fileName) => {
|
|
|
1437
1475
|
};
|
|
1438
1476
|
var compileSchema = async (options) => {
|
|
1439
1477
|
const root2 = options.rootPath;
|
|
1440
|
-
const tinaPath =
|
|
1441
|
-
const tinaGeneratedPath =
|
|
1442
|
-
const tinaConfigPath =
|
|
1443
|
-
let
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
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);
|
|
1447
1501
|
delete configCopy.schema;
|
|
1448
|
-
if (
|
|
1449
|
-
schema = __spreadProps(__spreadValues({},
|
|
1502
|
+
if (config2 == null ? void 0 : config2.schema) {
|
|
1503
|
+
schema = __spreadProps(__spreadValues({}, config2.schema), { config: configCopy });
|
|
1450
1504
|
}
|
|
1451
|
-
} catch (e) {
|
|
1452
1505
|
}
|
|
1453
|
-
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));
|
|
1454
1507
|
return schema;
|
|
1455
1508
|
};
|
|
1456
1509
|
var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJSONFilePath) => {
|
|
@@ -1461,7 +1514,7 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
|
|
|
1461
1514
|
const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
|
|
1462
1515
|
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
1463
1516
|
const external = Object.keys(__spreadValues(__spreadValues(__spreadValues({}, deps), peerDeps), devDeps));
|
|
1464
|
-
const prebuiltInputPath =
|
|
1517
|
+
const prebuiltInputPath = import_path5.default.join(tempDir, "temp-output.jsx");
|
|
1465
1518
|
await (0, import_esbuild.build)({
|
|
1466
1519
|
bundle: true,
|
|
1467
1520
|
platform: "neutral",
|
|
@@ -1473,9 +1526,9 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
|
|
|
1473
1526
|
outfile: prebuiltInputPath,
|
|
1474
1527
|
define
|
|
1475
1528
|
});
|
|
1476
|
-
const tempTsConfigPath =
|
|
1529
|
+
const tempTsConfigPath = import_path5.default.join(tempDir, "temp-tsconfig.json");
|
|
1477
1530
|
await import_fs_extra3.default.outputFileSync(tempTsConfigPath, "{}");
|
|
1478
|
-
const outputPath =
|
|
1531
|
+
const outputPath = import_path5.default.join(tempDir, outputFile);
|
|
1479
1532
|
await (0, import_esbuild.build)({
|
|
1480
1533
|
bundle: true,
|
|
1481
1534
|
platform: "neutral",
|
|
@@ -1491,8 +1544,8 @@ var transpile = async (inputFile, outputFile, tempDir, verbose, define, packageJ
|
|
|
1491
1544
|
if (verbose)
|
|
1492
1545
|
logger.info(logText(`Javascript built`));
|
|
1493
1546
|
};
|
|
1494
|
-
var defineSchema = (
|
|
1495
|
-
return
|
|
1547
|
+
var defineSchema = (config2) => {
|
|
1548
|
+
return config2;
|
|
1496
1549
|
};
|
|
1497
1550
|
var loaders = {
|
|
1498
1551
|
".aac": "file",
|
|
@@ -1521,7 +1574,7 @@ var loaders = {
|
|
|
1521
1574
|
};
|
|
1522
1575
|
|
|
1523
1576
|
// src/cmds/start-server/index.ts
|
|
1524
|
-
var
|
|
1577
|
+
var import_path13 = __toModule(require("path"));
|
|
1525
1578
|
var import_chalk6 = __toModule(require("chalk"));
|
|
1526
1579
|
var import_chokidar = __toModule(require("chokidar"));
|
|
1527
1580
|
var import_metrics3 = __toModule(require("@tinacms/metrics"));
|
|
@@ -1542,12 +1595,12 @@ var AsyncLock = class {
|
|
|
1542
1595
|
var import_fs_extra7 = __toModule(require("fs-extra"));
|
|
1543
1596
|
var import_graphql9 = __toModule(require("@tinacms/graphql"));
|
|
1544
1597
|
var import_datalayer = __toModule(require("@tinacms/datalayer"));
|
|
1545
|
-
var
|
|
1598
|
+
var import_path10 = __toModule(require("path"));
|
|
1546
1599
|
|
|
1547
1600
|
// src/cmds/query-gen/genTypes.ts
|
|
1548
1601
|
var import_graphql8 = __toModule(require("graphql"));
|
|
1549
1602
|
var import_fs_extra4 = __toModule(require("fs-extra"));
|
|
1550
|
-
var
|
|
1603
|
+
var import_path7 = __toModule(require("path"));
|
|
1551
1604
|
|
|
1552
1605
|
// src/codegen/index.ts
|
|
1553
1606
|
var import_graphql7 = __toModule(require("graphql"));
|
|
@@ -1604,7 +1657,7 @@ var import_typescript = __toModule(require("@graphql-codegen/typescript"));
|
|
|
1604
1657
|
// src/codegen/sdkPlugin/index.ts
|
|
1605
1658
|
var import_graphql5 = __toModule(require("graphql"));
|
|
1606
1659
|
var import_graphql6 = __toModule(require("graphql"));
|
|
1607
|
-
var
|
|
1660
|
+
var import_path6 = __toModule(require("path"));
|
|
1608
1661
|
|
|
1609
1662
|
// src/codegen/sdkPlugin/visitor.ts
|
|
1610
1663
|
var import_visitor_plugin_common = __toModule(require("@graphql-codegen/visitor-plugin-common"));
|
|
@@ -1657,7 +1710,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
1657
1710
|
};
|
|
1658
1711
|
|
|
1659
1712
|
// src/codegen/sdkPlugin/index.ts
|
|
1660
|
-
var plugin = (schema, documents,
|
|
1713
|
+
var plugin = (schema, documents, config2) => {
|
|
1661
1714
|
const allAst = (0, import_graphql6.concatAST)(documents.reduce((prev, v) => {
|
|
1662
1715
|
return [...prev, v.document];
|
|
1663
1716
|
}, []));
|
|
@@ -1668,9 +1721,9 @@ var plugin = (schema, documents, config) => {
|
|
|
1668
1721
|
onType: fragmentDef.typeCondition.name.value,
|
|
1669
1722
|
isExternal: false
|
|
1670
1723
|
})),
|
|
1671
|
-
...
|
|
1724
|
+
...config2.externalFragments || []
|
|
1672
1725
|
];
|
|
1673
|
-
const visitor = new GenericSdkVisitor(schema, allFragments,
|
|
1726
|
+
const visitor = new GenericSdkVisitor(schema, allFragments, config2);
|
|
1674
1727
|
const visitorResult = (0, import_graphql5.visit)(allAst, { leave: visitor });
|
|
1675
1728
|
return {
|
|
1676
1729
|
content: [
|
|
@@ -1741,15 +1794,16 @@ var loadGraphQLDocuments = async (globPath) => {
|
|
|
1741
1794
|
var import_esbuild2 = __toModule(require("esbuild"));
|
|
1742
1795
|
var TINA_HOST = "content.tinajs.io";
|
|
1743
1796
|
var root = process.cwd();
|
|
1744
|
-
var generatedPath =
|
|
1797
|
+
var generatedPath = import_path7.default.join(root, ".tina", "__generated__");
|
|
1745
1798
|
async function genClient({
|
|
1746
1799
|
tinaSchema,
|
|
1747
1800
|
usingTs
|
|
1748
|
-
},
|
|
1749
|
-
var _a, _b, _c;
|
|
1801
|
+
}, options) {
|
|
1802
|
+
var _a, _b, _c, _d, _e;
|
|
1750
1803
|
const branch = (_a = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _a.branch;
|
|
1751
1804
|
const clientId = (_b = tinaSchema == null ? void 0 : tinaSchema.config) == null ? void 0 : _b.clientId;
|
|
1752
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}`;
|
|
1753
1807
|
if ((!branch || !clientId || !token) && !(options == null ? void 0 : options.local)) {
|
|
1754
1808
|
const missing = [];
|
|
1755
1809
|
if (!branch)
|
|
@@ -1760,14 +1814,14 @@ async function genClient({
|
|
|
1760
1814
|
missing.push("token");
|
|
1761
1815
|
throw new Error(`Client not configured properly. Missing ${missing.join(", ")}. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information`);
|
|
1762
1816
|
}
|
|
1763
|
-
const apiURL = options.local ?
|
|
1764
|
-
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"}`);
|
|
1765
1819
|
import_fs_extra4.default.writeFileSync(clientPath, `import { createClient } from "tinacms/dist/client";
|
|
1766
1820
|
import { queries } from "./types";
|
|
1767
1821
|
export const client = createClient({ url: '${apiURL}', token: '${token}', queries });
|
|
1768
1822
|
export default client;
|
|
1769
1823
|
`);
|
|
1770
|
-
return
|
|
1824
|
+
return apiURL;
|
|
1771
1825
|
}
|
|
1772
1826
|
async function genTypes({ schema, usingTs }, next, options) {
|
|
1773
1827
|
const typesPath = process.cwd() + "/.tina/__generated__/types.ts";
|
|
@@ -1813,12 +1867,12 @@ schema {
|
|
|
1813
1867
|
var import_fs_extra5 = __toModule(require("fs-extra"));
|
|
1814
1868
|
var import_ini = __toModule(require("ini"));
|
|
1815
1869
|
var import_os = __toModule(require("os"));
|
|
1816
|
-
var
|
|
1870
|
+
var import_path8 = __toModule(require("path"));
|
|
1817
1871
|
var resolveGitRoot = async () => {
|
|
1818
|
-
const pathParts = process.cwd().split(
|
|
1872
|
+
const pathParts = process.cwd().split(import_path8.default.sep);
|
|
1819
1873
|
while (true) {
|
|
1820
|
-
const pathToGit = pathParts.join(
|
|
1821
|
-
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"))) {
|
|
1822
1876
|
return pathToGit;
|
|
1823
1877
|
}
|
|
1824
1878
|
if (!pathParts.length) {
|
|
@@ -1843,14 +1897,14 @@ async function makeIsomorphicOptions(fsBridge) {
|
|
|
1843
1897
|
await fsBridge.delete(filepath);
|
|
1844
1898
|
}
|
|
1845
1899
|
};
|
|
1846
|
-
const userGitConfig = `${import_os.default.homedir()}${
|
|
1900
|
+
const userGitConfig = `${import_os.default.homedir()}${import_path8.default.sep}.gitconfig`;
|
|
1847
1901
|
if (await import_fs_extra5.default.pathExists(userGitConfig)) {
|
|
1848
|
-
const
|
|
1849
|
-
if ((_a =
|
|
1850
|
-
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"];
|
|
1851
1905
|
}
|
|
1852
|
-
if ((_b =
|
|
1853
|
-
options.author.email =
|
|
1906
|
+
if ((_b = config2["user"]) == null ? void 0 : _b["email"]) {
|
|
1907
|
+
options.author.email = config2["user"]["email"];
|
|
1854
1908
|
}
|
|
1855
1909
|
}
|
|
1856
1910
|
let repoGitConfig = void 0;
|
|
@@ -1896,20 +1950,21 @@ async function spin({
|
|
|
1896
1950
|
spinner.start();
|
|
1897
1951
|
const res = await waitFor();
|
|
1898
1952
|
spinner.stop();
|
|
1953
|
+
console.log("");
|
|
1899
1954
|
return res;
|
|
1900
1955
|
}
|
|
1901
1956
|
|
|
1902
1957
|
// src/buildTina/attachPath.ts
|
|
1903
1958
|
var import_fs_extra6 = __toModule(require("fs-extra"));
|
|
1904
|
-
var
|
|
1959
|
+
var import_path9 = __toModule(require("path"));
|
|
1905
1960
|
var attachPath = async (ctx, next, _options) => {
|
|
1906
1961
|
ctx.rootPath = process.cwd();
|
|
1907
1962
|
ctx.usingTs = await isProjectTs(ctx.rootPath);
|
|
1908
1963
|
next();
|
|
1909
1964
|
};
|
|
1910
1965
|
var isProjectTs = async (rootPath2) => {
|
|
1911
|
-
const tinaPath =
|
|
1912
|
-
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"));
|
|
1913
1968
|
};
|
|
1914
1969
|
|
|
1915
1970
|
// src/buildTina/index.ts
|
|
@@ -1938,6 +1993,7 @@ var buildSetupCmdServerStart = async (ctx, next, opts) => {
|
|
|
1938
1993
|
var buildSetupCmdAudit = async (ctx, next, options) => {
|
|
1939
1994
|
const rootPath2 = ctx.rootPath;
|
|
1940
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__"));
|
|
1941
1997
|
const store = new import_datalayer.LevelStore(rootPath2, false);
|
|
1942
1998
|
const database = await (0, import_graphql9.createDatabase)({ store, bridge });
|
|
1943
1999
|
ctx.bridge = bridge;
|
|
@@ -1953,6 +2009,7 @@ var buildSetup = async ({
|
|
|
1953
2009
|
const fsBridge = new import_datalayer.FilesystemBridge(rootPath2);
|
|
1954
2010
|
const isomorphicOptions = isomorphicGitBridge2 && await makeIsomorphicOptions(fsBridge);
|
|
1955
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__"));
|
|
1956
2013
|
const store = new import_datalayer.LevelStore(rootPath2, useMemoryStore);
|
|
1957
2014
|
const database = await (0, import_graphql9.createDatabase)({ store, bridge });
|
|
1958
2015
|
return { database, bridge, store };
|
|
@@ -1961,17 +2018,20 @@ var buildCmdBuild = async (ctx, next, options) => {
|
|
|
1961
2018
|
const { schema } = await ctx.builder.build(__spreadValues({
|
|
1962
2019
|
rootPath: ctx.rootPath
|
|
1963
2020
|
}, options));
|
|
1964
|
-
|
|
2021
|
+
ctx.schema = schema;
|
|
2022
|
+
const apiUrl = await ctx.builder.genTypedClient({
|
|
1965
2023
|
compiledSchema: schema,
|
|
1966
2024
|
local: options.local,
|
|
1967
2025
|
noSDK: options.noSDK,
|
|
1968
2026
|
verbose: options.verbose,
|
|
1969
|
-
usingTs: ctx.usingTs
|
|
2027
|
+
usingTs: ctx.usingTs,
|
|
2028
|
+
port: options.port
|
|
1970
2029
|
});
|
|
1971
2030
|
await buildAdmin({
|
|
1972
2031
|
local: options.local,
|
|
1973
2032
|
rootPath: ctx.rootPath,
|
|
1974
|
-
schema
|
|
2033
|
+
schema,
|
|
2034
|
+
apiUrl
|
|
1975
2035
|
});
|
|
1976
2036
|
next();
|
|
1977
2037
|
};
|
|
@@ -1981,7 +2041,12 @@ var auditCmdBuild = async (ctx, next, options) => {
|
|
|
1981
2041
|
}, options), {
|
|
1982
2042
|
verbose: true
|
|
1983
2043
|
}));
|
|
1984
|
-
await
|
|
2044
|
+
await spin({
|
|
2045
|
+
waitFor: async () => {
|
|
2046
|
+
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
2047
|
+
},
|
|
2048
|
+
text: "Indexing local files"
|
|
2049
|
+
});
|
|
1985
2050
|
next();
|
|
1986
2051
|
};
|
|
1987
2052
|
var ConfigBuilder = class {
|
|
@@ -1993,7 +2058,7 @@ var ConfigBuilder = class {
|
|
|
1993
2058
|
if (!rootPath2) {
|
|
1994
2059
|
throw new Error("Root path has not been attached");
|
|
1995
2060
|
}
|
|
1996
|
-
const tinaGeneratedPath =
|
|
2061
|
+
const tinaGeneratedPath = import_path10.default.join(rootPath2, ".tina", "__generated__");
|
|
1997
2062
|
this.database.clearCache();
|
|
1998
2063
|
await import_fs_extra7.default.mkdirp(tinaGeneratedPath);
|
|
1999
2064
|
await this.database.store.close();
|
|
@@ -2015,7 +2080,8 @@ var ConfigBuilder = class {
|
|
|
2015
2080
|
compiledSchema,
|
|
2016
2081
|
noSDK,
|
|
2017
2082
|
verbose,
|
|
2018
|
-
local
|
|
2083
|
+
local,
|
|
2084
|
+
port
|
|
2019
2085
|
}) {
|
|
2020
2086
|
const astSchema = await (0, import_graphql9.getASTSchema)(this.database);
|
|
2021
2087
|
await genTypes({ schema: astSchema, usingTs }, () => {
|
|
@@ -2023,32 +2089,40 @@ var ConfigBuilder = class {
|
|
|
2023
2089
|
noSDK,
|
|
2024
2090
|
verbose
|
|
2025
2091
|
});
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2092
|
+
return genClient({ tinaSchema: compiledSchema, usingTs }, {
|
|
2093
|
+
local,
|
|
2094
|
+
port
|
|
2029
2095
|
});
|
|
2030
2096
|
}
|
|
2031
2097
|
};
|
|
2032
2098
|
var buildAdmin = async ({
|
|
2033
2099
|
schema,
|
|
2034
2100
|
local,
|
|
2035
|
-
rootPath: rootPath2
|
|
2101
|
+
rootPath: rootPath2,
|
|
2102
|
+
apiUrl
|
|
2036
2103
|
}) => {
|
|
2037
2104
|
var _a;
|
|
2038
2105
|
if ((_a = schema == null ? void 0 : schema.config) == null ? void 0 : _a.build) {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
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
|
+
}
|
|
2052
2126
|
}
|
|
2053
2127
|
};
|
|
2054
2128
|
|
|
@@ -2096,25 +2170,28 @@ async function startServer(ctx, next, {
|
|
|
2096
2170
|
try {
|
|
2097
2171
|
const s = (init_server3(), server_exports);
|
|
2098
2172
|
state.server = await s.default(database);
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
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)}
|
|
2105
2181
|
or`);
|
|
2106
|
-
|
|
2182
|
+
logger.info(`Enter the CMS at ${import_chalk6.default.underline.blueBright(cmsUrl)}
|
|
2107
2183
|
`);
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
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
|
+
});
|
|
2118
2195
|
});
|
|
2119
2196
|
} catch (error) {
|
|
2120
2197
|
throw error;
|
|
@@ -2146,18 +2223,26 @@ or`);
|
|
|
2146
2223
|
dev,
|
|
2147
2224
|
verbose
|
|
2148
2225
|
});
|
|
2149
|
-
|
|
2226
|
+
ctx.schema = schema;
|
|
2227
|
+
const apiUrl = await ctx.builder.genTypedClient({
|
|
2150
2228
|
compiledSchema: schema,
|
|
2151
2229
|
local: true,
|
|
2152
2230
|
noSDK,
|
|
2153
2231
|
verbose,
|
|
2154
|
-
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"
|
|
2155
2240
|
});
|
|
2156
|
-
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
2157
2241
|
await buildAdmin({
|
|
2158
2242
|
local: true,
|
|
2159
2243
|
rootPath: ctx.rootPath,
|
|
2160
|
-
schema
|
|
2244
|
+
schema,
|
|
2245
|
+
apiUrl
|
|
2161
2246
|
});
|
|
2162
2247
|
} catch (error) {
|
|
2163
2248
|
throw error;
|
|
@@ -2165,7 +2250,7 @@ or`);
|
|
|
2165
2250
|
await afterBuild();
|
|
2166
2251
|
}
|
|
2167
2252
|
};
|
|
2168
|
-
const foldersToWatch = (watchFolders || []).map((x) =>
|
|
2253
|
+
const foldersToWatch = (watchFolders || []).map((x) => import_path13.default.join(rootPath2, x));
|
|
2169
2254
|
if (!noWatch && !process.env.CI) {
|
|
2170
2255
|
import_chokidar.default.watch([
|
|
2171
2256
|
...foldersToWatch,
|
|
@@ -2175,7 +2260,7 @@ or`);
|
|
|
2175
2260
|
ignored: [
|
|
2176
2261
|
"**/node_modules/**/*",
|
|
2177
2262
|
"**/.next/**/*",
|
|
2178
|
-
`${
|
|
2263
|
+
`${import_path13.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
2179
2264
|
]
|
|
2180
2265
|
}).on("ready", async () => {
|
|
2181
2266
|
if (verbose)
|
|
@@ -2190,8 +2275,7 @@ or`);
|
|
|
2190
2275
|
next();
|
|
2191
2276
|
} catch (e) {
|
|
2192
2277
|
handleServerErrors(e);
|
|
2193
|
-
|
|
2194
|
-
process.exit(0);
|
|
2278
|
+
throw e;
|
|
2195
2279
|
}
|
|
2196
2280
|
}).on("all", async () => {
|
|
2197
2281
|
if (ready) {
|
|
@@ -2230,7 +2314,8 @@ or`);
|
|
|
2230
2314
|
}
|
|
2231
2315
|
}
|
|
2232
2316
|
|
|
2233
|
-
// src/cmds/
|
|
2317
|
+
// src/cmds/statusChecks/waitForIndexing.ts
|
|
2318
|
+
var import_progress2 = __toModule(require("progress"));
|
|
2234
2319
|
var POLLING_INTERVAL = 5e3;
|
|
2235
2320
|
var STATUS_INPROGRESS = "inprogress";
|
|
2236
2321
|
var STATUS_COMPLETE = "complete";
|
|
@@ -2242,23 +2327,15 @@ var IndexFailedError = class extends Error {
|
|
|
2242
2327
|
}
|
|
2243
2328
|
};
|
|
2244
2329
|
var waitForDB = async (ctx, next, options) => {
|
|
2245
|
-
if (options.verbose) {
|
|
2246
|
-
logger.info(logText("Waiting for DB..."));
|
|
2247
|
-
}
|
|
2248
2330
|
if (!ctx.client) {
|
|
2249
|
-
|
|
2250
|
-
logger.info(logText("client is unavailable, skipping..."));
|
|
2251
|
-
}
|
|
2252
|
-
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");
|
|
2253
2332
|
}
|
|
2254
2333
|
const client = ctx.client;
|
|
2255
2334
|
const { host, clientId, branch, isLocalClient } = client.parseURL();
|
|
2256
2335
|
if (isLocalClient) {
|
|
2257
|
-
if (options.verbose) {
|
|
2258
|
-
logger.info(logText("client is local, skipping..."));
|
|
2259
|
-
}
|
|
2260
2336
|
return next();
|
|
2261
2337
|
}
|
|
2338
|
+
const bar = new import_progress2.default("Checking indexing process in Tina Cloud... :prog", 1);
|
|
2262
2339
|
const pollForStatus = async () => {
|
|
2263
2340
|
try {
|
|
2264
2341
|
if (options.verbose) {
|
|
@@ -2274,11 +2351,11 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
2274
2351
|
headers
|
|
2275
2352
|
});
|
|
2276
2353
|
const { status, error } = await response.json();
|
|
2277
|
-
const statusMessage = `
|
|
2354
|
+
const statusMessage = `Indexing status: '${status}'`;
|
|
2278
2355
|
if (status === STATUS_COMPLETE) {
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
}
|
|
2356
|
+
bar.tick({
|
|
2357
|
+
prog: "\u2705"
|
|
2358
|
+
});
|
|
2282
2359
|
return next();
|
|
2283
2360
|
} else if (status === STATUS_INPROGRESS) {
|
|
2284
2361
|
if (options.verbose) {
|
|
@@ -2286,22 +2363,25 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
2286
2363
|
}
|
|
2287
2364
|
setTimeout(pollForStatus, POLLING_INTERVAL);
|
|
2288
2365
|
} else if (status === STATUS_FAILED) {
|
|
2289
|
-
throw new IndexFailedError(`Attempting to index
|
|
2366
|
+
throw new IndexFailedError(`Attempting to index but responded with status 'failed', ${error}`);
|
|
2290
2367
|
} else {
|
|
2291
|
-
|
|
2292
|
-
logger.info(logText(`${statusMessage}`));
|
|
2293
|
-
}
|
|
2294
|
-
return next();
|
|
2368
|
+
throw new IndexFailedError(`Attempting to index but responded with status 'unknown', ${error}`);
|
|
2295
2369
|
}
|
|
2296
2370
|
} catch (e) {
|
|
2297
2371
|
if (e instanceof IndexFailedError) {
|
|
2372
|
+
bar.tick({
|
|
2373
|
+
prog: "\u274C"
|
|
2374
|
+
});
|
|
2298
2375
|
throw e;
|
|
2299
2376
|
} else {
|
|
2300
2377
|
throw new Error(`Unable to query DB for indexing status, encountered error: ${e.message}`);
|
|
2301
2378
|
}
|
|
2302
2379
|
}
|
|
2303
2380
|
};
|
|
2304
|
-
|
|
2381
|
+
spin({
|
|
2382
|
+
text: "Checking indexing process in Tina Cloud...",
|
|
2383
|
+
waitFor: pollForStatus
|
|
2384
|
+
});
|
|
2305
2385
|
};
|
|
2306
2386
|
|
|
2307
2387
|
// src/cmds/startSubprocess/index.ts
|
|
@@ -2329,6 +2409,252 @@ stack: ${code.stack || "No stack was provided"}`);
|
|
|
2329
2409
|
}
|
|
2330
2410
|
};
|
|
2331
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 internalDeps = ["tinacms", "@tinacms/cli"];
|
|
2509
|
+
const externalDeps = ["styled-components"];
|
|
2510
|
+
const deps = [...internalDeps, externalDeps];
|
|
2511
|
+
const packageManagers = {
|
|
2512
|
+
pnpm: process.env.USE_WORKSPACE ? `pnpm add ${internalDeps.join(" ")} --workspace && pnpm add ${externalDeps.join(" ")}` : `pnpm add ${deps.join(" ")}`,
|
|
2513
|
+
npm: `npm install ${deps.join(" ")}`,
|
|
2514
|
+
yarn: `yarn add ${deps.join(" ")}`
|
|
2515
|
+
};
|
|
2516
|
+
logger.info(` ${logText(packageManagers[packageManager])}`);
|
|
2517
|
+
await execShellCommand(packageManagers[packageManager]);
|
|
2518
|
+
};
|
|
2519
|
+
var addConfigFile = async (publicFolder, usingTypescript) => {
|
|
2520
|
+
const configPath = import_path14.default.join(".tina", `config.${usingTypescript ? "ts" : "js"}`);
|
|
2521
|
+
const fullConfigPath = import_path14.default.join(baseDir2, configPath);
|
|
2522
|
+
if (import_fs_extra9.default.pathExistsSync(fullConfigPath)) {
|
|
2523
|
+
const override = await (0, import_prompts3.default)({
|
|
2524
|
+
name: "selection",
|
|
2525
|
+
type: "confirm",
|
|
2526
|
+
message: `Found existing file at ${configPath}. Would you like to override?`
|
|
2527
|
+
});
|
|
2528
|
+
if (override["selection"]) {
|
|
2529
|
+
logger.info(logText(`Overriding file at ${configPath}.`));
|
|
2530
|
+
await import_fs_extra9.default.outputFileSync(fullConfigPath, config({ publicFolder }));
|
|
2531
|
+
} else {
|
|
2532
|
+
logger.info(logText(`Not overriding file at ${configPath}.`));
|
|
2533
|
+
}
|
|
2534
|
+
} else {
|
|
2535
|
+
logger.info(logText(`Adding config file at .tina/config.${usingTypescript ? "ts" : "js"}`));
|
|
2536
|
+
await import_fs_extra9.default.outputFileSync(fullConfigPath, config({ publicFolder }));
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
var addContentFile = async () => {
|
|
2540
|
+
const contentPath = import_path14.default.join("content", "posts", "hello-world.md");
|
|
2541
|
+
const fullContentPath = import_path14.default.join(baseDir2, contentPath);
|
|
2542
|
+
if (import_fs_extra9.default.pathExistsSync(fullContentPath)) {
|
|
2543
|
+
const override = await (0, import_prompts3.default)({
|
|
2544
|
+
name: "selection",
|
|
2545
|
+
type: "confirm",
|
|
2546
|
+
message: `Found existing file at ${contentPath}. Would you like to override?`
|
|
2547
|
+
});
|
|
2548
|
+
if (override["selection"]) {
|
|
2549
|
+
logger.info(logText(`Overriding file at ${contentPath}.`));
|
|
2550
|
+
await import_fs_extra9.default.outputFileSync(fullContentPath, content);
|
|
2551
|
+
} else {
|
|
2552
|
+
logger.info(logText(`Not overriding file at ${contentPath}.`));
|
|
2553
|
+
}
|
|
2554
|
+
} else {
|
|
2555
|
+
logger.info(logText(`Adding content file at ${contentPath}`));
|
|
2556
|
+
await import_fs_extra9.default.outputFileSync(fullContentPath, content);
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
var logNextSteps = (packageManager) => {
|
|
2560
|
+
logger.info(`
|
|
2561
|
+
${successText("TinaCMS has been initialized, to get started run:")}
|
|
2562
|
+
|
|
2563
|
+
${packageManager} tinacms dev -c "<your dev command>"
|
|
2564
|
+
`);
|
|
2565
|
+
};
|
|
2566
|
+
var config = (args) => `
|
|
2567
|
+
import { defineStaticConfig } from "tinacms";
|
|
2568
|
+
|
|
2569
|
+
// Your hosting provider likely exposes this as an environment variable
|
|
2570
|
+
const branch = process.env.HEAD || process.env.VERCEL_GIT_COMMIT_REF || "main";
|
|
2571
|
+
|
|
2572
|
+
export default defineStaticConfig({
|
|
2573
|
+
branch,
|
|
2574
|
+
clientId: null, // Get this from tina.io
|
|
2575
|
+
token: null, // Get this from tina.io
|
|
2576
|
+
build: {
|
|
2577
|
+
outputFolder: "admin",
|
|
2578
|
+
publicFolder: "${args.publicFolder}",
|
|
2579
|
+
},
|
|
2580
|
+
media: {
|
|
2581
|
+
tina: {
|
|
2582
|
+
mediaRoot: "uploads",
|
|
2583
|
+
publicFolder: "${args.publicFolder}",
|
|
2584
|
+
},
|
|
2585
|
+
},
|
|
2586
|
+
schema: {
|
|
2587
|
+
collections: [
|
|
2588
|
+
{
|
|
2589
|
+
name: "post",
|
|
2590
|
+
label: "Posts",
|
|
2591
|
+
path: "content/posts",
|
|
2592
|
+
fields: [
|
|
2593
|
+
{
|
|
2594
|
+
type: "string",
|
|
2595
|
+
name: "title",
|
|
2596
|
+
label: "Title",
|
|
2597
|
+
isTitle: true,
|
|
2598
|
+
},
|
|
2599
|
+
{
|
|
2600
|
+
type: "rich-text",
|
|
2601
|
+
name: "body",
|
|
2602
|
+
label: "Body",
|
|
2603
|
+
isBody: true,
|
|
2604
|
+
},
|
|
2605
|
+
],
|
|
2606
|
+
},
|
|
2607
|
+
],
|
|
2608
|
+
},
|
|
2609
|
+
});
|
|
2610
|
+
`;
|
|
2611
|
+
var content = `---
|
|
2612
|
+
title: Hello, World!
|
|
2613
|
+
---
|
|
2614
|
+
|
|
2615
|
+
## Hello World!
|
|
2616
|
+
|
|
2617
|
+
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.
|
|
2618
|
+
|
|
2619
|
+
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.
|
|
2620
|
+
`;
|
|
2621
|
+
|
|
2622
|
+
// src/cmds/statusChecks/checkClientInformation.ts
|
|
2623
|
+
var import_progress3 = __toModule(require("progress"));
|
|
2624
|
+
var checkClientInfo = async (ctx, next, _options) => {
|
|
2625
|
+
var _a;
|
|
2626
|
+
const client = ctx.client;
|
|
2627
|
+
const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
|
|
2628
|
+
const bar = new import_progress3.default("Checking clientId, token and branch. :prog", 1);
|
|
2629
|
+
try {
|
|
2630
|
+
await client.request({
|
|
2631
|
+
query: `query {
|
|
2632
|
+
collections {
|
|
2633
|
+
name
|
|
2634
|
+
}
|
|
2635
|
+
}`
|
|
2636
|
+
});
|
|
2637
|
+
bar.tick({
|
|
2638
|
+
prog: "\u2705"
|
|
2639
|
+
});
|
|
2640
|
+
} catch (e) {
|
|
2641
|
+
bar.tick({
|
|
2642
|
+
prog: "\u274C"
|
|
2643
|
+
});
|
|
2644
|
+
console.warn(`Error when checking client information. You provided
|
|
2645
|
+
|
|
2646
|
+
${JSON.stringify({
|
|
2647
|
+
branch: config2 == null ? void 0 : config2.branch,
|
|
2648
|
+
clientId: config2 == null ? void 0 : config2.clientId,
|
|
2649
|
+
token: config2 == null ? void 0 : config2.token
|
|
2650
|
+
}, null, 2)}
|
|
2651
|
+
|
|
2652
|
+
Please check you have the correct "clientId", "branch" and "token" configured. For more information see https://tina.io/docs/tina-cloud/connecting-site/`);
|
|
2653
|
+
throw e;
|
|
2654
|
+
}
|
|
2655
|
+
next();
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2332
2658
|
// src/cmds/baseCmds.ts
|
|
2333
2659
|
var CMD_START_SERVER = "server:start";
|
|
2334
2660
|
var CMD_DEV = "dev";
|
|
@@ -2367,6 +2693,10 @@ var cleanOption = {
|
|
|
2367
2693
|
name: "--clean",
|
|
2368
2694
|
description: "Updates all content files to remove any data not explicitly permitted by the current schema definition"
|
|
2369
2695
|
};
|
|
2696
|
+
var staticOption = {
|
|
2697
|
+
name: "--static",
|
|
2698
|
+
description: "Bundle Tina as a static assset"
|
|
2699
|
+
};
|
|
2370
2700
|
var useDefaultValuesOption = {
|
|
2371
2701
|
name: "--useDefaultValues",
|
|
2372
2702
|
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`)"
|
|
@@ -2467,6 +2797,7 @@ var baseCmds = [
|
|
|
2467
2797
|
buildSetupCmdBuild,
|
|
2468
2798
|
buildCmdBuild,
|
|
2469
2799
|
compileClient,
|
|
2800
|
+
checkClientInfo,
|
|
2470
2801
|
waitForDB
|
|
2471
2802
|
], options)
|
|
2472
2803
|
},
|
|
@@ -2476,20 +2807,27 @@ var baseCmds = [
|
|
|
2476
2807
|
experimentalDatalayer,
|
|
2477
2808
|
isomorphicGitBridge,
|
|
2478
2809
|
noTelemetryOption,
|
|
2479
|
-
schemaFileType
|
|
2810
|
+
schemaFileType,
|
|
2811
|
+
staticOption
|
|
2480
2812
|
],
|
|
2481
2813
|
description: "Add Tina Cloud to an existing project",
|
|
2482
|
-
action: (options) =>
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2814
|
+
action: (options) => {
|
|
2815
|
+
if (options.static) {
|
|
2816
|
+
chain([attachPath, checkOptions, initStaticTina], options);
|
|
2817
|
+
} else {
|
|
2818
|
+
chain([
|
|
2819
|
+
attachPath,
|
|
2820
|
+
checkOptions,
|
|
2821
|
+
checkDeps,
|
|
2822
|
+
initTina,
|
|
2823
|
+
installDeps,
|
|
2824
|
+
buildSetupCmdBuild,
|
|
2825
|
+
buildCmdBuild,
|
|
2826
|
+
tinaSetup,
|
|
2827
|
+
successMessage
|
|
2828
|
+
], options);
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2493
2831
|
},
|
|
2494
2832
|
{
|
|
2495
2833
|
options: [
|