@jxsuite/create 1.5.5 → 1.7.0
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/generate.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Shared project generation logic. Used by both the CLI scaffolder and the Studio server endpoint. */
|
|
2
2
|
|
|
3
3
|
import { chmod, cp, lstat, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { adapterNeedsWrangler, buildWranglerJsonc, isJsonObject
|
|
4
|
+
import { adapterNeedsWrangler, buildWranglerJsonc, isJsonObject } from "./scaffold";
|
|
5
5
|
import { basename, join, relative, sep } from "node:path";
|
|
6
6
|
|
|
7
7
|
import { Buffer } from "node:buffer";
|
|
@@ -12,7 +12,12 @@ import type { TemplateId } from "./templates";
|
|
|
12
12
|
import type { JsonObject } from "./scaffold";
|
|
13
13
|
|
|
14
14
|
import TEMPLATE_VERSIONS from "./template-versions.json";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
NEW_PROJECT_FILE_NAME,
|
|
17
|
+
parseProjectSource,
|
|
18
|
+
serializeProjectFile,
|
|
19
|
+
} from "@jxsuite/schema/project-file";
|
|
20
|
+
import { projectFilePath } from "@jxsuite/schema/project-file/node";
|
|
16
21
|
|
|
17
22
|
const __dirname = import.meta.dirname;
|
|
18
23
|
const TEMPLATE_DIR = join(__dirname, "template");
|
|
@@ -200,7 +205,10 @@ async function populateProject(destPath: string, opts: ProjectOptions) {
|
|
|
200
205
|
const packageJson = buildPackageJson({ adapter, description, name });
|
|
201
206
|
|
|
202
207
|
const writes = [
|
|
203
|
-
writeFile(
|
|
208
|
+
writeFile(
|
|
209
|
+
join(destPath, NEW_PROJECT_FILE_NAME),
|
|
210
|
+
withExtensionsNote(serializeProjectFile(projectJson, null)),
|
|
211
|
+
),
|
|
204
212
|
writeFile(join(destPath, "package.json"), `${JSON.stringify(packageJson, null, " ")}\n`),
|
|
205
213
|
cp(join(TEMPLATE_DIR, "gitignore"), join(destPath, ".gitignore")),
|
|
206
214
|
cp(join(TEMPLATE_DIR, "layouts"), join(destPath, "layouts"), { recursive: true }),
|
|
@@ -213,6 +221,7 @@ async function populateProject(destPath: string, opts: ProjectOptions) {
|
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
await Promise.all(writes);
|
|
224
|
+
await writeEditorSupport(destPath);
|
|
216
225
|
|
|
217
226
|
// The .gitignore, layouts/ and pages/ above are copies too, carrying the template's modes.
|
|
218
227
|
// The overlay below would otherwise fail to `force` over a file that came across read-only.
|
|
@@ -272,14 +281,13 @@ async function scaffoldFromStarter(
|
|
|
272
281
|
// Before the re-stamp below, which writes straight back into the tree that was just copied.
|
|
273
282
|
await makeWritable(destPath);
|
|
274
283
|
|
|
275
|
-
// Re-stamp project
|
|
276
|
-
// Content types, image pipeline, and
|
|
277
|
-
const projectPath =
|
|
284
|
+
// Re-stamp the project file with the new project's identity, keeping the starter's design tokens,
|
|
285
|
+
// Content types, image pipeline, head, and in a project.jxn its comments.
|
|
286
|
+
const projectPath = projectFilePath(destPath);
|
|
278
287
|
const starterText = await readFile(projectPath, "utf8");
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
288
|
+
/* SAFETY: both readers answer an object, or throw (a starter whose project file is a list is
|
|
289
|
+
refused there, naming the file), and every member below is one the re-stamp owns. */
|
|
290
|
+
const project = parseProjectSource(starterText, projectPath) as JsonObject;
|
|
283
291
|
project.name = name;
|
|
284
292
|
if (url) {
|
|
285
293
|
project.url = url;
|
|
@@ -293,7 +301,10 @@ async function scaffoldFromStarter(
|
|
|
293
301
|
if (design) {
|
|
294
302
|
applyDesign(project, design, { starter: true });
|
|
295
303
|
}
|
|
296
|
-
await writeFile(projectPath, serializeProjectFile(project, starterText));
|
|
304
|
+
await writeFile(projectPath, serializeProjectFile(project, starterText, projectPath));
|
|
305
|
+
await writeEditorSupport(destPath);
|
|
306
|
+
// Copied from a read-only install as the rest was, so made writable as the rest was.
|
|
307
|
+
await makeWritable(destPath);
|
|
297
308
|
|
|
298
309
|
// Rebuild package.json so scaffolded projects get current dep ranges and scripts regardless of
|
|
299
310
|
// What the in-repo starter pinned.
|
|
@@ -310,6 +321,36 @@ async function scaffoldFromStarter(
|
|
|
310
321
|
}
|
|
311
322
|
}
|
|
312
323
|
|
|
324
|
+
/**
|
|
325
|
+
* A new project file, with one comment in it saying what `extensions` is for: the line a new user
|
|
326
|
+
* most needs explained, and the format's main advantage shown rather than described
|
|
327
|
+
* (`site-architecture.md` §2.4). The canonical form has no comments, so it goes in after.
|
|
328
|
+
*
|
|
329
|
+
* @param text The project file in its canonical form.
|
|
330
|
+
*/
|
|
331
|
+
function withExtensionsNote(text: string): string {
|
|
332
|
+
return text.replace(
|
|
333
|
+
/^extensions\b/m,
|
|
334
|
+
"// Extensions add what Jx does not do on its own. @jxsuite/parser reads pages/index.md and\n" +
|
|
335
|
+
"// every Markdown collection; turn others on in Studio, under Project Settings > Extensions.\n" +
|
|
336
|
+
"extensions",
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* What lets an editor and GitHub read `.jxn` from the first commit: Linguist knows KDL only as
|
|
342
|
+
* `.kdl`, and VS Code needs telling too. Both cost nothing, and an existing file is kept.
|
|
343
|
+
*
|
|
344
|
+
* @param destPath The project's root.
|
|
345
|
+
*/
|
|
346
|
+
async function writeEditorSupport(destPath: string): Promise<void> {
|
|
347
|
+
await mkdir(join(destPath, ".vscode"), { recursive: true });
|
|
348
|
+
await Promise.all([
|
|
349
|
+
cp(join(TEMPLATE_DIR, "gitattributes"), join(destPath, ".gitattributes"), { force: false }),
|
|
350
|
+
cp(join(TEMPLATE_DIR, "vscode"), join(destPath, ".vscode"), { force: false, recursive: true }),
|
|
351
|
+
]);
|
|
352
|
+
}
|
|
353
|
+
|
|
313
354
|
/**
|
|
314
355
|
* Apply the design quickstart (colors, fonts, breakpoints) to a project.json object, in place.
|
|
315
356
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jxsuite/create",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Scaffold a new Jx project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test:coverage": "bun test --isolate --coverage"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jxsuite/schema": "^5.
|
|
41
|
-
"@jxsuite/starters": "^3.
|
|
40
|
+
"@jxsuite/schema": "^5.5.0",
|
|
41
|
+
"@jxsuite/starters": "^3.4.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/template-versions.json
CHANGED