@tinacms/scripts 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tina-build +3 -1
- package/dist/index.js +396 -355
- package/package.json +5 -1
package/bin/tina-build
CHANGED
package/dist/index.js
CHANGED
|
@@ -55,22 +55,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
55
55
|
// src/index.ts
|
|
56
56
|
var index_exports = {};
|
|
57
57
|
__export(index_exports, {
|
|
58
|
-
|
|
59
|
-
init: () => init,
|
|
60
|
-
run: () => run,
|
|
61
|
-
sequential: () => sequential
|
|
58
|
+
BuildTina: () => BuildTina
|
|
62
59
|
});
|
|
63
60
|
module.exports = __toCommonJS(index_exports);
|
|
64
|
-
var
|
|
65
|
-
var import_esbuild = require("esbuild");
|
|
66
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
67
|
-
var import_node_path = __toESM(require("path"));
|
|
68
|
-
var import_chokidar = __toESM(require("chokidar"));
|
|
61
|
+
var fs = __toESM(require("fs"));
|
|
69
62
|
var import_node_child_process = require("child_process");
|
|
63
|
+
var import_node_path = __toESM(require("path"));
|
|
70
64
|
var import_chalk = __toESM(require("chalk"));
|
|
65
|
+
var import_chokidar = __toESM(require("chokidar"));
|
|
66
|
+
var import_commander = __toESM(require("commander"));
|
|
67
|
+
var import_esbuild = require("esbuild");
|
|
68
|
+
var import_fs_extra = require("fs-extra");
|
|
71
69
|
var import_json_diff = __toESM(require("json-diff"));
|
|
72
|
-
var
|
|
73
|
-
|
|
70
|
+
var import_vite = require("vite");
|
|
71
|
+
|
|
72
|
+
// src/utils.ts
|
|
73
|
+
function deepMerge(target, source) {
|
|
74
74
|
for (const key in source) {
|
|
75
75
|
if (!source.hasOwnProperty(key) || key === "__proto__" || key === "constructor")
|
|
76
76
|
continue;
|
|
@@ -85,203 +85,255 @@ var deepMerge = (target, source) => {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
return target;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
}
|
|
89
|
+
async function sequential(items, callback) {
|
|
90
|
+
const accum = [];
|
|
91
|
+
if (!items) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const reducePromises = async (previous, endpoint) => {
|
|
95
|
+
const prev = await previous;
|
|
96
|
+
if (prev) accum.push(prev);
|
|
97
|
+
return callback(endpoint, accum.length);
|
|
98
|
+
};
|
|
99
|
+
const result = await items.reduce(reducePromises, Promise.resolve());
|
|
100
|
+
if (result) {
|
|
101
|
+
accum.push(result);
|
|
102
|
+
}
|
|
103
|
+
return accum;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/index.ts
|
|
107
|
+
var BuildTina = class {
|
|
108
|
+
constructor(name) {
|
|
109
|
+
this.program = new import_commander.default.Command(name);
|
|
110
|
+
}
|
|
111
|
+
registerCommands(commands, noHelp = false) {
|
|
112
|
+
for (const command of commands) {
|
|
113
|
+
const options = command.options || [];
|
|
114
|
+
let newCmd = this.program.command(command.command, { hidden: noHelp }).description(command.description).action((...args) => {
|
|
115
|
+
command.action(...args);
|
|
116
|
+
});
|
|
117
|
+
if (command.alias) {
|
|
118
|
+
newCmd = newCmd.alias(command.alias);
|
|
119
|
+
}
|
|
120
|
+
newCmd.on("--help", () => {
|
|
121
|
+
if (command.examples) console.log(`
|
|
101
122
|
Examples:
|
|
102
123
|
${command.examples}`);
|
|
124
|
+
if (command.subCommands) {
|
|
125
|
+
console.log("\nCommands:");
|
|
126
|
+
const optionTag = " [options]";
|
|
127
|
+
for (const subcommand of command.subCommands) {
|
|
128
|
+
const commandStr = `${subcommand.command}${options.length ? optionTag : ""}`;
|
|
129
|
+
const padLength = Math.max(
|
|
130
|
+
...command.subCommands.map((sub) => sub.command.length)
|
|
131
|
+
) + optionTag.length;
|
|
132
|
+
console.log(
|
|
133
|
+
`${commandStr.padEnd(padLength)} ${subcommand.description}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
console.log("");
|
|
138
|
+
});
|
|
139
|
+
for (const option of options) {
|
|
140
|
+
newCmd.option(option.name, option.description);
|
|
103
141
|
}
|
|
104
|
-
if (command.subCommands)
|
|
105
|
-
console.log("\nCommands:");
|
|
106
|
-
const optionTag = " [options]";
|
|
107
|
-
command.subCommands.forEach((subcommand, i2) => {
|
|
108
|
-
const commandStr = `${subcommand.command}${(subcommand.options || []).length ? optionTag : ""}`;
|
|
109
|
-
const padLength = Math.max(...command.subCommands.map((sub) => sub.command.length)) + optionTag.length;
|
|
110
|
-
console.log(
|
|
111
|
-
`${commandStr.padEnd(padLength)} ${subcommand.description}`
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
console.log("");
|
|
116
|
-
});
|
|
117
|
-
(command.options || []).forEach((option) => {
|
|
118
|
-
newCmd.option(option.name, option.description);
|
|
119
|
-
});
|
|
120
|
-
if (command.subCommands) {
|
|
121
|
-
registerCommands(command.subCommands, true);
|
|
142
|
+
if (command.subCommands) this.registerCommands(command.subCommands, true);
|
|
122
143
|
}
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
var run = async (args) => {
|
|
126
|
-
var _a;
|
|
127
|
-
if (args.dir) {
|
|
128
|
-
process.chdir(args.dir);
|
|
129
|
-
}
|
|
130
|
-
const packageDir = process.cwd();
|
|
131
|
-
const packageJSON = JSON.parse(
|
|
132
|
-
await import_fs_extra.default.readFileSync(import_node_path.default.join(packageDir, "package.json")).toString()
|
|
133
|
-
);
|
|
134
|
-
if (["@tinacms/scripts", "@tinacms/webpack-helpers"].includes(packageJSON.name)) {
|
|
135
|
-
console.log(`skipping ${packageJSON.name}`);
|
|
136
|
-
return;
|
|
137
144
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
async run(args) {
|
|
146
|
+
var _a;
|
|
147
|
+
if (args.dir) process.chdir(args.dir);
|
|
148
|
+
let packageJson = null;
|
|
149
|
+
try {
|
|
150
|
+
const packageJsonContent = fs.readFileSync(
|
|
151
|
+
import_node_path.default.join(process.cwd(), "package.json")
|
|
152
|
+
);
|
|
153
|
+
packageJson = JSON.parse(packageJsonContent.toString());
|
|
154
|
+
} catch (err) {
|
|
155
|
+
const error = err;
|
|
156
|
+
console.error(`Failed to parse package.json: ${error.message}`);
|
|
157
|
+
process.exit(1);
|
|
147
158
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
var watch = () => {
|
|
154
|
-
(0, import_node_child_process.exec)("pnpm list -r --json", (error, stdout, stderr) => {
|
|
155
|
-
if (error) {
|
|
156
|
-
console.error(`exec error: ${error}`);
|
|
159
|
+
if (["@tinacms/scripts", "@tinacms/webpack-helpers"].includes(
|
|
160
|
+
packageJson.name
|
|
161
|
+
)) {
|
|
162
|
+
console.info(`Skipping ${packageJson.name}`);
|
|
157
163
|
return;
|
|
158
164
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
const successMessage = `${import_chalk.default.blue(`${packageJson.name}`)} built in`;
|
|
166
|
+
console.time(successMessage);
|
|
167
|
+
const entries = ((_a = packageJson.buildConfig) == null ? void 0 : _a.entryPoints.map(
|
|
168
|
+
(ep) => {
|
|
169
|
+
if (typeof ep === "string") {
|
|
170
|
+
return { name: ep, target: "browser" };
|
|
171
|
+
}
|
|
172
|
+
return ep;
|
|
164
173
|
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!import_fs_extra.default.existsSync(`tina/tina-lock.json`)) {
|
|
177
|
-
console.error(
|
|
178
|
-
"No Tina lock found. Please run this command from the root of a Tina project \u274C"
|
|
179
|
-
);
|
|
180
|
-
process.exit(1);
|
|
174
|
+
)) || [{ name: "src/index.ts", target: "browser" }];
|
|
175
|
+
try {
|
|
176
|
+
await sequential(entries, async (entry) => {
|
|
177
|
+
return this.buildPackage(entry, packageJson);
|
|
178
|
+
});
|
|
179
|
+
if (args.dir) console.timeEnd(successMessage);
|
|
180
|
+
} catch (err) {
|
|
181
|
+
const error = err;
|
|
182
|
+
console.error(`Failed to build ${packageJson.name}: ${error.message}`);
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
181
185
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
watch() {
|
|
187
|
+
try {
|
|
188
|
+
(0, import_node_child_process.exec)("pnpm list -r --json", (error, stdout) => {
|
|
189
|
+
if (error) {
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
const json = JSON.parse(stdout);
|
|
193
|
+
const watchPaths = [];
|
|
194
|
+
for (const pkg of json) {
|
|
195
|
+
const pkgPath = "packages";
|
|
196
|
+
if (pkg.path.includes(pkgPath)) watchPaths.push(pkg.path);
|
|
197
|
+
}
|
|
198
|
+
import_chokidar.default.watch(
|
|
199
|
+
watchPaths.map((p) => import_node_path.default.join(p, "src", "**/*")),
|
|
200
|
+
{ ignored: ["**/spec/**/*", "node_modules"] }
|
|
201
|
+
).on("change", async (path2) => {
|
|
202
|
+
const changedPackagePath = watchPaths.find(
|
|
203
|
+
(p) => path2.startsWith(p)
|
|
204
|
+
);
|
|
205
|
+
await this.run({ dir: changedPackagePath });
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
} catch (err) {
|
|
209
|
+
const error = err;
|
|
210
|
+
console.error(`Failed to exec watch command: ${error.message}`);
|
|
211
|
+
process.exit(1);
|
|
212
|
+
}
|
|
188
213
|
}
|
|
189
|
-
(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (error) {
|
|
194
|
-
console.error(`exec error: ${error} \u274C`);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (stdout) {
|
|
198
|
-
console.log(
|
|
199
|
-
stdout.split("\n").map((line) => `> ${line}`).join("\n")
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
if (stderr) {
|
|
203
|
-
console.error(`stderr: ${stderr}`);
|
|
204
|
-
}
|
|
205
|
-
const newTinaLock = JSON.parse(
|
|
206
|
-
import_fs_extra.default.readFileSync(`tina/tina-lock.json`).toString()
|
|
214
|
+
diffTinaLock() {
|
|
215
|
+
if (!fs.existsSync(`tina/tina-lock.json`)) {
|
|
216
|
+
console.error(
|
|
217
|
+
"No Tina lock found. Please run this command from the root of a Tina project \u274C"
|
|
207
218
|
);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
const schemaDiff = import_json_diff.default.diffString(schema, newSchema);
|
|
215
|
-
if (schemaDiff) {
|
|
216
|
-
console.error("Unexpected change(s) to Tina schema \u274C");
|
|
217
|
-
console.log(schemaDiff);
|
|
218
|
-
process.exit(1);
|
|
219
|
-
}
|
|
220
|
-
const graphqlDiff = import_json_diff.default.diffString(
|
|
221
|
-
tinaLock.graphql,
|
|
222
|
-
newTinaLock.graphql
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
let tinaLock = null;
|
|
222
|
+
try {
|
|
223
|
+
const tinaLockContent = fs.readFileSync(
|
|
224
|
+
"tina/tina-lock.json"
|
|
223
225
|
);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
process.exit(1);
|
|
226
|
+
tinaLock = JSON.parse(tinaLockContent.toString());
|
|
227
|
+
if (!tinaLock.schema) {
|
|
228
|
+
throw new Error("No schema found in the Tina lock \u274C");
|
|
228
229
|
}
|
|
229
|
-
|
|
230
|
+
} catch (err) {
|
|
231
|
+
const error = err;
|
|
232
|
+
console.error(`Failed to parse tina/tina-lock.json: ${error.message}`);
|
|
233
|
+
process.exit(1);
|
|
230
234
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
235
|
+
try {
|
|
236
|
+
(0, import_node_child_process.exec)(
|
|
237
|
+
"pnpm exec tinacms dev --no-server",
|
|
238
|
+
{ cwd: process.cwd() },
|
|
239
|
+
(error, stdout, stderr) => {
|
|
240
|
+
if (error) {
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
if (stderr) {
|
|
244
|
+
throw new Error(stderr);
|
|
245
|
+
}
|
|
246
|
+
if (stdout) {
|
|
247
|
+
console.log(
|
|
248
|
+
stdout.split("\n").map((line) => `> ${line}`).join("\n")
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
let newTinaLock = null;
|
|
252
|
+
try {
|
|
253
|
+
const newTinaLockContent = fs.readFileSync(
|
|
254
|
+
"tina/tina-lock.json"
|
|
255
|
+
);
|
|
256
|
+
newTinaLock = JSON.parse(newTinaLockContent.toString());
|
|
257
|
+
if (!newTinaLock.schema) {
|
|
258
|
+
throw new Error("No schema found in the new Tina lock \u274C");
|
|
259
|
+
}
|
|
260
|
+
} catch (err) {
|
|
261
|
+
const error2 = err;
|
|
262
|
+
console.error(
|
|
263
|
+
`Failed to parse tina/tina-lock.json: ${error2.message}`
|
|
264
|
+
);
|
|
265
|
+
throw error2;
|
|
266
|
+
}
|
|
267
|
+
const _a = tinaLock.schema, { version } = _a, schema = __objRest(_a, ["version"]);
|
|
268
|
+
const _b = newTinaLock.schema, { version: newVersion } = _b, newSchema = __objRest(_b, ["version"]);
|
|
269
|
+
const schemaDiff = import_json_diff.default.diffString(schema, newSchema);
|
|
270
|
+
if (schemaDiff) {
|
|
271
|
+
console.error("Unexpected change(s) to Tina schema \u274C");
|
|
272
|
+
console.error(schemaDiff);
|
|
273
|
+
throw new Error("Unexpected change(s) to Tina schema \u274C");
|
|
274
|
+
}
|
|
275
|
+
const graphqlDiff = import_json_diff.default.diffString(
|
|
276
|
+
tinaLock.graphql,
|
|
277
|
+
newTinaLock.graphql
|
|
278
|
+
);
|
|
279
|
+
if (graphqlDiff) {
|
|
280
|
+
console.error("Unexpected change(s) to Tina graphql schema \u274C");
|
|
281
|
+
console.error(graphqlDiff);
|
|
282
|
+
throw new Error("Unexpected change(s) to Tina grahpql schema \u274C");
|
|
283
|
+
}
|
|
284
|
+
console.log("No changes found in Tina lock \u2705");
|
|
242
285
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
description: "Watch",
|
|
249
|
-
action: () => watch()
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
command: "diff-tina-lock",
|
|
253
|
-
description: "Compare the current schema for a tina project with newly generated schema",
|
|
254
|
-
action: () => diffTinaLock()
|
|
286
|
+
);
|
|
287
|
+
} catch (err) {
|
|
288
|
+
const error = err;
|
|
289
|
+
console.error(`Failed to start dev server: ${error.message}`);
|
|
290
|
+
process.exit(1);
|
|
255
291
|
}
|
|
256
|
-
]);
|
|
257
|
-
program.usage("command [options]");
|
|
258
|
-
program.on("command:*", function() {
|
|
259
|
-
console.error(
|
|
260
|
-
"Invalid command: %s\nSee --help for a list of available commands.",
|
|
261
|
-
args.join(" ")
|
|
262
|
-
);
|
|
263
|
-
process.exit(1);
|
|
264
|
-
});
|
|
265
|
-
program.on("--help", function() {
|
|
266
|
-
console.log(`
|
|
267
|
-
You can get help on any command with "-h" or "--help".
|
|
268
|
-
e.g: "forestry types:gen --help"
|
|
269
|
-
`);
|
|
270
|
-
});
|
|
271
|
-
if (!process.argv.slice(2).length) {
|
|
272
|
-
program.help();
|
|
273
292
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
293
|
+
init(args) {
|
|
294
|
+
this.registerCommands([
|
|
295
|
+
{
|
|
296
|
+
command: "build",
|
|
297
|
+
description: "Build",
|
|
298
|
+
options: [
|
|
299
|
+
{
|
|
300
|
+
name: "--watch",
|
|
301
|
+
description: "Watch for file changes and rebuild"
|
|
302
|
+
}
|
|
303
|
+
],
|
|
304
|
+
action: (options) => this.run(options)
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
command: "watch",
|
|
308
|
+
description: "Watch",
|
|
309
|
+
action: () => this.watch()
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
command: "diff-tina-lock",
|
|
313
|
+
description: "Compare the current schema for a tina project with newly generated schema",
|
|
314
|
+
action: () => this.diffTinaLock()
|
|
315
|
+
}
|
|
316
|
+
]);
|
|
317
|
+
this.program.usage("command [options]");
|
|
318
|
+
this.program.on("command:*", function() {
|
|
319
|
+
console.error(
|
|
320
|
+
`Invalid command: ${args.join(" ")}
|
|
321
|
+
See --help for a list of available commands.`
|
|
322
|
+
);
|
|
323
|
+
process.exit(1);
|
|
324
|
+
});
|
|
325
|
+
this.program.on("--help", function() {
|
|
326
|
+
console.log(
|
|
327
|
+
'You can get help on any command with "-h" or "--help".\ne.g: "forestry types:gen --help"'
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
if (!process.argv.slice(2).length) {
|
|
331
|
+
this.program.help();
|
|
332
|
+
}
|
|
333
|
+
this.program.parse(args);
|
|
334
|
+
}
|
|
335
|
+
getOutputPaths(entry) {
|
|
336
|
+
const { dir, name } = import_node_path.default.parse(entry);
|
|
285
337
|
const outdir = dir.replace("src", "dist");
|
|
286
338
|
const outfile = name;
|
|
287
339
|
const relativeOutfile = import_node_path.default.join(
|
|
@@ -290,181 +342,170 @@ var buildIt = async (entryPoint, packageJSON) => {
|
|
|
290
342
|
name
|
|
291
343
|
);
|
|
292
344
|
return { outdir, outfile, relativeOutfile };
|
|
293
|
-
};
|
|
294
|
-
const outInfo = out(entry);
|
|
295
|
-
if (["@tinacms/app"].includes(packageJSON.name)) {
|
|
296
|
-
console.log("skipping @tinacms/app");
|
|
297
|
-
return;
|
|
298
345
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
await (0, import_esbuild.build)({
|
|
303
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
304
|
-
bundle: true,
|
|
305
|
-
platform: "node",
|
|
306
|
-
// FIXME: no idea why but even though I'm on node14 it doesn't like
|
|
307
|
-
// the syntax for optional chaining, should be supported on 14
|
|
308
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
|
|
309
|
-
target: "node12",
|
|
310
|
-
// Use the outfile if it is provided
|
|
311
|
-
outfile: outInfo.outfile ? import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.js`) : import_node_path.default.join(process.cwd(), "dist", "index.js"),
|
|
312
|
-
external: external.filter(
|
|
313
|
-
(item) => !packageJSON.buildConfig.entryPoints[0].bundle.includes(item)
|
|
314
|
-
)
|
|
315
|
-
});
|
|
316
|
-
await (0, import_esbuild.build)({
|
|
317
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
318
|
-
bundle: true,
|
|
319
|
-
platform: "node",
|
|
320
|
-
target: "es2020",
|
|
321
|
-
format: "esm",
|
|
322
|
-
outfile: outInfo.outfile ? import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.mjs`) : import_node_path.default.join(process.cwd(), "dist", "index.mjs"),
|
|
323
|
-
external
|
|
324
|
-
});
|
|
325
|
-
} else if (["@tinacms/mdx"].includes(packageJSON.name)) {
|
|
326
|
-
const peerDeps2 = packageJSON.peerDependencies;
|
|
327
|
-
await (0, import_esbuild.build)({
|
|
328
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
329
|
-
bundle: true,
|
|
330
|
-
platform: "node",
|
|
331
|
-
// FIXME: no idea why but even though I'm on node14 it doesn't like
|
|
332
|
-
// the syntax for optional chaining, should be supported on 14
|
|
333
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
|
|
334
|
-
target: "node12",
|
|
335
|
-
format: "cjs",
|
|
336
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", "index.js"),
|
|
337
|
-
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
338
|
-
});
|
|
339
|
-
await (0, import_esbuild.build)({
|
|
340
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
341
|
-
bundle: true,
|
|
342
|
-
platform: "node",
|
|
343
|
-
target: "es2020",
|
|
344
|
-
format: "esm",
|
|
345
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", "index.mjs"),
|
|
346
|
-
// Bundle dependencies, the remark ecosystem only publishes ES modules
|
|
347
|
-
// and includes "development" export maps which actually throw errors during
|
|
348
|
-
// development, which we don't want to expose our users to.
|
|
349
|
-
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
350
|
-
});
|
|
351
|
-
await (0, import_esbuild.build)({
|
|
352
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
353
|
-
bundle: true,
|
|
354
|
-
platform: "browser",
|
|
355
|
-
target: "es2020",
|
|
356
|
-
format: "esm",
|
|
357
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", "index.browser.mjs"),
|
|
358
|
-
// Bundle dependencies, the remark ecosystem only publishes ES modules
|
|
359
|
-
// and includes "development" export maps which actually throw errors during
|
|
360
|
-
// development, which we don't want to expose our users to.
|
|
361
|
-
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
362
|
-
});
|
|
363
|
-
} else {
|
|
364
|
-
await (0, import_esbuild.build)({
|
|
365
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
366
|
-
bundle: true,
|
|
367
|
-
platform: "node",
|
|
368
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.js`),
|
|
369
|
-
external,
|
|
370
|
-
target: "node12"
|
|
371
|
-
});
|
|
372
|
-
}
|
|
346
|
+
async buildPackage(entryPoint, packageJSON) {
|
|
347
|
+
const entry = entryPoint.name;
|
|
348
|
+
const target = entryPoint.target;
|
|
373
349
|
const extension = import_node_path.default.extname(entry);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
350
|
+
const deps = packageJSON.dependencies;
|
|
351
|
+
const peerDeps = packageJSON.peerDependencies;
|
|
352
|
+
const external = Object.keys(__spreadValues(__spreadValues({}, deps), peerDeps));
|
|
353
|
+
const outInfo = this.getOutputPaths(entry);
|
|
354
|
+
const globals = {};
|
|
355
|
+
if (["@tinacms/app"].includes(packageJSON.name)) {
|
|
356
|
+
console.log("skipping @tinacms/app");
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
external.forEach((ext) => globals[ext] = "NOOP");
|
|
360
|
+
if (target === "node") {
|
|
361
|
+
if (["@tinacms/graphql", "@tinacms/datalayer"].includes(packageJSON.name)) {
|
|
362
|
+
await (0, import_esbuild.build)({
|
|
363
|
+
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
364
|
+
bundle: true,
|
|
365
|
+
platform: "node",
|
|
366
|
+
target: "node20",
|
|
367
|
+
outfile: import_node_path.default.join(
|
|
368
|
+
process.cwd(),
|
|
369
|
+
"dist",
|
|
370
|
+
`${outInfo.outfile ? outInfo.outfile : "index"}.js`
|
|
371
|
+
),
|
|
372
|
+
external: external.filter((item) => {
|
|
373
|
+
const entryPoint2 = packageJSON.buildConfig.entryPoints[0];
|
|
374
|
+
if (typeof entryPoint2 === "string") return false;
|
|
375
|
+
return !entryPoint2.bundle.includes(item);
|
|
376
|
+
})
|
|
377
|
+
});
|
|
378
|
+
await (0, import_esbuild.build)({
|
|
379
|
+
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
380
|
+
bundle: true,
|
|
381
|
+
platform: "node",
|
|
382
|
+
target: "es2020",
|
|
383
|
+
format: "esm",
|
|
384
|
+
outfile: import_node_path.default.join(
|
|
385
|
+
process.cwd(),
|
|
386
|
+
"dist",
|
|
387
|
+
`${outInfo.outfile ? outInfo.outfile : "index"}.mjs`
|
|
388
|
+
),
|
|
389
|
+
external
|
|
390
|
+
});
|
|
391
|
+
} else if (["@tinacms/mdx"].includes(packageJSON.name)) {
|
|
392
|
+
const peerDeps2 = packageJSON.peerDependencies;
|
|
393
|
+
await (0, import_esbuild.build)({
|
|
394
|
+
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
395
|
+
bundle: true,
|
|
396
|
+
platform: "node",
|
|
397
|
+
target: "node20",
|
|
398
|
+
format: "cjs",
|
|
399
|
+
outfile: import_node_path.default.join(process.cwd(), "dist", "index.js"),
|
|
400
|
+
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
401
|
+
});
|
|
402
|
+
await (0, import_esbuild.build)({
|
|
403
|
+
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
404
|
+
bundle: true,
|
|
405
|
+
platform: "node",
|
|
406
|
+
target: "es2020",
|
|
407
|
+
format: "esm",
|
|
408
|
+
outfile: import_node_path.default.join(process.cwd(), "dist", "index.mjs"),
|
|
409
|
+
// Bundle dependencies, the remark ecosystem only publishes ES modules
|
|
410
|
+
// and includes "development" export maps which actually throw errors during
|
|
411
|
+
// development, which we don't want to expose our users to.
|
|
412
|
+
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
413
|
+
});
|
|
414
|
+
await (0, import_esbuild.build)({
|
|
415
|
+
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
416
|
+
bundle: true,
|
|
417
|
+
platform: "browser",
|
|
418
|
+
target: "es2020",
|
|
419
|
+
format: "esm",
|
|
420
|
+
outfile: import_node_path.default.join(process.cwd(), "dist", "index.browser.mjs"),
|
|
421
|
+
// Bundle dependencies, the remark ecosystem only publishes ES modules
|
|
422
|
+
// and includes "development" export maps which actually throw errors during
|
|
423
|
+
// development, which we don't want to expose our users to.
|
|
424
|
+
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
425
|
+
});
|
|
426
|
+
} else {
|
|
427
|
+
await (0, import_esbuild.build)({
|
|
428
|
+
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
429
|
+
bundle: true,
|
|
430
|
+
platform: "node",
|
|
431
|
+
target: "node20",
|
|
432
|
+
outfile: import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.js`),
|
|
433
|
+
external
|
|
434
|
+
});
|
|
389
435
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
436
|
+
fs.writeFileSync(
|
|
437
|
+
import_node_path.default.join(
|
|
438
|
+
process.cwd(),
|
|
439
|
+
"dist",
|
|
440
|
+
entry.replace("src/", "").replace(extension, ".d.ts")
|
|
441
|
+
),
|
|
442
|
+
`export * from "../${entry.replace(extension, "")}"`
|
|
443
|
+
);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
const defaultBuildConfig = {
|
|
447
|
+
resolve: {
|
|
448
|
+
alias: {
|
|
449
|
+
"@toolkit": import_node_path.default.resolve(process.cwd(), "src/toolkit"),
|
|
450
|
+
"@tinacms/toolkit": import_node_path.default.resolve(
|
|
451
|
+
process.cwd(),
|
|
452
|
+
"src/toolkit/index.ts"
|
|
453
|
+
)
|
|
399
454
|
}
|
|
400
455
|
},
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return;
|
|
456
|
+
build: {
|
|
457
|
+
minify: false,
|
|
458
|
+
assetsInlineLimit: 0,
|
|
459
|
+
lib: {
|
|
460
|
+
entry: import_node_path.default.resolve(process.cwd(), entry),
|
|
461
|
+
name: packageJSON.name,
|
|
462
|
+
fileName: (format) => {
|
|
463
|
+
return format === "umd" ? `${outInfo.outfile}.js` : `${outInfo.outfile}.mjs`;
|
|
410
464
|
}
|
|
411
|
-
warn(warning);
|
|
412
465
|
},
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
//
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
466
|
+
outDir: outInfo.outdir,
|
|
467
|
+
emptyOutDir: false,
|
|
468
|
+
// We build multiple files in to the dir.
|
|
469
|
+
sourcemap: false,
|
|
470
|
+
rollupOptions: {
|
|
471
|
+
onwarn(warning, warn) {
|
|
472
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
warn(warning);
|
|
476
|
+
},
|
|
477
|
+
plugins: [],
|
|
478
|
+
/**
|
|
479
|
+
* For some reason Rollup thinks it needs a global, though
|
|
480
|
+
* I'm pretty sure it doesn't, since everything works
|
|
481
|
+
*
|
|
482
|
+
* By setting a global for each external dep we're silencing these warnings
|
|
483
|
+
* No name was provided for external module 'react-beautiful-dnd' in output.globals – guessing 'reactBeautifulDnd'
|
|
484
|
+
*
|
|
485
|
+
* They don't occur for es builds, only UMD and I can't quite find
|
|
486
|
+
* an authoritative response on wny they're needed or how they're
|
|
487
|
+
* used in the UMD context.
|
|
488
|
+
*
|
|
489
|
+
* https://github.com/rollup/rollup/issues/1514#issuecomment-321877507
|
|
490
|
+
* https://github.com/rollup/rollup/issues/1169#issuecomment-268815735
|
|
491
|
+
*/
|
|
492
|
+
output: {
|
|
493
|
+
globals
|
|
494
|
+
},
|
|
495
|
+
external
|
|
496
|
+
}
|
|
435
497
|
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
return true;
|
|
445
|
-
};
|
|
446
|
-
var sequential = async (items, callback) => {
|
|
447
|
-
const accum = [];
|
|
448
|
-
if (!items) {
|
|
449
|
-
return [];
|
|
450
|
-
}
|
|
451
|
-
const reducePromises = async (previous, endpoint) => {
|
|
452
|
-
const prev = await previous;
|
|
453
|
-
if (prev) {
|
|
454
|
-
accum.push(prev);
|
|
455
|
-
}
|
|
456
|
-
return callback(endpoint, accum.length);
|
|
457
|
-
};
|
|
458
|
-
const result = await items.reduce(reducePromises, Promise.resolve());
|
|
459
|
-
if (result) {
|
|
460
|
-
accum.push(result);
|
|
498
|
+
};
|
|
499
|
+
const buildConfig = packageJSON.buildConfig ? deepMerge(defaultBuildConfig, packageJSON.buildConfig) : defaultBuildConfig;
|
|
500
|
+
await (0, import_vite.build)(__spreadValues({}, buildConfig));
|
|
501
|
+
(0, import_fs_extra.outputFileSync)(
|
|
502
|
+
import_node_path.default.join(outInfo.outdir, `${outInfo.outfile}.d.ts`),
|
|
503
|
+
`export * from "${outInfo.relativeOutfile}"`
|
|
504
|
+
);
|
|
505
|
+
return true;
|
|
461
506
|
}
|
|
462
|
-
return accum;
|
|
463
507
|
};
|
|
464
508
|
// Annotate the CommonJS export names for ESM import in node:
|
|
465
509
|
0 && (module.exports = {
|
|
466
|
-
|
|
467
|
-
init,
|
|
468
|
-
run,
|
|
469
|
-
sequential
|
|
510
|
+
BuildTina
|
|
470
511
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/scripts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"typescript": "^5.7.3",
|
|
25
25
|
"vite": "^4.5.9"
|
|
26
26
|
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/fs-extra": "^11.0.4",
|
|
29
|
+
"@types/json-diff": "^1.0.3"
|
|
30
|
+
},
|
|
27
31
|
"scripts": {
|
|
28
32
|
"build:all": "bin/tina-build build:all",
|
|
29
33
|
"watch": "node bin/tina-build watch",
|