@tinacms/scripts 1.3.3 → 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/__mocks__/styleMock.js +1 -1
- package/bin/tina-build +3 -1
- package/dist/index.js +396 -353
- package/package.json +5 -1
package/__mocks__/styleMock.js
CHANGED
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,201 +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
|
+
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
|
+
}
|
|
186
213
|
}
|
|
187
|
-
(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (error) {
|
|
192
|
-
console.error(`exec error: ${error} \u274C`);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (stdout) {
|
|
196
|
-
console.log(
|
|
197
|
-
stdout.split("\n").map((line) => `> ${line}`).join("\n")
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
if (stderr) {
|
|
201
|
-
console.error(`stderr: ${stderr}`);
|
|
202
|
-
}
|
|
203
|
-
const newTinaLock = JSON.parse(
|
|
204
|
-
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"
|
|
205
218
|
);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
const schemaDiff = import_json_diff.default.diffString(schema, newSchema);
|
|
213
|
-
if (schemaDiff) {
|
|
214
|
-
console.error("Unexpected change(s) to Tina schema \u274C");
|
|
215
|
-
console.log(schemaDiff);
|
|
216
|
-
process.exit(1);
|
|
217
|
-
}
|
|
218
|
-
const graphqlDiff = import_json_diff.default.diffString(
|
|
219
|
-
tinaLock.graphql,
|
|
220
|
-
newTinaLock.graphql
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
let tinaLock = null;
|
|
222
|
+
try {
|
|
223
|
+
const tinaLockContent = fs.readFileSync(
|
|
224
|
+
"tina/tina-lock.json"
|
|
221
225
|
);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
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");
|
|
226
229
|
}
|
|
227
|
-
|
|
230
|
+
} catch (err) {
|
|
231
|
+
const error = err;
|
|
232
|
+
console.error(`Failed to parse tina/tina-lock.json: ${error.message}`);
|
|
233
|
+
process.exit(1);
|
|
228
234
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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");
|
|
240
285
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
description: "Watch",
|
|
247
|
-
action: () => watch()
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
command: "diff-tina-lock",
|
|
251
|
-
description: "Compare the current schema for a tina project with newly generated schema",
|
|
252
|
-
action: () => diffTinaLock()
|
|
286
|
+
);
|
|
287
|
+
} catch (err) {
|
|
288
|
+
const error = err;
|
|
289
|
+
console.error(`Failed to start dev server: ${error.message}`);
|
|
290
|
+
process.exit(1);
|
|
253
291
|
}
|
|
254
|
-
]);
|
|
255
|
-
program.usage("command [options]");
|
|
256
|
-
program.on("command:*", function() {
|
|
257
|
-
console.error(
|
|
258
|
-
"Invalid command: %s\nSee --help for a list of available commands.",
|
|
259
|
-
args.join(" ")
|
|
260
|
-
);
|
|
261
|
-
process.exit(1);
|
|
262
|
-
});
|
|
263
|
-
program.on("--help", function() {
|
|
264
|
-
console.log(`
|
|
265
|
-
You can get help on any command with "-h" or "--help".
|
|
266
|
-
e.g: "forestry types:gen --help"
|
|
267
|
-
`);
|
|
268
|
-
});
|
|
269
|
-
if (!process.argv.slice(2).length) {
|
|
270
|
-
program.help();
|
|
271
292
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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);
|
|
283
337
|
const outdir = dir.replace("src", "dist");
|
|
284
338
|
const outfile = name;
|
|
285
339
|
const relativeOutfile = import_node_path.default.join(
|
|
@@ -288,181 +342,170 @@ var buildIt = async (entryPoint, packageJSON) => {
|
|
|
288
342
|
name
|
|
289
343
|
);
|
|
290
344
|
return { outdir, outfile, relativeOutfile };
|
|
291
|
-
};
|
|
292
|
-
const outInfo = out(entry);
|
|
293
|
-
if (["@tinacms/app"].includes(packageJSON.name)) {
|
|
294
|
-
console.log("skipping @tinacms/app");
|
|
295
|
-
return;
|
|
296
345
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
await (0, import_esbuild.build)({
|
|
301
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
302
|
-
bundle: true,
|
|
303
|
-
platform: "node",
|
|
304
|
-
// FIXME: no idea why but even though I'm on node14 it doesn't like
|
|
305
|
-
// the syntax for optional chaining, should be supported on 14
|
|
306
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
|
|
307
|
-
target: "node12",
|
|
308
|
-
// Use the outfile if it is provided
|
|
309
|
-
outfile: outInfo.outfile ? import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.js`) : import_node_path.default.join(process.cwd(), "dist", "index.js"),
|
|
310
|
-
external: external.filter(
|
|
311
|
-
(item) => !packageJSON.buildConfig.entryPoints[0].bundle.includes(item)
|
|
312
|
-
)
|
|
313
|
-
});
|
|
314
|
-
await (0, import_esbuild.build)({
|
|
315
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
316
|
-
bundle: true,
|
|
317
|
-
platform: "node",
|
|
318
|
-
target: "es2020",
|
|
319
|
-
format: "esm",
|
|
320
|
-
outfile: outInfo.outfile ? import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.mjs`) : import_node_path.default.join(process.cwd(), "dist", "index.mjs"),
|
|
321
|
-
external
|
|
322
|
-
});
|
|
323
|
-
} else if (["@tinacms/mdx"].includes(packageJSON.name)) {
|
|
324
|
-
const peerDeps2 = packageJSON.peerDependencies;
|
|
325
|
-
await (0, import_esbuild.build)({
|
|
326
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
327
|
-
bundle: true,
|
|
328
|
-
platform: "node",
|
|
329
|
-
// FIXME: no idea why but even though I'm on node14 it doesn't like
|
|
330
|
-
// the syntax for optional chaining, should be supported on 14
|
|
331
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
|
|
332
|
-
target: "node12",
|
|
333
|
-
format: "cjs",
|
|
334
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", "index.js"),
|
|
335
|
-
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
336
|
-
});
|
|
337
|
-
await (0, import_esbuild.build)({
|
|
338
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
339
|
-
bundle: true,
|
|
340
|
-
platform: "node",
|
|
341
|
-
target: "es2020",
|
|
342
|
-
format: "esm",
|
|
343
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", "index.mjs"),
|
|
344
|
-
// Bundle dependencies, the remark ecosystem only publishes ES modules
|
|
345
|
-
// and includes "development" export maps which actually throw errors during
|
|
346
|
-
// development, which we don't want to expose our users to.
|
|
347
|
-
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
348
|
-
});
|
|
349
|
-
await (0, import_esbuild.build)({
|
|
350
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
351
|
-
bundle: true,
|
|
352
|
-
platform: "browser",
|
|
353
|
-
target: "es2020",
|
|
354
|
-
format: "esm",
|
|
355
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", "index.browser.mjs"),
|
|
356
|
-
// Bundle dependencies, the remark ecosystem only publishes ES modules
|
|
357
|
-
// and includes "development" export maps which actually throw errors during
|
|
358
|
-
// development, which we don't want to expose our users to.
|
|
359
|
-
external: Object.keys(__spreadValues({}, peerDeps2))
|
|
360
|
-
});
|
|
361
|
-
} else {
|
|
362
|
-
await (0, import_esbuild.build)({
|
|
363
|
-
entryPoints: [import_node_path.default.join(process.cwd(), entry)],
|
|
364
|
-
bundle: true,
|
|
365
|
-
platform: "node",
|
|
366
|
-
outfile: import_node_path.default.join(process.cwd(), "dist", `${outInfo.outfile}.js`),
|
|
367
|
-
external,
|
|
368
|
-
target: "node12"
|
|
369
|
-
});
|
|
370
|
-
}
|
|
346
|
+
async buildPackage(entryPoint, packageJSON) {
|
|
347
|
+
const entry = entryPoint.name;
|
|
348
|
+
const target = entryPoint.target;
|
|
371
349
|
const extension = import_node_path.default.extname(entry);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
+
});
|
|
387
435
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
+
)
|
|
397
454
|
}
|
|
398
455
|
},
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
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`;
|
|
408
464
|
}
|
|
409
|
-
warn(warning);
|
|
410
465
|
},
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
//
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
+
}
|
|
433
497
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return true;
|
|
443
|
-
};
|
|
444
|
-
var sequential = async (items, callback) => {
|
|
445
|
-
const accum = [];
|
|
446
|
-
if (!items) {
|
|
447
|
-
return [];
|
|
448
|
-
}
|
|
449
|
-
const reducePromises = async (previous, endpoint) => {
|
|
450
|
-
const prev = await previous;
|
|
451
|
-
if (prev) {
|
|
452
|
-
accum.push(prev);
|
|
453
|
-
}
|
|
454
|
-
return callback(endpoint, accum.length);
|
|
455
|
-
};
|
|
456
|
-
const result = await items.reduce(reducePromises, Promise.resolve());
|
|
457
|
-
if (result) {
|
|
458
|
-
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;
|
|
459
506
|
}
|
|
460
|
-
return accum;
|
|
461
507
|
};
|
|
462
508
|
// Annotate the CommonJS export names for ESM import in node:
|
|
463
509
|
0 && (module.exports = {
|
|
464
|
-
|
|
465
|
-
init,
|
|
466
|
-
run,
|
|
467
|
-
sequential
|
|
510
|
+
BuildTina
|
|
468
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",
|