@patterkit/ops 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40 -38
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -226,6 +226,7 @@ function applyWrites(writes) {
|
|
|
226
226
|
|
|
227
227
|
// src/validate.ts
|
|
228
228
|
import { readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
229
|
+
import { basename as basename2, isAbsolute, join as join2, relative } from "path";
|
|
229
230
|
|
|
230
231
|
// src/merge.ts
|
|
231
232
|
import { canonicalStringify } from "@patterkit/core";
|
|
@@ -846,23 +847,24 @@ function runValidate(loaded) {
|
|
|
846
847
|
};
|
|
847
848
|
}
|
|
848
849
|
function orphanShards(loaded) {
|
|
849
|
-
const
|
|
850
|
-
loaded.projectFile,
|
|
851
|
-
...Object.values(loaded.sceneFiles),
|
|
852
|
-
...loaded.localeFiles,
|
|
853
|
-
...loaded.authoringFiles
|
|
854
|
-
]);
|
|
850
|
+
const layout = { flow: "scenes/", strings: "loc/", authoring: "authoring/", ...loaded.project.layout };
|
|
855
851
|
const kind = {
|
|
856
|
-
".patterflow": "scene",
|
|
857
|
-
".patterloc": "
|
|
858
|
-
".patterx": "authoring",
|
|
859
|
-
".patterproj": "project"
|
|
852
|
+
".patterflow": { what: "scene", home: layout.flow },
|
|
853
|
+
".patterloc": { what: "strings", home: layout.strings },
|
|
854
|
+
".patterx": { what: "authoring", home: layout.authoring },
|
|
855
|
+
".patterproj": { what: "project", home: null }
|
|
856
|
+
};
|
|
857
|
+
const inside = (file, dir) => {
|
|
858
|
+
const r = relative(dir, file);
|
|
859
|
+
return r !== "" && !r.startsWith("..") && !isAbsolute(r);
|
|
860
860
|
};
|
|
861
861
|
const out = [];
|
|
862
|
-
for (const [ext, what] of Object.entries(kind)) {
|
|
862
|
+
for (const [ext, { what, home }] of Object.entries(kind)) {
|
|
863
863
|
for (const file of walkFiles(loaded.root, ext)) {
|
|
864
|
-
if (
|
|
865
|
-
|
|
864
|
+
if (home ? inside(file, join2(loaded.root, home)) : file === loaded.projectFile) continue;
|
|
865
|
+
const rel = relative(loaded.root, file);
|
|
866
|
+
const message = home ? `${rel} is a ${what} file outside the project's folders: nothing loads it, so none of it is in the project. Move it under ${home}, or delete it.` : `${rel} is a second project file: only ${basename2(loaded.projectFile)} is read. Delete it, or move it out of the project.`;
|
|
867
|
+
out.push({ file, message });
|
|
866
868
|
}
|
|
867
869
|
}
|
|
868
870
|
return out;
|
|
@@ -926,7 +928,7 @@ function checkHygiene(files) {
|
|
|
926
928
|
}
|
|
927
929
|
|
|
928
930
|
// src/export.ts
|
|
929
|
-
import { basename as
|
|
931
|
+
import { basename as basename3, isAbsolute as isAbsolute2, join as join3 } from "path";
|
|
930
932
|
import { exportBundle as exportBundle3 } from "@patterkit/compiler";
|
|
931
933
|
import { isContentlessBeat } from "@patterkit/model";
|
|
932
934
|
function compileScenes(loaded) {
|
|
@@ -972,9 +974,9 @@ function runExportFull(loaded) {
|
|
|
972
974
|
}
|
|
973
975
|
function bundleOutputPath(loaded) {
|
|
974
976
|
const override = loaded.project.export?.bundle;
|
|
975
|
-
if (override) return
|
|
976
|
-
const stem =
|
|
977
|
-
return
|
|
977
|
+
if (override) return isAbsolute2(override) ? override : join3(loaded.root, override);
|
|
978
|
+
const stem = basename3(loaded.projectFile).replace(/\.patterproj$/, "");
|
|
979
|
+
return join3(loaded.root, "dist", `${stem}.patterc`);
|
|
978
980
|
}
|
|
979
981
|
|
|
980
982
|
// src/export-html.ts
|
|
@@ -1179,7 +1181,7 @@ ${PLAYER_JS}`,
|
|
|
1179
1181
|
|
|
1180
1182
|
// src/audio-scan.ts
|
|
1181
1183
|
import { readdirSync as readdirSync2 } from "fs";
|
|
1182
|
-
import { resolve as resolve2, extname, basename as
|
|
1184
|
+
import { resolve as resolve2, extname, basename as basename4 } from "path";
|
|
1183
1185
|
import { deriveRecordingFolders, DEFAULT_RECORDING_STATUSES } from "@patterkit/model";
|
|
1184
1186
|
var AUDIO_EXT = /* @__PURE__ */ new Set([".wav", ".mp3"]);
|
|
1185
1187
|
function scanAudioStatus(loaded) {
|
|
@@ -1198,7 +1200,7 @@ function scanAudioStatus(loaded) {
|
|
|
1198
1200
|
}
|
|
1199
1201
|
for (const f of files) {
|
|
1200
1202
|
const ext = extname(f).toLowerCase();
|
|
1201
|
-
if (AUDIO_EXT.has(ext)) out.set(
|
|
1203
|
+
if (AUDIO_EXT.has(ext)) out.set(basename4(f, extname(f)), rung.name);
|
|
1202
1204
|
}
|
|
1203
1205
|
}
|
|
1204
1206
|
return out;
|
|
@@ -2092,7 +2094,7 @@ async function runReportXlsx(data) {
|
|
|
2092
2094
|
}
|
|
2093
2095
|
|
|
2094
2096
|
// src/localisation.ts
|
|
2095
|
-
import { basename as
|
|
2097
|
+
import { basename as basename5, join as join4, sep } from "path";
|
|
2096
2098
|
import { canonicalStringify as canonicalStringify4 } from "@patterkit/core";
|
|
2097
2099
|
import { walkNodes as walkNodes3, castStringKey, PROJECT_LOCALE_SCENE } from "@patterkit/model";
|
|
2098
2100
|
|
|
@@ -2214,14 +2216,14 @@ function targetLocPath(loaded, scene, locale, defaultLocale) {
|
|
|
2214
2216
|
}
|
|
2215
2217
|
}
|
|
2216
2218
|
const stem = scene === PROJECT_LOCALE_SCENE ? "_project" : scene;
|
|
2217
|
-
return
|
|
2219
|
+
return join4(loaded.root, layoutOf(loaded).strings, locale, `${stem}.patterloc`);
|
|
2218
2220
|
}
|
|
2219
2221
|
function authoringPath(loaded, scene) {
|
|
2220
|
-
const dir =
|
|
2221
|
-
if (scene === PROJECT_LOCALE_SCENE) return
|
|
2222
|
+
const dir = join4(loaded.root, layoutOf(loaded).authoring);
|
|
2223
|
+
if (scene === PROJECT_LOCALE_SCENE) return join4(dir, "_project.patterx");
|
|
2222
2224
|
const flow = loaded.sceneFiles[scene];
|
|
2223
|
-
const stem = flow ?
|
|
2224
|
-
return
|
|
2225
|
+
const stem = flow ? basename5(flow).replace(/\.patterflow$/, "") : scene;
|
|
2226
|
+
return join4(dir, `${stem}.patterx`);
|
|
2225
2227
|
}
|
|
2226
2228
|
var findFile = (files, items, path) => {
|
|
2227
2229
|
const i = files.indexOf(path);
|
|
@@ -3069,12 +3071,12 @@ async function scriptToPdf(doc) {
|
|
|
3069
3071
|
}
|
|
3070
3072
|
|
|
3071
3073
|
// src/init.ts
|
|
3072
|
-
import { join as
|
|
3074
|
+
import { join as join5, basename as basename6, resolve as resolve3 } from "path";
|
|
3073
3075
|
import { readdirSync as readdirSync3, existsSync as existsSync2 } from "fs";
|
|
3074
3076
|
import { newId, slug, canonicalStringify as canonicalStringify5 } from "@patterkit/core";
|
|
3075
3077
|
function runInit(opts) {
|
|
3076
3078
|
const dir = resolve3(opts.dir);
|
|
3077
|
-
const name = opts.name?.trim() ||
|
|
3079
|
+
const name = opts.name?.trim() || basename6(dir).replace(/\.patter$/, "");
|
|
3078
3080
|
const fileSlug = slug(name);
|
|
3079
3081
|
let existing = [];
|
|
3080
3082
|
try {
|
|
@@ -3122,12 +3124,12 @@ function runInit(opts) {
|
|
|
3122
3124
|
strings: { [beatId]: `Welcome to ${name}. This is the first line of your story - replace it with your own.` }
|
|
3123
3125
|
};
|
|
3124
3126
|
const bundle = opts.bundle ?? "commit";
|
|
3125
|
-
const projectFile =
|
|
3127
|
+
const projectFile = join5(dir, `${fileSlug}.patterproj`);
|
|
3126
3128
|
const writes = [
|
|
3127
3129
|
{ path: projectFile, content: canonicalStringify5(project) },
|
|
3128
|
-
{ path:
|
|
3129
|
-
{ path:
|
|
3130
|
-
{ path:
|
|
3130
|
+
{ path: join5(dir, "scenes", "start.patterflow"), content: canonicalStringify5(flow) },
|
|
3131
|
+
{ path: join5(dir, "loc", "en", "start.patterloc"), content: canonicalStringify5(locale) },
|
|
3132
|
+
{ path: join5(dir, ".editorconfig"), content: EDITORCONFIG },
|
|
3131
3133
|
...vcsConfigWrites(dir, opts.vcs, bundle)
|
|
3132
3134
|
];
|
|
3133
3135
|
const collisions = writes.map((w) => w.path).filter((p) => existsSync2(p));
|
|
@@ -3137,10 +3139,10 @@ function runInit(opts) {
|
|
|
3137
3139
|
return { writes, projectFile, name };
|
|
3138
3140
|
}
|
|
3139
3141
|
function vcsConfigWrites(dir, vcs, bundle = "commit") {
|
|
3140
|
-
const writes = [{ path:
|
|
3141
|
-
if (vcs === "git") writes.push({ path:
|
|
3142
|
+
const writes = [{ path: join5(dir, "vcs-setup.md"), content: vcsSetup(vcs, bundle) }];
|
|
3143
|
+
if (vcs === "git") writes.push({ path: join5(dir, ".gitattributes"), content: GITATTRIBUTES });
|
|
3142
3144
|
const ignore = ignoreFileFor(vcs);
|
|
3143
|
-
if (ignore) writes.push({ path:
|
|
3145
|
+
if (ignore) writes.push({ path: join5(dir, ignore), content: ignoreContent(bundle) });
|
|
3144
3146
|
return writes;
|
|
3145
3147
|
}
|
|
3146
3148
|
var EDITORCONFIG = `# Patter projects are UTF-8 + LF, always (spec - patter format enforces this).
|
|
@@ -3615,7 +3617,7 @@ function runReplace(loaded, opts) {
|
|
|
3615
3617
|
// src/pack.ts
|
|
3616
3618
|
import JSZip from "jszip";
|
|
3617
3619
|
import { readFileSync as readFileSync4 } from "fs";
|
|
3618
|
-
import { dirname as dirname4, relative, sep as sep2 } from "path";
|
|
3620
|
+
import { dirname as dirname4, relative as relative2, sep as sep2 } from "path";
|
|
3619
3621
|
import { parseSource as parseSource4 } from "@patterkit/core";
|
|
3620
3622
|
import { ARCHIVE_ENTRY_OPTS } from "@wildwinter/toolkit/archive";
|
|
3621
3623
|
var SHARD_EXTENSIONS = [".patterflow", ".patterloc", ".patterx", ".patterproj"];
|
|
@@ -3631,7 +3633,7 @@ async function runPack(startPath) {
|
|
|
3631
3633
|
` + unresolved.map((i) => ` ${i.file}`).join("\n")
|
|
3632
3634
|
);
|
|
3633
3635
|
}
|
|
3634
|
-
const files = SHARD_EXTENSIONS.flatMap((ext) => walkFiles(root, ext)).map((abs) => ({ abs, rel:
|
|
3636
|
+
const files = SHARD_EXTENSIONS.flatMap((ext) => walkFiles(root, ext)).map((abs) => ({ abs, rel: relative2(root, abs).split(sep2).join("/") })).sort((a, b) => a.rel.localeCompare(b.rel));
|
|
3635
3637
|
const manifest = {
|
|
3636
3638
|
schema: "patter/document@0",
|
|
3637
3639
|
project: { id: project.project.id, name: project.project.name },
|
|
@@ -3645,7 +3647,7 @@ async function runPack(startPath) {
|
|
|
3645
3647
|
|
|
3646
3648
|
// src/unpack.ts
|
|
3647
3649
|
import JSZip2 from "jszip";
|
|
3648
|
-
import { join as
|
|
3650
|
+
import { join as join6, resolve as resolve4, sep as sep3 } from "path";
|
|
3649
3651
|
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
3650
3652
|
import { parseSource as parseSource5, canonicalStringify as canonicalStringify7 } from "@patterkit/core";
|
|
3651
3653
|
import { isUnsafeEntry } from "@wildwinter/toolkit/archive";
|
|
@@ -3736,7 +3738,7 @@ async function runUnpackMerge(returnedBytes, baseBytes, projectDir) {
|
|
|
3736
3738
|
}
|
|
3737
3739
|
function containedWrite(dir, name) {
|
|
3738
3740
|
const root = resolve4(dir);
|
|
3739
|
-
const full = resolve4(
|
|
3741
|
+
const full = resolve4(join6(dir, name));
|
|
3740
3742
|
if (full !== root && !full.startsWith(root + sep3)) {
|
|
3741
3743
|
throw new UnsafeEntryError(`document entry escapes the target directory: ${name}`);
|
|
3742
3744
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patterkit/ops",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "The shared operations layer: every project operation (load, validate, export, format, play, ...) as a pure function, consumed by the patter CLI and Patterpad alike.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|