@tinacms/cli 1.3.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tinacms +3 -1
- package/dist/cmds/forestry-migrate/util/index.d.ts +14 -14
- package/dist/cmds/init/index.d.ts +4 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2233 -2063
- package/dist/logger/index.d.ts +16 -3
- package/dist/logger/is-unicode-supported.d.ts +1 -0
- package/dist/next/codegen/codegen/index.d.ts +5 -0
- package/dist/{codegen → next/codegen/codegen}/plugin.d.ts +2 -2
- package/dist/{codegen → next/codegen/codegen}/sdkPlugin/index.d.ts +1 -1
- package/dist/next/codegen/index.d.ts +30 -0
- package/dist/{cmds/audit → next/commands/audit-command}/audit.d.ts +7 -5
- package/dist/next/commands/audit-command/index.d.ts +13 -0
- package/dist/next/commands/build-command/index.d.ts +24 -0
- package/dist/next/commands/build-command/server.d.ts +3 -0
- package/dist/next/commands/build-command/tailwind.d.ts +2 -0
- package/dist/next/commands/build-command/waitForDB.d.ts +7 -0
- package/dist/next/commands/codemod-command/index.d.ts +9 -0
- package/dist/next/commands/dev-command/html.d.ts +1 -0
- package/dist/next/commands/dev-command/index.d.ts +22 -0
- package/dist/next/commands/dev-command/server/index.d.ts +3 -0
- package/dist/next/commands/dev-command/server/media.d.ts +45 -0
- package/dist/next/commands/dev-command/tailwind.d.ts +2 -0
- package/dist/next/commands/init-command/index.d.ts +9 -0
- package/dist/next/config-manager.d.ts +54 -0
- package/dist/next/database.d.ts +4 -0
- package/dist/next/vite/index.d.ts +12 -0
- package/dist/next/vite/tailwind.d.ts +2 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/start-subprocess.d.ts +5 -0
- package/package.json +17 -6
- package/dist/buildTina/attachDatabase.d.ts +0 -8
- package/dist/buildTina/attachPath.d.ts +0 -5
- package/dist/buildTina/git.d.ts +0 -13
- package/dist/buildTina/index.d.ts +0 -71
- package/dist/cmds/audit/index.d.ts +0 -5
- package/dist/cmds/baseCmds.d.ts +0 -11
- package/dist/cmds/compile/defaultSchema.d.ts +0 -4
- package/dist/cmds/compile/index.d.ts +0 -24
- package/dist/cmds/query-gen/genTypes.d.ts +0 -16
- package/dist/cmds/query-gen/index.d.ts +0 -4
- package/dist/cmds/start-server/errors/index.d.ts +0 -10
- package/dist/cmds/start-server/index.d.ts +0 -27
- package/dist/cmds/start-server/lock.d.ts +0 -9
- package/dist/cmds/start-server/server.d.ts +0 -5
- package/dist/cmds/startSubprocess/index.d.ts +0 -8
- package/dist/cmds/statusChecks/checkClientInformation.d.ts +0 -32
- package/dist/cmds/statusChecks/waitForIndexing.d.ts +0 -11
- package/dist/codegen/index.d.ts +0 -8
- package/dist/command.d.ts +0 -19
- package/dist/middleware.d.ts +0 -4
- /package/dist/{codegen → next/codegen/codegen}/sdkPlugin/config.d.ts +0 -0
- /package/dist/{codegen → next/codegen/codegen}/sdkPlugin/visitor.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -4,9 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __esm = (fn, res) => function __init() {
|
|
8
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
-
};
|
|
10
7
|
var __export = (target, all) => {
|
|
11
8
|
for (var name2 in all)
|
|
12
9
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
@@ -25,282 +22,43 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
22
|
));
|
|
26
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
24
|
|
|
28
|
-
// src/utils/index.ts
|
|
29
|
-
var parseMediaFolder;
|
|
30
|
-
var init_utils = __esm({
|
|
31
|
-
"src/utils/index.ts"() {
|
|
32
|
-
parseMediaFolder = (str) => {
|
|
33
|
-
let returnString = str;
|
|
34
|
-
if (returnString.startsWith("/"))
|
|
35
|
-
returnString = returnString.substr(1);
|
|
36
|
-
if (returnString.endsWith("/"))
|
|
37
|
-
returnString = returnString.substr(0, returnString.length - 1);
|
|
38
|
-
return returnString;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// src/server/models/media.ts
|
|
44
|
-
var import_fs_extra6, import_path6, MediaModel;
|
|
45
|
-
var init_media = __esm({
|
|
46
|
-
"src/server/models/media.ts"() {
|
|
47
|
-
import_fs_extra6 = __toESM(require("fs-extra"));
|
|
48
|
-
import_path6 = require("path");
|
|
49
|
-
init_utils();
|
|
50
|
-
MediaModel = class {
|
|
51
|
-
constructor({ rootPath: rootPath2, publicFolder, mediaRoot }) {
|
|
52
|
-
this.rootPath = rootPath2;
|
|
53
|
-
this.mediaRoot = mediaRoot;
|
|
54
|
-
this.publicFolder = publicFolder;
|
|
55
|
-
}
|
|
56
|
-
async listMedia(args) {
|
|
57
|
-
try {
|
|
58
|
-
const folderPath = (0, import_path6.join)(
|
|
59
|
-
this.rootPath,
|
|
60
|
-
this.publicFolder,
|
|
61
|
-
this.mediaRoot,
|
|
62
|
-
args.searchPath
|
|
63
|
-
);
|
|
64
|
-
const searchPath = parseMediaFolder(args.searchPath);
|
|
65
|
-
const filesStr = await import_fs_extra6.default.readdir(folderPath);
|
|
66
|
-
const filesProm = filesStr.map(async (file) => {
|
|
67
|
-
const filePath = (0, import_path6.join)(folderPath, file);
|
|
68
|
-
const stat = await import_fs_extra6.default.stat(filePath);
|
|
69
|
-
let src = `/${file}`;
|
|
70
|
-
const isFile = stat.isFile();
|
|
71
|
-
if (!isFile) {
|
|
72
|
-
return {
|
|
73
|
-
isFile,
|
|
74
|
-
size: stat.size,
|
|
75
|
-
src,
|
|
76
|
-
filename: file
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
if (searchPath) {
|
|
80
|
-
src = `/${searchPath}${src}`;
|
|
81
|
-
}
|
|
82
|
-
if (this.mediaRoot) {
|
|
83
|
-
src = `/${this.mediaRoot}${src}`;
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
isFile,
|
|
87
|
-
size: stat.size,
|
|
88
|
-
src,
|
|
89
|
-
filename: file
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
const offset = Number(args.cursor) || 0;
|
|
93
|
-
const limit = Number(args.limit) || 20;
|
|
94
|
-
const rawItems = await Promise.all(filesProm);
|
|
95
|
-
const sortedItems = rawItems.sort((a, b) => {
|
|
96
|
-
if (a.isFile && !b.isFile) {
|
|
97
|
-
return 1;
|
|
98
|
-
}
|
|
99
|
-
if (!a.isFile && b.isFile) {
|
|
100
|
-
return -1;
|
|
101
|
-
}
|
|
102
|
-
return 0;
|
|
103
|
-
});
|
|
104
|
-
const limitItems = sortedItems.slice(offset, offset + limit);
|
|
105
|
-
const files = limitItems.filter((x) => x.isFile);
|
|
106
|
-
const directories = limitItems.filter((x) => !x.isFile).map((x) => x.src);
|
|
107
|
-
const cursor = rawItems.length > offset + limit ? String(offset + limit) : null;
|
|
108
|
-
return {
|
|
109
|
-
files,
|
|
110
|
-
directories,
|
|
111
|
-
cursor
|
|
112
|
-
};
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.error(error);
|
|
115
|
-
return {
|
|
116
|
-
files: [],
|
|
117
|
-
directories: [],
|
|
118
|
-
error: error == null ? void 0 : error.toString()
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async deleteMedia(args) {
|
|
123
|
-
try {
|
|
124
|
-
const file = (0, import_path6.join)(
|
|
125
|
-
this.rootPath,
|
|
126
|
-
this.publicFolder,
|
|
127
|
-
this.mediaRoot,
|
|
128
|
-
args.searchPath
|
|
129
|
-
);
|
|
130
|
-
await import_fs_extra6.default.stat(file);
|
|
131
|
-
await import_fs_extra6.default.remove(file);
|
|
132
|
-
return { ok: true };
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error(error);
|
|
135
|
-
return { ok: false, message: error == null ? void 0 : error.toString() };
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// src/server/routes/index.ts
|
|
143
|
-
var import_express, import_path7, import_multer, createMediaRouter;
|
|
144
|
-
var init_routes = __esm({
|
|
145
|
-
"src/server/routes/index.ts"() {
|
|
146
|
-
import_express = require("express");
|
|
147
|
-
import_path7 = require("path");
|
|
148
|
-
import_multer = __toESM(require("multer"));
|
|
149
|
-
init_media();
|
|
150
|
-
createMediaRouter = (config2) => {
|
|
151
|
-
const mediaFolder = (0, import_path7.join)(
|
|
152
|
-
config2.rootPath,
|
|
153
|
-
config2.publicFolder,
|
|
154
|
-
config2.mediaRoot
|
|
155
|
-
);
|
|
156
|
-
const storage = import_multer.default.diskStorage({
|
|
157
|
-
destination: function(req, file, cb) {
|
|
158
|
-
cb(null, mediaFolder);
|
|
159
|
-
},
|
|
160
|
-
filename: function(req, _file, cb) {
|
|
161
|
-
const file = req.params[0];
|
|
162
|
-
cb(null, file);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const upload = (0, import_multer.default)({ storage });
|
|
166
|
-
const uploadRoute = upload.single("file");
|
|
167
|
-
const mediaModel = new MediaModel(config2);
|
|
168
|
-
const mediaRouter = (0, import_express.Router)();
|
|
169
|
-
mediaRouter.get("/list/*", async (req, res) => {
|
|
170
|
-
const folder = req.params[0];
|
|
171
|
-
const cursor = req.query.cursor;
|
|
172
|
-
const limit = req.query.limit;
|
|
173
|
-
const media = await mediaModel.listMedia({
|
|
174
|
-
searchPath: folder,
|
|
175
|
-
cursor,
|
|
176
|
-
limit
|
|
177
|
-
});
|
|
178
|
-
res.json(media);
|
|
179
|
-
});
|
|
180
|
-
mediaRouter.delete("/*", async (req, res) => {
|
|
181
|
-
const file = req.params[0];
|
|
182
|
-
const didDelete = await mediaModel.deleteMedia({ searchPath: file });
|
|
183
|
-
res.json(didDelete);
|
|
184
|
-
});
|
|
185
|
-
mediaRouter.post("/upload/*", async function(req, res) {
|
|
186
|
-
await uploadRoute(req, res, (err) => {
|
|
187
|
-
if (err instanceof import_multer.default.MulterError) {
|
|
188
|
-
res.status(500).json({ message: err.message });
|
|
189
|
-
} else if (err) {
|
|
190
|
-
res.status(500).json({ message: err.message });
|
|
191
|
-
} else {
|
|
192
|
-
res.json({ success: true });
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
return mediaRouter;
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// src/server/server.ts
|
|
202
|
-
var import_cors, import_http, import_express2, import_altair_express_middleware, import_body_parser, gqlServer;
|
|
203
|
-
var init_server = __esm({
|
|
204
|
-
"src/server/server.ts"() {
|
|
205
|
-
import_cors = __toESM(require("cors"));
|
|
206
|
-
import_http = __toESM(require("http"));
|
|
207
|
-
import_express2 = __toESM(require("express"));
|
|
208
|
-
import_altair_express_middleware = require("altair-express-middleware");
|
|
209
|
-
import_body_parser = __toESM(require("body-parser"));
|
|
210
|
-
init_routes();
|
|
211
|
-
init_utils();
|
|
212
|
-
gqlServer = async (database, verbose) => {
|
|
213
|
-
var _a, _b, _c;
|
|
214
|
-
const gqlPackage = require("@tinacms/graphql");
|
|
215
|
-
const app = (0, import_express2.default)();
|
|
216
|
-
const server = import_http.default.createServer(app);
|
|
217
|
-
app.use((0, import_cors.default)());
|
|
218
|
-
app.use(import_body_parser.default.json());
|
|
219
|
-
app.use(
|
|
220
|
-
"/altair",
|
|
221
|
-
(0, import_altair_express_middleware.altairExpress)({
|
|
222
|
-
endpointURL: "/graphql",
|
|
223
|
-
initialQuery: `# Welcome to Tina!
|
|
224
|
-
# We've got a simple query set up for you to get started
|
|
225
|
-
# but there's plenty more for you to explore on your own!
|
|
226
|
-
query MyQuery {
|
|
227
|
-
collections {
|
|
228
|
-
documents {
|
|
229
|
-
id
|
|
230
|
-
sys {
|
|
231
|
-
filename
|
|
232
|
-
extension
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}`
|
|
237
|
-
})
|
|
238
|
-
);
|
|
239
|
-
app.post("/graphql", async (req, res) => {
|
|
240
|
-
const { query, variables } = req.body;
|
|
241
|
-
const config2 = {
|
|
242
|
-
useRelativeMedia: true
|
|
243
|
-
};
|
|
244
|
-
const result = await gqlPackage.resolve({
|
|
245
|
-
config: config2,
|
|
246
|
-
database,
|
|
247
|
-
query,
|
|
248
|
-
variables,
|
|
249
|
-
verbose
|
|
250
|
-
});
|
|
251
|
-
return res.json(result);
|
|
252
|
-
});
|
|
253
|
-
const db = database;
|
|
254
|
-
const schema = await db.getSchema();
|
|
255
|
-
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;
|
|
256
|
-
app.use(
|
|
257
|
-
"/media",
|
|
258
|
-
createMediaRouter({
|
|
259
|
-
rootPath: db.bridge.rootPath,
|
|
260
|
-
publicFolder: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.publicFolder) || ""),
|
|
261
|
-
mediaRoot: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.mediaRoot) || "")
|
|
262
|
-
})
|
|
263
|
-
);
|
|
264
|
-
return server;
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// src/server/index.ts
|
|
270
|
-
var init_server2 = __esm({
|
|
271
|
-
"src/server/index.ts"() {
|
|
272
|
-
init_server();
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
// src/cmds/start-server/server.ts
|
|
277
|
-
var server_exports = {};
|
|
278
|
-
__export(server_exports, {
|
|
279
|
-
default: () => server_default
|
|
280
|
-
});
|
|
281
|
-
var server_default;
|
|
282
|
-
var init_server3 = __esm({
|
|
283
|
-
"src/cmds/start-server/server.ts"() {
|
|
284
|
-
init_server2();
|
|
285
|
-
server_default = gqlServer;
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
|
|
289
25
|
// src/index.ts
|
|
290
26
|
var src_exports = {};
|
|
291
27
|
__export(src_exports, {
|
|
292
|
-
|
|
293
|
-
init: () => init
|
|
28
|
+
default: () => src_default
|
|
294
29
|
});
|
|
295
30
|
module.exports = __toCommonJS(src_exports);
|
|
296
|
-
var
|
|
31
|
+
var import_clipanion5 = require("clipanion");
|
|
297
32
|
|
|
298
33
|
// package.json
|
|
299
|
-
var
|
|
300
|
-
var version = "1.3.3";
|
|
34
|
+
var version = "1.4.1";
|
|
301
35
|
|
|
302
|
-
// src/
|
|
303
|
-
var
|
|
36
|
+
// src/next/commands/dev-command/index.ts
|
|
37
|
+
var import_clipanion = require("clipanion");
|
|
38
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
39
|
+
var import_path6 = __toESM(require("path"));
|
|
40
|
+
var import_chokidar = __toESM(require("chokidar"));
|
|
41
|
+
var import_graphql8 = require("@tinacms/graphql");
|
|
42
|
+
|
|
43
|
+
// src/next/config-manager.ts
|
|
44
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
45
|
+
var import_path = __toESM(require("path"));
|
|
46
|
+
var import_os = __toESM(require("os"));
|
|
47
|
+
var esbuild = __toESM(require("esbuild"));
|
|
48
|
+
var url = __toESM(require("url"));
|
|
49
|
+
var dotenv = __toESM(require("dotenv"));
|
|
50
|
+
var import_normalize_path = __toESM(require("normalize-path"));
|
|
51
|
+
|
|
52
|
+
// src/logger/index.ts
|
|
53
|
+
var import_chalk = __toESM(require("chalk"));
|
|
54
|
+
|
|
55
|
+
// src/logger/is-unicode-supported.ts
|
|
56
|
+
function isUnicodeSupported() {
|
|
57
|
+
if (process.platform !== "win32") {
|
|
58
|
+
return process.env.TERM !== "linux";
|
|
59
|
+
}
|
|
60
|
+
return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || Boolean(process.env.TERMINUS_SUBLIME) || process.env.ConEmuTask === "{cmd::Cmder}" || process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
61
|
+
}
|
|
304
62
|
|
|
305
63
|
// src/logger/index.ts
|
|
306
64
|
var import_log4js = __toESM(require("log4js"));
|
|
@@ -312,658 +70,947 @@ import_log4js.default.configure({
|
|
|
312
70
|
categories: { default: { appenders: ["out"], level: "info" } }
|
|
313
71
|
});
|
|
314
72
|
logger.level = "info";
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
73
|
+
function ansiRegex() {
|
|
74
|
+
const pattern = [
|
|
75
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
76
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
|
|
77
|
+
].join("|");
|
|
78
|
+
return new RegExp(pattern, "g");
|
|
79
|
+
}
|
|
80
|
+
var bar = "\u2502";
|
|
81
|
+
var strip = (str) => str.replace(ansiRegex(), "");
|
|
82
|
+
var note = (message = "", title = "") => {
|
|
83
|
+
const lines = `
|
|
84
|
+
${message}
|
|
85
|
+
`.split("\n");
|
|
86
|
+
const len = lines.reduce((sum, ln) => {
|
|
87
|
+
ln = strip(ln);
|
|
88
|
+
return ln.length > sum ? ln.length : sum;
|
|
89
|
+
}, 0) + 2;
|
|
90
|
+
const msg = lines.map(
|
|
91
|
+
(ln) => `${import_chalk.default.gray(bar)} ${import_chalk.default.white(ln)}${" ".repeat(
|
|
92
|
+
len - strip(ln).length
|
|
93
|
+
)}${import_chalk.default.gray(bar)}`
|
|
94
|
+
).join("\n");
|
|
95
|
+
process.stdout.write(
|
|
96
|
+
`${import_chalk.default.gray(bar)}
|
|
97
|
+
${import_chalk.default.green("\u25CB")} ${import_chalk.default.reset(
|
|
98
|
+
title
|
|
99
|
+
)} ${import_chalk.default.gray(
|
|
100
|
+
"\u2500".repeat(len - title.length - 1) + "\u256E"
|
|
101
|
+
)}
|
|
102
|
+
${msg}
|
|
103
|
+
${import_chalk.default.gray("\u251C" + "\u2500".repeat(len + 2) + "\u256F")}
|
|
104
|
+
`
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
var summary = (content2) => {
|
|
108
|
+
const outString = [];
|
|
109
|
+
let longestKey = 0;
|
|
110
|
+
content2.items.forEach((item) => {
|
|
111
|
+
item.subItems.forEach((subItem) => {
|
|
112
|
+
if (subItem.key.length > longestKey) {
|
|
113
|
+
longestKey = subItem.key.length;
|
|
114
|
+
}
|
|
340
115
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
116
|
+
});
|
|
117
|
+
content2.items.forEach((item) => {
|
|
118
|
+
outString.push(`${item.emoji} ${import_chalk.default.cyan(item.heading)}`);
|
|
119
|
+
item.subItems.forEach((subItem) => {
|
|
120
|
+
const spaces = longestKey - subItem.key.length + 4;
|
|
121
|
+
outString.push(
|
|
122
|
+
` ${subItem.key}:${[...Array(spaces)].join(" ")}${import_chalk.default.cyan(
|
|
123
|
+
subItem.value
|
|
124
|
+
)}`
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
outString.push(``);
|
|
128
|
+
});
|
|
129
|
+
if (process.env.CI) {
|
|
130
|
+
logger.info(JSON.stringify(content2, null, 2));
|
|
131
|
+
} else {
|
|
132
|
+
note(outString.join("\n"), content2.heading);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var unicode = isUnicodeSupported();
|
|
136
|
+
var s = (c, fallback) => unicode ? c : fallback;
|
|
137
|
+
var S_STEP_ACTIVE = s("\u25C6", "*");
|
|
138
|
+
var S_STEP_CANCEL = s("\u25A0", "x");
|
|
139
|
+
var S_STEP_ERROR = s("\u25B2", "x");
|
|
140
|
+
var S_STEP_SUBMIT = s("\u25C7", "o");
|
|
141
|
+
var S_BAR_START = s("\u250C", "T");
|
|
142
|
+
var S_BAR = s("\u2502", "|");
|
|
143
|
+
var S_BAR_END = s("\u2514", "\u2014");
|
|
144
|
+
var S_RADIO_ACTIVE = s("\u25CF", ">");
|
|
145
|
+
var S_RADIO_INACTIVE = s("\u25CB", " ");
|
|
146
|
+
var S_CHECKBOX_ACTIVE = s("\u25FB", "[\u2022]");
|
|
147
|
+
var S_CHECKBOX_SELECTED = s("\u25FC", "[+]");
|
|
148
|
+
var S_CHECKBOX_INACTIVE = s("\u25FB", "[ ]");
|
|
149
|
+
var S_PASSWORD_MASK = s("\u25AA", "\u2022");
|
|
150
|
+
var S_BAR_H = s("\u2500", "-");
|
|
151
|
+
var S_CORNER_TOP_RIGHT = s("\u256E", "+");
|
|
152
|
+
var S_CONNECT_LEFT = s("\u251C", "+");
|
|
153
|
+
var S_CORNER_BOTTOM_RIGHT = s("\u256F", "+");
|
|
154
|
+
var S_INFO = s("\u25CF", "\u2022");
|
|
155
|
+
var S_SUCCESS = s("\u25C6", "*");
|
|
156
|
+
var S_WARN = s("\u25B2", "!");
|
|
157
|
+
var S_ERROR = s("\u25A0", "x");
|
|
158
|
+
|
|
159
|
+
// src/next/config-manager.ts
|
|
160
|
+
var TINA_FOLDER = "tina";
|
|
161
|
+
var LEGACY_TINA_FOLDER = ".tina";
|
|
162
|
+
var GENERATED_FOLDER = "__generated__";
|
|
163
|
+
var GRAPHQL_JSON_FILE = "_graphql.json";
|
|
164
|
+
var GRAPHQL_GQL_FILE = "schema.gql";
|
|
165
|
+
var SCHEMA_JSON_FILE = "_schema.json";
|
|
166
|
+
var LOOKUP_JSON_FILE = "_lookup.json";
|
|
167
|
+
var ConfigManager = class {
|
|
168
|
+
constructor(rootPath = process.cwd(), tinaGraphQLVersion) {
|
|
169
|
+
this.rootPath = (0, import_normalize_path.default)(rootPath);
|
|
170
|
+
this.tinaGraphQLVersionFromCLI = tinaGraphQLVersion;
|
|
171
|
+
}
|
|
172
|
+
isUsingTs() {
|
|
173
|
+
return [".ts", ".tsx"].includes(import_path.default.extname(this.tinaConfigFilePath));
|
|
174
|
+
}
|
|
175
|
+
hasSelfHostedConfig() {
|
|
176
|
+
return !!this.selfHostedDatabaseFilePath;
|
|
177
|
+
}
|
|
178
|
+
hasSeparateContentRoot() {
|
|
179
|
+
return this.rootPath !== this.contentRootPath;
|
|
180
|
+
}
|
|
181
|
+
async processConfig() {
|
|
182
|
+
this.tinaFolderPath = await this.getTinaFolderPath(this.rootPath);
|
|
183
|
+
this.envFilePath = import_path.default.resolve(
|
|
184
|
+
import_path.default.join(this.tinaFolderPath, "..", ".env")
|
|
185
|
+
);
|
|
186
|
+
dotenv.config({ path: this.envFilePath });
|
|
187
|
+
this.tinaConfigFilePath = await this.getPathWithExtension(
|
|
188
|
+
import_path.default.join(this.tinaFolderPath, "config")
|
|
189
|
+
);
|
|
190
|
+
if (!this.tinaConfigFilePath) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Unable to find confg file in ${this.tinaFolderPath}. Looking for a file named "config.{ts,tsx,js,jsx}"`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
this.selfHostedDatabaseFilePath = await this.getPathWithExtension(
|
|
196
|
+
import_path.default.join(this.tinaFolderPath, "database")
|
|
197
|
+
);
|
|
198
|
+
this.generatedFolderPath = import_path.default.join(this.tinaFolderPath, GENERATED_FOLDER);
|
|
199
|
+
this.config = await this.loadConfigFile(
|
|
200
|
+
this.generatedFolderPath,
|
|
201
|
+
this.tinaConfigFilePath
|
|
202
|
+
);
|
|
203
|
+
this.generatedGraphQLGQLPath = import_path.default.join(
|
|
204
|
+
this.generatedFolderPath,
|
|
205
|
+
GRAPHQL_GQL_FILE
|
|
206
|
+
);
|
|
207
|
+
this.generatedGraphQLJSONPath = import_path.default.join(
|
|
208
|
+
this.generatedFolderPath,
|
|
209
|
+
GRAPHQL_JSON_FILE
|
|
210
|
+
);
|
|
211
|
+
this.generatedSchemaJSONPath = import_path.default.join(
|
|
212
|
+
this.generatedFolderPath,
|
|
213
|
+
SCHEMA_JSON_FILE
|
|
214
|
+
);
|
|
215
|
+
this.generatedLookupJSONPath = import_path.default.join(
|
|
216
|
+
this.generatedFolderPath,
|
|
217
|
+
LOOKUP_JSON_FILE
|
|
218
|
+
);
|
|
219
|
+
this.generatedQueriesFilePath = import_path.default.join(
|
|
220
|
+
this.generatedFolderPath,
|
|
221
|
+
"queries.gql"
|
|
222
|
+
);
|
|
223
|
+
this.generatedFragmentsFilePath = import_path.default.join(
|
|
224
|
+
this.generatedFolderPath,
|
|
225
|
+
"frags.gql"
|
|
226
|
+
);
|
|
227
|
+
const fullLocalContentPath = import_path.default.join(
|
|
228
|
+
this.tinaFolderPath,
|
|
229
|
+
this.config.localContentPath || ""
|
|
230
|
+
);
|
|
231
|
+
if (this.config.localContentPath && await import_fs_extra.default.existsSync(fullLocalContentPath)) {
|
|
232
|
+
logger.info(`Using separate content repo at ${fullLocalContentPath}`);
|
|
233
|
+
this.contentRootPath = fullLocalContentPath;
|
|
351
234
|
} else {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
235
|
+
this.contentRootPath = this.rootPath;
|
|
236
|
+
}
|
|
237
|
+
this.generatedTypesTSFilePath = import_path.default.join(
|
|
238
|
+
this.generatedFolderPath,
|
|
239
|
+
"types.ts"
|
|
240
|
+
);
|
|
241
|
+
this.generatedTypesJSFilePath = import_path.default.join(
|
|
242
|
+
this.generatedFolderPath,
|
|
243
|
+
"types.js"
|
|
244
|
+
);
|
|
245
|
+
this.generatedTypesDFilePath = import_path.default.join(
|
|
246
|
+
this.generatedFolderPath,
|
|
247
|
+
"types.d.ts"
|
|
248
|
+
);
|
|
249
|
+
this.userQueriesAndFragmentsGlob = import_path.default.join(
|
|
250
|
+
this.tinaFolderPath,
|
|
251
|
+
"queries/**/*.{graphql,gql}"
|
|
252
|
+
);
|
|
253
|
+
this.generatedQueriesAndFragmentsGlob = import_path.default.join(
|
|
254
|
+
this.generatedFolderPath,
|
|
255
|
+
"*.{graphql,gql}"
|
|
256
|
+
);
|
|
257
|
+
this.generatedClientTSFilePath = import_path.default.join(
|
|
258
|
+
this.generatedFolderPath,
|
|
259
|
+
"client.ts"
|
|
260
|
+
);
|
|
261
|
+
this.generatedClientJSFilePath = import_path.default.join(
|
|
262
|
+
this.generatedFolderPath,
|
|
263
|
+
"client.js"
|
|
264
|
+
);
|
|
265
|
+
this.publicFolderPath = import_path.default.join(
|
|
266
|
+
this.rootPath,
|
|
267
|
+
this.config.build.publicFolder
|
|
268
|
+
);
|
|
269
|
+
this.outputFolderPath = import_path.default.join(
|
|
270
|
+
this.publicFolderPath,
|
|
271
|
+
this.config.build.outputFolder
|
|
272
|
+
);
|
|
273
|
+
this.outputHTMLFilePath = import_path.default.join(this.outputFolderPath, "index.html");
|
|
274
|
+
this.outputGitignorePath = import_path.default.join(this.outputFolderPath, ".gitignore");
|
|
275
|
+
this.spaHTMLPath = url.pathToFileURL(
|
|
276
|
+
require.resolve("@tinacms/app")
|
|
277
|
+
).pathname;
|
|
278
|
+
this.spaRootPath = this.spaHTMLPath.replace("/index.html", "");
|
|
279
|
+
this.spaMainPath = import_path.default.join(this.spaRootPath, "src", "main.tsx");
|
|
280
|
+
}
|
|
281
|
+
async getTinaFolderPath(rootPath) {
|
|
282
|
+
const tinaFolderPath = import_path.default.join(rootPath, TINA_FOLDER);
|
|
283
|
+
const tinaFolderExists = await import_fs_extra.default.pathExists(tinaFolderPath);
|
|
284
|
+
if (tinaFolderExists) {
|
|
285
|
+
this.isUsingLegacyFolder = false;
|
|
286
|
+
return tinaFolderPath;
|
|
287
|
+
}
|
|
288
|
+
const legacyFolderPath = import_path.default.join(rootPath, LEGACY_TINA_FOLDER);
|
|
289
|
+
const legacyFolderExists = await import_fs_extra.default.pathExists(legacyFolderPath);
|
|
290
|
+
if (legacyFolderExists) {
|
|
291
|
+
this.isUsingLegacyFolder = true;
|
|
292
|
+
return legacyFolderPath;
|
|
293
|
+
}
|
|
294
|
+
throw new Error(
|
|
295
|
+
`Unable to find Tina folder, if you're working in folder outside of the Tina config be sure to specify --rootPath`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
getTinaGraphQLVersion() {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
if (this.tinaGraphQLVersionFromCLI) {
|
|
301
|
+
return this.tinaGraphQLVersionFromCLI;
|
|
302
|
+
}
|
|
303
|
+
const generatedSchema = import_fs_extra.default.readJSONSync(this.generatedSchemaJSONPath);
|
|
304
|
+
if (!generatedSchema || !(typeof (generatedSchema == null ? void 0 : generatedSchema.version) !== "undefined") || !(typeof ((_a = generatedSchema == null ? void 0 : generatedSchema.version) == null ? void 0 : _a.major) === "string") || !(typeof ((_b = generatedSchema == null ? void 0 : generatedSchema.version) == null ? void 0 : _b.minor) === "string")) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
`Can not find Tina GraphQL version in ${this.generatedSchemaJSONPath}`
|
|
368
307
|
);
|
|
369
|
-
const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentUpdateMutation!) {
|
|
370
|
-
updateDocument(
|
|
371
|
-
collection: $collection,
|
|
372
|
-
relativePath: $relativePath,
|
|
373
|
-
params: $params
|
|
374
|
-
){__typename}
|
|
375
|
-
}`;
|
|
376
|
-
const mutationRes = await (0, import_graphql.resolve)({
|
|
377
|
-
database,
|
|
378
|
-
query: mutation,
|
|
379
|
-
variables: {
|
|
380
|
-
params,
|
|
381
|
-
collection: collection.name,
|
|
382
|
-
relativePath
|
|
383
|
-
},
|
|
384
|
-
isAudit: true,
|
|
385
|
-
silenceErrors: true,
|
|
386
|
-
verbose: args.verbose || false
|
|
387
|
-
});
|
|
388
|
-
if (mutationRes.errors) {
|
|
389
|
-
mutationRes.errors.forEach((err) => {
|
|
390
|
-
error = true;
|
|
391
|
-
logger.error(import_chalk.default.red(err.message));
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
308
|
}
|
|
309
|
+
return `${generatedSchema.version.major}.${generatedSchema.version.minor}`;
|
|
395
310
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
|
|
402
|
-
return instructions.includeCollection ? { [_collection]: { ...defaults, ...filterObject(paramsWithTemplate) } } : { ...defaults, ...filterObject(paramsWithTemplate) };
|
|
403
|
-
};
|
|
404
|
-
var transformParams = (data) => {
|
|
405
|
-
if (["string", "number", "boolean"].includes(typeof data)) {
|
|
406
|
-
return data;
|
|
311
|
+
printGeneratedClientFilePath() {
|
|
312
|
+
if (this.isUsingTs()) {
|
|
313
|
+
return this.generatedClientTSFilePath.replace(`${this.rootPath}/`, "");
|
|
314
|
+
}
|
|
315
|
+
return this.generatedClientJSFilePath.replace(`${this.rootPath}/`, "");
|
|
407
316
|
}
|
|
408
|
-
|
|
409
|
-
return
|
|
317
|
+
printGeneratedTypesFilePath() {
|
|
318
|
+
return this.generatedTypesTSFilePath.replace(`${this.rootPath}/`, "");
|
|
410
319
|
}
|
|
411
|
-
|
|
412
|
-
(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
)
|
|
416
|
-
|
|
417
|
-
const nested = transformParams(rest);
|
|
418
|
-
return { [_template]: nested };
|
|
419
|
-
} catch (e) {
|
|
420
|
-
if (e.message === "Failed to assertShape - _template is a required field") {
|
|
421
|
-
if (!data) {
|
|
422
|
-
return void 0;
|
|
423
|
-
return [];
|
|
424
|
-
}
|
|
425
|
-
const accum = {};
|
|
426
|
-
Object.entries(data).map(([keyName, value]) => {
|
|
427
|
-
accum[keyName] = transformParams(value);
|
|
428
|
-
});
|
|
429
|
-
return accum;
|
|
430
|
-
} else {
|
|
431
|
-
if (!data) {
|
|
432
|
-
return void 0;
|
|
433
|
-
return [];
|
|
434
|
-
}
|
|
435
|
-
throw e;
|
|
320
|
+
printoutputHTMLFilePath() {
|
|
321
|
+
return this.outputHTMLFilePath.replace(`${this.publicFolderPath}/`, "");
|
|
322
|
+
}
|
|
323
|
+
printRelativePath(filename) {
|
|
324
|
+
if (filename) {
|
|
325
|
+
return filename.replace(`${this.rootPath}/`, "");
|
|
436
326
|
}
|
|
327
|
+
throw `No path provided to print`;
|
|
437
328
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
329
|
+
printContentRelativePath(filename) {
|
|
330
|
+
if (filename) {
|
|
331
|
+
return filename.replace(`${this.contentRootPath}/`, "");
|
|
332
|
+
}
|
|
333
|
+
throw `No path provided to print`;
|
|
334
|
+
}
|
|
335
|
+
async getPathWithExtension(filepath) {
|
|
336
|
+
const extensions = ["tsx", "ts", "jsx", "js"];
|
|
337
|
+
let result;
|
|
338
|
+
await Promise.all(
|
|
339
|
+
extensions.map(async (ext) => {
|
|
340
|
+
if (result) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const filepathWithExtension = `${filepath}.${ext}`;
|
|
344
|
+
const exists = await import_fs_extra.default.existsSync(filepathWithExtension);
|
|
345
|
+
if (exists) {
|
|
346
|
+
result = filepathWithExtension;
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
);
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
async loadDatabaseFile() {
|
|
353
|
+
const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
|
|
354
|
+
const outfile = import_path.default.join(tmpdir, "database.build.js");
|
|
355
|
+
await esbuild.build({
|
|
356
|
+
entryPoints: [this.selfHostedDatabaseFilePath],
|
|
357
|
+
bundle: true,
|
|
358
|
+
platform: "node",
|
|
359
|
+
outfile
|
|
360
|
+
});
|
|
361
|
+
const result = require(outfile);
|
|
362
|
+
await import_fs_extra.default.removeSync(outfile);
|
|
363
|
+
return result.default;
|
|
364
|
+
}
|
|
365
|
+
async loadConfigFile(generatedFolderPath, configFilePath) {
|
|
366
|
+
const tmpdir = import_path.default.join(import_os.default.tmpdir(), Date.now().toString());
|
|
367
|
+
const outfile = import_path.default.join(tmpdir, "config.build.jsx");
|
|
368
|
+
const outfile2 = import_path.default.join(tmpdir, "config.build.js");
|
|
369
|
+
const tempTSConfigFile = import_path.default.join(tmpdir, "tsconfig.json");
|
|
370
|
+
await import_fs_extra.default.outputFileSync(tempTSConfigFile, "{}");
|
|
371
|
+
await esbuild.build({
|
|
372
|
+
entryPoints: [configFilePath],
|
|
373
|
+
bundle: true,
|
|
374
|
+
target: ["es2020"],
|
|
375
|
+
platform: "node",
|
|
376
|
+
outfile
|
|
377
|
+
});
|
|
378
|
+
await esbuild.build({
|
|
379
|
+
entryPoints: [outfile],
|
|
380
|
+
bundle: true,
|
|
381
|
+
platform: "node",
|
|
382
|
+
outfile: outfile2
|
|
383
|
+
});
|
|
384
|
+
const result = require(outfile2);
|
|
385
|
+
await import_fs_extra.default.removeSync(outfile);
|
|
386
|
+
await import_fs_extra.default.removeSync(outfile2);
|
|
387
|
+
return result.default;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// src/next/commands/dev-command/html.ts
|
|
392
|
+
var devHTML = (port) => `<!DOCTYPE html>
|
|
393
|
+
<html lang="en">
|
|
394
|
+
<head>
|
|
395
|
+
<meta charset="UTF-8" />
|
|
396
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
397
|
+
<title>TinaCMS</title>
|
|
398
|
+
</head>
|
|
399
|
+
|
|
400
|
+
<!-- if development -->
|
|
401
|
+
<script type="module">
|
|
402
|
+
import RefreshRuntime from 'http://localhost:${port}/@react-refresh'
|
|
403
|
+
RefreshRuntime.injectIntoGlobalHook(window)
|
|
404
|
+
window.$RefreshReg$ = () => {}
|
|
405
|
+
window.$RefreshSig$ = () => (type) => type
|
|
406
|
+
window.__vite_plugin_react_preamble_installed__ = true
|
|
407
|
+
<\/script>
|
|
408
|
+
<script type="module" src="http://localhost:${port}/@vite/client"><\/script>
|
|
409
|
+
<script
|
|
410
|
+
type="module"
|
|
411
|
+
src="http://localhost:${port}/src/main.tsx"
|
|
412
|
+
><\/script>
|
|
413
|
+
<body class="tina-tailwind">
|
|
414
|
+
<div id="root"></div>
|
|
415
|
+
</body>
|
|
416
|
+
</html>`;
|
|
417
|
+
|
|
418
|
+
// src/next/commands/dev-command/server/index.ts
|
|
419
|
+
var import_body_parser = __toESM(require("body-parser"));
|
|
420
|
+
var import_path5 = __toESM(require("path"));
|
|
421
|
+
var import_cors = __toESM(require("cors"));
|
|
422
|
+
var import_vite2 = require("vite");
|
|
423
|
+
var import_graphql = require("@tinacms/graphql");
|
|
449
424
|
|
|
450
|
-
// src/
|
|
451
|
-
var
|
|
452
|
-
var
|
|
453
|
-
var
|
|
454
|
-
var
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const telemetry = new import_metrics.Telemetry({ disabled: options.noTelemetry });
|
|
471
|
-
await telemetry.submitRecord({
|
|
472
|
-
event: {
|
|
473
|
-
name: "tinacms:cli:audit:invoke",
|
|
474
|
-
clean: Boolean(options.clean),
|
|
475
|
-
useDefaults: Boolean(options.useDefaultValues)
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
if (options.clean) {
|
|
479
|
-
logger.info(
|
|
480
|
-
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${import_chalk3.default.bold(
|
|
481
|
-
"clean git tree"
|
|
482
|
-
)} so unwanted changes can be undone.
|
|
483
|
-
|
|
484
|
-
`
|
|
485
|
-
);
|
|
486
|
-
const res = await (0, import_prompts.default)({
|
|
487
|
-
name: "useClean",
|
|
488
|
-
type: "confirm",
|
|
489
|
-
message: `Do you want to continue?`
|
|
425
|
+
// src/next/commands/dev-command/server/media.ts
|
|
426
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
427
|
+
var import_path2 = __toESM(require("path"));
|
|
428
|
+
var import_busboy = __toESM(require("busboy"));
|
|
429
|
+
var createMediaRouter = (config3) => {
|
|
430
|
+
const mediaFolder = import_path2.default.join(
|
|
431
|
+
config3.rootPath,
|
|
432
|
+
config3.publicFolder,
|
|
433
|
+
config3.mediaRoot
|
|
434
|
+
);
|
|
435
|
+
const mediaModel = new MediaModel(config3);
|
|
436
|
+
const handleList = async (req, res) => {
|
|
437
|
+
const requestURL = new URL(req.url, config3.apiURL);
|
|
438
|
+
const folder = requestURL.pathname.replace("/media/list/", "");
|
|
439
|
+
const limit = requestURL.searchParams.get("limit");
|
|
440
|
+
const cursor = requestURL.searchParams.get("cursor");
|
|
441
|
+
const media = await mediaModel.listMedia({
|
|
442
|
+
searchPath: folder,
|
|
443
|
+
cursor,
|
|
444
|
+
limit
|
|
490
445
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
const database = ctx.database;
|
|
504
|
-
const schema = await database.getSchema();
|
|
505
|
-
const collections = schema.getCollections();
|
|
506
|
-
let error = false;
|
|
507
|
-
for (let i = 0; i < collections.length; i++) {
|
|
508
|
-
const collection = collections[i];
|
|
509
|
-
const docs = await database.query(
|
|
510
|
-
{ collection: collection.name, first: -1, filterChain: [] },
|
|
511
|
-
(item) => ({ path: item })
|
|
512
|
-
);
|
|
513
|
-
logger.info(
|
|
514
|
-
`Checking ${neutralText(collection.name)} collection. ${docs.edges.length} Documents`
|
|
515
|
-
);
|
|
516
|
-
const returnError = await auditDocuments({
|
|
517
|
-
collection,
|
|
518
|
-
database,
|
|
519
|
-
rootPath,
|
|
520
|
-
useDefaultValues: options.useDefaultValues,
|
|
521
|
-
documents: docs.edges,
|
|
522
|
-
verbose: ctx.verbose
|
|
446
|
+
res.end(JSON.stringify(media));
|
|
447
|
+
};
|
|
448
|
+
const handleDelete = async (req, res) => {
|
|
449
|
+
const file = decodeURIComponent(req.url.slice("/media/".length));
|
|
450
|
+
const didDelete = await mediaModel.deleteMedia({ searchPath: file });
|
|
451
|
+
res.end(JSON.stringify(didDelete));
|
|
452
|
+
};
|
|
453
|
+
const handlePost = async function(req, res) {
|
|
454
|
+
const bb = (0, import_busboy.default)({ headers: req.headers });
|
|
455
|
+
bb.on("file", (name2, file, info) => {
|
|
456
|
+
const saveTo = import_path2.default.join(mediaFolder, info.filename);
|
|
457
|
+
file.pipe(import_fs_extra2.default.createWriteStream(saveTo));
|
|
523
458
|
});
|
|
524
|
-
error
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
459
|
+
bb.on("error", (error) => {
|
|
460
|
+
res.statusCode = 500;
|
|
461
|
+
if (error instanceof Error) {
|
|
462
|
+
res.end(JSON.stringify({ message: error }));
|
|
463
|
+
} else {
|
|
464
|
+
res.end(JSON.stringify({ message: "Unknown error while uploading" }));
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
bb.on("close", () => {
|
|
468
|
+
res.statusCode = 200;
|
|
469
|
+
res.end(JSON.stringify({ success: true }));
|
|
470
|
+
});
|
|
471
|
+
req.pipe(bb);
|
|
472
|
+
};
|
|
473
|
+
return { handleList, handleDelete, handlePost };
|
|
474
|
+
};
|
|
475
|
+
var parseMediaFolder = (str) => {
|
|
476
|
+
let returnString = str;
|
|
477
|
+
if (returnString.startsWith("/"))
|
|
478
|
+
returnString = returnString.substr(1);
|
|
479
|
+
if (returnString.endsWith("/"))
|
|
480
|
+
returnString = returnString.substr(0, returnString.length - 1);
|
|
481
|
+
return returnString;
|
|
482
|
+
};
|
|
483
|
+
var MediaModel = class {
|
|
484
|
+
constructor({ rootPath, publicFolder, mediaRoot }) {
|
|
485
|
+
this.rootPath = rootPath;
|
|
486
|
+
this.mediaRoot = mediaRoot;
|
|
487
|
+
this.publicFolder = publicFolder;
|
|
488
|
+
}
|
|
489
|
+
async listMedia(args) {
|
|
552
490
|
try {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
491
|
+
const folderPath = (0, import_path2.join)(
|
|
492
|
+
this.rootPath,
|
|
493
|
+
this.publicFolder,
|
|
494
|
+
this.mediaRoot,
|
|
495
|
+
args.searchPath
|
|
557
496
|
);
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
497
|
+
const searchPath = parseMediaFolder(args.searchPath);
|
|
498
|
+
const filesStr = await import_fs_extra2.default.readdir(folderPath);
|
|
499
|
+
const filesProm = filesStr.map(async (file) => {
|
|
500
|
+
const filePath = (0, import_path2.join)(folderPath, file);
|
|
501
|
+
const stat = await import_fs_extra2.default.stat(filePath);
|
|
502
|
+
let src = `/${file}`;
|
|
503
|
+
const isFile = stat.isFile();
|
|
504
|
+
if (!isFile) {
|
|
505
|
+
return {
|
|
506
|
+
isFile,
|
|
507
|
+
size: stat.size,
|
|
508
|
+
src,
|
|
509
|
+
filename: file
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
if (searchPath) {
|
|
513
|
+
src = `/${searchPath}${src}`;
|
|
514
|
+
}
|
|
515
|
+
if (this.mediaRoot) {
|
|
516
|
+
src = `/${this.mediaRoot}${src}`;
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
isFile,
|
|
520
|
+
size: stat.size,
|
|
521
|
+
src,
|
|
522
|
+
filename: file
|
|
523
|
+
};
|
|
524
|
+
});
|
|
525
|
+
const offset = Number(args.cursor) || 0;
|
|
526
|
+
const limit = Number(args.limit) || 20;
|
|
527
|
+
const rawItems = await Promise.all(filesProm);
|
|
528
|
+
const sortedItems = rawItems.sort((a, b) => {
|
|
529
|
+
if (a.isFile && !b.isFile) {
|
|
530
|
+
return 1;
|
|
531
|
+
}
|
|
532
|
+
if (!a.isFile && b.isFile) {
|
|
533
|
+
return -1;
|
|
534
|
+
}
|
|
535
|
+
return 0;
|
|
536
|
+
});
|
|
537
|
+
const limitItems = sortedItems.slice(offset, offset + limit);
|
|
538
|
+
const files = limitItems.filter((x) => x.isFile);
|
|
539
|
+
const directories = limitItems.filter((x) => !x.isFile).map((x) => x.src);
|
|
540
|
+
const cursor = rawItems.length > offset + limit ? String(offset + limit) : null;
|
|
541
|
+
return {
|
|
542
|
+
files,
|
|
543
|
+
directories,
|
|
544
|
+
cursor
|
|
545
|
+
};
|
|
546
|
+
} catch (error) {
|
|
547
|
+
console.error(error);
|
|
548
|
+
return {
|
|
549
|
+
files: [],
|
|
550
|
+
directories: [],
|
|
551
|
+
error: error == null ? void 0 : error.toString()
|
|
552
|
+
};
|
|
564
553
|
}
|
|
565
|
-
};
|
|
566
|
-
if (cmds.length > 0) {
|
|
567
|
-
await next(0);
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
// src/cmds/baseCmds.ts
|
|
572
|
-
var import_chalk4 = __toESM(require("chalk"));
|
|
573
|
-
|
|
574
|
-
// src/cmds/start-server/index.ts
|
|
575
|
-
var import_path8 = __toESM(require("path"));
|
|
576
|
-
var import_chokidar = __toESM(require("chokidar"));
|
|
577
|
-
var import_metrics2 = require("@tinacms/metrics");
|
|
578
|
-
|
|
579
|
-
// src/cmds/start-server/lock.ts
|
|
580
|
-
var AsyncLock = class {
|
|
581
|
-
constructor() {
|
|
582
|
-
this.disable = () => {
|
|
583
|
-
};
|
|
584
|
-
this.promise = Promise.resolve();
|
|
585
|
-
}
|
|
586
|
-
enable() {
|
|
587
|
-
this.promise = new Promise((resolve2) => this.disable = resolve2);
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
// src/cmds/start-server/errors/index.ts
|
|
592
|
-
var import_graphql3 = require("@tinacms/graphql");
|
|
593
|
-
var BuildSchemaError = class extends Error {
|
|
594
|
-
constructor(message) {
|
|
595
|
-
super(message);
|
|
596
|
-
this.name = "BuildSchemaError";
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
var ExecuteSchemaError = class extends Error {
|
|
600
|
-
constructor(message) {
|
|
601
|
-
super(message);
|
|
602
|
-
this.name = "ExecuteSchemaError";
|
|
603
554
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
)
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
logger.error(`${dangerText(
|
|
620
|
-
"ERROR: your schema was not successfully validated: see https://tina.io/docs/schema/ for instructions on how to setup a schema"
|
|
621
|
-
)}
|
|
622
|
-
Error Message Below
|
|
623
|
-
${e}`);
|
|
624
|
-
} else if (e instanceof import_graphql3.TinaFetchError) {
|
|
625
|
-
(0, import_graphql3.handleFetchErrorError)(e, true);
|
|
626
|
-
} else {
|
|
627
|
-
logger.info(
|
|
628
|
-
dangerText(
|
|
629
|
-
"Compilation failed with errors. Server has not been restarted."
|
|
630
|
-
) + ` see error below
|
|
631
|
-
${e.message}`
|
|
632
|
-
);
|
|
555
|
+
async deleteMedia(args) {
|
|
556
|
+
try {
|
|
557
|
+
const file = (0, import_path2.join)(
|
|
558
|
+
this.rootPath,
|
|
559
|
+
this.publicFolder,
|
|
560
|
+
this.mediaRoot,
|
|
561
|
+
args.searchPath
|
|
562
|
+
);
|
|
563
|
+
await import_fs_extra2.default.stat(file);
|
|
564
|
+
await import_fs_extra2.default.remove(file);
|
|
565
|
+
return { ok: true };
|
|
566
|
+
} catch (error) {
|
|
567
|
+
console.error(error);
|
|
568
|
+
return { ok: false, message: error == null ? void 0 : error.toString() };
|
|
569
|
+
}
|
|
633
570
|
}
|
|
634
571
|
};
|
|
635
572
|
|
|
636
|
-
// src/
|
|
637
|
-
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
638
|
-
var import_graphql9 = require("@tinacms/graphql");
|
|
639
|
-
var import_datalayer = require("@tinacms/datalayer");
|
|
640
|
-
var import_memory_level = require("memory-level");
|
|
641
|
-
var import_path5 = __toESM(require("path"));
|
|
642
|
-
|
|
643
|
-
// src/cmds/compile/index.ts
|
|
644
|
-
var _ = __toESM(require("lodash"));
|
|
645
|
-
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
646
|
-
var import_path2 = __toESM(require("path"));
|
|
573
|
+
// src/next/commands/dev-command/server/index.ts
|
|
647
574
|
var import_esbuild = require("esbuild");
|
|
648
575
|
|
|
649
|
-
// src/
|
|
650
|
-
var
|
|
651
|
-
var
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
576
|
+
// src/next/vite/index.ts
|
|
577
|
+
var import_path4 = __toESM(require("path"));
|
|
578
|
+
var import_vite = require("vite");
|
|
579
|
+
|
|
580
|
+
// src/next/vite/tailwind.ts
|
|
581
|
+
var import_tailwindcss = __toESM(require("tailwindcss"));
|
|
582
|
+
var import_postcss_nested = __toESM(require("postcss-nested/index.js"));
|
|
583
|
+
var import_nesting = __toESM(require("tailwindcss/nesting/index.js"));
|
|
584
|
+
var import_defaultTheme = __toESM(require("tailwindcss/defaultTheme.js"));
|
|
585
|
+
var import_typography = __toESM(require("@tailwindcss/typography"));
|
|
586
|
+
var import_line_clamp = __toESM(require("@tailwindcss/line-clamp"));
|
|
587
|
+
var import_aspect_ratio = __toESM(require("@tailwindcss/aspect-ratio"));
|
|
588
|
+
var import_path3 = __toESM(require("path"));
|
|
589
|
+
var tinaTailwind = (spaPath, configFilePath) => {
|
|
590
|
+
return {
|
|
591
|
+
name: "vite-plugin-tina",
|
|
592
|
+
config: (viteConfig) => {
|
|
593
|
+
const plugins = [];
|
|
594
|
+
const content2 = [
|
|
595
|
+
import_path3.default.join(spaPath, "src/**/*.{vue,js,ts,jsx,tsx,svelte}"),
|
|
596
|
+
import_path3.default.join(configFilePath, "../**/*.{vue,js,ts,jsx,tsx,svelte}")
|
|
597
|
+
];
|
|
598
|
+
const tw = (0, import_tailwindcss.default)({
|
|
599
|
+
important: ".tina-tailwind",
|
|
600
|
+
theme: {
|
|
601
|
+
columns: {
|
|
602
|
+
auto: "auto",
|
|
603
|
+
1: "1",
|
|
604
|
+
2: "2",
|
|
605
|
+
3: "3",
|
|
606
|
+
4: "4",
|
|
607
|
+
5: "5",
|
|
608
|
+
6: "6",
|
|
609
|
+
7: "7",
|
|
610
|
+
8: "8",
|
|
611
|
+
9: "9",
|
|
612
|
+
10: "10",
|
|
613
|
+
11: "11",
|
|
614
|
+
12: "12",
|
|
615
|
+
"3xs": "256px",
|
|
616
|
+
"2xs": "288px",
|
|
617
|
+
xs: "320px",
|
|
618
|
+
sm: "384px",
|
|
619
|
+
md: "448px",
|
|
620
|
+
lg: "512px",
|
|
621
|
+
xl: "576px",
|
|
622
|
+
"2xl": "672px",
|
|
623
|
+
"3xl": "768px",
|
|
624
|
+
"4xl": "896px",
|
|
625
|
+
"5xl": "1024px",
|
|
626
|
+
"6xl": "1152px",
|
|
627
|
+
"7xl": "1280px"
|
|
628
|
+
},
|
|
629
|
+
spacing: {
|
|
630
|
+
px: "1px",
|
|
631
|
+
0: "0px",
|
|
632
|
+
0.5: "2px",
|
|
633
|
+
1: "4px",
|
|
634
|
+
1.5: "6px",
|
|
635
|
+
2: "8px",
|
|
636
|
+
2.5: "10px",
|
|
637
|
+
3: "12px",
|
|
638
|
+
3.5: "14px",
|
|
639
|
+
4: "16px",
|
|
640
|
+
5: "20px",
|
|
641
|
+
6: "24px",
|
|
642
|
+
7: "28px",
|
|
643
|
+
8: "32px",
|
|
644
|
+
9: "36px",
|
|
645
|
+
10: "40px",
|
|
646
|
+
11: "44px",
|
|
647
|
+
12: "48px",
|
|
648
|
+
14: "56px",
|
|
649
|
+
16: "64px",
|
|
650
|
+
18: "72px",
|
|
651
|
+
20: "80px",
|
|
652
|
+
24: "96px",
|
|
653
|
+
28: "114px",
|
|
654
|
+
32: "128px",
|
|
655
|
+
36: "144px",
|
|
656
|
+
40: "160px",
|
|
657
|
+
44: "176px",
|
|
658
|
+
48: "192px",
|
|
659
|
+
52: "208px",
|
|
660
|
+
56: "224px",
|
|
661
|
+
60: "240px",
|
|
662
|
+
64: "256px",
|
|
663
|
+
72: "288px",
|
|
664
|
+
80: "320px",
|
|
665
|
+
96: "384px"
|
|
666
|
+
},
|
|
667
|
+
borderRadius: {
|
|
668
|
+
none: "0px",
|
|
669
|
+
sm: "2px",
|
|
670
|
+
DEFAULT: "4px",
|
|
671
|
+
md: "6px",
|
|
672
|
+
lg: "8px",
|
|
673
|
+
xl: "12px",
|
|
674
|
+
"2xl": "16px",
|
|
675
|
+
"3xl": "24px",
|
|
676
|
+
full: "9999px"
|
|
677
|
+
},
|
|
678
|
+
borderWidth: {
|
|
679
|
+
DEFAULT: "1px",
|
|
680
|
+
0: "0",
|
|
681
|
+
2: "2px",
|
|
682
|
+
3: "3px",
|
|
683
|
+
4: "4px",
|
|
684
|
+
6: "6px",
|
|
685
|
+
8: "8px"
|
|
686
|
+
},
|
|
687
|
+
fontSize: {
|
|
688
|
+
xs: ["13px", { lineHeight: "1.33" }],
|
|
689
|
+
sm: ["14px", { lineHeight: "1.43" }],
|
|
690
|
+
base: ["16px", { lineHeight: "1.5" }],
|
|
691
|
+
md: ["16px", { lineHeight: "1.5" }],
|
|
692
|
+
lg: ["18px", { lineHeight: "1.55" }],
|
|
693
|
+
xl: ["20px", { lineHeight: "1.4" }],
|
|
694
|
+
"2xl": ["24px", { lineHeight: "1.33" }],
|
|
695
|
+
"3xl": ["30px", { lineHeight: "1.2" }],
|
|
696
|
+
"4xl": ["36px", { lineHeight: "1.1" }],
|
|
697
|
+
"5xl": ["48px", { lineHeight: "1" }],
|
|
698
|
+
"6xl": ["60px", { lineHeight: "1" }],
|
|
699
|
+
"7xl": ["72px", { lineHeight: "1" }],
|
|
700
|
+
"8xl": ["96px", { lineHeight: "1" }],
|
|
701
|
+
"9xl": ["128px", { lineHeight: "1" }]
|
|
702
|
+
},
|
|
703
|
+
opacity: {
|
|
704
|
+
0: "0",
|
|
705
|
+
5: ".05",
|
|
706
|
+
7: ".07",
|
|
707
|
+
10: ".1",
|
|
708
|
+
15: ".15",
|
|
709
|
+
20: ".2",
|
|
710
|
+
25: ".25",
|
|
711
|
+
30: ".3",
|
|
712
|
+
40: ".4",
|
|
713
|
+
50: ".5",
|
|
714
|
+
60: ".6",
|
|
715
|
+
70: ".7",
|
|
716
|
+
75: ".75",
|
|
717
|
+
80: ".8",
|
|
718
|
+
90: ".9",
|
|
719
|
+
100: "1"
|
|
720
|
+
},
|
|
721
|
+
zIndex: {
|
|
722
|
+
"-1": "-1",
|
|
723
|
+
base: "9000",
|
|
724
|
+
panel: "9400",
|
|
725
|
+
menu: "9800",
|
|
726
|
+
chrome: "10200",
|
|
727
|
+
overlay: "10600",
|
|
728
|
+
modal: "10800",
|
|
729
|
+
0: "0",
|
|
730
|
+
10: "10",
|
|
731
|
+
20: "20",
|
|
732
|
+
30: "30",
|
|
733
|
+
40: "40",
|
|
734
|
+
25: "25",
|
|
735
|
+
50: "50",
|
|
736
|
+
75: "75",
|
|
737
|
+
100: "100",
|
|
738
|
+
auto: "auto"
|
|
739
|
+
},
|
|
740
|
+
extend: {
|
|
741
|
+
scale: {
|
|
742
|
+
97: ".97",
|
|
743
|
+
103: "1.03"
|
|
744
|
+
},
|
|
745
|
+
transitionDuration: {
|
|
746
|
+
0: "0ms",
|
|
747
|
+
2e3: "2000ms"
|
|
748
|
+
},
|
|
749
|
+
boxShadow: {
|
|
750
|
+
xs: "0 0 0 1px rgba(0, 0, 0, 0.05)",
|
|
751
|
+
outline: "0 0 0 3px rgba(66, 153, 225, 0.5)"
|
|
752
|
+
},
|
|
753
|
+
colors: {
|
|
754
|
+
blue: {
|
|
755
|
+
50: "#DCEEFF",
|
|
756
|
+
100: "#B4DBFF",
|
|
757
|
+
200: "#85C5FE",
|
|
758
|
+
300: "#4EABFE",
|
|
759
|
+
400: "#2296fe",
|
|
760
|
+
500: "#0084FF",
|
|
761
|
+
600: "#0574e4",
|
|
762
|
+
700: "#0D5DBD",
|
|
763
|
+
800: "#144696",
|
|
764
|
+
900: "#1D2C6C",
|
|
765
|
+
1e3: "#241748"
|
|
766
|
+
},
|
|
767
|
+
gray: {
|
|
768
|
+
50: "#F6F6F9",
|
|
769
|
+
100: "#EDECF3",
|
|
770
|
+
150: "#E6E3EF",
|
|
771
|
+
200: "#E1DDEC",
|
|
772
|
+
250: "#C9C5D5",
|
|
773
|
+
300: "#b2adbe",
|
|
774
|
+
400: "#918c9e",
|
|
775
|
+
500: "#716c7f",
|
|
776
|
+
600: "#565165",
|
|
777
|
+
700: "#433e52",
|
|
778
|
+
800: "#363145",
|
|
779
|
+
900: "#252336",
|
|
780
|
+
1e3: "#1c1b2e"
|
|
781
|
+
},
|
|
782
|
+
orange: {
|
|
783
|
+
400: "#EB6337",
|
|
784
|
+
500: "#EC4815",
|
|
785
|
+
600: "#DC4419"
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
fontFamily: {
|
|
789
|
+
sans: ["Inter", ...import_defaultTheme.default.fontFamily.sans]
|
|
790
|
+
},
|
|
791
|
+
lineHeight: {
|
|
792
|
+
3: "12px",
|
|
793
|
+
4: "16px",
|
|
794
|
+
5: "20px",
|
|
795
|
+
6: "24px",
|
|
796
|
+
7: "28px",
|
|
797
|
+
8: "32px",
|
|
798
|
+
9: "36px",
|
|
799
|
+
10: "40px"
|
|
800
|
+
},
|
|
801
|
+
maxWidth: {
|
|
802
|
+
form: "900px"
|
|
803
|
+
},
|
|
804
|
+
screens: {
|
|
805
|
+
xs: "320px",
|
|
806
|
+
sm: "560px",
|
|
807
|
+
md: "720px",
|
|
808
|
+
lg: "1030px"
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
content: content2,
|
|
813
|
+
plugins: [
|
|
814
|
+
(0, import_typography.default)({ className: "tina-prose" }),
|
|
815
|
+
import_line_clamp.default,
|
|
816
|
+
import_aspect_ratio.default
|
|
817
|
+
]
|
|
818
|
+
});
|
|
819
|
+
plugins.push(import_nesting.default);
|
|
820
|
+
plugins.push(import_postcss_nested.default);
|
|
821
|
+
plugins.push(tw);
|
|
822
|
+
return {
|
|
823
|
+
css: {
|
|
824
|
+
postcss: {
|
|
825
|
+
plugins
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
};
|
|
668
829
|
}
|
|
669
|
-
|
|
670
|
-
});
|
|
671
|
-
return Boolean(inputFile);
|
|
830
|
+
};
|
|
672
831
|
};
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
const filePaths = allowedTypes.map(
|
|
687
|
-
(ext) => import_path.default.join(projectDir, `${filename}.${ext}`)
|
|
688
|
-
);
|
|
689
|
-
let inputFile = void 0;
|
|
690
|
-
filePaths.every((path11) => {
|
|
691
|
-
if (import_fs_extra.default.existsSync(path11)) {
|
|
692
|
-
inputFile = path11;
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
return true;
|
|
696
|
-
});
|
|
697
|
-
if (!inputFile && errorMessage) {
|
|
698
|
-
throw new Error(errorMessage);
|
|
699
|
-
}
|
|
700
|
-
return inputFile;
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
// src/cmds/compile/index.ts
|
|
704
|
-
var generatedFilesToRemove = [
|
|
705
|
-
"_graphql.json",
|
|
706
|
-
"__lookup.json",
|
|
707
|
-
"__schema.json",
|
|
708
|
-
"frags.gql",
|
|
709
|
-
"queries.gql",
|
|
710
|
-
"schema.gql",
|
|
711
|
-
"db"
|
|
712
|
-
];
|
|
713
|
-
var resetGeneratedFolder = async ({
|
|
714
|
-
tinaGeneratedPath,
|
|
715
|
-
usingTs,
|
|
716
|
-
isBuild
|
|
832
|
+
|
|
833
|
+
// src/next/vite/index.ts
|
|
834
|
+
var import_normalize_path2 = __toESM(require("normalize-path"));
|
|
835
|
+
var createConfig = async ({
|
|
836
|
+
configManager,
|
|
837
|
+
database,
|
|
838
|
+
apiURL,
|
|
839
|
+
plugins = [],
|
|
840
|
+
noSDK,
|
|
841
|
+
noWatch,
|
|
842
|
+
rollupOptions
|
|
717
843
|
}) => {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
if (file === "db") {
|
|
725
|
-
try {
|
|
726
|
-
await import_fs_extra2.default.remove(import_path2.default.join(tinaGeneratedPath, file));
|
|
727
|
-
} catch (_e) {
|
|
728
|
-
}
|
|
844
|
+
const publicEnv = {};
|
|
845
|
+
Object.keys(process.env).forEach((key) => {
|
|
846
|
+
if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
|
|
847
|
+
try {
|
|
848
|
+
if (typeof process.env[key] === "string") {
|
|
849
|
+
publicEnv[key] = process.env[key];
|
|
729
850
|
} else {
|
|
730
|
-
|
|
851
|
+
publicEnv[key] = JSON.stringify(process.env[key]);
|
|
731
852
|
}
|
|
853
|
+
} catch (error) {
|
|
854
|
+
console.warn(
|
|
855
|
+
`Could not stringify public env process.env.${key} env variable`
|
|
856
|
+
);
|
|
857
|
+
console.warn(error);
|
|
732
858
|
}
|
|
733
859
|
}
|
|
734
|
-
} catch (e) {
|
|
735
|
-
console.log(e);
|
|
736
|
-
}
|
|
737
|
-
await import_fs_extra2.default.mkdirp(tinaGeneratedPath);
|
|
738
|
-
const ext = usingTs ? "ts" : "js";
|
|
739
|
-
if (!await import_fs_extra2.default.pathExists(import_path2.default.join(tinaGeneratedPath, `types.${ext}`))) {
|
|
740
|
-
await import_fs_extra2.default.writeFile(
|
|
741
|
-
import_path2.default.join(tinaGeneratedPath, `types.${ext}`),
|
|
742
|
-
`
|
|
743
|
-
export const queries = (client)=>({})
|
|
744
|
-
`
|
|
745
|
-
);
|
|
746
|
-
}
|
|
747
|
-
if (!await import_fs_extra2.default.pathExists(import_path2.default.join(tinaGeneratedPath, `client.${ext}`))) {
|
|
748
|
-
await import_fs_extra2.default.writeFile(
|
|
749
|
-
import_path2.default.join(tinaGeneratedPath, `client.${ext}`),
|
|
750
|
-
`
|
|
751
|
-
export const client = ()=>{}
|
|
752
|
-
export default client
|
|
753
|
-
`
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
await import_fs_extra2.default.outputFile(
|
|
757
|
-
import_path2.default.join(tinaGeneratedPath, ".gitignore"),
|
|
758
|
-
`app
|
|
759
|
-
db
|
|
760
|
-
prebuild
|
|
761
|
-
client.ts
|
|
762
|
-
client.js
|
|
763
|
-
types.ts
|
|
764
|
-
types.js
|
|
765
|
-
types.d.ts
|
|
766
|
-
frags.gql
|
|
767
|
-
queries.gql
|
|
768
|
-
schema.gql
|
|
769
|
-
out.jsx
|
|
770
|
-
`
|
|
771
|
-
);
|
|
772
|
-
};
|
|
773
|
-
var cleanup = async ({ tinaTempPath }) => {
|
|
774
|
-
await import_fs_extra2.default.remove(tinaTempPath);
|
|
775
|
-
};
|
|
776
|
-
var compileFile = async (options, fileName) => {
|
|
777
|
-
const root = options.rootPath;
|
|
778
|
-
if (!root) {
|
|
779
|
-
throw new Error("ctx.rootPath has not been attached");
|
|
780
|
-
}
|
|
781
|
-
const tinaPath = import_path2.default.join(root, ".tina");
|
|
782
|
-
const tsConfigPath = import_path2.default.join(root, "tsconfig.json");
|
|
783
|
-
const tinaGeneratedPath = import_path2.default.join(tinaPath, "__generated__");
|
|
784
|
-
const tinaTempPath = import_path2.default.join(tinaGeneratedPath, `temp_${fileName}`);
|
|
785
|
-
const packageJSONFilePath = import_path2.default.join(root, "package.json");
|
|
786
|
-
if (!options.schemaFileType) {
|
|
787
|
-
const usingTs = await import_fs_extra2.default.pathExists(tsConfigPath);
|
|
788
|
-
options = { ...options, schemaFileType: usingTs ? "ts" : "js" };
|
|
789
|
-
}
|
|
790
|
-
if (options.verbose) {
|
|
791
|
-
logger.info(logText(`Compiling ${fileName}...`));
|
|
792
|
-
}
|
|
793
|
-
const { schemaFileType: requestedSchemaFileType = "ts" } = options;
|
|
794
|
-
const schemaFileType2 = (requestedSchemaFileType === "ts" || requestedSchemaFileType === "tsx") && "ts" || (requestedSchemaFileType === "js" || requestedSchemaFileType === "jsx") && "js";
|
|
795
|
-
if (!schemaFileType2) {
|
|
796
|
-
throw new Error(
|
|
797
|
-
`Requested schema file type '${requestedSchemaFileType}' is not valid. Supported schema file types: 'ts, js, tsx, jsx'`
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
try {
|
|
801
|
-
const define = {};
|
|
802
|
-
if (!process.env.NODE_ENV) {
|
|
803
|
-
define["process.env.NODE_ENV"] = options.dev ? '"development"' : '"production"';
|
|
804
|
-
}
|
|
805
|
-
const inputFile = getPath({
|
|
806
|
-
projectDir: tinaPath,
|
|
807
|
-
filename: fileName,
|
|
808
|
-
allowedTypes: ["js", "jsx", "tsx", "ts"],
|
|
809
|
-
errorMessage: `Must provide a ${fileName}.{js,jsx,tsx,ts}`
|
|
810
|
-
});
|
|
811
|
-
await transpile(
|
|
812
|
-
inputFile,
|
|
813
|
-
`${fileName}.cjs`,
|
|
814
|
-
tinaTempPath,
|
|
815
|
-
options.verbose,
|
|
816
|
-
define,
|
|
817
|
-
packageJSONFilePath
|
|
818
|
-
);
|
|
819
|
-
} catch (e) {
|
|
820
|
-
await cleanup({ tinaTempPath });
|
|
821
|
-
throw new BuildSchemaError(e);
|
|
822
|
-
}
|
|
823
|
-
Object.keys(require.cache).map((key) => {
|
|
824
|
-
if (key.startsWith(tinaTempPath)) {
|
|
825
|
-
delete require.cache[require.resolve(key)];
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
let returnObject = {};
|
|
829
|
-
try {
|
|
830
|
-
const schemaFunc = require(import_path2.default.join(tinaTempPath, `${fileName}.cjs`));
|
|
831
|
-
returnObject = schemaFunc.default;
|
|
832
|
-
await cleanup({ tinaTempPath });
|
|
833
|
-
} catch (e) {
|
|
834
|
-
await cleanup({ tinaTempPath });
|
|
835
|
-
if (e instanceof Error) {
|
|
836
|
-
if (e.name === "TinaSchemaValidationError") {
|
|
837
|
-
throw e;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
throw new ExecuteSchemaError(e);
|
|
841
|
-
}
|
|
842
|
-
return returnObject;
|
|
843
|
-
};
|
|
844
|
-
var compileSchema = async (options) => {
|
|
845
|
-
const root = options.rootPath;
|
|
846
|
-
const tinaPath = import_path2.default.join(root, ".tina");
|
|
847
|
-
const tinaGeneratedPath = import_path2.default.join(tinaPath, "__generated__");
|
|
848
|
-
const tinaConfigPath = import_path2.default.join(tinaGeneratedPath, "config");
|
|
849
|
-
const schemaExists = fileExists({
|
|
850
|
-
projectDir: tinaPath,
|
|
851
|
-
filename: "schema",
|
|
852
|
-
allowedTypes: ["js", "jsx", "tsx", "ts"]
|
|
853
860
|
});
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
"
|
|
862
|
-
|
|
863
|
-
}
|
|
864
|
-
let schema;
|
|
865
|
-
if (schemaExists && !configExists) {
|
|
866
|
-
console.warn(
|
|
867
|
-
`schema.{ts,tsx,js,jsx} will soon be deprecated, in favor of the new config.{ts,tsx,js,jsx}
|
|
868
|
-
See here for migration steps, see here: https://tina.io/blog/upgrading-to-iframe`
|
|
861
|
+
const alias = {
|
|
862
|
+
TINA_IMPORT: configManager.tinaConfigFilePath,
|
|
863
|
+
SCHEMA_IMPORT: configManager.generatedGraphQLJSONPath
|
|
864
|
+
};
|
|
865
|
+
if (noSDK) {
|
|
866
|
+
alias["CLIENT_IMPORT"] = import_path4.default.join(
|
|
867
|
+
configManager.spaRootPath,
|
|
868
|
+
"src",
|
|
869
|
+
"dummy-client.ts"
|
|
869
870
|
);
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
871
|
+
} else {
|
|
872
|
+
alias["CLIENT_IMPORT"] = configManager.isUsingTs() ? configManager.generatedTypesTSFilePath : configManager.generatedTypesJSFilePath;
|
|
873
|
+
}
|
|
874
|
+
const config3 = {
|
|
875
|
+
root: configManager.spaRootPath,
|
|
876
|
+
base: `/${(0, import_normalize_path2.default)(configManager.config.build.outputFolder)}/`,
|
|
877
|
+
appType: "spa",
|
|
878
|
+
resolve: {
|
|
879
|
+
alias,
|
|
880
|
+
dedupe: ["graphql", "tinacms", "@tinacms/toolkit", "react", "react-dom"]
|
|
881
|
+
},
|
|
882
|
+
define: {
|
|
883
|
+
"process.env": `new Object(${JSON.stringify(publicEnv)})`,
|
|
884
|
+
"process.platform": `"${process.platform}"`,
|
|
885
|
+
__API_URL__: `"${apiURL}"`,
|
|
886
|
+
__TOKEN__: `"${configManager.config.token}"`,
|
|
887
|
+
__TINA_GRAPHQL_VERSION__: `"${configManager.getTinaGraphQLVersion()}"`
|
|
888
|
+
},
|
|
889
|
+
optimizeDeps: {
|
|
890
|
+
force: true,
|
|
891
|
+
include: ["react/jsx-runtime", "react/jsx-dev-runtime"]
|
|
892
|
+
},
|
|
893
|
+
server: {
|
|
894
|
+
watch: noWatch ? {
|
|
895
|
+
ignored: ["**/*"]
|
|
896
|
+
} : void 0,
|
|
897
|
+
fs: {
|
|
898
|
+
strict: false
|
|
899
|
+
}
|
|
900
|
+
},
|
|
901
|
+
build: {
|
|
902
|
+
sourcemap: true,
|
|
903
|
+
outDir: configManager.outputFolderPath,
|
|
904
|
+
emptyOutDir: true,
|
|
905
|
+
rollupOptions
|
|
906
|
+
},
|
|
907
|
+
plugins: [
|
|
908
|
+
(0, import_vite.splitVendorChunkPlugin)(),
|
|
909
|
+
tinaTailwind(configManager.spaRootPath, configManager.tinaConfigFilePath),
|
|
910
|
+
...plugins
|
|
911
|
+
]
|
|
912
|
+
};
|
|
913
|
+
return config3;
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
// src/next/commands/dev-command/server/index.ts
|
|
917
|
+
var createDevServer = async (configManager, database, apiURL, noSDK, noWatch) => {
|
|
918
|
+
const plugins = [
|
|
919
|
+
{
|
|
920
|
+
name: "transform-tsx",
|
|
921
|
+
async transform(code, id) {
|
|
922
|
+
if (id.startsWith(configManager.rootPath)) {
|
|
923
|
+
const extName = import_path5.default.extname(id);
|
|
924
|
+
if (extName.startsWith(".tsx") || extName.startsWith(".ts")) {
|
|
925
|
+
const result = await (0, import_esbuild.transform)(code, { loader: "tsx" });
|
|
926
|
+
return {
|
|
927
|
+
code: result.code
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
name: "graphql-endpoints",
|
|
935
|
+
configureServer(server) {
|
|
936
|
+
server.middlewares.use((0, import_cors.default)());
|
|
937
|
+
server.middlewares.use(import_body_parser.default.json());
|
|
938
|
+
server.middlewares.use(async (req, res, next) => {
|
|
939
|
+
var _a;
|
|
940
|
+
const mediaPaths = (_a = configManager.config.media) == null ? void 0 : _a.tina;
|
|
941
|
+
const mediaRouter = createMediaRouter({
|
|
942
|
+
rootPath: configManager.rootPath,
|
|
943
|
+
apiURL,
|
|
944
|
+
publicFolder: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.publicFolder) || ""),
|
|
945
|
+
mediaRoot: parseMediaFolder((mediaPaths == null ? void 0 : mediaPaths.mediaRoot) || "")
|
|
946
|
+
});
|
|
947
|
+
if (req.url.startsWith("/media/upload")) {
|
|
948
|
+
await mediaRouter.handlePost(req, res);
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
if (req.url.startsWith("/media")) {
|
|
952
|
+
if (req.method === "DELETE") {
|
|
953
|
+
await mediaRouter.handleDelete(req, res);
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (req.url.startsWith("/media/list")) {
|
|
958
|
+
await mediaRouter.handleList(req, res);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (req.url === "/altair") {
|
|
962
|
+
res.end(
|
|
963
|
+
JSON.stringify({
|
|
964
|
+
status: "The GraphQL playground has moved to <your-dev-url>/index.html#/graphql"
|
|
965
|
+
})
|
|
966
|
+
);
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
if (req.url === "/graphql") {
|
|
970
|
+
const { query, variables } = req.body;
|
|
971
|
+
const result = await (0, import_graphql.resolve)({
|
|
972
|
+
config: {
|
|
973
|
+
useRelativeMedia: true
|
|
974
|
+
},
|
|
975
|
+
database,
|
|
976
|
+
query,
|
|
977
|
+
variables,
|
|
978
|
+
verbose: false
|
|
979
|
+
});
|
|
980
|
+
res.end(JSON.stringify(result));
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
next();
|
|
984
|
+
});
|
|
985
|
+
}
|
|
878
986
|
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
987
|
+
];
|
|
988
|
+
return (0, import_vite2.createServer)(
|
|
989
|
+
await createConfig({
|
|
990
|
+
configManager,
|
|
991
|
+
database,
|
|
992
|
+
apiURL,
|
|
993
|
+
plugins,
|
|
994
|
+
noSDK,
|
|
995
|
+
noWatch,
|
|
996
|
+
rollupOptions: {
|
|
997
|
+
input: configManager.spaMainPath
|
|
998
|
+
}
|
|
999
|
+
})
|
|
883
1000
|
);
|
|
884
|
-
return schema;
|
|
885
1001
|
};
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
logger.info(logText("Building javascript..."));
|
|
889
|
-
const packageJSON = JSON.parse(
|
|
890
|
-
import_fs_extra2.default.readFileSync(packageJSONFilePath).toString() || "{}"
|
|
891
|
-
);
|
|
892
|
-
const deps = (packageJSON == null ? void 0 : packageJSON.dependencies) || [];
|
|
893
|
-
const peerDeps = (packageJSON == null ? void 0 : packageJSON.peerDependencies) || [];
|
|
894
|
-
const devDeps = (packageJSON == null ? void 0 : packageJSON.devDependencies) || [];
|
|
895
|
-
const external = Object.keys({ ...deps, ...peerDeps, ...devDeps });
|
|
896
|
-
const prebuiltInputPath = import_path2.default.join(tempDir, "temp-output.jsx");
|
|
897
|
-
await (0, import_esbuild.build)({
|
|
898
|
-
bundle: true,
|
|
899
|
-
platform,
|
|
900
|
-
target: ["es2020"],
|
|
901
|
-
entryPoints: [inputFile],
|
|
902
|
-
treeShaking: true,
|
|
903
|
-
external: [...external, "./node_modules/*"],
|
|
904
|
-
loader: loaders,
|
|
905
|
-
outfile: prebuiltInputPath,
|
|
906
|
-
define
|
|
907
|
-
});
|
|
908
|
-
const tempTsConfigPath = import_path2.default.join(tempDir, "temp-tsconfig.json");
|
|
909
|
-
await import_fs_extra2.default.outputFileSync(tempTsConfigPath, "{}");
|
|
910
|
-
const outputPath = import_path2.default.join(tempDir, outputFile);
|
|
911
|
-
await (0, import_esbuild.build)({
|
|
912
|
-
bundle: true,
|
|
913
|
-
platform,
|
|
914
|
-
target: ["node10.4"],
|
|
915
|
-
entryPoints: [prebuiltInputPath],
|
|
916
|
-
format: "cjs",
|
|
917
|
-
treeShaking: true,
|
|
918
|
-
external: [...external, "./node_modules/*"],
|
|
919
|
-
tsconfig: tempTsConfigPath,
|
|
920
|
-
loader: loaders,
|
|
921
|
-
outfile: outputPath,
|
|
922
|
-
define
|
|
923
|
-
});
|
|
924
|
-
if (verbose)
|
|
925
|
-
logger.info(logText(`Javascript built`));
|
|
926
|
-
};
|
|
927
|
-
var defineSchema = (config2) => {
|
|
928
|
-
return config2;
|
|
929
|
-
};
|
|
930
|
-
var loaders = {
|
|
931
|
-
".aac": "file",
|
|
932
|
-
".css": "file",
|
|
933
|
-
".eot": "file",
|
|
934
|
-
".flac": "file",
|
|
935
|
-
".gif": "file",
|
|
936
|
-
".jpeg": "file",
|
|
937
|
-
".jpg": "file",
|
|
938
|
-
".json": "json",
|
|
939
|
-
".mp3": "file",
|
|
940
|
-
".mp4": "file",
|
|
941
|
-
".ogg": "file",
|
|
942
|
-
".otf": "file",
|
|
943
|
-
".png": "file",
|
|
944
|
-
".svg": "file",
|
|
945
|
-
".ttf": "file",
|
|
946
|
-
".wav": "file",
|
|
947
|
-
".webm": "file",
|
|
948
|
-
".webp": "file",
|
|
949
|
-
".woff": "file",
|
|
950
|
-
".woff2": "file",
|
|
951
|
-
".js": "jsx",
|
|
952
|
-
".jsx": "jsx",
|
|
953
|
-
".tsx": "tsx"
|
|
954
|
-
};
|
|
955
|
-
|
|
956
|
-
// src/cmds/query-gen/genTypes.ts
|
|
957
|
-
var import_graphql8 = require("graphql");
|
|
1002
|
+
|
|
1003
|
+
// src/next/codegen/index.ts
|
|
958
1004
|
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
959
|
-
var
|
|
1005
|
+
var import_graphql6 = require("graphql");
|
|
960
1006
|
|
|
961
|
-
// src/codegen/index.ts
|
|
962
|
-
var
|
|
1007
|
+
// src/next/codegen/codegen/index.ts
|
|
1008
|
+
var import_graphql5 = require("graphql");
|
|
963
1009
|
|
|
964
|
-
// src/codegen/plugin.ts
|
|
965
|
-
var AddGeneratedClientFunc = (
|
|
966
|
-
return
|
|
1010
|
+
// src/next/codegen/codegen/plugin.ts
|
|
1011
|
+
var AddGeneratedClientFunc = (apiURL) => {
|
|
1012
|
+
return (_schema, _documents, _config, _info) => {
|
|
1013
|
+
return `
|
|
967
1014
|
// TinaSDK generated code
|
|
968
1015
|
import { createClient, TinaClient } from "tinacms/dist/client";
|
|
969
1016
|
|
|
@@ -990,7 +1037,7 @@ const generateRequester = (client: TinaClient) => {
|
|
|
990
1037
|
**/
|
|
991
1038
|
export const ExperimentalGetTinaClient = () =>
|
|
992
1039
|
getSdk(
|
|
993
|
-
generateRequester(createClient({ url: "
|
|
1040
|
+
generateRequester(createClient({ url: "${apiURL}", queries }))
|
|
994
1041
|
);
|
|
995
1042
|
|
|
996
1043
|
export const queries = (client: TinaClient) => {
|
|
@@ -998,26 +1045,27 @@ export const queries = (client: TinaClient) => {
|
|
|
998
1045
|
return getSdk(requester);
|
|
999
1046
|
};
|
|
1000
1047
|
`;
|
|
1048
|
+
};
|
|
1001
1049
|
};
|
|
1002
|
-
var AddGeneratedClient = {
|
|
1003
|
-
plugin: AddGeneratedClientFunc
|
|
1004
|
-
};
|
|
1050
|
+
var AddGeneratedClient = (apiURL) => ({
|
|
1051
|
+
plugin: AddGeneratedClientFunc(apiURL)
|
|
1052
|
+
});
|
|
1005
1053
|
|
|
1006
|
-
// src/codegen/index.ts
|
|
1054
|
+
// src/next/codegen/codegen/index.ts
|
|
1007
1055
|
var import_graphql_file_loader = require("@graphql-tools/graphql-file-loader");
|
|
1008
1056
|
var import_core = require("@graphql-codegen/core");
|
|
1009
1057
|
var import_load = require("@graphql-tools/load");
|
|
1010
1058
|
var import_typescript_operations = require("@graphql-codegen/typescript-operations");
|
|
1011
1059
|
var import_typescript = require("@graphql-codegen/typescript");
|
|
1012
1060
|
|
|
1013
|
-
// src/codegen/sdkPlugin/index.ts
|
|
1014
|
-
var
|
|
1015
|
-
var
|
|
1061
|
+
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
1062
|
+
var import_graphql3 = require("graphql");
|
|
1063
|
+
var import_graphql4 = require("graphql");
|
|
1016
1064
|
|
|
1017
|
-
// src/codegen/sdkPlugin/visitor.ts
|
|
1065
|
+
// src/next/codegen/codegen/sdkPlugin/visitor.ts
|
|
1018
1066
|
var import_visitor_plugin_common = require("@graphql-codegen/visitor-plugin-common");
|
|
1019
1067
|
var import_auto_bind = __toESM(require("auto-bind"));
|
|
1020
|
-
var
|
|
1068
|
+
var import_graphql2 = require("graphql");
|
|
1021
1069
|
var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBaseVisitor {
|
|
1022
1070
|
constructor(schema, fragments, rawConfig) {
|
|
1023
1071
|
super(schema, fragments, rawConfig, {
|
|
@@ -1034,7 +1082,7 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
1034
1082
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
1035
1083
|
if (node.name == null) {
|
|
1036
1084
|
throw new Error(
|
|
1037
|
-
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + (0,
|
|
1085
|
+
"Plugin 'generic-sdk' cannot generate SDK for unnamed operation.\n\n" + (0, import_graphql2.print)(node)
|
|
1038
1086
|
);
|
|
1039
1087
|
} else {
|
|
1040
1088
|
this._operationsToInclude.push({
|
|
@@ -1051,13 +1099,13 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
1051
1099
|
const usingObservable = !!this.config.usingObservableFrom;
|
|
1052
1100
|
const allPossibleActions = this._operationsToInclude.map((o) => {
|
|
1053
1101
|
const optionalVariables = !o.node.variableDefinitions || o.node.variableDefinitions.length === 0 || o.node.variableDefinitions.every(
|
|
1054
|
-
(v) => v.type.kind !==
|
|
1102
|
+
(v) => v.type.kind !== import_graphql2.Kind.NON_NULL_TYPE || v.defaultValue
|
|
1055
1103
|
);
|
|
1056
1104
|
const returnType = usingObservable && o.operationType === "Subscription" ? "Observable" : "Promise";
|
|
1057
1105
|
return `${o.node.name.value}(variables${optionalVariables ? "?" : ""}: ${o.operationVariablesTypes}, options?: C): ${returnType}<${o.operationResultType}> {
|
|
1058
1106
|
return requester<${o.operationResultType}, ${o.operationVariablesTypes}>(${o.documentVariableName}, variables, options);
|
|
1059
1107
|
}`;
|
|
1060
|
-
}).map((
|
|
1108
|
+
}).map((s2) => (0, import_visitor_plugin_common.indentMultiline)(s2, 2));
|
|
1061
1109
|
return `export type Requester<C= {}> = <R, V>(doc: ${this.config.documentMode === import_visitor_plugin_common.DocumentMode.string ? "string" : "DocumentNode"}, vars?: V, options?: C) => ${usingObservable ? "Promise<R> & Observable<R>" : "Promise<R>"}
|
|
1062
1110
|
export function getSdk<C>(requester: Requester<C>) {
|
|
1063
1111
|
return {
|
|
@@ -1068,26 +1116,26 @@ var GenericSdkVisitor = class extends import_visitor_plugin_common.ClientSideBas
|
|
|
1068
1116
|
}
|
|
1069
1117
|
};
|
|
1070
1118
|
|
|
1071
|
-
// src/codegen/sdkPlugin/index.ts
|
|
1072
|
-
var plugin = (schema, documents,
|
|
1073
|
-
const allAst = (0,
|
|
1119
|
+
// src/next/codegen/codegen/sdkPlugin/index.ts
|
|
1120
|
+
var plugin = (schema, documents, config3) => {
|
|
1121
|
+
const allAst = (0, import_graphql4.concatAST)(
|
|
1074
1122
|
documents.reduce((prev, v) => {
|
|
1075
1123
|
return [...prev, v.document];
|
|
1076
1124
|
}, [])
|
|
1077
1125
|
);
|
|
1078
1126
|
const allFragments = [
|
|
1079
1127
|
...allAst.definitions.filter(
|
|
1080
|
-
(d) => d.kind ===
|
|
1128
|
+
(d) => d.kind === import_graphql4.Kind.FRAGMENT_DEFINITION
|
|
1081
1129
|
).map((fragmentDef) => ({
|
|
1082
1130
|
node: fragmentDef,
|
|
1083
1131
|
name: fragmentDef.name.value,
|
|
1084
1132
|
onType: fragmentDef.typeCondition.name.value,
|
|
1085
1133
|
isExternal: false
|
|
1086
1134
|
})),
|
|
1087
|
-
...
|
|
1135
|
+
...config3.externalFragments || []
|
|
1088
1136
|
];
|
|
1089
|
-
const visitor = new GenericSdkVisitor(schema, allFragments,
|
|
1090
|
-
const visitorResult = (0,
|
|
1137
|
+
const visitor = new GenericSdkVisitor(schema, allFragments, config3);
|
|
1138
|
+
const visitorResult = (0, import_graphql3.visit)(allAst, { leave: visitor });
|
|
1091
1139
|
return {
|
|
1092
1140
|
content: [
|
|
1093
1141
|
visitor.fragments,
|
|
@@ -1097,22 +1145,15 @@ var plugin = (schema, documents, config2) => {
|
|
|
1097
1145
|
};
|
|
1098
1146
|
};
|
|
1099
1147
|
|
|
1100
|
-
// src/codegen/index.ts
|
|
1101
|
-
var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(),
|
|
1102
|
-
noSDK: false,
|
|
1103
|
-
verbose: false
|
|
1104
|
-
}) => {
|
|
1105
|
-
if (options.verbose)
|
|
1106
|
-
logger.info("Generating types...");
|
|
1148
|
+
// src/next/codegen/codegen/index.ts
|
|
1149
|
+
var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath = process.cwd(), apiURL) => {
|
|
1107
1150
|
let docs = [];
|
|
1108
1151
|
let fragDocs = [];
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
fragDocs = await loadGraphQLDocuments(fragDocPath);
|
|
1112
|
-
}
|
|
1152
|
+
docs = await loadGraphQLDocuments(queryPathGlob);
|
|
1153
|
+
fragDocs = await loadGraphQLDocuments(fragDocPath);
|
|
1113
1154
|
const res = await (0, import_core.codegen)({
|
|
1114
1155
|
filename: process.cwd(),
|
|
1115
|
-
schema: (0,
|
|
1156
|
+
schema: (0, import_graphql5.parse)((0, import_graphql5.printSchema)(schema)),
|
|
1116
1157
|
documents: [...docs, ...fragDocs],
|
|
1117
1158
|
config: {},
|
|
1118
1159
|
plugins: [
|
|
@@ -1133,7 +1174,7 @@ var generateTypes = async (schema, queryPathGlob = process.cwd(), fragDocPath =
|
|
|
1133
1174
|
typescriptSdk: {
|
|
1134
1175
|
plugin
|
|
1135
1176
|
},
|
|
1136
|
-
AddGeneratedClient
|
|
1177
|
+
AddGeneratedClient: AddGeneratedClient(apiURL)
|
|
1137
1178
|
}
|
|
1138
1179
|
});
|
|
1139
1180
|
return res;
|
|
@@ -1155,66 +1196,132 @@ var loadGraphQLDocuments = async (globPath) => {
|
|
|
1155
1196
|
return result;
|
|
1156
1197
|
};
|
|
1157
1198
|
|
|
1158
|
-
// src/
|
|
1199
|
+
// src/next/codegen/index.ts
|
|
1159
1200
|
var import_esbuild2 = require("esbuild");
|
|
1160
1201
|
var TINA_HOST = "content.tinajs.io";
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1202
|
+
var Codegen = class {
|
|
1203
|
+
constructor({
|
|
1204
|
+
configManager,
|
|
1205
|
+
port,
|
|
1206
|
+
schema,
|
|
1207
|
+
noSDK,
|
|
1208
|
+
queryDoc,
|
|
1209
|
+
fragDoc
|
|
1210
|
+
}) {
|
|
1211
|
+
this.configManager = configManager;
|
|
1212
|
+
this.port = port;
|
|
1213
|
+
this.schema = schema;
|
|
1214
|
+
this.noSDK = noSDK;
|
|
1215
|
+
this.queryDoc = queryDoc;
|
|
1216
|
+
this.fragDoc = fragDoc;
|
|
1217
|
+
}
|
|
1218
|
+
async removeGeneratedFilesIfExists() {
|
|
1219
|
+
await unlinkIfExists(this.configManager.generatedClientJSFilePath);
|
|
1220
|
+
await unlinkIfExists(this.configManager.generatedTypesDFilePath);
|
|
1221
|
+
await unlinkIfExists(this.configManager.generatedTypesJSFilePath);
|
|
1222
|
+
await unlinkIfExists(this.configManager.generatedTypesTSFilePath);
|
|
1223
|
+
await unlinkIfExists(this.configManager.generatedClientTSFilePath);
|
|
1224
|
+
await unlinkIfExists(this.configManager.generatedQueriesFilePath);
|
|
1225
|
+
await unlinkIfExists(this.configManager.generatedFragmentsFilePath);
|
|
1226
|
+
}
|
|
1227
|
+
async execute() {
|
|
1228
|
+
const apiURL = this.getApiURL();
|
|
1229
|
+
if (this.noSDK) {
|
|
1230
|
+
await this.removeGeneratedFilesIfExists();
|
|
1231
|
+
return apiURL;
|
|
1232
|
+
}
|
|
1233
|
+
await import_fs_extra3.default.outputFile(
|
|
1234
|
+
this.configManager.generatedQueriesFilePath,
|
|
1235
|
+
this.queryDoc
|
|
1184
1236
|
);
|
|
1237
|
+
await import_fs_extra3.default.outputFile(
|
|
1238
|
+
this.configManager.generatedFragmentsFilePath,
|
|
1239
|
+
this.fragDoc
|
|
1240
|
+
);
|
|
1241
|
+
await maybeWarnFragmentSize(this.configManager.generatedFragmentsFilePath);
|
|
1242
|
+
const { clientString } = await this.genClient();
|
|
1243
|
+
const { codeString, schemaString } = await this.genTypes();
|
|
1244
|
+
await import_fs_extra3.default.outputFile(
|
|
1245
|
+
this.configManager.generatedGraphQLGQLPath,
|
|
1246
|
+
schemaString
|
|
1247
|
+
);
|
|
1248
|
+
if (this.configManager.isUsingTs()) {
|
|
1249
|
+
await import_fs_extra3.default.outputFile(
|
|
1250
|
+
this.configManager.generatedTypesTSFilePath,
|
|
1251
|
+
codeString
|
|
1252
|
+
);
|
|
1253
|
+
await import_fs_extra3.default.outputFile(
|
|
1254
|
+
this.configManager.generatedClientTSFilePath,
|
|
1255
|
+
clientString
|
|
1256
|
+
);
|
|
1257
|
+
await unlinkIfExists(this.configManager.generatedClientJSFilePath);
|
|
1258
|
+
await unlinkIfExists(this.configManager.generatedTypesDFilePath);
|
|
1259
|
+
await unlinkIfExists(this.configManager.generatedTypesJSFilePath);
|
|
1260
|
+
} else {
|
|
1261
|
+
await import_fs_extra3.default.outputFile(
|
|
1262
|
+
this.configManager.generatedTypesDFilePath,
|
|
1263
|
+
codeString
|
|
1264
|
+
);
|
|
1265
|
+
const jsCode = await (0, import_esbuild2.transform)(codeString, { loader: "ts" });
|
|
1266
|
+
await import_fs_extra3.default.outputFile(
|
|
1267
|
+
this.configManager.generatedTypesJSFilePath,
|
|
1268
|
+
jsCode.code
|
|
1269
|
+
);
|
|
1270
|
+
await import_fs_extra3.default.outputFile(
|
|
1271
|
+
this.configManager.generatedClientJSFilePath,
|
|
1272
|
+
clientString
|
|
1273
|
+
);
|
|
1274
|
+
await unlinkIfExists(this.configManager.generatedTypesTSFilePath);
|
|
1275
|
+
await unlinkIfExists(this.configManager.generatedClientTSFilePath);
|
|
1276
|
+
}
|
|
1277
|
+
return apiURL;
|
|
1185
1278
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1279
|
+
getApiURL() {
|
|
1280
|
+
var _a, _b, _c, _d;
|
|
1281
|
+
const branch = (_a = this.configManager.config) == null ? void 0 : _a.branch;
|
|
1282
|
+
const clientId = (_b = this.configManager.config) == null ? void 0 : _b.clientId;
|
|
1283
|
+
const token = (_c = this.configManager.config) == null ? void 0 : _c.token;
|
|
1284
|
+
const version2 = this.configManager.getTinaGraphQLVersion();
|
|
1285
|
+
const baseUrl = ((_d = this.configManager.config.tinaioConfig) == null ? void 0 : _d.contentApiUrlOverride) || `https://${TINA_HOST}`;
|
|
1286
|
+
if ((!branch || !clientId || !token) && !this.port && !this.configManager.config.contentApiUrlOverride) {
|
|
1287
|
+
const missing = [];
|
|
1288
|
+
if (!branch)
|
|
1289
|
+
missing.push("branch");
|
|
1290
|
+
if (!clientId)
|
|
1291
|
+
missing.push("clientId");
|
|
1292
|
+
if (!token)
|
|
1293
|
+
missing.push("token");
|
|
1294
|
+
throw new Error(
|
|
1295
|
+
`Client not configured properly. Missing ${missing.join(
|
|
1296
|
+
", "
|
|
1297
|
+
)}. Please visit https://tina.io/docs/tina-cloud/connecting-site/ for more information`
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
let apiURL = this.port ? `http://localhost:${this.port}/graphql` : `${baseUrl}/${version2}/content/${clientId}/github/${branch}`;
|
|
1301
|
+
if (this.configManager.config.contentApiUrlOverride) {
|
|
1302
|
+
apiURL = this.configManager.config.contentApiUrlOverride;
|
|
1303
|
+
}
|
|
1304
|
+
return apiURL;
|
|
1189
1305
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1306
|
+
async genClient() {
|
|
1307
|
+
var _a;
|
|
1308
|
+
const token = (_a = this.configManager.config) == null ? void 0 : _a.token;
|
|
1309
|
+
const apiURL = this.getApiURL();
|
|
1310
|
+
const clientString = `import { createClient } from "tinacms/dist/client";
|
|
1194
1311
|
import { queries } from "./types";
|
|
1195
1312
|
export const client = createClient({ url: '${apiURL}', token: '${token}', queries });
|
|
1196
1313
|
export default client;
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
const typesDPath = rootPath2 + "/.tina/__generated__/types.d.ts";
|
|
1209
|
-
const fragPath = rootPath2 + "/.tina/__generated__/*.{graphql,gql}";
|
|
1210
|
-
const queryPathGlob = rootPath2 + "/.tina/queries/**/*.{graphql,gql}";
|
|
1211
|
-
const typescriptTypes = await generateTypes(
|
|
1212
|
-
schema,
|
|
1213
|
-
queryPathGlob,
|
|
1214
|
-
fragPath,
|
|
1215
|
-
options
|
|
1216
|
-
);
|
|
1217
|
-
const code = `//@ts-nocheck
|
|
1314
|
+
`;
|
|
1315
|
+
return { apiURL, clientString };
|
|
1316
|
+
}
|
|
1317
|
+
async genTypes() {
|
|
1318
|
+
const typescriptTypes = await generateTypes(
|
|
1319
|
+
this.schema,
|
|
1320
|
+
this.configManager.userQueriesAndFragmentsGlob,
|
|
1321
|
+
this.configManager.generatedQueriesAndFragmentsGlob,
|
|
1322
|
+
this.getApiURL()
|
|
1323
|
+
);
|
|
1324
|
+
const codeString = `//@ts-nocheck
|
|
1218
1325
|
// DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
1219
1326
|
export function gql(strings: TemplateStringsArray, ...args: string[]): string {
|
|
1220
1327
|
let str = ''
|
|
@@ -1225,31 +1332,141 @@ async function genTypes({
|
|
|
1225
1332
|
}
|
|
1226
1333
|
${typescriptTypes}
|
|
1227
1334
|
`;
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
} else {
|
|
1231
|
-
await import_fs_extra3.default.outputFile(typesDPath, code);
|
|
1232
|
-
const jsCode = await (0, import_esbuild2.transform)(code, { loader: "ts" });
|
|
1233
|
-
await import_fs_extra3.default.outputFile(typesJSPath, jsCode.code);
|
|
1234
|
-
}
|
|
1235
|
-
const schemaString = await (0, import_graphql8.printSchema)(schema);
|
|
1236
|
-
const schemaPath = rootPath2 + "/.tina/__generated__/schema.gql";
|
|
1237
|
-
await import_fs_extra3.default.outputFile(
|
|
1238
|
-
schemaPath,
|
|
1239
|
-
`# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
1240
|
-
${schemaString}
|
|
1335
|
+
const schemaString = `# DO NOT MODIFY THIS FILE. This file is automatically generated by Tina
|
|
1336
|
+
${await (0, import_graphql6.printSchema)(this.schema)}
|
|
1241
1337
|
schema {
|
|
1242
1338
|
query: Query
|
|
1243
1339
|
mutation: Mutation
|
|
1244
1340
|
}
|
|
1245
|
-
|
|
1341
|
+
`;
|
|
1342
|
+
return { codeString, schemaString };
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
var maybeWarnFragmentSize = async (filepath) => {
|
|
1346
|
+
if (await (await import_fs_extra3.default.stat(filepath)).size > 100 * 1024) {
|
|
1347
|
+
console.warn(
|
|
1348
|
+
"Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below."
|
|
1349
|
+
);
|
|
1350
|
+
console.log(
|
|
1351
|
+
`const schema = defineSchema({
|
|
1352
|
+
config: {
|
|
1353
|
+
client: {
|
|
1354
|
+
referenceDepth: 1,
|
|
1355
|
+
},
|
|
1356
|
+
}
|
|
1357
|
+
// ...
|
|
1358
|
+
})`
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
var unlinkIfExists = async (filepath) => {
|
|
1363
|
+
if (await import_fs_extra3.default.existsSync(filepath)) {
|
|
1364
|
+
await import_fs_extra3.default.unlinkSync(filepath);
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
// src/next/commands/dev-command/index.ts
|
|
1369
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
1370
|
+
|
|
1371
|
+
// src/utils/start-subprocess.ts
|
|
1372
|
+
var import_child_process = __toESM(require("child_process"));
|
|
1373
|
+
|
|
1374
|
+
// src/utils/theme.ts
|
|
1375
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
1376
|
+
var successText = import_chalk2.default.bold.green;
|
|
1377
|
+
var focusText = import_chalk2.default.bold;
|
|
1378
|
+
var dangerText = import_chalk2.default.bold.red;
|
|
1379
|
+
var neutralText = import_chalk2.default.bold.cyan;
|
|
1380
|
+
var linkText = import_chalk2.default.bold.cyan;
|
|
1381
|
+
var labelText = import_chalk2.default.bold;
|
|
1382
|
+
var cmdText = import_chalk2.default.inverse;
|
|
1383
|
+
var indentedCmd = (str) => {
|
|
1384
|
+
return ` \u2503 ` + str;
|
|
1385
|
+
};
|
|
1386
|
+
var logText = import_chalk2.default.italic.gray;
|
|
1387
|
+
var warnText = import_chalk2.default.yellowBright.bgBlack;
|
|
1388
|
+
var titleText = import_chalk2.default.bgHex("d2f1f8").hex("ec4816");
|
|
1389
|
+
var CONFIRMATION_TEXT = import_chalk2.default.dim("enter to confirm");
|
|
1390
|
+
|
|
1391
|
+
// src/utils/start-subprocess.ts
|
|
1392
|
+
var startSubprocess2 = async ({ command }) => {
|
|
1393
|
+
if (typeof command === "string") {
|
|
1394
|
+
const commands = command.split(" ");
|
|
1395
|
+
const firstCommand = commands[0];
|
|
1396
|
+
const args = commands.slice(1) || [];
|
|
1397
|
+
const ps = import_child_process.default.spawn(firstCommand, args, {
|
|
1398
|
+
stdio: "inherit",
|
|
1399
|
+
shell: true
|
|
1400
|
+
});
|
|
1401
|
+
ps.on("error", (code) => {
|
|
1402
|
+
logger.error(
|
|
1403
|
+
dangerText(
|
|
1404
|
+
`An error has occurred in the Next.js child process. Error message below`
|
|
1405
|
+
)
|
|
1406
|
+
);
|
|
1407
|
+
logger.error(`name: ${code.name}
|
|
1408
|
+
message: ${code.message}
|
|
1409
|
+
|
|
1410
|
+
stack: ${code.stack || "No stack was provided"}`);
|
|
1411
|
+
});
|
|
1412
|
+
ps.on("close", (code) => {
|
|
1413
|
+
logger.info(`child process exited with code ${code}`);
|
|
1414
|
+
process.exit(code);
|
|
1415
|
+
});
|
|
1416
|
+
return ps;
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
|
|
1420
|
+
// src/next/database.ts
|
|
1421
|
+
var import_graphql7 = require("@tinacms/graphql");
|
|
1422
|
+
var import_readable_stream = require("readable-stream");
|
|
1423
|
+
var import_net = require("net");
|
|
1424
|
+
var import_many_level = require("many-level");
|
|
1425
|
+
var import_memory_level = require("memory-level");
|
|
1426
|
+
var createDBServer = (port) => {
|
|
1427
|
+
const levelHost = new import_many_level.ManyLevelHost(
|
|
1428
|
+
new import_memory_level.MemoryLevel({
|
|
1429
|
+
valueEncoding: "json"
|
|
1430
|
+
})
|
|
1246
1431
|
);
|
|
1247
|
-
|
|
1432
|
+
const dbServer = (0, import_net.createServer)(function(socket) {
|
|
1433
|
+
return (0, import_readable_stream.pipeline)(socket, levelHost.createRpcStream(), socket, () => {
|
|
1434
|
+
});
|
|
1435
|
+
});
|
|
1436
|
+
dbServer.once("error", (err) => {
|
|
1437
|
+
if ((err == null ? void 0 : err.code) === "EADDRINUSE") {
|
|
1438
|
+
throw new Error(
|
|
1439
|
+
`Tina Dev server is already in use. Datalayer server is busy on port ${port}`
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
dbServer.listen(port);
|
|
1444
|
+
};
|
|
1445
|
+
async function createAndInitializeDatabase(configManager, bridgeOverride) {
|
|
1446
|
+
let database;
|
|
1447
|
+
const bridge = bridgeOverride || new import_graphql7.FilesystemBridge(configManager.rootPath, configManager.contentRootPath);
|
|
1448
|
+
if (configManager.hasSelfHostedConfig() && configManager.config.contentApiUrlOverride) {
|
|
1449
|
+
database = await configManager.loadDatabaseFile();
|
|
1450
|
+
database.bridge = bridge;
|
|
1451
|
+
} else {
|
|
1452
|
+
if (configManager.hasSelfHostedConfig() && !configManager.config.contentApiUrlOverride) {
|
|
1453
|
+
logger.warn(
|
|
1454
|
+
`Found a database config file at ${configManager.printRelativePath(
|
|
1455
|
+
configManager.selfHostedDatabaseFilePath
|
|
1456
|
+
)} but there was no "contentApiUrlOverride" set. Falling back to built-in datalayer`
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
const level = new import_graphql7.TinaLevelClient();
|
|
1460
|
+
level.openConnection();
|
|
1461
|
+
database = (0, import_graphql7.createDatabase)({
|
|
1462
|
+
bridge,
|
|
1463
|
+
level,
|
|
1464
|
+
tinaDirectory: configManager.isUsingLegacyFolder ? LEGACY_TINA_FOLDER : TINA_FOLDER
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
return database;
|
|
1248
1468
|
}
|
|
1249
1469
|
|
|
1250
|
-
// src/buildTina/index.ts
|
|
1251
|
-
var import_app = require("@tinacms/app");
|
|
1252
|
-
|
|
1253
1470
|
// src/utils/spinner.ts
|
|
1254
1471
|
var import_cli_spinner = require("cli-spinner");
|
|
1255
1472
|
async function localSpin({
|
|
@@ -1286,423 +1503,346 @@ function spin({
|
|
|
1286
1503
|
}
|
|
1287
1504
|
}
|
|
1288
1505
|
|
|
1289
|
-
// src/
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
const database = await (0, import_graphql9.createDatabase)({
|
|
1326
|
-
level: new import_memory_level.MemoryLevel({
|
|
1327
|
-
valueEncoding: "json"
|
|
1328
|
-
}),
|
|
1329
|
-
bridge
|
|
1330
|
-
});
|
|
1331
|
-
ctx.bridge = bridge;
|
|
1332
|
-
ctx.database = database;
|
|
1333
|
-
ctx.builder = new ConfigBuilder(ctx.database);
|
|
1334
|
-
next();
|
|
1335
|
-
};
|
|
1336
|
-
var buildSetup = async ({ rootPath: rootPath2 }) => {
|
|
1337
|
-
await import_fs_extra5.default.ensureDirSync(import_path5.default.join(rootPath2, ".tina", "__generated__"));
|
|
1338
|
-
};
|
|
1339
|
-
var buildCmdBuild = async (ctx, next, options) => {
|
|
1340
|
-
const { schema, graphQLSchema, tinaSchema } = await ctx.builder.build({
|
|
1341
|
-
rootPath: ctx.rootPath,
|
|
1342
|
-
...options
|
|
1343
|
-
});
|
|
1344
|
-
ctx.schema = schema;
|
|
1345
|
-
ctx.graphQLSchema = graphQLSchema;
|
|
1346
|
-
ctx.tinaSchema = tinaSchema;
|
|
1347
|
-
const apiUrl = await ctx.builder.genTypedClient({
|
|
1348
|
-
compiledSchema: schema,
|
|
1349
|
-
local: options.local,
|
|
1350
|
-
noSDK: options.noSDK,
|
|
1351
|
-
verbose: options.verbose,
|
|
1352
|
-
usingTs: ctx.usingTs,
|
|
1353
|
-
rootPath: ctx.rootPath,
|
|
1354
|
-
port: options.port
|
|
1355
|
-
});
|
|
1356
|
-
ctx.apiUrl = apiUrl;
|
|
1357
|
-
await buildAdmin({
|
|
1358
|
-
local: options.local,
|
|
1359
|
-
rootPath: ctx.rootPath,
|
|
1360
|
-
schema,
|
|
1361
|
-
apiUrl
|
|
1362
|
-
});
|
|
1363
|
-
next();
|
|
1364
|
-
};
|
|
1365
|
-
var auditCmdBuild = async (ctx, next, options) => {
|
|
1366
|
-
const { graphQLSchema, tinaSchema } = await ctx.builder.build({
|
|
1367
|
-
rootPath: ctx.rootPath,
|
|
1368
|
-
...options,
|
|
1369
|
-
verbose: true
|
|
1370
|
-
});
|
|
1371
|
-
await spin({
|
|
1372
|
-
waitFor: async () => {
|
|
1373
|
-
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
1374
|
-
},
|
|
1375
|
-
text: "Indexing local files"
|
|
1376
|
-
});
|
|
1377
|
-
next();
|
|
1378
|
-
};
|
|
1379
|
-
var indexIntoSelfHostedDatabase = async (ctx, next) => {
|
|
1380
|
-
if (!ctx.isSelfHostedDatabase) {
|
|
1381
|
-
return next();
|
|
1382
|
-
}
|
|
1383
|
-
const { graphQLSchema, tinaSchema } = ctx;
|
|
1384
|
-
await spin({
|
|
1385
|
-
waitFor: async () => {
|
|
1386
|
-
await ctx.database.indexContent({ graphQLSchema, tinaSchema });
|
|
1387
|
-
},
|
|
1388
|
-
text: "Indexing to self-hosted database"
|
|
1389
|
-
});
|
|
1390
|
-
next();
|
|
1391
|
-
};
|
|
1392
|
-
var ConfigBuilder = class {
|
|
1393
|
-
constructor(database) {
|
|
1394
|
-
this.database = database;
|
|
1395
|
-
}
|
|
1396
|
-
async build({ dev, verbose, rootPath: rootPath2, local }) {
|
|
1397
|
-
var _a, _b, _c;
|
|
1398
|
-
const usingTs = await isProjectTs(rootPath2);
|
|
1399
|
-
if (!rootPath2) {
|
|
1400
|
-
throw new Error("Root path has not been attached");
|
|
1401
|
-
}
|
|
1402
|
-
const tinaGeneratedPath = import_path5.default.join(rootPath2, ".tina", "__generated__");
|
|
1403
|
-
this.database.clearCache();
|
|
1404
|
-
await import_fs_extra5.default.mkdirp(tinaGeneratedPath);
|
|
1405
|
-
await resetGeneratedFolder({
|
|
1406
|
-
tinaGeneratedPath,
|
|
1407
|
-
usingTs,
|
|
1408
|
-
isBuild: !local
|
|
1409
|
-
});
|
|
1410
|
-
const compiledSchema = await compileSchema({
|
|
1411
|
-
verbose,
|
|
1412
|
-
dev,
|
|
1413
|
-
rootPath: rootPath2
|
|
1414
|
-
});
|
|
1415
|
-
if (this.database.bridge.addOutputPath && ((_a = compiledSchema.config) == null ? void 0 : _a.localContentPath)) {
|
|
1416
|
-
if ((_c = (_b = compiledSchema == null ? void 0 : compiledSchema.config) == null ? void 0 : _b.media) == null ? void 0 : _c.tina) {
|
|
1417
|
-
throw new Error(
|
|
1418
|
-
`"media.tina" is not supported when the "localContentPath" property is present.`
|
|
1419
|
-
);
|
|
1420
|
-
}
|
|
1421
|
-
let localContentPath = compiledSchema.config.localContentPath;
|
|
1422
|
-
if (!localContentPath.startsWith("/")) {
|
|
1423
|
-
localContentPath = import_path5.default.join(process.cwd(), ".tina", localContentPath);
|
|
1424
|
-
}
|
|
1425
|
-
if (await import_fs_extra5.default.pathExists(localContentPath)) {
|
|
1426
|
-
logger.info(logText(`Using separate content path ${localContentPath}`));
|
|
1427
|
-
} else {
|
|
1428
|
-
logger.warn(
|
|
1429
|
-
warnText(
|
|
1430
|
-
`Using separate content path ${localContentPath}
|
|
1431
|
-
but no directory was found at that location, creating one...`
|
|
1432
|
-
)
|
|
1433
|
-
);
|
|
1434
|
-
await import_fs_extra5.default.mkdir(localContentPath);
|
|
1435
|
-
}
|
|
1436
|
-
this.database.bridge.addOutputPath(localContentPath);
|
|
1437
|
-
}
|
|
1438
|
-
const { graphQLSchema, tinaSchema } = await (0, import_graphql9.buildSchema)(
|
|
1439
|
-
rootPath2,
|
|
1440
|
-
this.database,
|
|
1441
|
-
["experimentalData", "isomorphicGitBridge"]
|
|
1442
|
-
);
|
|
1443
|
-
return { schema: compiledSchema, graphQLSchema, tinaSchema };
|
|
1444
|
-
}
|
|
1445
|
-
async genTypedClient({
|
|
1446
|
-
usingTs,
|
|
1447
|
-
compiledSchema,
|
|
1448
|
-
noSDK,
|
|
1449
|
-
verbose,
|
|
1450
|
-
local,
|
|
1451
|
-
port,
|
|
1452
|
-
rootPath: rootPath2
|
|
1453
|
-
}) {
|
|
1454
|
-
const astSchema = await (0, import_graphql9.getASTSchema)(this.database);
|
|
1455
|
-
await genTypes({ schema: astSchema, usingTs, rootPath: rootPath2 }, () => {
|
|
1456
|
-
}, {
|
|
1457
|
-
noSDK,
|
|
1458
|
-
verbose
|
|
1506
|
+
// src/next/commands/dev-command/index.ts
|
|
1507
|
+
var DevCommand = class extends import_clipanion.Command {
|
|
1508
|
+
constructor() {
|
|
1509
|
+
super(...arguments);
|
|
1510
|
+
this.port = import_clipanion.Option.String("-p,--port", "4001", {
|
|
1511
|
+
description: "Specify a port to run the server on. (default 4001)"
|
|
1512
|
+
});
|
|
1513
|
+
this.datalayerPort = import_clipanion.Option.String("--datalayer-port", "9000", {
|
|
1514
|
+
description: "Specify a port to run the datalayer server on. (default 4001)"
|
|
1515
|
+
});
|
|
1516
|
+
this.subCommand = import_clipanion.Option.String("-c,--command", {
|
|
1517
|
+
description: "The sub-command to run"
|
|
1518
|
+
});
|
|
1519
|
+
this.rootPath = import_clipanion.Option.String("--rootPath", {
|
|
1520
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
1521
|
+
});
|
|
1522
|
+
this.watchFolders = import_clipanion.Option.String("-w,--watchFolders", {
|
|
1523
|
+
description: "DEPRECATED - a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
1524
|
+
});
|
|
1525
|
+
this.isomorphicGitBridge = import_clipanion.Option.Boolean("--isomorphicGitBridge", {
|
|
1526
|
+
description: "DEPRECATED - Enable Isomorphic Git Bridge Implementation"
|
|
1527
|
+
});
|
|
1528
|
+
this.experimentalDataLayer = import_clipanion.Option.Boolean("--experimentalData", {
|
|
1529
|
+
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
1530
|
+
});
|
|
1531
|
+
this.verbose = import_clipanion.Option.Boolean("-v,--verbose", false, {
|
|
1532
|
+
description: "increase verbosity of logged output"
|
|
1533
|
+
});
|
|
1534
|
+
this.noWatch = import_clipanion.Option.Boolean("--noWatch", false, {
|
|
1535
|
+
description: "Don't regenerate config on file changes"
|
|
1536
|
+
});
|
|
1537
|
+
this.noSDK = import_clipanion.Option.Boolean("--noSDK", false, {
|
|
1538
|
+
description: "Don't generate the generated client SDK"
|
|
1539
|
+
});
|
|
1540
|
+
this.noTelemetry = import_clipanion.Option.Boolean("--noTelemetry", false, {
|
|
1541
|
+
description: "Disable anonymous telemetry that is collected"
|
|
1459
1542
|
});
|
|
1460
|
-
return genClient(
|
|
1461
|
-
{ tinaSchema: compiledSchema, usingTs, rootPath: rootPath2 },
|
|
1462
|
-
{
|
|
1463
|
-
local,
|
|
1464
|
-
port
|
|
1465
|
-
}
|
|
1466
|
-
);
|
|
1467
1543
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
rootPath: rootPath2,
|
|
1473
|
-
apiUrl
|
|
1474
|
-
}) => {
|
|
1475
|
-
var _a;
|
|
1476
|
-
if ((_a = schema == null ? void 0 : schema.config) == null ? void 0 : _a.build) {
|
|
1477
|
-
const buildVite = async () => {
|
|
1478
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1479
|
-
await (0, import_app.viteBuild)({
|
|
1480
|
-
local,
|
|
1481
|
-
rootPath: rootPath2,
|
|
1482
|
-
outputFolder: (_b = (_a2 = schema == null ? void 0 : schema.config) == null ? void 0 : _a2.build) == null ? void 0 : _b.outputFolder,
|
|
1483
|
-
publicFolder: (_d = (_c = schema == null ? void 0 : schema.config) == null ? void 0 : _c.build) == null ? void 0 : _d.publicFolder,
|
|
1484
|
-
apiUrl,
|
|
1485
|
-
host: (_g = (_f = (_e = schema == null ? void 0 : schema.config) == null ? void 0 : _e.build) == null ? void 0 : _f.host) != null ? _g : false
|
|
1486
|
-
});
|
|
1487
|
-
};
|
|
1488
|
-
if (local) {
|
|
1489
|
-
logger.info(logText("Starting Tina asset server"));
|
|
1490
|
-
await buildVite();
|
|
1491
|
-
} else {
|
|
1492
|
-
await spin({
|
|
1493
|
-
text: logText("Building static site"),
|
|
1494
|
-
waitFor: buildVite
|
|
1495
|
-
});
|
|
1496
|
-
logger.info(logText("\nDone building static site"));
|
|
1497
|
-
}
|
|
1544
|
+
async catch(error) {
|
|
1545
|
+
logger.error("Error occured during tinacms dev");
|
|
1546
|
+
console.error(error);
|
|
1547
|
+
process.exit(1);
|
|
1498
1548
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
var gqlPackageFile = require.resolve("@tinacms/graphql");
|
|
1505
|
-
async function startServer(ctx, next, {
|
|
1506
|
-
port = 4001,
|
|
1507
|
-
noWatch,
|
|
1508
|
-
noSDK,
|
|
1509
|
-
noTelemetry,
|
|
1510
|
-
watchFolders,
|
|
1511
|
-
verbose,
|
|
1512
|
-
dev
|
|
1513
|
-
}) {
|
|
1514
|
-
buildLock.disable();
|
|
1515
|
-
reBuildLock.disable();
|
|
1516
|
-
const rootPath2 = ctx.rootPath;
|
|
1517
|
-
const t = new import_metrics2.Telemetry({ disabled: Boolean(noTelemetry) });
|
|
1518
|
-
t.submitRecord({
|
|
1519
|
-
event: {
|
|
1520
|
-
name: "tinacms:cli:server:start:invoke"
|
|
1549
|
+
async execute() {
|
|
1550
|
+
if (this.watchFolders) {
|
|
1551
|
+
logger.warn(
|
|
1552
|
+
"--watchFolders has been deprecated, imports from your Tina config file will be watched automatically. If you still need it please open a ticket at https://github.com/tinacms/tinacms/issues"
|
|
1553
|
+
);
|
|
1521
1554
|
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
const database = ctx.database;
|
|
1525
|
-
const shouldBuild = bridge.supportsBuilding();
|
|
1526
|
-
let ready = false;
|
|
1527
|
-
const state = {
|
|
1528
|
-
server: null,
|
|
1529
|
-
sockets: []
|
|
1530
|
-
};
|
|
1531
|
-
let isReady = false;
|
|
1532
|
-
const beforeBuild = async () => {
|
|
1533
|
-
await buildLock.promise;
|
|
1534
|
-
buildLock.enable();
|
|
1535
|
-
};
|
|
1536
|
-
const afterBuild = async () => {
|
|
1537
|
-
buildLock.disable();
|
|
1538
|
-
};
|
|
1539
|
-
const start = async () => {
|
|
1540
|
-
await buildLock.promise;
|
|
1541
|
-
buildLock.enable();
|
|
1542
|
-
try {
|
|
1543
|
-
const s = (init_server3(), __toCommonJS(server_exports));
|
|
1544
|
-
state.server = await s.default(database);
|
|
1545
|
-
await new Promise((resolve2, reject) => {
|
|
1546
|
-
state.server.listen(port, () => {
|
|
1547
|
-
var _a, _b;
|
|
1548
|
-
const altairUrl = `http://localhost:${port}/altair/`;
|
|
1549
|
-
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`;
|
|
1550
|
-
if (verbose)
|
|
1551
|
-
logger.info(`Started Filesystem GraphQL server on port: ${port}`);
|
|
1552
|
-
console.log("");
|
|
1553
|
-
logger.info(indentedCmd(`GraphQL playground: ${linkText(altairUrl)}`));
|
|
1554
|
-
logger.info(indentedCmd(`CMS: ${linkText(cmsUrl)}
|
|
1555
|
-
`));
|
|
1556
|
-
resolve2();
|
|
1557
|
-
});
|
|
1558
|
-
state.server.on("error", function(e) {
|
|
1559
|
-
if (e.code === "EADDRINUSE") {
|
|
1560
|
-
logger.error(dangerText(`Port ${port} already in use`));
|
|
1561
|
-
}
|
|
1562
|
-
reject(e);
|
|
1563
|
-
});
|
|
1564
|
-
state.server.on("connection", (socket) => {
|
|
1565
|
-
state.sockets.push(socket);
|
|
1566
|
-
});
|
|
1567
|
-
});
|
|
1568
|
-
} catch (error) {
|
|
1569
|
-
throw error;
|
|
1570
|
-
} finally {
|
|
1571
|
-
buildLock.disable();
|
|
1555
|
+
if (this.isomorphicGitBridge) {
|
|
1556
|
+
logger.warn("--isomorphicGitBridge has been deprecated");
|
|
1572
1557
|
}
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1558
|
+
if (this.experimentalDataLayer) {
|
|
1559
|
+
logger.warn(
|
|
1560
|
+
"--experimentalDataLayer has been deprecated, the data layer is now built-in automatically"
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
const configManager = new ConfigManager(this.rootPath);
|
|
1564
|
+
logger.info("Starting Tina Dev Server");
|
|
1565
|
+
createDBServer(Number(this.datalayerPort));
|
|
1566
|
+
let database = null;
|
|
1567
|
+
const setup = async ({ firstTime }) => {
|
|
1568
|
+
try {
|
|
1569
|
+
await configManager.processConfig();
|
|
1570
|
+
} catch (e) {
|
|
1571
|
+
logger.error(e.message);
|
|
1572
|
+
if (this.verbose) {
|
|
1573
|
+
console.error(e);
|
|
1581
1574
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
await
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1575
|
+
if (firstTime) {
|
|
1576
|
+
logger.error(
|
|
1577
|
+
"Unable to start dev server, please fix your Tina config and try again"
|
|
1578
|
+
);
|
|
1579
|
+
process.exit(1);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (firstTime) {
|
|
1583
|
+
database = await createAndInitializeDatabase(configManager);
|
|
1584
|
+
} else {
|
|
1585
|
+
database.clearCache();
|
|
1586
|
+
}
|
|
1587
|
+
const { tinaSchema, graphQLSchema, queryDoc, fragDoc } = await (0, import_graphql8.buildSchema)(database, configManager.config);
|
|
1588
|
+
if (!configManager.isUsingLegacyFolder) {
|
|
1589
|
+
delete require.cache[configManager.generatedSchemaJSONPath];
|
|
1590
|
+
delete require.cache[configManager.generatedLookupJSONPath];
|
|
1591
|
+
delete require.cache[configManager.generatedGraphQLJSONPath];
|
|
1592
|
+
const schemaObject = require(configManager.generatedSchemaJSONPath);
|
|
1593
|
+
const lookupObject = require(configManager.generatedLookupJSONPath);
|
|
1594
|
+
const graphqlSchemaObject = require(configManager.generatedGraphQLJSONPath);
|
|
1595
|
+
await import_fs_extra4.default.writeFileSync(
|
|
1596
|
+
import_path6.default.join(configManager.tinaFolderPath, "tina-lock.json"),
|
|
1597
|
+
JSON.stringify({
|
|
1598
|
+
schema: schemaObject,
|
|
1599
|
+
lookup: lookupObject,
|
|
1600
|
+
graphql: graphqlSchemaObject
|
|
1601
|
+
})
|
|
1607
1602
|
);
|
|
1608
1603
|
}
|
|
1609
|
-
const
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
rootPath: ctx.rootPath
|
|
1604
|
+
const codegen2 = new Codegen({
|
|
1605
|
+
schema: await (0, import_graphql8.getASTSchema)(database),
|
|
1606
|
+
configManager,
|
|
1607
|
+
port: Number(this.port),
|
|
1608
|
+
noSDK: this.noSDK,
|
|
1609
|
+
queryDoc,
|
|
1610
|
+
fragDoc
|
|
1617
1611
|
});
|
|
1612
|
+
const apiURL2 = await codegen2.execute();
|
|
1613
|
+
if (!this.noWatch) {
|
|
1614
|
+
this.watchQueries(configManager, async () => await codegen2.execute());
|
|
1615
|
+
}
|
|
1616
|
+
const warnings = [];
|
|
1618
1617
|
await spin({
|
|
1619
1618
|
waitFor: async () => {
|
|
1620
|
-
await
|
|
1619
|
+
const res = await database.indexContent({
|
|
1620
|
+
graphQLSchema,
|
|
1621
|
+
tinaSchema
|
|
1622
|
+
});
|
|
1623
|
+
warnings.push(...res.warnings);
|
|
1621
1624
|
},
|
|
1622
|
-
text:
|
|
1625
|
+
text: "Indexing local files"
|
|
1623
1626
|
});
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1627
|
+
if (warnings.length > 0) {
|
|
1628
|
+
logger.warn(`Indexing completed with ${warnings.length} warning(s)`);
|
|
1629
|
+
warnings.forEach((warning) => {
|
|
1630
|
+
logger.warn(warnText(`${warning}`));
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
return { apiURL: apiURL2, database };
|
|
1634
|
+
};
|
|
1635
|
+
const { apiURL } = await setup({ firstTime: true });
|
|
1636
|
+
await import_fs_extra4.default.outputFile(configManager.outputHTMLFilePath, devHTML(this.port));
|
|
1637
|
+
await import_fs_extra4.default.outputFile(
|
|
1638
|
+
configManager.outputGitignorePath,
|
|
1639
|
+
"index.html\nassets/"
|
|
1640
|
+
);
|
|
1641
|
+
const server = await createDevServer(
|
|
1642
|
+
configManager,
|
|
1643
|
+
database,
|
|
1644
|
+
apiURL,
|
|
1645
|
+
this.noSDK,
|
|
1646
|
+
this.noWatch
|
|
1647
|
+
);
|
|
1648
|
+
await server.listen(Number(this.port));
|
|
1649
|
+
if (!this.noWatch) {
|
|
1650
|
+
this.watchContentFiles(configManager, database);
|
|
1634
1651
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
{
|
|
1645
|
-
ignored: [
|
|
1646
|
-
"**/node_modules/**/*",
|
|
1647
|
-
"**/.next/**/*",
|
|
1648
|
-
`${import_path8.default.resolve(rootPath2)}/.tina/__generated__/**/*`
|
|
1649
|
-
]
|
|
1652
|
+
server.watcher.on("change", async (changedPath) => {
|
|
1653
|
+
if (changedPath.includes("__generated__")) {
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
if (changedPath.includes("@tinacms/app")) {
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
if (changedPath.includes("tinacms/dist")) {
|
|
1660
|
+
return;
|
|
1650
1661
|
}
|
|
1651
|
-
).on("ready", async () => {
|
|
1652
|
-
if (verbose)
|
|
1653
|
-
console.log("Generating Tina config");
|
|
1654
1662
|
try {
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
}
|
|
1658
|
-
ready = true;
|
|
1659
|
-
isReady = true;
|
|
1660
|
-
await start();
|
|
1661
|
-
next();
|
|
1663
|
+
logger.info("Tina config updated");
|
|
1664
|
+
await setup({ firstTime: false });
|
|
1662
1665
|
} catch (e) {
|
|
1663
|
-
|
|
1664
|
-
throw e;
|
|
1666
|
+
logger.error(e.message);
|
|
1665
1667
|
}
|
|
1666
|
-
})
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1668
|
+
});
|
|
1669
|
+
const subItems = [];
|
|
1670
|
+
if (configManager.hasSeparateContentRoot()) {
|
|
1671
|
+
subItems.push({
|
|
1672
|
+
key: "Content repo",
|
|
1673
|
+
value: configManager.contentRootPath
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
const summaryItems = [
|
|
1677
|
+
{
|
|
1678
|
+
emoji: "\u{1F999}",
|
|
1679
|
+
heading: "Tina Config",
|
|
1680
|
+
subItems: [
|
|
1681
|
+
{
|
|
1682
|
+
key: "CMS",
|
|
1683
|
+
value: `<your-dev-server-url>/${configManager.printoutputHTMLFilePath()}`
|
|
1684
|
+
},
|
|
1685
|
+
{
|
|
1686
|
+
key: "API playground",
|
|
1687
|
+
value: `<your-dev-server-url>/${configManager.printoutputHTMLFilePath()}#/graphql`
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
key: "API url",
|
|
1691
|
+
value: apiURL
|
|
1692
|
+
},
|
|
1693
|
+
...subItems
|
|
1694
|
+
]
|
|
1689
1695
|
}
|
|
1696
|
+
];
|
|
1697
|
+
if (!this.noSDK) {
|
|
1698
|
+
summaryItems.push({
|
|
1699
|
+
emoji: "\u{1F916}",
|
|
1700
|
+
heading: "Auto-generated files",
|
|
1701
|
+
subItems: [
|
|
1702
|
+
{
|
|
1703
|
+
key: "GraphQL Client",
|
|
1704
|
+
value: configManager.printGeneratedClientFilePath()
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
key: "Typescript Types",
|
|
1708
|
+
value: configManager.printGeneratedTypesFilePath()
|
|
1709
|
+
}
|
|
1710
|
+
]
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
summary({
|
|
1714
|
+
heading: "Tina Dev Server is running...",
|
|
1715
|
+
items: [
|
|
1716
|
+
...summaryItems
|
|
1717
|
+
]
|
|
1690
1718
|
});
|
|
1691
|
-
|
|
1692
|
-
if (
|
|
1693
|
-
|
|
1719
|
+
let subProc;
|
|
1720
|
+
if (this.subCommand) {
|
|
1721
|
+
subProc = await startSubprocess2({ command: this.subCommand });
|
|
1722
|
+
logger.info(`Starting subprocess: ${import_chalk3.default.cyan(this.subCommand)}`);
|
|
1694
1723
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1724
|
+
function exitHandler(options, exitCode) {
|
|
1725
|
+
if (subProc) {
|
|
1726
|
+
subProc.kill();
|
|
1727
|
+
}
|
|
1728
|
+
process.exit();
|
|
1697
1729
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1730
|
+
process.on("exit", exitHandler);
|
|
1731
|
+
process.on("SIGINT", exitHandler);
|
|
1732
|
+
process.on("SIGUSR1", exitHandler);
|
|
1733
|
+
process.on("SIGUSR2", exitHandler);
|
|
1734
|
+
process.on("uncaughtException", exitHandler);
|
|
1735
|
+
}
|
|
1736
|
+
watchContentFiles(configManager, database) {
|
|
1737
|
+
const collectionContentFiles = [];
|
|
1738
|
+
configManager.config.schema.collections.forEach((collection) => {
|
|
1739
|
+
const collectionGlob = `${import_path6.default.join(
|
|
1740
|
+
configManager.contentRootPath,
|
|
1741
|
+
collection.path
|
|
1742
|
+
)}/**/*.${collection.format || "md"}`;
|
|
1743
|
+
collectionContentFiles.push(collectionGlob);
|
|
1744
|
+
});
|
|
1745
|
+
let ready = false;
|
|
1746
|
+
import_chokidar.default.watch(collectionContentFiles).on("ready", () => {
|
|
1747
|
+
ready = true;
|
|
1748
|
+
}).on("add", async (addedFile) => {
|
|
1749
|
+
if (!ready) {
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
const pathFromRoot = configManager.printContentRelativePath(addedFile);
|
|
1753
|
+
database.indexContentByPaths([pathFromRoot]);
|
|
1754
|
+
}).on("change", async (changedFile) => {
|
|
1755
|
+
const pathFromRoot = configManager.printContentRelativePath(changedFile);
|
|
1756
|
+
database.indexContentByPaths([pathFromRoot]);
|
|
1757
|
+
}).on("unlink", async (removedFile) => {
|
|
1758
|
+
const pathFromRoot = configManager.printContentRelativePath(removedFile);
|
|
1759
|
+
database.deleteContentByPaths([pathFromRoot]);
|
|
1760
|
+
});
|
|
1700
1761
|
}
|
|
1701
|
-
|
|
1762
|
+
watchQueries(configManager, callback) {
|
|
1763
|
+
let ready = false;
|
|
1764
|
+
import_chokidar.default.watch(configManager.userQueriesAndFragmentsGlob).on("ready", () => {
|
|
1765
|
+
ready = true;
|
|
1766
|
+
}).on("add", async (addedFile) => {
|
|
1767
|
+
await callback();
|
|
1768
|
+
}).on("change", async (changedFile) => {
|
|
1769
|
+
await callback();
|
|
1770
|
+
}).on("unlink", async (removedFile) => {
|
|
1771
|
+
await callback();
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
DevCommand.paths = [["dev"], ["server:start"]];
|
|
1776
|
+
DevCommand.usage = import_clipanion.Command.Usage({
|
|
1777
|
+
category: `Commands`,
|
|
1778
|
+
description: `Builds Tina and starts the dev server`,
|
|
1779
|
+
examples: [
|
|
1780
|
+
[`A basic example`, `$0 dev`],
|
|
1781
|
+
[`A second example`, `$0 dev --rootPath`]
|
|
1782
|
+
]
|
|
1783
|
+
});
|
|
1702
1784
|
|
|
1703
|
-
// src/
|
|
1785
|
+
// src/next/commands/build-command/index.ts
|
|
1786
|
+
var import_node_fetch2 = __toESM(require("node-fetch"));
|
|
1787
|
+
var import_clipanion2 = require("clipanion");
|
|
1788
|
+
var import_progress2 = __toESM(require("progress"));
|
|
1789
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
1790
|
+
var import_graphql9 = require("@tinacms/graphql");
|
|
1791
|
+
|
|
1792
|
+
// src/next/commands/build-command/server.ts
|
|
1793
|
+
var import_vite4 = require("vite");
|
|
1794
|
+
var buildProductionSpa = async (configManager, database, apiURL, noSDK) => {
|
|
1795
|
+
const publicEnv = {};
|
|
1796
|
+
Object.keys(process.env).forEach((key) => {
|
|
1797
|
+
if (key.startsWith("TINA_PUBLIC_") || key.startsWith("NEXT_PUBLIC_") || key === "NODE_ENV" || key === "HEAD") {
|
|
1798
|
+
try {
|
|
1799
|
+
if (typeof process.env[key] === "string") {
|
|
1800
|
+
publicEnv[key] = process.env[key];
|
|
1801
|
+
} else {
|
|
1802
|
+
publicEnv[key] = JSON.stringify(process.env[key]);
|
|
1803
|
+
}
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
console.warn(
|
|
1806
|
+
`Could not stringify public env process.env.${key} env variable`
|
|
1807
|
+
);
|
|
1808
|
+
console.warn(error);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
const config3 = await createConfig({
|
|
1813
|
+
configManager,
|
|
1814
|
+
database,
|
|
1815
|
+
apiURL,
|
|
1816
|
+
noSDK,
|
|
1817
|
+
noWatch: true
|
|
1818
|
+
});
|
|
1819
|
+
return (0, import_vite4.build)(config3);
|
|
1820
|
+
};
|
|
1821
|
+
|
|
1822
|
+
// src/next/commands/build-command/index.ts
|
|
1823
|
+
var import_schema_tools2 = require("@tinacms/schema-tools");
|
|
1824
|
+
var import_graphql10 = require("graphql");
|
|
1825
|
+
var import_core2 = require("@graphql-inspector/core");
|
|
1826
|
+
|
|
1827
|
+
// src/next/commands/build-command/waitForDB.ts
|
|
1704
1828
|
var import_progress = __toESM(require("progress"));
|
|
1705
1829
|
var import_schema_tools = require("@tinacms/schema-tools");
|
|
1830
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
1831
|
+
|
|
1832
|
+
// src/utils/sleep.ts
|
|
1833
|
+
function timeout(ms) {
|
|
1834
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1835
|
+
}
|
|
1836
|
+
async function sleepAndCallFunc({
|
|
1837
|
+
fn,
|
|
1838
|
+
ms
|
|
1839
|
+
}) {
|
|
1840
|
+
await timeout(ms);
|
|
1841
|
+
const res = await fn();
|
|
1842
|
+
return res;
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// src/next/commands/build-command/waitForDB.ts
|
|
1706
1846
|
var POLLING_INTERVAL = 5e3;
|
|
1707
1847
|
var STATUS_INPROGRESS = "inprogress";
|
|
1708
1848
|
var STATUS_COMPLETE = "complete";
|
|
@@ -1713,30 +1853,30 @@ var IndexFailedError = class extends Error {
|
|
|
1713
1853
|
this.name = "IndexFailedError";
|
|
1714
1854
|
}
|
|
1715
1855
|
};
|
|
1716
|
-
var waitForDB = async (
|
|
1717
|
-
const token =
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
return
|
|
1856
|
+
var waitForDB = async (config3, apiUrl, verbose) => {
|
|
1857
|
+
const token = config3.token;
|
|
1858
|
+
const { clientId, branch, isLocalClient, host } = (0, import_schema_tools.parseURL)(apiUrl);
|
|
1859
|
+
if (isLocalClient || !host || !clientId || !branch) {
|
|
1860
|
+
if (verbose) {
|
|
1861
|
+
logger.info(logText("Not using Tina Cloud, skipping DB check"));
|
|
1862
|
+
}
|
|
1863
|
+
return;
|
|
1724
1864
|
}
|
|
1725
|
-
const
|
|
1865
|
+
const bar2 = new import_progress.default(
|
|
1726
1866
|
"Checking indexing process in Tina Cloud... :prog",
|
|
1727
1867
|
1
|
|
1728
1868
|
);
|
|
1729
1869
|
const pollForStatus = async () => {
|
|
1730
1870
|
try {
|
|
1731
|
-
if (
|
|
1871
|
+
if (verbose) {
|
|
1732
1872
|
logger.info(logText("Polling for status..."));
|
|
1733
1873
|
}
|
|
1734
|
-
const headers = new Headers();
|
|
1874
|
+
const headers = new import_node_fetch.Headers();
|
|
1735
1875
|
headers.append("Content-Type", "application/json");
|
|
1736
1876
|
if (token) {
|
|
1737
1877
|
headers.append("X-API-KEY", token);
|
|
1738
1878
|
}
|
|
1739
|
-
const response = await
|
|
1879
|
+
const response = await (0, import_node_fetch.default)(
|
|
1740
1880
|
`https://${host}/db/${clientId}/status/${branch}`,
|
|
1741
1881
|
{
|
|
1742
1882
|
method: "GET",
|
|
@@ -1747,15 +1887,14 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
1747
1887
|
const { status, error } = await response.json();
|
|
1748
1888
|
const statusMessage = `Indexing status: '${status}'`;
|
|
1749
1889
|
if (status === STATUS_COMPLETE) {
|
|
1750
|
-
|
|
1890
|
+
bar2.tick({
|
|
1751
1891
|
prog: "\u2705"
|
|
1752
1892
|
});
|
|
1753
|
-
return next();
|
|
1754
1893
|
} else if (status === STATUS_INPROGRESS) {
|
|
1755
|
-
if (
|
|
1894
|
+
if (verbose) {
|
|
1756
1895
|
logger.info(logText(`${statusMessage}, trying again in 5 seconds`));
|
|
1757
1896
|
}
|
|
1758
|
-
|
|
1897
|
+
await sleepAndCallFunc({ fn: pollForStatus, ms: POLLING_INTERVAL });
|
|
1759
1898
|
} else if (status === STATUS_FAILED) {
|
|
1760
1899
|
throw new IndexFailedError(
|
|
1761
1900
|
`Attempting to index but responded with status 'failed', To retry the indexing process, click \u201CReset Repository Cache\u201D in tina cloud advance settings. ${error}`
|
|
@@ -1767,7 +1906,7 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
1767
1906
|
}
|
|
1768
1907
|
} catch (e) {
|
|
1769
1908
|
if (e instanceof IndexFailedError) {
|
|
1770
|
-
|
|
1909
|
+
bar2.tick({
|
|
1771
1910
|
prog: "\u274C"
|
|
1772
1911
|
});
|
|
1773
1912
|
throw e;
|
|
@@ -1778,47 +1917,603 @@ var waitForDB = async (ctx, next, options) => {
|
|
|
1778
1917
|
}
|
|
1779
1918
|
}
|
|
1780
1919
|
};
|
|
1781
|
-
spin({
|
|
1920
|
+
await spin({
|
|
1782
1921
|
text: "Checking indexing process in Tina Cloud...",
|
|
1783
1922
|
waitFor: pollForStatus
|
|
1784
1923
|
});
|
|
1785
1924
|
};
|
|
1786
1925
|
|
|
1787
|
-
// src/
|
|
1788
|
-
var
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1926
|
+
// src/next/commands/build-command/index.ts
|
|
1927
|
+
var BuildCommand = class extends import_clipanion2.Command {
|
|
1928
|
+
constructor() {
|
|
1929
|
+
super(...arguments);
|
|
1930
|
+
this.rootPath = import_clipanion2.Option.String("--rootPath", {
|
|
1931
|
+
description: "Specify the root directory to run the CLI from (defaults to current working directory)"
|
|
1932
|
+
});
|
|
1933
|
+
this.verbose = import_clipanion2.Option.Boolean("-v,--verbose", false, {
|
|
1934
|
+
description: "increase verbosity of logged output"
|
|
1935
|
+
});
|
|
1936
|
+
this.noSDK = import_clipanion2.Option.Boolean("--noSDK", false, {
|
|
1937
|
+
description: "Don't generate the generated client SDK"
|
|
1938
|
+
});
|
|
1939
|
+
this.datalayerPort = import_clipanion2.Option.String("--datalayer-port", "9000", {
|
|
1940
|
+
description: "Specify a port to run the datalayer server on. (default 4001)"
|
|
1941
|
+
});
|
|
1942
|
+
this.isomorphicGitBridge = import_clipanion2.Option.Boolean("--isomorphicGitBridge", {
|
|
1943
|
+
description: "DEPRECATED - Enable Isomorphic Git Bridge Implementation"
|
|
1944
|
+
});
|
|
1945
|
+
this.localOption = import_clipanion2.Option.Boolean("--local", {
|
|
1946
|
+
description: "DEPRECATED: Uses the local file system graphql server"
|
|
1947
|
+
});
|
|
1948
|
+
this.experimentalDataLayer = import_clipanion2.Option.Boolean("--experimentalData", {
|
|
1949
|
+
description: "DEPRECATED - Build the server with additional data querying capabilities"
|
|
1950
|
+
});
|
|
1951
|
+
this.noTelemetry = import_clipanion2.Option.Boolean("--noTelemetry", false, {
|
|
1952
|
+
description: "Disable anonymous telemetry that is collected"
|
|
1953
|
+
});
|
|
1954
|
+
this.tinaGraphQLVersion = import_clipanion2.Option.String("--tina-graphql-version", {
|
|
1955
|
+
description: "Specify the version of @tinacms/graphql to use (defaults to latest)"
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
async catch(error) {
|
|
1959
|
+
console.error(error);
|
|
1960
|
+
process.exit(1);
|
|
1961
|
+
}
|
|
1962
|
+
async execute() {
|
|
1963
|
+
const configManager = new ConfigManager(
|
|
1964
|
+
this.rootPath,
|
|
1965
|
+
this.tinaGraphQLVersion
|
|
1966
|
+
);
|
|
1967
|
+
logger.info("Starting Tina build");
|
|
1968
|
+
if (this.isomorphicGitBridge) {
|
|
1969
|
+
logger.warn("--isomorphicGitBridge has been deprecated");
|
|
1970
|
+
}
|
|
1971
|
+
if (this.experimentalDataLayer) {
|
|
1972
|
+
logger.warn(
|
|
1973
|
+
"--experimentalDataLayer has been deprecated, the data layer is now built-in automatically"
|
|
1974
|
+
);
|
|
1975
|
+
}
|
|
1976
|
+
if (this.localOption) {
|
|
1977
|
+
logger.warn("--local has been deprecated");
|
|
1978
|
+
}
|
|
1979
|
+
try {
|
|
1980
|
+
await configManager.processConfig();
|
|
1981
|
+
} catch (e) {
|
|
1982
|
+
logger.error(e.message);
|
|
1983
|
+
logger.error("Unable to build, please fix your Tina config and try again");
|
|
1984
|
+
process.exit(1);
|
|
1985
|
+
}
|
|
1986
|
+
createDBServer(Number(this.datalayerPort));
|
|
1987
|
+
const database = await createAndInitializeDatabase(configManager);
|
|
1988
|
+
const { queryDoc, fragDoc } = await (0, import_graphql9.buildSchema)(
|
|
1989
|
+
database,
|
|
1990
|
+
configManager.config
|
|
1991
|
+
);
|
|
1992
|
+
const codegen2 = new Codegen({
|
|
1993
|
+
schema: await (0, import_graphql9.getASTSchema)(database),
|
|
1994
|
+
configManager,
|
|
1995
|
+
noSDK: this.noSDK,
|
|
1996
|
+
queryDoc,
|
|
1997
|
+
fragDoc
|
|
1998
|
+
});
|
|
1999
|
+
const apiURL = await codegen2.execute();
|
|
2000
|
+
await this.checkClientInfo(configManager, apiURL);
|
|
2001
|
+
await waitForDB(configManager.config, apiURL, false);
|
|
2002
|
+
await this.checkGraphqlSchema(configManager, database, apiURL);
|
|
2003
|
+
await buildProductionSpa(configManager, database, apiURL, this.noSDK);
|
|
2004
|
+
await import_fs_extra5.default.outputFile(
|
|
2005
|
+
configManager.outputGitignorePath,
|
|
2006
|
+
"index.html\nassets/"
|
|
2007
|
+
);
|
|
2008
|
+
const summaryItems = [];
|
|
2009
|
+
if (!this.noSDK) {
|
|
2010
|
+
summaryItems.push({
|
|
2011
|
+
emoji: "\u{1F916}",
|
|
2012
|
+
heading: "Auto-generated files",
|
|
2013
|
+
subItems: [
|
|
2014
|
+
{
|
|
2015
|
+
key: "GraphQL Client",
|
|
2016
|
+
value: configManager.printGeneratedClientFilePath()
|
|
2017
|
+
},
|
|
2018
|
+
{
|
|
2019
|
+
key: "Typescript Types",
|
|
2020
|
+
value: configManager.printGeneratedTypesFilePath()
|
|
2021
|
+
}
|
|
2022
|
+
]
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
summary({
|
|
2026
|
+
heading: "Tina build complete",
|
|
2027
|
+
items: [
|
|
2028
|
+
{
|
|
2029
|
+
emoji: "\u{1F999}",
|
|
2030
|
+
heading: "Tina Config",
|
|
2031
|
+
subItems: [
|
|
2032
|
+
{
|
|
2033
|
+
key: "API url",
|
|
2034
|
+
value: apiURL
|
|
2035
|
+
}
|
|
2036
|
+
]
|
|
2037
|
+
},
|
|
2038
|
+
...summaryItems
|
|
2039
|
+
]
|
|
2040
|
+
});
|
|
2041
|
+
process.exit();
|
|
2042
|
+
}
|
|
2043
|
+
async checkClientInfo(configManager, apiURL) {
|
|
2044
|
+
const { config: config3 } = configManager;
|
|
2045
|
+
const token = config3.token;
|
|
2046
|
+
const { clientId, branch, host } = (0, import_schema_tools2.parseURL)(apiURL);
|
|
2047
|
+
const url2 = `https://${host}/db/${clientId}/status/${branch}`;
|
|
2048
|
+
const bar2 = new import_progress2.default("Checking clientId and token. :prog", 1);
|
|
2049
|
+
let branchKnown = false;
|
|
2050
|
+
try {
|
|
2051
|
+
const res = await request({
|
|
2052
|
+
token,
|
|
2053
|
+
url: url2
|
|
2054
|
+
});
|
|
2055
|
+
bar2.tick({
|
|
2056
|
+
prog: "\u2705"
|
|
2057
|
+
});
|
|
2058
|
+
if (!(res.status === "unknown")) {
|
|
2059
|
+
branchKnown = true;
|
|
2060
|
+
}
|
|
2061
|
+
} catch (e) {
|
|
2062
|
+
summary({
|
|
2063
|
+
heading: "Error when checking client information",
|
|
2064
|
+
items: [
|
|
2065
|
+
{
|
|
2066
|
+
emoji: "\u274C",
|
|
2067
|
+
heading: "You provided",
|
|
2068
|
+
subItems: [
|
|
2069
|
+
{
|
|
2070
|
+
key: "clientId",
|
|
2071
|
+
value: config3.clientId
|
|
2072
|
+
},
|
|
2073
|
+
{
|
|
2074
|
+
key: "token",
|
|
2075
|
+
value: config3.token
|
|
2076
|
+
}
|
|
2077
|
+
]
|
|
2078
|
+
}
|
|
2079
|
+
]
|
|
2080
|
+
});
|
|
2081
|
+
throw e;
|
|
2082
|
+
}
|
|
2083
|
+
const branchBar = new import_progress2.default("Checking branch is on Tina Cloud. :prog", 1);
|
|
2084
|
+
if (branchKnown) {
|
|
2085
|
+
branchBar.tick({
|
|
2086
|
+
prog: "\u2705"
|
|
2087
|
+
});
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
for (let i = 0; i <= 5; i++) {
|
|
2091
|
+
await sleepAndCallFunc({
|
|
2092
|
+
fn: async () => {
|
|
2093
|
+
const res = await request({
|
|
2094
|
+
token,
|
|
2095
|
+
url: url2
|
|
2096
|
+
});
|
|
2097
|
+
if (this.verbose) {
|
|
2098
|
+
logger.info(
|
|
2099
|
+
`Branch status: ${res.status}. Attempt: ${i + 1}. Trying again in 5 seconds.`
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
if (!(res.status === "unknown")) {
|
|
2103
|
+
branchBar.tick({
|
|
2104
|
+
prog: "\u2705"
|
|
2105
|
+
});
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
},
|
|
2109
|
+
ms: 5e3
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
branchBar.tick({
|
|
2113
|
+
prog: "\u274C"
|
|
2114
|
+
});
|
|
2115
|
+
logger.error(
|
|
2116
|
+
`${dangerText(
|
|
2117
|
+
`ERROR: Branch '${branch}' is not on Tina Cloud.`
|
|
2118
|
+
)} Please make sure that branch '${branch}' exists in your repository and that you have pushed your all changes to the remote. View all all branches and there current status here: ${linkText(
|
|
2119
|
+
`https://app.tina.io/projects/${clientId}/configuration`
|
|
2120
|
+
)}`
|
|
2121
|
+
);
|
|
2122
|
+
throw new Error("Branch is not on Tina Cloud");
|
|
2123
|
+
}
|
|
2124
|
+
async checkGraphqlSchema(configManager, database, apiURL) {
|
|
2125
|
+
const bar2 = new import_progress2.default(
|
|
2126
|
+
"Checking local GraphQL Schema matches server. :prog",
|
|
2127
|
+
1
|
|
2128
|
+
);
|
|
2129
|
+
const { config: config3 } = configManager;
|
|
2130
|
+
const token = config3.token;
|
|
2131
|
+
const remoteSchema = await fetchRemoteGraphqlSchema({
|
|
2132
|
+
url: apiURL,
|
|
2133
|
+
token
|
|
2134
|
+
});
|
|
2135
|
+
const remoteGqlSchema = (0, import_graphql10.buildClientSchema)(remoteSchema);
|
|
2136
|
+
const localSchemaDocument = await database.getGraphQLSchemaFromBridge();
|
|
2137
|
+
const localGraphqlSchema = (0, import_graphql10.buildASTSchema)(localSchemaDocument);
|
|
2138
|
+
const diffResult = await (0, import_core2.diff)(localGraphqlSchema, remoteGqlSchema);
|
|
2139
|
+
if (diffResult.length === 0) {
|
|
2140
|
+
bar2.tick({
|
|
2141
|
+
prog: "\u2705"
|
|
2142
|
+
});
|
|
2143
|
+
} else {
|
|
2144
|
+
bar2.tick({
|
|
2145
|
+
prog: "\u274C"
|
|
2146
|
+
});
|
|
2147
|
+
let errorMessage = `The local GraphQL schema doesn't match the remote GraphQL schema. Please push up your changes to Github to update your remote GraphQL schema.`;
|
|
2148
|
+
if (config3 == null ? void 0 : config3.branch) {
|
|
2149
|
+
errorMessage += `
|
|
2150
|
+
|
|
2151
|
+
Additional info: Branch: ${config3.branch}, Client ID: ${config3.clientId} `;
|
|
2152
|
+
}
|
|
2153
|
+
throw new Error(errorMessage);
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
BuildCommand.paths = [["build"]];
|
|
2158
|
+
BuildCommand.usage = import_clipanion2.Command.Usage({
|
|
2159
|
+
category: `Commands`,
|
|
2160
|
+
description: `Build the CMS and autogenerated modules for usage with Tina Cloud`
|
|
2161
|
+
});
|
|
2162
|
+
async function request(args) {
|
|
2163
|
+
const headers = new import_node_fetch2.Headers();
|
|
2164
|
+
if (args.token) {
|
|
2165
|
+
headers.append("X-API-KEY", args.token);
|
|
2166
|
+
}
|
|
2167
|
+
headers.append("Content-Type", "application/json");
|
|
2168
|
+
const url2 = args == null ? void 0 : args.url;
|
|
2169
|
+
const res = await (0, import_node_fetch2.default)(url2, {
|
|
2170
|
+
method: "GET",
|
|
2171
|
+
headers,
|
|
2172
|
+
redirect: "follow"
|
|
2173
|
+
});
|
|
2174
|
+
const json = await res.json();
|
|
2175
|
+
if (!res.ok) {
|
|
2176
|
+
let additionalInfo = "";
|
|
2177
|
+
if (res.status === 401 || res.status === 403) {
|
|
2178
|
+
additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
|
|
2179
|
+
}
|
|
2180
|
+
if (json) {
|
|
2181
|
+
additionalInfo += `
|
|
2182
|
+
|
|
2183
|
+
Message from server: ${json.message}`;
|
|
2184
|
+
}
|
|
2185
|
+
throw new Error(
|
|
2186
|
+
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
if (json.errors) {
|
|
2190
|
+
throw new Error(
|
|
2191
|
+
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
|
|
2192
|
+
|
|
2193
|
+
Errors:
|
|
2194
|
+
${json.errors.map((error) => error.message).join("\n")}`
|
|
2195
|
+
);
|
|
2196
|
+
}
|
|
2197
|
+
return {
|
|
2198
|
+
status: json == null ? void 0 : json.status,
|
|
2199
|
+
timestamp: json == null ? void 0 : json.timestamp
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
var fetchRemoteGraphqlSchema = async ({
|
|
2203
|
+
url: url2,
|
|
2204
|
+
token
|
|
2205
|
+
}) => {
|
|
2206
|
+
const headers = new import_node_fetch2.Headers();
|
|
2207
|
+
if (token) {
|
|
2208
|
+
headers.append("X-API-KEY", token);
|
|
2209
|
+
}
|
|
2210
|
+
const body = JSON.stringify({ query: (0, import_graphql10.getIntrospectionQuery)(), variables: {} });
|
|
2211
|
+
headers.append("Content-Type", "application/json");
|
|
2212
|
+
const res = await (0, import_node_fetch2.default)(url2, {
|
|
2213
|
+
method: "POST",
|
|
2214
|
+
headers,
|
|
2215
|
+
body
|
|
2216
|
+
});
|
|
2217
|
+
const data = await res.json();
|
|
2218
|
+
return data == null ? void 0 : data.data;
|
|
2219
|
+
};
|
|
2220
|
+
|
|
2221
|
+
// src/next/commands/audit-command/index.ts
|
|
2222
|
+
var import_clipanion3 = require("clipanion");
|
|
2223
|
+
var import_graphql13 = require("@tinacms/graphql");
|
|
2224
|
+
|
|
2225
|
+
// src/next/commands/audit-command/audit.ts
|
|
2226
|
+
var import_prompts = __toESM(require("prompts"));
|
|
2227
|
+
var import_metrics = require("@tinacms/metrics");
|
|
2228
|
+
var import_graphql11 = require("@tinacms/graphql");
|
|
2229
|
+
var import_graphql12 = require("@tinacms/graphql");
|
|
2230
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
2231
|
+
var audit = async ({
|
|
2232
|
+
database,
|
|
2233
|
+
clean,
|
|
2234
|
+
useDefaultValues,
|
|
2235
|
+
noTelemetry,
|
|
2236
|
+
verbose
|
|
2237
|
+
}) => {
|
|
2238
|
+
const telemetry = new import_metrics.Telemetry({ disabled: noTelemetry });
|
|
2239
|
+
await telemetry.submitRecord({
|
|
2240
|
+
event: {
|
|
2241
|
+
name: "tinacms:cli:audit:invoke",
|
|
2242
|
+
clean: Boolean(clean),
|
|
2243
|
+
useDefaults: Boolean(useDefaultValues)
|
|
2244
|
+
}
|
|
2245
|
+
});
|
|
2246
|
+
if (clean) {
|
|
2247
|
+
logger.info(
|
|
2248
|
+
`You are using the \`--clean\` option. This will modify your content as if a user is submitting a form. Before running this you should have a ${import_chalk4.default.bold(
|
|
2249
|
+
"clean git tree"
|
|
2250
|
+
)} so unwanted changes can be undone.
|
|
2251
|
+
|
|
2252
|
+
`
|
|
2253
|
+
);
|
|
2254
|
+
const res = await (0, import_prompts.default)({
|
|
2255
|
+
name: "useClean",
|
|
2256
|
+
type: "confirm",
|
|
2257
|
+
message: `Do you want to continue?`
|
|
2258
|
+
});
|
|
2259
|
+
if (!res.useClean) {
|
|
2260
|
+
logger.warn(import_chalk4.default.yellowBright("\u26A0\uFE0F Audit not complete"));
|
|
2261
|
+
process.exit(0);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
if (useDefaultValues && !clean) {
|
|
2265
|
+
logger.warn(
|
|
2266
|
+
import_chalk4.default.yellowBright(
|
|
2267
|
+
"WARNING: using the `--useDefaultValues` without the `--clean` flag has no effect. Please re-run audit and add the `--clean` flag"
|
|
2268
|
+
)
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
const schema = await database.getSchema();
|
|
2272
|
+
const collections = schema.getCollections();
|
|
2273
|
+
let error = false;
|
|
2274
|
+
for (let i = 0; i < collections.length; i++) {
|
|
2275
|
+
const collection = collections[i];
|
|
2276
|
+
const docs = await database.query(
|
|
2277
|
+
{ collection: collection.name, first: -1, filterChain: [] },
|
|
2278
|
+
(item) => ({ path: item })
|
|
2279
|
+
);
|
|
2280
|
+
logger.info(
|
|
2281
|
+
`Checking ${neutralText(collection.name)} collection. ${docs.edges.length} Documents`
|
|
2282
|
+
);
|
|
2283
|
+
const returnError = await auditDocuments({
|
|
2284
|
+
collection,
|
|
2285
|
+
database,
|
|
2286
|
+
useDefaultValues,
|
|
2287
|
+
documents: docs.edges,
|
|
2288
|
+
verbose
|
|
2289
|
+
});
|
|
2290
|
+
error = error || returnError;
|
|
2291
|
+
}
|
|
2292
|
+
if (error) {
|
|
2293
|
+
logger.error(
|
|
2294
|
+
import_chalk4.default.redBright(`\u203C\uFE0F Audit ${import_chalk4.default.bold("failed")} with errors`)
|
|
2295
|
+
);
|
|
2296
|
+
} else {
|
|
2297
|
+
logger.info(import_chalk4.default.greenBright("\u2705 Audit passed"));
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
var auditDocuments = async (args) => {
|
|
2301
|
+
const { collection, database, useDefaultValues, documents } = args;
|
|
2302
|
+
let error = false;
|
|
2303
|
+
for (let i = 0; i < documents.length; i++) {
|
|
2304
|
+
const node = documents[i].node;
|
|
2305
|
+
const relativePath = node.path.replace(`${collection.path}/`, "");
|
|
2306
|
+
const documentQuery = `query {
|
|
2307
|
+
document(collection: "${collection.name}", relativePath: "${relativePath}") {
|
|
2308
|
+
__typename
|
|
2309
|
+
...on Document {
|
|
2310
|
+
_values
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
}`;
|
|
2314
|
+
const docResult = await (0, import_graphql11.resolve)({
|
|
2315
|
+
database,
|
|
2316
|
+
query: documentQuery,
|
|
2317
|
+
variables: {},
|
|
2318
|
+
silenceErrors: true,
|
|
2319
|
+
verbose: args.verbose || false,
|
|
2320
|
+
isAudit: true
|
|
2321
|
+
});
|
|
2322
|
+
if (docResult.errors) {
|
|
2323
|
+
error = true;
|
|
2324
|
+
docResult.errors.forEach((err) => {
|
|
2325
|
+
logger.error(import_chalk4.default.red(err.message));
|
|
2326
|
+
if (err.originalError.originalError) {
|
|
2327
|
+
logger.error(
|
|
2328
|
+
import_chalk4.default.red(` ${err.originalError.originalError.message}`)
|
|
2329
|
+
);
|
|
2330
|
+
}
|
|
2331
|
+
});
|
|
2332
|
+
} else {
|
|
2333
|
+
const topLevelDefaults = {};
|
|
2334
|
+
if (useDefaultValues && typeof collection.fields !== "string") {
|
|
2335
|
+
collection.fields.filter((x) => !x.list).forEach((x) => {
|
|
2336
|
+
const value = x.ui;
|
|
2337
|
+
if (typeof value !== "undefined") {
|
|
2338
|
+
topLevelDefaults[x.name] = value.defaultValue;
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
const params = transformDocumentIntoMutationRequestPayload(
|
|
2343
|
+
docResult.data.document._values,
|
|
2344
|
+
{
|
|
2345
|
+
includeCollection: true,
|
|
2346
|
+
includeTemplate: typeof collection.templates !== "undefined"
|
|
2347
|
+
},
|
|
2348
|
+
topLevelDefaults
|
|
2349
|
+
);
|
|
2350
|
+
const mutation = `mutation($collection: String!, $relativePath: String!, $params: DocumentUpdateMutation!) {
|
|
2351
|
+
updateDocument(
|
|
2352
|
+
collection: $collection,
|
|
2353
|
+
relativePath: $relativePath,
|
|
2354
|
+
params: $params
|
|
2355
|
+
){__typename}
|
|
2356
|
+
}`;
|
|
2357
|
+
const mutationRes = await (0, import_graphql11.resolve)({
|
|
2358
|
+
database,
|
|
2359
|
+
query: mutation,
|
|
2360
|
+
variables: {
|
|
2361
|
+
params,
|
|
2362
|
+
collection: collection.name,
|
|
2363
|
+
relativePath
|
|
2364
|
+
},
|
|
2365
|
+
isAudit: true,
|
|
2366
|
+
silenceErrors: true,
|
|
2367
|
+
verbose: args.verbose || false
|
|
2368
|
+
});
|
|
2369
|
+
if (mutationRes.errors) {
|
|
2370
|
+
mutationRes.errors.forEach((err) => {
|
|
2371
|
+
error = true;
|
|
2372
|
+
logger.error(import_chalk4.default.red(err.message));
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
return error;
|
|
2378
|
+
};
|
|
2379
|
+
var transformDocumentIntoMutationRequestPayload = (document, instructions, defaults) => {
|
|
2380
|
+
const { _collection, __typename, _template, ...rest } = document;
|
|
2381
|
+
const params = transformParams(rest);
|
|
2382
|
+
const paramsWithTemplate = instructions.includeTemplate ? { [_template]: params } : params;
|
|
2383
|
+
return instructions.includeCollection ? { [_collection]: { ...defaults, ...filterObject(paramsWithTemplate) } } : { ...defaults, ...filterObject(paramsWithTemplate) };
|
|
2384
|
+
};
|
|
2385
|
+
var transformParams = (data) => {
|
|
2386
|
+
if (["string", "number", "boolean"].includes(typeof data)) {
|
|
2387
|
+
return data;
|
|
2388
|
+
}
|
|
2389
|
+
if (Array.isArray(data)) {
|
|
2390
|
+
return data.map((item) => transformParams(item));
|
|
2391
|
+
}
|
|
2392
|
+
try {
|
|
2393
|
+
(0, import_graphql12.assertShape)(
|
|
2394
|
+
data,
|
|
2395
|
+
(yup) => yup.object({ _template: yup.string().required() })
|
|
2396
|
+
);
|
|
2397
|
+
const { _template, __typename, ...rest } = data;
|
|
2398
|
+
const nested = transformParams(rest);
|
|
2399
|
+
return { [_template]: nested };
|
|
2400
|
+
} catch (e) {
|
|
2401
|
+
if (e.message === "Failed to assertShape - _template is a required field") {
|
|
2402
|
+
if (!data) {
|
|
2403
|
+
return void 0;
|
|
2404
|
+
return [];
|
|
2405
|
+
}
|
|
2406
|
+
const accum = {};
|
|
2407
|
+
Object.entries(data).map(([keyName, value]) => {
|
|
2408
|
+
accum[keyName] = transformParams(value);
|
|
2409
|
+
});
|
|
2410
|
+
return accum;
|
|
2411
|
+
} else {
|
|
2412
|
+
if (!data) {
|
|
2413
|
+
return void 0;
|
|
2414
|
+
return [];
|
|
2415
|
+
}
|
|
2416
|
+
throw e;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
function filterObject(obj) {
|
|
2421
|
+
const ret = {};
|
|
2422
|
+
Object.keys(obj).filter((key) => obj[key] !== void 0).forEach((key) => ret[key] = obj[key]);
|
|
2423
|
+
return ret;
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
// src/next/commands/audit-command/index.ts
|
|
2427
|
+
var import_graphql14 = require("@tinacms/graphql");
|
|
2428
|
+
var AuditCommand = class extends import_clipanion3.Command {
|
|
2429
|
+
constructor() {
|
|
2430
|
+
super(...arguments);
|
|
2431
|
+
this.rootPath = import_clipanion3.Option.String("--rootPath", {
|
|
2432
|
+
description: "Specify the root directory to run the CLI from"
|
|
1797
2433
|
});
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
dangerText(
|
|
1801
|
-
`An error has occurred in the Next.js child process. Error message below`
|
|
1802
|
-
)
|
|
1803
|
-
);
|
|
1804
|
-
logger.error(`name: ${code.name}
|
|
1805
|
-
message: ${code.message}
|
|
1806
|
-
|
|
1807
|
-
stack: ${code.stack || "No stack was provided"}`);
|
|
2434
|
+
this.verbose = import_clipanion3.Option.Boolean("-v,--verbose", false, {
|
|
2435
|
+
description: "increase verbosity of logged output"
|
|
1808
2436
|
});
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
2437
|
+
this.clean = import_clipanion3.Option.Boolean("--clean", false, {
|
|
2438
|
+
description: "Clean the output"
|
|
2439
|
+
});
|
|
2440
|
+
this.useDefaultValues = import_clipanion3.Option.Boolean("--useDefaultValues", false, {
|
|
2441
|
+
description: "When cleaning the output, use defaults on the config"
|
|
1812
2442
|
});
|
|
2443
|
+
this.noTelemetry = import_clipanion3.Option.Boolean("--noTelemetry", false, {
|
|
2444
|
+
description: "Disable anonymous telemetry that is collected"
|
|
2445
|
+
});
|
|
2446
|
+
this.datalayerPort = import_clipanion3.Option.String("--datalayer-port", "9000", {
|
|
2447
|
+
description: "Specify a port to run the datalayer server on. (default 4001)"
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
async catch(error) {
|
|
2451
|
+
logger.error("Error occured during tinacms audit");
|
|
2452
|
+
if (this.verbose) {
|
|
2453
|
+
console.error(error);
|
|
2454
|
+
}
|
|
2455
|
+
process.exit(1);
|
|
2456
|
+
}
|
|
2457
|
+
async execute() {
|
|
2458
|
+
const configManager = new ConfigManager(this.rootPath);
|
|
2459
|
+
logger.info("Starting Tina Audit");
|
|
2460
|
+
try {
|
|
2461
|
+
await configManager.processConfig();
|
|
2462
|
+
} catch (e) {
|
|
2463
|
+
logger.error(e.message);
|
|
2464
|
+
process.exit(1);
|
|
2465
|
+
}
|
|
2466
|
+
createDBServer(Number(this.datalayerPort));
|
|
2467
|
+
const database = await createAndInitializeDatabase(
|
|
2468
|
+
configManager,
|
|
2469
|
+
this.clean ? void 0 : new import_graphql14.AuditFileSystemBridge(configManager.rootPath)
|
|
2470
|
+
);
|
|
2471
|
+
const { tinaSchema, graphQLSchema } = await (0, import_graphql13.buildSchema)(
|
|
2472
|
+
database,
|
|
2473
|
+
configManager.config
|
|
2474
|
+
);
|
|
2475
|
+
const warnings = [];
|
|
2476
|
+
await spin({
|
|
2477
|
+
waitFor: async () => {
|
|
2478
|
+
const res = await database.indexContent({
|
|
2479
|
+
graphQLSchema,
|
|
2480
|
+
tinaSchema
|
|
2481
|
+
});
|
|
2482
|
+
warnings.push(...res.warnings);
|
|
2483
|
+
},
|
|
2484
|
+
text: "Indexing local files"
|
|
2485
|
+
});
|
|
2486
|
+
if (warnings.length > 0) {
|
|
2487
|
+
logger.warn(`Indexing completed with ${warnings.length} warning(s)`);
|
|
2488
|
+
warnings.forEach((warning) => {
|
|
2489
|
+
logger.warn(warnText(`${warning}`));
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
await audit({
|
|
2493
|
+
database,
|
|
2494
|
+
clean: this.clean,
|
|
2495
|
+
noTelemetry: this.noTelemetry,
|
|
2496
|
+
useDefaultValues: this.useDefaultValues,
|
|
2497
|
+
verbose: this.verbose
|
|
2498
|
+
});
|
|
2499
|
+
process.exit();
|
|
1813
2500
|
}
|
|
1814
2501
|
};
|
|
2502
|
+
AuditCommand.paths = [["audit"]];
|
|
2503
|
+
AuditCommand.usage = import_clipanion3.Command.Usage({
|
|
2504
|
+
category: `Commands`,
|
|
2505
|
+
description: `Audit config and content files`
|
|
2506
|
+
});
|
|
2507
|
+
|
|
2508
|
+
// src/next/commands/init-command/index.ts
|
|
2509
|
+
var import_clipanion4 = require("clipanion");
|
|
1815
2510
|
|
|
1816
2511
|
// src/cmds/init/index.ts
|
|
1817
|
-
var
|
|
2512
|
+
var import_path9 = __toESM(require("path"));
|
|
1818
2513
|
var import_prettier = require("prettier");
|
|
1819
|
-
var
|
|
2514
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
1820
2515
|
var import_prompts2 = __toESM(require("prompts"));
|
|
1821
|
-
var
|
|
2516
|
+
var import_metrics2 = require("@tinacms/metrics");
|
|
1822
2517
|
|
|
1823
2518
|
// src/cmds/init/setup-files/index.ts
|
|
1824
2519
|
var nextPostPage = ({
|
|
@@ -2159,8 +2854,8 @@ var configExamples = {
|
|
|
2159
2854
|
};
|
|
2160
2855
|
|
|
2161
2856
|
// src/cmds/forestry-migrate/util/index.ts
|
|
2162
|
-
var
|
|
2163
|
-
var
|
|
2857
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
2858
|
+
var import_path7 = __toESM(require("path"));
|
|
2164
2859
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
2165
2860
|
var import_zod = __toESM(require("zod"));
|
|
2166
2861
|
|
|
@@ -2298,7 +2993,7 @@ var FrontmatterTemplateSchema = import_zod.default.object({
|
|
|
2298
2993
|
});
|
|
2299
2994
|
var transformForestryFieldsToTinaFields = ({
|
|
2300
2995
|
fields,
|
|
2301
|
-
rootPath
|
|
2996
|
+
rootPath,
|
|
2302
2997
|
template,
|
|
2303
2998
|
skipBlocks = false
|
|
2304
2999
|
}) => {
|
|
@@ -2415,7 +3110,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
2415
3110
|
label: forestryField2.label,
|
|
2416
3111
|
fields: transformForestryFieldsToTinaFields({
|
|
2417
3112
|
fields: forestryField2.fields,
|
|
2418
|
-
rootPath
|
|
3113
|
+
rootPath,
|
|
2419
3114
|
template,
|
|
2420
3115
|
skipBlocks
|
|
2421
3116
|
})
|
|
@@ -2430,7 +3125,7 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
2430
3125
|
fields: transformForestryFieldsToTinaFields({
|
|
2431
3126
|
fields: forestryField2.fields,
|
|
2432
3127
|
template,
|
|
2433
|
-
rootPath
|
|
3128
|
+
rootPath,
|
|
2434
3129
|
skipBlocks
|
|
2435
3130
|
})
|
|
2436
3131
|
};
|
|
@@ -2484,9 +3179,9 @@ var transformForestryFieldsToTinaFields = ({
|
|
|
2484
3179
|
});
|
|
2485
3180
|
return tinaFields;
|
|
2486
3181
|
};
|
|
2487
|
-
var getFieldsFromTemplates = ({ tem, rootPath
|
|
2488
|
-
const templatePath =
|
|
2489
|
-
|
|
3182
|
+
var getFieldsFromTemplates = ({ tem, rootPath, skipBlocks = false }) => {
|
|
3183
|
+
const templatePath = import_path7.default.join(
|
|
3184
|
+
rootPath,
|
|
2490
3185
|
".forestry",
|
|
2491
3186
|
"front_matter",
|
|
2492
3187
|
"templates",
|
|
@@ -2494,7 +3189,7 @@ var getFieldsFromTemplates = ({ tem, rootPath: rootPath2, skipBlocks = false })
|
|
|
2494
3189
|
);
|
|
2495
3190
|
let templateString = "";
|
|
2496
3191
|
try {
|
|
2497
|
-
templateString =
|
|
3192
|
+
templateString = import_fs_extra6.default.readFileSync(templatePath).toString();
|
|
2498
3193
|
} catch {
|
|
2499
3194
|
throw new Error(
|
|
2500
3195
|
`Could not find template ${tem} at ${templatePath}
|
|
@@ -2506,7 +3201,7 @@ var getFieldsFromTemplates = ({ tem, rootPath: rootPath2, skipBlocks = false })
|
|
|
2506
3201
|
const template = parseTemplates({ val: templateObj });
|
|
2507
3202
|
const fields = transformForestryFieldsToTinaFields({
|
|
2508
3203
|
fields: template.fields,
|
|
2509
|
-
rootPath
|
|
3204
|
+
rootPath,
|
|
2510
3205
|
template: tem,
|
|
2511
3206
|
skipBlocks
|
|
2512
3207
|
});
|
|
@@ -2516,9 +3211,9 @@ var parseTemplates = ({ val }) => {
|
|
|
2516
3211
|
const template = FrontmatterTemplateSchema.parse(val);
|
|
2517
3212
|
return template;
|
|
2518
3213
|
};
|
|
2519
|
-
var hasForestryConfig = async ({ rootPath
|
|
2520
|
-
const forestryPath =
|
|
2521
|
-
const exists = await
|
|
3214
|
+
var hasForestryConfig = async ({ rootPath }) => {
|
|
3215
|
+
const forestryPath = import_path7.default.join(rootPath, ".forestry", "settings.yml");
|
|
3216
|
+
const exists = await import_fs_extra6.default.pathExists(forestryPath);
|
|
2522
3217
|
return {
|
|
2523
3218
|
path: forestryPath,
|
|
2524
3219
|
exists
|
|
@@ -2530,11 +3225,11 @@ var parseSections = ({ val }) => {
|
|
|
2530
3225
|
};
|
|
2531
3226
|
|
|
2532
3227
|
// src/cmds/forestry-migrate/index.ts
|
|
2533
|
-
var
|
|
2534
|
-
var
|
|
3228
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
3229
|
+
var import_path8 = __toESM(require("path"));
|
|
2535
3230
|
var import_js_yaml2 = __toESM(require("js-yaml"));
|
|
2536
3231
|
var import_minimatch = __toESM(require("minimatch"));
|
|
2537
|
-
var
|
|
3232
|
+
var import_graphql15 = require("@tinacms/graphql");
|
|
2538
3233
|
var BODY_FIELD = {
|
|
2539
3234
|
type: "rich-text",
|
|
2540
3235
|
name: "body",
|
|
@@ -2546,17 +3241,17 @@ var stringifyLabel = (label) => {
|
|
|
2546
3241
|
return label.replace(/[^a-zA-Z0-9]/g, "_").toLowerCase();
|
|
2547
3242
|
};
|
|
2548
3243
|
var generateAllCollections = async ({
|
|
2549
|
-
rootPath
|
|
3244
|
+
rootPath
|
|
2550
3245
|
}) => {
|
|
2551
|
-
const allTemplates = (await
|
|
2552
|
-
|
|
2553
|
-
)).map((tem) =>
|
|
3246
|
+
const allTemplates = (await import_fs_extra7.default.readdir(
|
|
3247
|
+
import_path8.default.join(rootPath, ".forestry", "front_matter", "templates")
|
|
3248
|
+
)).map((tem) => import_path8.default.basename(tem, ".yml"));
|
|
2554
3249
|
const templateMap = /* @__PURE__ */ new Map();
|
|
2555
3250
|
const proms = allTemplates.map(async (tem) => {
|
|
2556
3251
|
try {
|
|
2557
3252
|
const { fields, templateObj } = getFieldsFromTemplates({
|
|
2558
3253
|
tem,
|
|
2559
|
-
rootPath
|
|
3254
|
+
rootPath
|
|
2560
3255
|
});
|
|
2561
3256
|
templateMap.set(tem, { fields, templateObj });
|
|
2562
3257
|
} catch (e) {
|
|
@@ -2570,10 +3265,10 @@ var generateAllCollections = async ({
|
|
|
2570
3265
|
};
|
|
2571
3266
|
var generateCollections = async ({
|
|
2572
3267
|
forestryPath,
|
|
2573
|
-
rootPath
|
|
3268
|
+
rootPath
|
|
2574
3269
|
}) => {
|
|
2575
|
-
const templateMap = await generateAllCollections({ rootPath
|
|
2576
|
-
const forestryConfig = await
|
|
3270
|
+
const templateMap = await generateAllCollections({ rootPath });
|
|
3271
|
+
const forestryConfig = await import_fs_extra7.default.readFile(forestryPath);
|
|
2577
3272
|
const forestryYaml = import_js_yaml2.default.load(forestryConfig.toString());
|
|
2578
3273
|
const forestrySchema = parseSections({ val: forestryYaml });
|
|
2579
3274
|
const collections = [];
|
|
@@ -2611,10 +3306,10 @@ var generateCollections = async ({
|
|
|
2611
3306
|
});
|
|
2612
3307
|
(_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
|
|
2613
3308
|
try {
|
|
2614
|
-
const filePath =
|
|
2615
|
-
const extname =
|
|
2616
|
-
const fileContent =
|
|
2617
|
-
const content2 = (0,
|
|
3309
|
+
const filePath = import_path8.default.join(rootPath, page);
|
|
3310
|
+
const extname = import_path8.default.extname(filePath);
|
|
3311
|
+
const fileContent = import_fs_extra7.default.readFileSync(filePath).toString();
|
|
3312
|
+
const content2 = (0, import_graphql15.parseFile)(
|
|
2618
3313
|
fileContent,
|
|
2619
3314
|
extname,
|
|
2620
3315
|
(yup) => yup.object({})
|
|
@@ -2623,9 +3318,9 @@ var generateCollections = async ({
|
|
|
2623
3318
|
_template: stringifyLabel(tem),
|
|
2624
3319
|
...content2
|
|
2625
3320
|
};
|
|
2626
|
-
|
|
3321
|
+
import_fs_extra7.default.writeFileSync(
|
|
2627
3322
|
filePath,
|
|
2628
|
-
(0,
|
|
3323
|
+
(0, import_graphql15.stringifyFile)(newContent, extname, true)
|
|
2629
3324
|
);
|
|
2630
3325
|
} catch (error) {
|
|
2631
3326
|
console.log("Error updating file", page);
|
|
@@ -2660,10 +3355,10 @@ var generateCollections = async ({
|
|
|
2660
3355
|
fields.push(...additionalFields);
|
|
2661
3356
|
(_a = templateObj == null ? void 0 : templateObj.pages) == null ? void 0 : _a.forEach((page) => {
|
|
2662
3357
|
try {
|
|
2663
|
-
const filePath =
|
|
2664
|
-
const extname =
|
|
2665
|
-
const fileContent =
|
|
2666
|
-
const content2 = (0,
|
|
3358
|
+
const filePath = import_path8.default.join(rootPath, page);
|
|
3359
|
+
const extname = import_path8.default.extname(filePath);
|
|
3360
|
+
const fileContent = import_fs_extra7.default.readFileSync(filePath).toString();
|
|
3361
|
+
const content2 = (0, import_graphql15.parseFile)(
|
|
2667
3362
|
fileContent,
|
|
2668
3363
|
extname,
|
|
2669
3364
|
(yup) => yup.object({})
|
|
@@ -2672,9 +3367,9 @@ var generateCollections = async ({
|
|
|
2672
3367
|
_template: stringifyLabel(tem),
|
|
2673
3368
|
...content2
|
|
2674
3369
|
};
|
|
2675
|
-
|
|
3370
|
+
import_fs_extra7.default.writeFileSync(
|
|
2676
3371
|
filePath,
|
|
2677
|
-
(0,
|
|
3372
|
+
(0, import_graphql15.stringifyFile)(newContent, extname, true)
|
|
2678
3373
|
);
|
|
2679
3374
|
} catch (error) {
|
|
2680
3375
|
logger.log("Error updating file", page);
|
|
@@ -2715,8 +3410,11 @@ var generateCollections = async ({
|
|
|
2715
3410
|
};
|
|
2716
3411
|
|
|
2717
3412
|
// src/cmds/init/index.ts
|
|
2718
|
-
async function initStaticTina(
|
|
2719
|
-
|
|
3413
|
+
async function initStaticTina({
|
|
3414
|
+
rootPath,
|
|
3415
|
+
noTelemetry
|
|
3416
|
+
}) {
|
|
3417
|
+
const baseDir = rootPath;
|
|
2720
3418
|
logger.level = "info";
|
|
2721
3419
|
const clientId = await chooseClientId();
|
|
2722
3420
|
let token = null;
|
|
@@ -2727,24 +3425,24 @@ async function initStaticTina(ctx, next, options) {
|
|
|
2727
3425
|
const framework = await chooseFramework();
|
|
2728
3426
|
const usingTypescript = await chooseTypescript();
|
|
2729
3427
|
const publicFolder = await choosePublicFolder({ framework });
|
|
2730
|
-
const forestryPath = await hasForestryConfig({ rootPath
|
|
3428
|
+
const forestryPath = await hasForestryConfig({ rootPath });
|
|
2731
3429
|
let collections;
|
|
2732
3430
|
if (forestryPath.exists) {
|
|
2733
3431
|
collections = await forestryMigrate({
|
|
2734
3432
|
forestryPath: forestryPath.path,
|
|
2735
|
-
rootPath
|
|
3433
|
+
rootPath
|
|
2736
3434
|
});
|
|
2737
3435
|
}
|
|
2738
3436
|
await reportTelemetry({
|
|
2739
3437
|
usingTypescript,
|
|
2740
3438
|
hasForestryConfig: forestryPath.exists,
|
|
2741
|
-
noTelemetry
|
|
3439
|
+
noTelemetry
|
|
2742
3440
|
});
|
|
2743
|
-
const hasPackageJSON = await
|
|
3441
|
+
const hasPackageJSON = await import_fs_extra8.default.pathExistsSync("package.json");
|
|
2744
3442
|
if (!hasPackageJSON) {
|
|
2745
3443
|
await createPackageJSON();
|
|
2746
3444
|
}
|
|
2747
|
-
const hasGitignore = await
|
|
3445
|
+
const hasGitignore = await import_fs_extra8.default.pathExistsSync(".gitignore");
|
|
2748
3446
|
if (!hasGitignore) {
|
|
2749
3447
|
await createGitignore({ baseDir });
|
|
2750
3448
|
} else {
|
|
@@ -2863,7 +3561,7 @@ var chooseFramework = async () => {
|
|
|
2863
3561
|
};
|
|
2864
3562
|
var forestryMigrate = async ({
|
|
2865
3563
|
forestryPath,
|
|
2866
|
-
rootPath
|
|
3564
|
+
rootPath
|
|
2867
3565
|
}) => {
|
|
2868
3566
|
logger.info(
|
|
2869
3567
|
`It looks like you have a ${focusText(
|
|
@@ -2897,7 +3595,7 @@ ${logText(
|
|
|
2897
3595
|
});
|
|
2898
3596
|
const collections = await generateCollections({
|
|
2899
3597
|
forestryPath,
|
|
2900
|
-
rootPath
|
|
3598
|
+
rootPath
|
|
2901
3599
|
});
|
|
2902
3600
|
ErrorSingleton.getInstance().printNameErrors();
|
|
2903
3601
|
return JSON.stringify(collections, null, 2);
|
|
@@ -2910,12 +3608,12 @@ var reportTelemetry = async ({
|
|
|
2910
3608
|
if (noTelemetry) {
|
|
2911
3609
|
logger.info(logText("Telemetry disabled"));
|
|
2912
3610
|
}
|
|
2913
|
-
const telemetry = new
|
|
2914
|
-
const
|
|
3611
|
+
const telemetry = new import_metrics2.Telemetry({ disabled: noTelemetry });
|
|
3612
|
+
const schemaFileType = usingTypescript ? "ts" : "js";
|
|
2915
3613
|
await telemetry.submitRecord({
|
|
2916
3614
|
event: {
|
|
2917
3615
|
name: "tinacms:cli:init:invoke",
|
|
2918
|
-
schemaFileType
|
|
3616
|
+
schemaFileType,
|
|
2919
3617
|
hasForestryConfig: hasForestryConfig2
|
|
2920
3618
|
}
|
|
2921
3619
|
});
|
|
@@ -2926,22 +3624,22 @@ var createPackageJSON = async () => {
|
|
|
2926
3624
|
};
|
|
2927
3625
|
var createGitignore = async ({ baseDir }) => {
|
|
2928
3626
|
logger.info(logText("No .gitignore found, creating one"));
|
|
2929
|
-
await
|
|
3627
|
+
await import_fs_extra8.default.outputFileSync(import_path9.default.join(baseDir, ".gitignore"), "node_modules");
|
|
2930
3628
|
};
|
|
2931
3629
|
var checkGitignoreForNodeModules = async ({
|
|
2932
3630
|
baseDir
|
|
2933
3631
|
}) => {
|
|
2934
|
-
const gitignoreContent = await
|
|
3632
|
+
const gitignoreContent = await import_fs_extra8.default.readFileSync(import_path9.default.join(baseDir, ".gitignore")).toString();
|
|
2935
3633
|
return gitignoreContent.split("\n").some((item) => item === "node_modules");
|
|
2936
3634
|
};
|
|
2937
3635
|
var addNodeModulesToGitignore = async ({ baseDir }) => {
|
|
2938
3636
|
logger.info(logText("Adding node_modules to .gitignore"));
|
|
2939
|
-
const gitignoreContent = await
|
|
3637
|
+
const gitignoreContent = await import_fs_extra8.default.readFileSync(import_path9.default.join(baseDir, ".gitignore")).toString();
|
|
2940
3638
|
const newGitignoreContent = [
|
|
2941
3639
|
...gitignoreContent.split("\n"),
|
|
2942
3640
|
"node_modules"
|
|
2943
3641
|
].join("\n");
|
|
2944
|
-
await
|
|
3642
|
+
await import_fs_extra8.default.writeFileSync(import_path9.default.join(baseDir, ".gitignore"), newGitignoreContent);
|
|
2945
3643
|
};
|
|
2946
3644
|
var addDependencies = async (packageManager) => {
|
|
2947
3645
|
logger.info(logText("Adding dependencies, this might take a moment..."));
|
|
@@ -2956,12 +3654,12 @@ var addDependencies = async (packageManager) => {
|
|
|
2956
3654
|
};
|
|
2957
3655
|
var addConfigFile = async (args) => {
|
|
2958
3656
|
const { baseDir, usingTypescript } = args;
|
|
2959
|
-
const configPath =
|
|
3657
|
+
const configPath = import_path9.default.join(
|
|
2960
3658
|
".tina",
|
|
2961
3659
|
`config.${usingTypescript ? "ts" : "js"}`
|
|
2962
3660
|
);
|
|
2963
|
-
const fullConfigPath =
|
|
2964
|
-
if (
|
|
3661
|
+
const fullConfigPath = import_path9.default.join(baseDir, configPath);
|
|
3662
|
+
if (import_fs_extra8.default.pathExistsSync(fullConfigPath)) {
|
|
2965
3663
|
const override = await (0, import_prompts2.default)({
|
|
2966
3664
|
name: "selection",
|
|
2967
3665
|
type: "confirm",
|
|
@@ -2969,7 +3667,7 @@ var addConfigFile = async (args) => {
|
|
|
2969
3667
|
});
|
|
2970
3668
|
if (override["selection"]) {
|
|
2971
3669
|
logger.info(logText(`Overriding file at ${configPath}.`));
|
|
2972
|
-
await
|
|
3670
|
+
await import_fs_extra8.default.outputFileSync(fullConfigPath, config2(args));
|
|
2973
3671
|
} else {
|
|
2974
3672
|
logger.info(logText(`Not overriding file at ${configPath}.`));
|
|
2975
3673
|
}
|
|
@@ -2979,13 +3677,13 @@ var addConfigFile = async (args) => {
|
|
|
2979
3677
|
`Adding config file at .tina/config.${usingTypescript ? "ts" : "js"}`
|
|
2980
3678
|
)
|
|
2981
3679
|
);
|
|
2982
|
-
await
|
|
3680
|
+
await import_fs_extra8.default.outputFileSync(fullConfigPath, config2(args));
|
|
2983
3681
|
}
|
|
2984
3682
|
};
|
|
2985
3683
|
var addContentFile = async ({ baseDir }) => {
|
|
2986
|
-
const contentPath =
|
|
2987
|
-
const fullContentPath =
|
|
2988
|
-
if (
|
|
3684
|
+
const contentPath = import_path9.default.join("content", "posts", "hello-world.md");
|
|
3685
|
+
const fullContentPath = import_path9.default.join(baseDir, contentPath);
|
|
3686
|
+
if (import_fs_extra8.default.pathExistsSync(fullContentPath)) {
|
|
2989
3687
|
const override = await (0, import_prompts2.default)({
|
|
2990
3688
|
name: "selection",
|
|
2991
3689
|
type: "confirm",
|
|
@@ -2993,13 +3691,13 @@ var addContentFile = async ({ baseDir }) => {
|
|
|
2993
3691
|
});
|
|
2994
3692
|
if (override["selection"]) {
|
|
2995
3693
|
logger.info(logText(`Overriding file at ${contentPath}.`));
|
|
2996
|
-
await
|
|
3694
|
+
await import_fs_extra8.default.outputFileSync(fullContentPath, content);
|
|
2997
3695
|
} else {
|
|
2998
3696
|
logger.info(logText(`Not overriding file at ${contentPath}.`));
|
|
2999
3697
|
}
|
|
3000
3698
|
} else {
|
|
3001
3699
|
logger.info(logText(`Adding content file at ${contentPath}`));
|
|
3002
|
-
await
|
|
3700
|
+
await import_fs_extra8.default.outputFileSync(fullContentPath, content);
|
|
3003
3701
|
}
|
|
3004
3702
|
};
|
|
3005
3703
|
var logNextSteps = ({
|
|
@@ -3041,8 +3739,8 @@ var frameworkDevCmds = {
|
|
|
3041
3739
|
return installText;
|
|
3042
3740
|
}
|
|
3043
3741
|
};
|
|
3044
|
-
var
|
|
3045
|
-
return (0, import_prettier.format)(configExamples[args.framework.name](args));
|
|
3742
|
+
var config2 = (args) => {
|
|
3743
|
+
return (0, import_prettier.format)(configExamples[args.framework.name](args), { parser: "babel" });
|
|
3046
3744
|
};
|
|
3047
3745
|
var content = `---
|
|
3048
3746
|
title: Hello, World!
|
|
@@ -3059,20 +3757,20 @@ var addReactiveFile = {
|
|
|
3059
3757
|
baseDir,
|
|
3060
3758
|
usingTypescript
|
|
3061
3759
|
}) => {
|
|
3062
|
-
const usingSrc = !
|
|
3063
|
-
const pagesPath =
|
|
3064
|
-
const packageJSONPath =
|
|
3065
|
-
const tinaBlogPagePath =
|
|
3066
|
-
const tinaBlogPagePathFile =
|
|
3760
|
+
const usingSrc = !import_fs_extra8.default.pathExistsSync(import_path9.default.join(baseDir, "pages"));
|
|
3761
|
+
const pagesPath = import_path9.default.join(baseDir, usingSrc ? "src" : "", "pages");
|
|
3762
|
+
const packageJSONPath = import_path9.default.join(baseDir, "package.json");
|
|
3763
|
+
const tinaBlogPagePath = import_path9.default.join(pagesPath, "demo", "blog");
|
|
3764
|
+
const tinaBlogPagePathFile = import_path9.default.join(
|
|
3067
3765
|
tinaBlogPagePath,
|
|
3068
3766
|
`[filename].${usingTypescript ? "tsx" : "js"}`
|
|
3069
3767
|
);
|
|
3070
|
-
if (!
|
|
3071
|
-
|
|
3072
|
-
|
|
3768
|
+
if (!import_fs_extra8.default.pathExistsSync(tinaBlogPagePathFile)) {
|
|
3769
|
+
import_fs_extra8.default.mkdirpSync(tinaBlogPagePath);
|
|
3770
|
+
import_fs_extra8.default.writeFileSync(tinaBlogPagePathFile, nextPostPage({ usingSrc }));
|
|
3073
3771
|
}
|
|
3074
3772
|
logger.info("Adding a nextjs example... \u2705");
|
|
3075
|
-
const pack = JSON.parse(
|
|
3773
|
+
const pack = JSON.parse(import_fs_extra8.default.readFileSync(packageJSONPath).toString());
|
|
3076
3774
|
const oldScripts = pack.scripts || {};
|
|
3077
3775
|
const newPack = JSON.stringify(
|
|
3078
3776
|
{
|
|
@@ -3082,7 +3780,7 @@ var addReactiveFile = {
|
|
|
3082
3780
|
null,
|
|
3083
3781
|
2
|
|
3084
3782
|
);
|
|
3085
|
-
|
|
3783
|
+
import_fs_extra8.default.writeFileSync(packageJSONPath, newPack);
|
|
3086
3784
|
}
|
|
3087
3785
|
};
|
|
3088
3786
|
function execShellCommand(cmd) {
|
|
@@ -3097,577 +3795,49 @@ function execShellCommand(cmd) {
|
|
|
3097
3795
|
});
|
|
3098
3796
|
}
|
|
3099
3797
|
|
|
3100
|
-
// src/
|
|
3101
|
-
var
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
// src/buildTina/git.ts
|
|
3107
|
-
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
3108
|
-
var import_ini = __toESM(require("ini"));
|
|
3109
|
-
var import_os = __toESM(require("os"));
|
|
3110
|
-
var import_path12 = __toESM(require("path"));
|
|
3111
|
-
var resolveGitRoot = async () => {
|
|
3112
|
-
const pathParts = process.cwd().split(import_path12.default.sep);
|
|
3113
|
-
while (true) {
|
|
3114
|
-
const pathToGit = pathParts.join(import_path12.default.sep);
|
|
3115
|
-
if (await import_fs_extra10.default.pathExists(import_path12.default.join(pathToGit, ".git"))) {
|
|
3116
|
-
return pathToGit;
|
|
3117
|
-
}
|
|
3118
|
-
if (!pathParts.length) {
|
|
3119
|
-
throw new Error(
|
|
3120
|
-
"Unable to locate your .git folder (required for isomorphicGitBridge)"
|
|
3121
|
-
);
|
|
3122
|
-
}
|
|
3123
|
-
pathParts.pop();
|
|
3124
|
-
}
|
|
3125
|
-
};
|
|
3126
|
-
async function makeIsomorphicOptions(fsBridge) {
|
|
3127
|
-
var _a, _b, _c, _d;
|
|
3128
|
-
const gitRoot = await resolveGitRoot();
|
|
3129
|
-
const options = {
|
|
3130
|
-
gitRoot,
|
|
3131
|
-
author: {
|
|
3132
|
-
name: "",
|
|
3133
|
-
email: ""
|
|
3134
|
-
},
|
|
3135
|
-
onPut: async (filepath, data) => {
|
|
3136
|
-
await fsBridge.put(filepath, data);
|
|
3137
|
-
},
|
|
3138
|
-
onDelete: async (filepath) => {
|
|
3139
|
-
await fsBridge.delete(filepath);
|
|
3140
|
-
}
|
|
3141
|
-
};
|
|
3142
|
-
const userGitConfig = `${import_os.default.homedir()}${import_path12.default.sep}.gitconfig`;
|
|
3143
|
-
if (await import_fs_extra10.default.pathExists(userGitConfig)) {
|
|
3144
|
-
const config2 = import_ini.default.parse(await import_fs_extra10.default.readFile(userGitConfig, "utf-8"));
|
|
3145
|
-
if ((_a = config2["user"]) == null ? void 0 : _a["name"]) {
|
|
3146
|
-
options.author.name = config2["user"]["name"];
|
|
3147
|
-
}
|
|
3148
|
-
if ((_b = config2["user"]) == null ? void 0 : _b["email"]) {
|
|
3149
|
-
options.author.email = config2["user"]["email"];
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
let repoGitConfig = void 0;
|
|
3153
|
-
if (!options.author.name) {
|
|
3154
|
-
repoGitConfig = import_ini.default.parse(
|
|
3155
|
-
await import_fs_extra10.default.readFile(`${gitRoot}/.git/config`, "utf-8")
|
|
3156
|
-
);
|
|
3157
|
-
if ((_c = repoGitConfig["user"]) == null ? void 0 : _c["name"]) {
|
|
3158
|
-
options.author.name = repoGitConfig["user"]["name"];
|
|
3159
|
-
}
|
|
3160
|
-
if (!options.author.name) {
|
|
3161
|
-
throw new Error(
|
|
3162
|
-
'Unable to determine user.name from git config. Hint: `git config --global user.name "John Doe"`'
|
|
3163
|
-
);
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
if (!options.author.email) {
|
|
3167
|
-
repoGitConfig = repoGitConfig || import_ini.default.parse(await import_fs_extra10.default.readFile(`${gitRoot}/.git/config`, "utf-8"));
|
|
3168
|
-
if ((_d = repoGitConfig["user"]) == null ? void 0 : _d["email"]) {
|
|
3169
|
-
options.author.email = repoGitConfig["user"]["email"];
|
|
3170
|
-
}
|
|
3171
|
-
if (!options.author.email) {
|
|
3172
|
-
throw new Error(
|
|
3173
|
-
"Unable to determine user.email from git config. Hint: `git config --global user.email johndoe@example.com`"
|
|
3174
|
-
);
|
|
3175
|
-
}
|
|
3176
|
-
}
|
|
3177
|
-
return options;
|
|
3178
|
-
}
|
|
3179
|
-
|
|
3180
|
-
// src/buildTina/attachDatabase.ts
|
|
3181
|
-
var import_memory_level2 = require("memory-level");
|
|
3182
|
-
var import_many_level = require("many-level");
|
|
3183
|
-
var import_readable_stream = require("readable-stream");
|
|
3184
|
-
var import_net = require("net");
|
|
3185
|
-
var attachDatabase = async (ctx, next, _options) => {
|
|
3186
|
-
const tinaPath = path10.join(ctx.rootPath, ".tina");
|
|
3187
|
-
const tinaGeneratedPath = path10.join(tinaPath, "__generated__");
|
|
3188
|
-
const tinaTempPath = path10.join(tinaGeneratedPath, `temp_database`);
|
|
3189
|
-
const define = {};
|
|
3190
|
-
if (!process.env.NODE_ENV) {
|
|
3191
|
-
define["process.env.NODE_ENV"] = _options.dev ? '"development"' : '"production"';
|
|
3192
|
-
}
|
|
3193
|
-
const inputFile = getPath({
|
|
3194
|
-
projectDir: path10.join(ctx.rootPath, ".tina"),
|
|
3195
|
-
filename: "database",
|
|
3196
|
-
allowedTypes: ["js", "jsx", "tsx", "ts"]
|
|
3197
|
-
});
|
|
3198
|
-
const fsBridge = new import_datalayer2.FilesystemBridge(ctx.rootPath);
|
|
3199
|
-
const levelHost = new import_many_level.ManyLevelHost(
|
|
3200
|
-
new import_memory_level2.MemoryLevel({
|
|
3201
|
-
valueEncoding: "json"
|
|
3202
|
-
})
|
|
3203
|
-
);
|
|
3204
|
-
const server = (0, import_net.createServer)(function(socket) {
|
|
3205
|
-
(0, import_readable_stream.pipeline)(socket, levelHost.createRpcStream(), socket, () => {
|
|
3206
|
-
});
|
|
3207
|
-
});
|
|
3208
|
-
server.listen(9e3);
|
|
3209
|
-
ctx.dbServer = server;
|
|
3210
|
-
if (inputFile) {
|
|
3211
|
-
try {
|
|
3212
|
-
await transpile(
|
|
3213
|
-
inputFile,
|
|
3214
|
-
"database.cjs",
|
|
3215
|
-
tinaTempPath,
|
|
3216
|
-
_options.verbose,
|
|
3217
|
-
define,
|
|
3218
|
-
path10.join(ctx.rootPath, "package.json"),
|
|
3219
|
-
"node"
|
|
3220
|
-
);
|
|
3221
|
-
} catch (e) {
|
|
3222
|
-
await import_fs_extra11.default.remove(tinaTempPath);
|
|
3223
|
-
throw new BuildSchemaError(e);
|
|
3224
|
-
}
|
|
3225
|
-
Object.keys(require.cache).map((key) => {
|
|
3226
|
-
if (key.startsWith(tinaTempPath)) {
|
|
3227
|
-
delete require.cache[require.resolve(key)];
|
|
3228
|
-
}
|
|
3229
|
-
});
|
|
3230
|
-
try {
|
|
3231
|
-
const databaseFunc = require(path10.join(tinaTempPath, `database.cjs`));
|
|
3232
|
-
ctx.database = databaseFunc.default;
|
|
3233
|
-
ctx.database.bridge = fsBridge;
|
|
3234
|
-
ctx.bridge = ctx.database.bridge;
|
|
3235
|
-
ctx.isSelfHostedDatabase = true;
|
|
3236
|
-
await import_fs_extra11.default.remove(tinaTempPath);
|
|
3237
|
-
} catch (e) {
|
|
3238
|
-
await import_fs_extra11.default.remove(tinaTempPath);
|
|
3239
|
-
throw e;
|
|
3240
|
-
}
|
|
3241
|
-
} else {
|
|
3242
|
-
const bridge = _options.isomorphicGitBridge ? new import_datalayer2.IsomorphicBridge(
|
|
3243
|
-
ctx.rootPath,
|
|
3244
|
-
_options.isomorphicGitBridge && await makeIsomorphicOptions(fsBridge)
|
|
3245
|
-
) : fsBridge;
|
|
3246
|
-
const level = new import_graphql11.TinaLevelClient();
|
|
3247
|
-
level.openConnection();
|
|
3248
|
-
ctx.database = await (0, import_graphql11.createDatabase)({ level, bridge });
|
|
3249
|
-
ctx.bridge = bridge;
|
|
3250
|
-
}
|
|
3251
|
-
next();
|
|
3252
|
-
};
|
|
3253
|
-
|
|
3254
|
-
// src/cmds/statusChecks/checkClientInformation.ts
|
|
3255
|
-
var import_progress2 = __toESM(require("progress"));
|
|
3256
|
-
var import_graphql12 = require("graphql");
|
|
3257
|
-
var import_core2 = require("@graphql-inspector/core");
|
|
3258
|
-
var import_schema_tools2 = require("@tinacms/schema-tools");
|
|
3259
|
-
async function request(args) {
|
|
3260
|
-
const headers = new Headers();
|
|
3261
|
-
if (args.token) {
|
|
3262
|
-
headers.append("X-API-KEY", args.token);
|
|
3263
|
-
}
|
|
3264
|
-
headers.append("Content-Type", "application/json");
|
|
3265
|
-
const url = args == null ? void 0 : args.url;
|
|
3266
|
-
const res = await fetch(url, {
|
|
3267
|
-
method: "GET",
|
|
3268
|
-
headers,
|
|
3269
|
-
redirect: "follow"
|
|
3270
|
-
});
|
|
3271
|
-
const json = await res.json();
|
|
3272
|
-
if (!res.ok) {
|
|
3273
|
-
let additionalInfo = "";
|
|
3274
|
-
if (res.status === 401 || res.status === 403) {
|
|
3275
|
-
additionalInfo = "Please check that your client ID, URL and read only token are configured properly.";
|
|
3276
|
-
}
|
|
3277
|
-
if (json) {
|
|
3278
|
-
additionalInfo += `
|
|
3279
|
-
|
|
3280
|
-
Message from server: ${json.message}`;
|
|
3281
|
-
}
|
|
3282
|
-
throw new Error(
|
|
3283
|
-
`Server responded with status code ${res.status}, ${res.statusText}. ${additionalInfo ? additionalInfo : ""} Please see our FAQ for more information: https://tina.io/docs/errors/faq/`
|
|
3284
|
-
);
|
|
3285
|
-
}
|
|
3286
|
-
if (json.errors) {
|
|
3287
|
-
throw new Error(
|
|
3288
|
-
`Unable to fetch, please see our FAQ for more information: https://tina.io/docs/errors/faq/
|
|
3289
|
-
|
|
3290
|
-
Errors:
|
|
3291
|
-
${json.errors.map((error) => error.message).join("\n")}`
|
|
3292
|
-
);
|
|
3293
|
-
}
|
|
3294
|
-
return {
|
|
3295
|
-
status: json == null ? void 0 : json.status,
|
|
3296
|
-
timestamp: json == null ? void 0 : json.timestamp
|
|
3297
|
-
};
|
|
3298
|
-
}
|
|
3299
|
-
var checkClientInfo = async (ctx, next, _options) => {
|
|
3300
|
-
var _a;
|
|
3301
|
-
if (ctx.isSelfHostedDatabase) {
|
|
3302
|
-
return next();
|
|
3303
|
-
}
|
|
3304
|
-
const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
|
|
3305
|
-
const token = config2.token;
|
|
3306
|
-
const { clientId, branch, host } = (0, import_schema_tools2.parseURL)(ctx.apiUrl);
|
|
3307
|
-
const url = `https://${host}/db/${clientId}/status/${branch}`;
|
|
3308
|
-
const bar = new import_progress2.default("Checking clientId, token and branch. :prog", 1);
|
|
3309
|
-
try {
|
|
3310
|
-
await request({
|
|
3311
|
-
token,
|
|
3312
|
-
url
|
|
3313
|
-
});
|
|
3314
|
-
bar.tick({
|
|
3315
|
-
prog: "\u2705"
|
|
3798
|
+
// src/next/commands/init-command/index.ts
|
|
3799
|
+
var InitCommand = class extends import_clipanion4.Command {
|
|
3800
|
+
constructor() {
|
|
3801
|
+
super(...arguments);
|
|
3802
|
+
this.rootPath = import_clipanion4.Option.String("--rootPath", {
|
|
3803
|
+
description: "Specify the root directory to run the CLI from"
|
|
3316
3804
|
});
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
prog: "\u274C"
|
|
3805
|
+
this.noTelemetry = import_clipanion4.Option.Boolean("--noTelemetry", false, {
|
|
3806
|
+
description: "Disable anonymous telemetry that is collected"
|
|
3320
3807
|
});
|
|
3321
|
-
console.warn(
|
|
3322
|
-
`Error when checking client information. You provided
|
|
3323
|
-
|
|
3324
|
-
${JSON.stringify(
|
|
3325
|
-
{
|
|
3326
|
-
branch: config2 == null ? void 0 : config2.branch,
|
|
3327
|
-
clientId: config2 == null ? void 0 : config2.clientId,
|
|
3328
|
-
token: config2 == null ? void 0 : config2.token
|
|
3329
|
-
},
|
|
3330
|
-
null,
|
|
3331
|
-
2
|
|
3332
|
-
)}
|
|
3333
|
-
|
|
3334
|
-
Please check you have the correct "clientId", "branch" and "token" configured. For more information see https://tina.io/docs/tina-cloud/connecting-site/`
|
|
3335
|
-
);
|
|
3336
|
-
throw e;
|
|
3337
3808
|
}
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
token
|
|
3343
|
-
}) => {
|
|
3344
|
-
const headers = new Headers();
|
|
3345
|
-
if (token) {
|
|
3346
|
-
headers.append("X-API-KEY", token);
|
|
3809
|
+
async catch(error) {
|
|
3810
|
+
logger.error("Error occured during tinacms init");
|
|
3811
|
+
console.error(error);
|
|
3812
|
+
process.exit(1);
|
|
3347
3813
|
}
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
headers,
|
|
3353
|
-
body
|
|
3354
|
-
});
|
|
3355
|
-
const data = await res.json();
|
|
3356
|
-
return data == null ? void 0 : data.data;
|
|
3357
|
-
};
|
|
3358
|
-
var checkGraphqlSchema = async (ctx, next, _options) => {
|
|
3359
|
-
var _a;
|
|
3360
|
-
const bar = new import_progress2.default(
|
|
3361
|
-
"Checking local GraphQL Schema matches server. :prog",
|
|
3362
|
-
1
|
|
3363
|
-
);
|
|
3364
|
-
const config2 = (_a = ctx.schema) == null ? void 0 : _a.config;
|
|
3365
|
-
const token = config2.token;
|
|
3366
|
-
const url = ctx.apiUrl;
|
|
3367
|
-
const remoteSchema = await fetchRemoteGraphqlSchema({
|
|
3368
|
-
url,
|
|
3369
|
-
token
|
|
3370
|
-
});
|
|
3371
|
-
const remoteGqlSchema = (0, import_graphql12.buildClientSchema)(remoteSchema);
|
|
3372
|
-
const localSchemaDocument = await ctx.database.getGraphQLSchemaFromBridge();
|
|
3373
|
-
const localGraphqlSchema = (0, import_graphql12.buildSchema)((0, import_graphql12.print)(localSchemaDocument));
|
|
3374
|
-
const diffResult = await (0, import_core2.diff)(localGraphqlSchema, remoteGqlSchema);
|
|
3375
|
-
if (diffResult.length === 0) {
|
|
3376
|
-
bar.tick({
|
|
3377
|
-
prog: "\u2705"
|
|
3378
|
-
});
|
|
3379
|
-
} else {
|
|
3380
|
-
bar.tick({
|
|
3381
|
-
prog: "\u274C"
|
|
3814
|
+
async execute() {
|
|
3815
|
+
await initStaticTina({
|
|
3816
|
+
rootPath: this.rootPath || process.cwd(),
|
|
3817
|
+
noTelemetry: this.noTelemetry
|
|
3382
3818
|
});
|
|
3383
|
-
|
|
3384
|
-
if (config2 == null ? void 0 : config2.branch) {
|
|
3385
|
-
errorMessage += `
|
|
3386
|
-
|
|
3387
|
-
Additional info: Branch: ${config2.branch}, Client ID: ${config2.clientId} `;
|
|
3388
|
-
}
|
|
3389
|
-
throw new Error(errorMessage);
|
|
3819
|
+
process.exit();
|
|
3390
3820
|
}
|
|
3391
|
-
next();
|
|
3392
|
-
};
|
|
3393
|
-
|
|
3394
|
-
// src/cmds/baseCmds.ts
|
|
3395
|
-
var CMD_START_SERVER = "server:start";
|
|
3396
|
-
var CMD_DEV = "dev";
|
|
3397
|
-
var INIT = "init";
|
|
3398
|
-
var AUDIT = "audit";
|
|
3399
|
-
var CMD_BUILD = "build";
|
|
3400
|
-
var startServerPortOption = {
|
|
3401
|
-
name: "--port <port>",
|
|
3402
|
-
description: "Specify a port to run the server on. (default 4001)"
|
|
3403
3821
|
};
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
name: "--experimentalData",
|
|
3410
|
-
description: "Build the server with additional data querying capabilities"
|
|
3411
|
-
};
|
|
3412
|
-
var isomorphicGitBridge = {
|
|
3413
|
-
name: "--isomorphicGitBridge",
|
|
3414
|
-
description: "Enable Isomorphic Git Bridge Implementation"
|
|
3415
|
-
};
|
|
3416
|
-
var schemaFileType = {
|
|
3417
|
-
name: "--schemaFileType [fileType]",
|
|
3418
|
-
description: "The file type to use for the Tina schema"
|
|
3419
|
-
};
|
|
3420
|
-
var subCommand = {
|
|
3421
|
-
name: "-c, --command <command>",
|
|
3422
|
-
description: "The sub-command to run"
|
|
3423
|
-
};
|
|
3424
|
-
var noWatchOption = {
|
|
3425
|
-
name: "--noWatch",
|
|
3426
|
-
description: "Don't regenerate config on file changes"
|
|
3427
|
-
};
|
|
3428
|
-
var noSDKCodegenOption = {
|
|
3429
|
-
name: "--noSDK",
|
|
3430
|
-
description: "Don't generate the generated client SDK"
|
|
3431
|
-
};
|
|
3432
|
-
var cleanOption = {
|
|
3433
|
-
name: "--clean",
|
|
3434
|
-
description: "Updates all content files to remove any data not explicitly permitted by the current schema definition"
|
|
3435
|
-
};
|
|
3436
|
-
var useDefaultValuesOption = {
|
|
3437
|
-
name: "--useDefaultValues",
|
|
3438
|
-
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`)"
|
|
3439
|
-
};
|
|
3440
|
-
var noTelemetryOption = {
|
|
3441
|
-
name: "--noTelemetry",
|
|
3442
|
-
description: "Disable anonymous telemetry that is collected"
|
|
3443
|
-
};
|
|
3444
|
-
var watchFileOption = {
|
|
3445
|
-
name: "-w, --watchFolders [folders...]",
|
|
3446
|
-
description: "a list of folders (relative to where this is being run) that the cli will watch for changes"
|
|
3447
|
-
};
|
|
3448
|
-
var verboseOption = {
|
|
3449
|
-
name: "-v, --verbose",
|
|
3450
|
-
description: "increase verbosity of logged output",
|
|
3451
|
-
defaultValue: false
|
|
3452
|
-
};
|
|
3453
|
-
var developmentOption = {
|
|
3454
|
-
name: "--dev",
|
|
3455
|
-
description: "Uses NODE_ENV=development when compiling client and schema"
|
|
3456
|
-
};
|
|
3457
|
-
var localOption = {
|
|
3458
|
-
name: "--local",
|
|
3459
|
-
description: "Uses the local file system graphql server",
|
|
3460
|
-
defaultValue: false
|
|
3461
|
-
};
|
|
3462
|
-
var checkOptions = async (_ctx, next, options) => {
|
|
3463
|
-
if (options == null ? void 0 : options.experimentalData) {
|
|
3464
|
-
logger.warn(
|
|
3465
|
-
warnText(
|
|
3466
|
-
"Warning: you are using the `--experimentalData`flag. This flag is not needed and can safely be removed. It will be deprecated in a future version"
|
|
3467
|
-
)
|
|
3468
|
-
);
|
|
3469
|
-
}
|
|
3470
|
-
next();
|
|
3471
|
-
};
|
|
3472
|
-
var baseCmds = [
|
|
3473
|
-
{
|
|
3474
|
-
command: CMD_START_SERVER,
|
|
3475
|
-
description: "Start Filesystem Graphql Server",
|
|
3476
|
-
options: [
|
|
3477
|
-
startServerPortOption,
|
|
3478
|
-
subCommand,
|
|
3479
|
-
experimentalDatalayer,
|
|
3480
|
-
isomorphicGitBridge,
|
|
3481
|
-
noWatchOption,
|
|
3482
|
-
noSDKCodegenOption,
|
|
3483
|
-
noTelemetryOption,
|
|
3484
|
-
watchFileOption,
|
|
3485
|
-
verboseOption,
|
|
3486
|
-
developmentOption,
|
|
3487
|
-
localOption
|
|
3488
|
-
],
|
|
3489
|
-
action: (options) => chain(
|
|
3490
|
-
[
|
|
3491
|
-
attachPath,
|
|
3492
|
-
attachDatabase,
|
|
3493
|
-
async (ctx, next, _2) => {
|
|
3494
|
-
logger.warn(
|
|
3495
|
-
warnText(
|
|
3496
|
-
"server:start will be deprecated in the future, please use `tinacms dev` instead"
|
|
3497
|
-
)
|
|
3498
|
-
);
|
|
3499
|
-
next();
|
|
3500
|
-
},
|
|
3501
|
-
checkOptions,
|
|
3502
|
-
buildSetupCmdServerStart,
|
|
3503
|
-
startServer,
|
|
3504
|
-
startSubprocess
|
|
3505
|
-
],
|
|
3506
|
-
options
|
|
3507
|
-
)
|
|
3508
|
-
},
|
|
3509
|
-
{
|
|
3510
|
-
command: CMD_DEV,
|
|
3511
|
-
description: "Builds tina and starts the dev server.",
|
|
3512
|
-
options: [
|
|
3513
|
-
startServerPortOption,
|
|
3514
|
-
subCommand,
|
|
3515
|
-
isomorphicGitBridge,
|
|
3516
|
-
noWatchOption,
|
|
3517
|
-
noSDKCodegenOption,
|
|
3518
|
-
noTelemetryOption,
|
|
3519
|
-
watchFileOption,
|
|
3520
|
-
verboseOption,
|
|
3521
|
-
rootPathOption
|
|
3522
|
-
],
|
|
3523
|
-
action: (options) => chain(
|
|
3524
|
-
[
|
|
3525
|
-
attachPath,
|
|
3526
|
-
attachDatabase,
|
|
3527
|
-
checkOptions,
|
|
3528
|
-
buildSetupCmdServerStart,
|
|
3529
|
-
startServer,
|
|
3530
|
-
startSubprocess
|
|
3531
|
-
],
|
|
3532
|
-
options
|
|
3533
|
-
)
|
|
3534
|
-
},
|
|
3535
|
-
{
|
|
3536
|
-
command: CMD_BUILD,
|
|
3537
|
-
description: "Build Tina",
|
|
3538
|
-
options: [
|
|
3539
|
-
experimentalDatalayer,
|
|
3540
|
-
isomorphicGitBridge,
|
|
3541
|
-
noSDKCodegenOption,
|
|
3542
|
-
noTelemetryOption,
|
|
3543
|
-
verboseOption,
|
|
3544
|
-
developmentOption,
|
|
3545
|
-
localOption,
|
|
3546
|
-
rootPathOption
|
|
3547
|
-
],
|
|
3548
|
-
action: (options) => chain(
|
|
3549
|
-
[
|
|
3550
|
-
attachPath,
|
|
3551
|
-
attachDatabase,
|
|
3552
|
-
checkOptions,
|
|
3553
|
-
buildSetupCmdBuild,
|
|
3554
|
-
buildCmdBuild,
|
|
3555
|
-
checkClientInfo,
|
|
3556
|
-
waitForDB,
|
|
3557
|
-
checkGraphqlSchema,
|
|
3558
|
-
indexIntoSelfHostedDatabase
|
|
3559
|
-
],
|
|
3560
|
-
options
|
|
3561
|
-
)
|
|
3562
|
-
},
|
|
3563
|
-
{
|
|
3564
|
-
command: INIT,
|
|
3565
|
-
options: [
|
|
3566
|
-
rootPathOption,
|
|
3567
|
-
experimentalDatalayer,
|
|
3568
|
-
isomorphicGitBridge,
|
|
3569
|
-
noTelemetryOption,
|
|
3570
|
-
schemaFileType
|
|
3571
|
-
],
|
|
3572
|
-
description: "Add Tina Cloud to an existing project",
|
|
3573
|
-
action: (options) => {
|
|
3574
|
-
chain([attachPath, checkOptions, initStaticTina], options);
|
|
3575
|
-
}
|
|
3576
|
-
},
|
|
3577
|
-
{
|
|
3578
|
-
options: [
|
|
3579
|
-
rootPathOption,
|
|
3580
|
-
cleanOption,
|
|
3581
|
-
useDefaultValuesOption,
|
|
3582
|
-
noTelemetryOption,
|
|
3583
|
-
verboseOption
|
|
3584
|
-
],
|
|
3585
|
-
command: AUDIT,
|
|
3586
|
-
description: "Audit your schema and the files to check for errors",
|
|
3587
|
-
action: (options) => chain(
|
|
3588
|
-
[
|
|
3589
|
-
attachPath,
|
|
3590
|
-
buildSetupCmdAudit,
|
|
3591
|
-
auditCmdBuild,
|
|
3592
|
-
async (_ctx, next) => {
|
|
3593
|
-
logger.level = "info";
|
|
3594
|
-
logger.info(
|
|
3595
|
-
import_chalk4.default.hex("#eb6337").bgWhite("Welcome to tina audit \u{1F999}")
|
|
3596
|
-
);
|
|
3597
|
-
next();
|
|
3598
|
-
},
|
|
3599
|
-
audit,
|
|
3600
|
-
printFinalMessage
|
|
3601
|
-
],
|
|
3602
|
-
options
|
|
3603
|
-
)
|
|
3604
|
-
}
|
|
3605
|
-
];
|
|
3822
|
+
InitCommand.paths = [["init"]];
|
|
3823
|
+
InitCommand.usage = import_clipanion4.Command.Usage({
|
|
3824
|
+
category: `Commands`,
|
|
3825
|
+
description: `Add Tina to an existing project`
|
|
3826
|
+
});
|
|
3606
3827
|
|
|
3607
3828
|
// src/index.ts
|
|
3608
|
-
var
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
command.action(...args);
|
|
3613
|
-
});
|
|
3614
|
-
if (command.alias) {
|
|
3615
|
-
newCmd = newCmd.alias(command.alias);
|
|
3616
|
-
}
|
|
3617
|
-
newCmd.on("--help", function() {
|
|
3618
|
-
if (command.examples) {
|
|
3619
|
-
logger.info(`
|
|
3620
|
-
Examples:
|
|
3621
|
-
${command.examples}`);
|
|
3622
|
-
}
|
|
3623
|
-
if (command.subCommands) {
|
|
3624
|
-
logger.info("\nCommands:");
|
|
3625
|
-
const optionTag = " [options]";
|
|
3626
|
-
command.subCommands.forEach((subcommand, i2) => {
|
|
3627
|
-
const commandStr = `${subcommand.command}${(subcommand.options || []).length ? optionTag : ""}`;
|
|
3628
|
-
const padLength = Math.max(...command.subCommands.map((sub) => sub.command.length)) + optionTag.length;
|
|
3629
|
-
logger.info(
|
|
3630
|
-
`${commandStr.padEnd(padLength)} ${subcommand.description}`
|
|
3631
|
-
);
|
|
3632
|
-
});
|
|
3633
|
-
}
|
|
3634
|
-
logger.info("");
|
|
3635
|
-
});
|
|
3636
|
-
(command.options || []).forEach((option) => {
|
|
3637
|
-
newCmd.option(option.name, option.description, option == null ? void 0 : option.defaultValue);
|
|
3638
|
-
});
|
|
3639
|
-
if (command.subCommands) {
|
|
3640
|
-
registerCommands(command.subCommands, true);
|
|
3641
|
-
}
|
|
3642
|
-
});
|
|
3643
|
-
};
|
|
3644
|
-
async function init(args) {
|
|
3645
|
-
program.version(version);
|
|
3646
|
-
const commands = [...baseCmds];
|
|
3647
|
-
registerCommands(commands);
|
|
3648
|
-
program.usage("command [options]");
|
|
3649
|
-
program.on("command:*", function() {
|
|
3650
|
-
logger.error(
|
|
3651
|
-
"Invalid command: %s\nSee --help for a list of available commands.",
|
|
3652
|
-
args.join(" ")
|
|
3653
|
-
);
|
|
3654
|
-
process.exit(1);
|
|
3655
|
-
});
|
|
3656
|
-
program.on("--help", function() {
|
|
3657
|
-
logger.info(
|
|
3658
|
-
logText(`
|
|
3659
|
-
You can get help on any command with "-h" or "--help".
|
|
3660
|
-
e.g: "tinacms server:start --help"
|
|
3661
|
-
`)
|
|
3662
|
-
);
|
|
3663
|
-
});
|
|
3664
|
-
if (!process.argv.slice(2).length) {
|
|
3665
|
-
program.help();
|
|
3666
|
-
}
|
|
3667
|
-
program.parse(args);
|
|
3668
|
-
}
|
|
3669
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
3670
|
-
0 && (module.exports = {
|
|
3671
|
-
defineSchema,
|
|
3672
|
-
init
|
|
3829
|
+
var cli = new import_clipanion5.Cli({
|
|
3830
|
+
binaryName: `tinacms`,
|
|
3831
|
+
binaryLabel: `TinaCMS`,
|
|
3832
|
+
binaryVersion: version
|
|
3673
3833
|
});
|
|
3834
|
+
cli.register(DevCommand);
|
|
3835
|
+
cli.register(BuildCommand);
|
|
3836
|
+
cli.register(AuditCommand);
|
|
3837
|
+
cli.register(InitCommand);
|
|
3838
|
+
cli.register(import_clipanion5.Builtins.DefinitionsCommand);
|
|
3839
|
+
cli.register(import_clipanion5.Builtins.HelpCommand);
|
|
3840
|
+
cli.register(import_clipanion5.Builtins.VersionCommand);
|
|
3841
|
+
var src_default = cli;
|
|
3842
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3843
|
+
0 && (module.exports = {});
|