@nshiab/setup-data-project 2.0.3 → 3.0.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/README.md +76 -28
- package/dist/main.mjs +852 -0
- package/dist/main.mjs.map +1 -0
- package/package.json +29 -18
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/helpers/combinePlotDocs.d.ts +0 -2
- package/esm/helpers/combinePlotDocs.d.ts.map +0 -1
- package/esm/helpers/combinePlotDocs.js +0 -111
- package/esm/helpers/createFolderStructure.d.ts +0 -2
- package/esm/helpers/createFolderStructure.d.ts.map +0 -1
- package/esm/helpers/createFolderStructure.js +0 -40
- package/esm/helpers/ensureAgents.d.ts +0 -3
- package/esm/helpers/ensureAgents.d.ts.map +0 -1
- package/esm/helpers/ensureAgents.js +0 -186
- package/esm/helpers/ensureEnvFile.d.ts +0 -2
- package/esm/helpers/ensureEnvFile.d.ts.map +0 -1
- package/esm/helpers/ensureEnvFile.js +0 -8
- package/esm/helpers/ensureGitignore.d.ts +0 -3
- package/esm/helpers/ensureGitignore.d.ts.map +0 -1
- package/esm/helpers/ensureGitignore.js +0 -24
- package/esm/helpers/ensureManagedSection.d.ts +0 -9
- package/esm/helpers/ensureManagedSection.d.ts.map +0 -1
- package/esm/helpers/ensureManagedSection.js +0 -33
- package/esm/helpers/ensureReadme.d.ts +0 -2
- package/esm/helpers/ensureReadme.d.ts.map +0 -1
- package/esm/helpers/ensureReadme.js +0 -61
- package/esm/helpers/fetchPackageDocs.d.ts +0 -12
- package/esm/helpers/fetchPackageDocs.d.ts.map +0 -1
- package/esm/helpers/fetchPackageDocs.js +0 -75
- package/esm/helpers/fetchPlotDocs.d.ts +0 -5
- package/esm/helpers/fetchPlotDocs.d.ts.map +0 -1
- package/esm/helpers/fetchPlotDocs.js +0 -103
- package/esm/helpers/getInstalledPackageVersions.d.ts +0 -2
- package/esm/helpers/getInstalledPackageVersions.d.ts.map +0 -1
- package/esm/helpers/getInstalledPackageVersions.js +0 -94
- package/esm/helpers/getProjectTasks.d.ts +0 -6
- package/esm/helpers/getProjectTasks.d.ts.map +0 -1
- package/esm/helpers/getProjectTasks.js +0 -17
- package/esm/helpers/getRuntime.d.ts +0 -5
- package/esm/helpers/getRuntime.d.ts.map +0 -1
- package/esm/helpers/getRuntime.js +0 -19
- package/esm/helpers/gitignoreEntries.d.ts +0 -2
- package/esm/helpers/gitignoreEntries.d.ts.map +0 -1
- package/esm/helpers/gitignoreEntries.js +0 -10
- package/esm/helpers/installPackages.d.ts +0 -7
- package/esm/helpers/installPackages.d.ts.map +0 -1
- package/esm/helpers/installPackages.js +0 -49
- package/esm/helpers/packageOptions.d.ts +0 -6
- package/esm/helpers/packageOptions.d.ts.map +0 -1
- package/esm/helpers/packageOptions.js +0 -6
- package/esm/helpers/packageRegistry.d.ts +0 -10
- package/esm/helpers/packageRegistry.d.ts.map +0 -1
- package/esm/helpers/packageRegistry.js +0 -89
- package/esm/helpers/parseArguments.d.ts +0 -7
- package/esm/helpers/parseArguments.d.ts.map +0 -1
- package/esm/helpers/parseArguments.js +0 -30
- package/esm/helpers/plotDocPages.d.ts +0 -2
- package/esm/helpers/plotDocPages.d.ts.map +0 -1
- package/esm/helpers/plotDocPages.js +0 -46
- package/esm/helpers/projectManifest.d.ts +0 -12
- package/esm/helpers/projectManifest.d.ts.map +0 -1
- package/esm/helpers/projectManifest.js +0 -80
- package/esm/helpers/syncPackageDocs.d.ts +0 -3
- package/esm/helpers/syncPackageDocs.d.ts.map +0 -1
- package/esm/helpers/syncPackageDocs.js +0 -50
- package/esm/main.d.ts +0 -3
- package/esm/main.d.ts.map +0 -1
- package/esm/main.js +0 -104
- package/esm/package.json +0 -3
- package/script/_dnt.shims.d.ts +0 -2
- package/script/_dnt.shims.d.ts.map +0 -1
- package/script/_dnt.shims.js +0 -60
- package/script/helpers/combinePlotDocs.d.ts +0 -2
- package/script/helpers/combinePlotDocs.d.ts.map +0 -1
- package/script/helpers/combinePlotDocs.js +0 -114
- package/script/helpers/createFolderStructure.d.ts +0 -2
- package/script/helpers/createFolderStructure.d.ts.map +0 -1
- package/script/helpers/createFolderStructure.js +0 -43
- package/script/helpers/ensureAgents.d.ts +0 -3
- package/script/helpers/ensureAgents.d.ts.map +0 -1
- package/script/helpers/ensureAgents.js +0 -189
- package/script/helpers/ensureEnvFile.d.ts +0 -2
- package/script/helpers/ensureEnvFile.d.ts.map +0 -1
- package/script/helpers/ensureEnvFile.js +0 -11
- package/script/helpers/ensureGitignore.d.ts +0 -3
- package/script/helpers/ensureGitignore.d.ts.map +0 -1
- package/script/helpers/ensureGitignore.js +0 -28
- package/script/helpers/ensureManagedSection.d.ts +0 -9
- package/script/helpers/ensureManagedSection.d.ts.map +0 -1
- package/script/helpers/ensureManagedSection.js +0 -36
- package/script/helpers/ensureReadme.d.ts +0 -2
- package/script/helpers/ensureReadme.d.ts.map +0 -1
- package/script/helpers/ensureReadme.js +0 -64
- package/script/helpers/fetchPackageDocs.d.ts +0 -12
- package/script/helpers/fetchPackageDocs.d.ts.map +0 -1
- package/script/helpers/fetchPackageDocs.js +0 -78
- package/script/helpers/fetchPlotDocs.d.ts +0 -5
- package/script/helpers/fetchPlotDocs.d.ts.map +0 -1
- package/script/helpers/fetchPlotDocs.js +0 -106
- package/script/helpers/getInstalledPackageVersions.d.ts +0 -2
- package/script/helpers/getInstalledPackageVersions.d.ts.map +0 -1
- package/script/helpers/getInstalledPackageVersions.js +0 -97
- package/script/helpers/getProjectTasks.d.ts +0 -6
- package/script/helpers/getProjectTasks.d.ts.map +0 -1
- package/script/helpers/getProjectTasks.js +0 -20
- package/script/helpers/getRuntime.d.ts +0 -5
- package/script/helpers/getRuntime.d.ts.map +0 -1
- package/script/helpers/getRuntime.js +0 -59
- package/script/helpers/gitignoreEntries.d.ts +0 -2
- package/script/helpers/gitignoreEntries.d.ts.map +0 -1
- package/script/helpers/gitignoreEntries.js +0 -13
- package/script/helpers/installPackages.d.ts +0 -7
- package/script/helpers/installPackages.d.ts.map +0 -1
- package/script/helpers/installPackages.js +0 -86
- package/script/helpers/packageOptions.d.ts +0 -6
- package/script/helpers/packageOptions.d.ts.map +0 -1
- package/script/helpers/packageOptions.js +0 -9
- package/script/helpers/packageRegistry.d.ts +0 -10
- package/script/helpers/packageRegistry.d.ts.map +0 -1
- package/script/helpers/packageRegistry.js +0 -93
- package/script/helpers/parseArguments.d.ts +0 -7
- package/script/helpers/parseArguments.d.ts.map +0 -1
- package/script/helpers/parseArguments.js +0 -34
- package/script/helpers/plotDocPages.d.ts +0 -2
- package/script/helpers/plotDocPages.d.ts.map +0 -1
- package/script/helpers/plotDocPages.js +0 -49
- package/script/helpers/projectManifest.d.ts +0 -12
- package/script/helpers/projectManifest.d.ts.map +0 -1
- package/script/helpers/projectManifest.js +0 -84
- package/script/helpers/syncPackageDocs.d.ts +0 -3
- package/script/helpers/syncPackageDocs.d.ts.map +0 -1
- package/script/helpers/syncPackageDocs.js +0 -53
- package/script/main.d.ts +0 -3
- package/script/main.d.ts.map +0 -1
- package/script/main.js +0 -109
- package/script/package.json +0 -3
package/esm/main.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { cancel, intro, isCancel, multiselect, outro, select, spinner, } from "@clack/prompts";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import { getRuntime } from "./helpers/getRuntime.js";
|
|
5
|
-
import { PACKAGE_OPTIONS } from "./helpers/packageOptions.js";
|
|
6
|
-
import { ensureGitignore } from "./helpers/ensureGitignore.js";
|
|
7
|
-
import { ensureReadme } from "./helpers/ensureReadme.js";
|
|
8
|
-
import { installPackages } from "./helpers/installPackages.js";
|
|
9
|
-
import { getProjectTasks } from "./helpers/getProjectTasks.js";
|
|
10
|
-
import { createFolderStructure } from "./helpers/createFolderStructure.js";
|
|
11
|
-
import { ensureEnvFile } from "./helpers/ensureEnvFile.js";
|
|
12
|
-
import { ensureAgents } from "./helpers/ensureAgents.js";
|
|
13
|
-
import { getInstalledPackageConfigs } from "./helpers/packageRegistry.js";
|
|
14
|
-
import { ProjectManifest } from "./helpers/projectManifest.js";
|
|
15
|
-
import { syncPackageDocs } from "./helpers/syncPackageDocs.js";
|
|
16
|
-
import { getInstalledPackageVersions } from "./helpers/getInstalledPackageVersions.js";
|
|
17
|
-
import { CLI_HELP, parseArguments } from "./helpers/parseArguments.js";
|
|
18
|
-
async function main() {
|
|
19
|
-
const cliOptions = parseArguments(process.argv.slice(2));
|
|
20
|
-
if (cliOptions.help) {
|
|
21
|
-
console.log(CLI_HELP);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const runtime = getRuntime();
|
|
25
|
-
console.log();
|
|
26
|
-
intro(`Hi! 👋 (Running on ${runtime})`);
|
|
27
|
-
const projectManifest = ProjectManifest.open(runtime);
|
|
28
|
-
projectManifest.updateTasks(getProjectTasks());
|
|
29
|
-
const installedPackages = projectManifest.getInstalledPackages();
|
|
30
|
-
const options = PACKAGE_OPTIONS.map((opt) => ({
|
|
31
|
-
...opt,
|
|
32
|
-
label: installedPackages.includes(opt.value)
|
|
33
|
-
? `${opt.label} \x1b[2m(installed)\x1b[22m`
|
|
34
|
-
: opt.label,
|
|
35
|
-
}));
|
|
36
|
-
const selectedPackages = cliOptions.package
|
|
37
|
-
? [cliOptions.package]
|
|
38
|
-
: (await multiselect({
|
|
39
|
-
message: "Which libraries would you like to install?\n\x1b[2m(space to select, arrows to navigate, enter to confirm)\x1b[22m\n",
|
|
40
|
-
options,
|
|
41
|
-
required: false,
|
|
42
|
-
}));
|
|
43
|
-
if (isCancel(selectedPackages)) {
|
|
44
|
-
cancel("Installation cancelled.");
|
|
45
|
-
process.exit(0);
|
|
46
|
-
}
|
|
47
|
-
const alreadyInstalled = selectedPackages.filter((pkg) => installedPackages.includes(pkg));
|
|
48
|
-
const packagesToInstall = [];
|
|
49
|
-
for (const pkg of selectedPackages) {
|
|
50
|
-
if (alreadyInstalled.includes(pkg)) {
|
|
51
|
-
if (cliOptions.package)
|
|
52
|
-
continue;
|
|
53
|
-
const action = await select({
|
|
54
|
-
message: `${pkg} is already installed. What would you like to do?`,
|
|
55
|
-
options: [
|
|
56
|
-
{ value: "skip", label: "Keep existing version" },
|
|
57
|
-
{ value: "update", label: "Update to latest" },
|
|
58
|
-
],
|
|
59
|
-
});
|
|
60
|
-
if (isCancel(action)) {
|
|
61
|
-
cancel("Installation cancelled.");
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
if (action === "update") {
|
|
65
|
-
packagesToInstall.push(pkg);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
packagesToInstall.push(pkg);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const sInstall = spinner();
|
|
73
|
-
sInstall.start("Installing packages...");
|
|
74
|
-
for (const pkg of packagesToInstall) {
|
|
75
|
-
try {
|
|
76
|
-
await installPackages([pkg], { silent: true });
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
sInstall.stop(`❌ Failed to install ${pkg}.`);
|
|
80
|
-
console.error(error);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
sInstall.stop("✅ Package installation complete.");
|
|
85
|
-
projectManifest.reload();
|
|
86
|
-
projectManifest.updateTasks(getProjectTasks());
|
|
87
|
-
const finalInstalledPackages = getInstalledPackageConfigs(projectManifest.getInstalledPackages()).map((pkg) => pkg.value);
|
|
88
|
-
const finalInstalledVersions = getInstalledPackageVersions(projectManifest.getInstalledPackageSpecifiers());
|
|
89
|
-
const sDocs = spinner();
|
|
90
|
-
sDocs.start("Fetching documentation for installed package versions...");
|
|
91
|
-
const docsMapping = await syncPackageDocs(finalInstalledPackages, finalInstalledVersions);
|
|
92
|
-
sDocs.stop("✅ Documentation synchronization complete.");
|
|
93
|
-
createFolderStructure(finalInstalledPackages);
|
|
94
|
-
ensureGitignore();
|
|
95
|
-
ensureEnvFile();
|
|
96
|
-
await ensureReadme(runtime, finalInstalledPackages);
|
|
97
|
-
await ensureAgents(docsMapping, runtime, finalInstalledPackages);
|
|
98
|
-
outro("You are all set! 🙌");
|
|
99
|
-
}
|
|
100
|
-
main().catch((error) => {
|
|
101
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
102
|
-
console.error(`❌ Error: ${message}`);
|
|
103
|
-
process.exitCode = 1;
|
|
104
|
-
});
|
package/esm/package.json
DELETED
package/script/_dnt.shims.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
package/script/_dnt.shims.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dntGlobalThis = void 0;
|
|
4
|
-
const dntGlobals = {};
|
|
5
|
-
exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
6
|
-
function createMergeProxy(baseObj, extObj) {
|
|
7
|
-
return new Proxy(baseObj, {
|
|
8
|
-
get(_target, prop, _receiver) {
|
|
9
|
-
if (prop in extObj) {
|
|
10
|
-
return extObj[prop];
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
return baseObj[prop];
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
set(_target, prop, value) {
|
|
17
|
-
if (prop in extObj) {
|
|
18
|
-
delete extObj[prop];
|
|
19
|
-
}
|
|
20
|
-
baseObj[prop] = value;
|
|
21
|
-
return true;
|
|
22
|
-
},
|
|
23
|
-
deleteProperty(_target, prop) {
|
|
24
|
-
let success = false;
|
|
25
|
-
if (prop in extObj) {
|
|
26
|
-
delete extObj[prop];
|
|
27
|
-
success = true;
|
|
28
|
-
}
|
|
29
|
-
if (prop in baseObj) {
|
|
30
|
-
delete baseObj[prop];
|
|
31
|
-
success = true;
|
|
32
|
-
}
|
|
33
|
-
return success;
|
|
34
|
-
},
|
|
35
|
-
ownKeys(_target) {
|
|
36
|
-
const baseKeys = Reflect.ownKeys(baseObj);
|
|
37
|
-
const extKeys = Reflect.ownKeys(extObj);
|
|
38
|
-
const extKeysSet = new Set(extKeys);
|
|
39
|
-
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
40
|
-
},
|
|
41
|
-
defineProperty(_target, prop, desc) {
|
|
42
|
-
if (prop in extObj) {
|
|
43
|
-
delete extObj[prop];
|
|
44
|
-
}
|
|
45
|
-
Reflect.defineProperty(baseObj, prop, desc);
|
|
46
|
-
return true;
|
|
47
|
-
},
|
|
48
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
49
|
-
if (prop in extObj) {
|
|
50
|
-
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
has(_target, prop) {
|
|
57
|
-
return prop in extObj || prop in baseObj;
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"combinePlotDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/combinePlotDocs.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM,CA4GR"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combinePlotDocs = combinePlotDocs;
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
|
-
// The Plot source uses ATX headings, explicit VitePress IDs, and Markdown fences.
|
|
6
|
-
// Keep code verbatim; rewrite only prose links and anchors while joining pages.
|
|
7
|
-
function combinePlotDocs(version, documents) {
|
|
8
|
-
const pages = [...documents.keys()].sort();
|
|
9
|
-
const source = `https://github.com/observablehq/plot/tree/v${version}/docs`;
|
|
10
|
-
const anchors = new Map();
|
|
11
|
-
const sections = new Map();
|
|
12
|
-
const pageId = (page) => `plot-${page.replace(/\.md$/, "").replaceAll("/", "--")}`;
|
|
13
|
-
for (const page of pages) {
|
|
14
|
-
const ids = new Map();
|
|
15
|
-
const headings = [];
|
|
16
|
-
const counts = new Map();
|
|
17
|
-
proseLines(documents.get(page), (line, number) => {
|
|
18
|
-
for (const match of line.matchAll(/\bid=["']([^"']+)["']/g)) {
|
|
19
|
-
ids.set(match[1], `${pageId(page)}--${match[1]}`);
|
|
20
|
-
}
|
|
21
|
-
const heading = line.match(/^ {0,3}#{1,6}\s+(.+?)\s*#*\s*$/);
|
|
22
|
-
if (!heading)
|
|
23
|
-
return line;
|
|
24
|
-
const explicit = heading[1].match(/\{#([^}]+)\}/)?.[1];
|
|
25
|
-
const title = heading[1].replace(/\s*\{#[^}]+\}/g, "");
|
|
26
|
-
const slug = explicit ?? title.replace(/<[^>]*>/g, "")
|
|
27
|
-
.toLowerCase().replace(/[^\p{L}\p{N}_\s-]/gu, "")
|
|
28
|
-
.trim().replace(/\s+/g, "-");
|
|
29
|
-
const count = counts.get(slug) ?? 0;
|
|
30
|
-
counts.set(slug, count + 1);
|
|
31
|
-
const localId = `${slug}${count ? `-${count}` : ""}`;
|
|
32
|
-
const id = `${pageId(page)}--${localId}`;
|
|
33
|
-
ids.set(localId, id);
|
|
34
|
-
headings.push({ line: number, title, id });
|
|
35
|
-
return line;
|
|
36
|
-
});
|
|
37
|
-
anchors.set(page, ids);
|
|
38
|
-
sections.set(page, headings);
|
|
39
|
-
}
|
|
40
|
-
function link(target, page) {
|
|
41
|
-
if (/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(target))
|
|
42
|
-
return target;
|
|
43
|
-
const [pathAndQuery, fragment] = target.split("#", 2);
|
|
44
|
-
const path = pathAndQuery.split("?", 1)[0];
|
|
45
|
-
const resolved = path === "" ? page : node_path_1.posix.normalize(path.startsWith("/")
|
|
46
|
-
? path.slice(1)
|
|
47
|
-
: node_path_1.posix.join(node_path_1.posix.dirname(page), path));
|
|
48
|
-
const markdown = [resolved, `${resolved}.md`, `${resolved}/index.md`]
|
|
49
|
-
.find((candidate) => documents.has(candidate));
|
|
50
|
-
if (markdown) {
|
|
51
|
-
const id = fragment
|
|
52
|
-
? anchors.get(markdown)?.get(decodeURIComponent(fragment))
|
|
53
|
-
: pageId(markdown);
|
|
54
|
-
if (id)
|
|
55
|
-
return `#${id}`;
|
|
56
|
-
// Preserve an upstream target when a fragment is not a known heading/ID.
|
|
57
|
-
return `${source}/${markdown}${fragment ? `#${fragment}` : ""}`;
|
|
58
|
-
}
|
|
59
|
-
if (resolved.endsWith(".md")) {
|
|
60
|
-
return `${source}/${resolved}${fragment ? `#${fragment}` : ""}`;
|
|
61
|
-
}
|
|
62
|
-
const base = "https://raw.githubusercontent.com/observablehq/plot/" +
|
|
63
|
-
`refs/tags/v${version}/docs/`;
|
|
64
|
-
return path.startsWith("/")
|
|
65
|
-
? new URL(`public${target}`, base).href
|
|
66
|
-
: new URL(target, `${base}${page}`).href;
|
|
67
|
-
}
|
|
68
|
-
const contents = pages.flatMap((page) => [
|
|
69
|
-
`- [${page}](#${pageId(page)})`,
|
|
70
|
-
...(sections.get(page) ?? []).map(({ title, id }) => ` - [${title.replace(/[\[\]]/g, "")}](#${id})`),
|
|
71
|
-
]).join("\n");
|
|
72
|
-
const combined = pages.map((page) => {
|
|
73
|
-
const headings = new Map(sections.get(page).map((heading) => [heading.line, heading]));
|
|
74
|
-
const body = proseLines(documents.get(page), (line, number) => {
|
|
75
|
-
const heading = headings.get(number);
|
|
76
|
-
// Inline code also remains verbatim. Plot's prose links have simple destinations.
|
|
77
|
-
line = line.split(/(`+[^`]*`+)/g).map((part, index) => {
|
|
78
|
-
if (index % 2)
|
|
79
|
-
return part;
|
|
80
|
-
return part.replace(/(\]\()([^\s)]+)([^)]*\))/g, (_, before, target, after) => `${before}${link(target, page)}${after}`).replace(/^( {0,3}\[[^\]]+\]:\s*)(\S+)/, (_, before, target) => `${before}${link(target, page)}`).replace(/(?<!:)\b(href|src)=(["'])([^"']+)\2/g, (_, attr, quote, target) => `${attr}=${quote}${link(target, page)}${quote}`).replace(/\bid=(["'])([^"']+)\1/g, (_, quote, id) => `id=${quote}${anchors.get(page)?.get(id) ?? id}${quote}`);
|
|
81
|
-
}).join("");
|
|
82
|
-
return heading
|
|
83
|
-
? `<a id="${heading.id}"></a>\n\n${line.replace(/\s*\{#[^}]+\}/g, "")}`
|
|
84
|
-
: line;
|
|
85
|
-
});
|
|
86
|
-
return `<a id="${pageId(page)}"></a>\n\n# ${page}\n\nSource: ${source}/${page}\n\n${body}`;
|
|
87
|
-
}).join("\n\n---\n\n");
|
|
88
|
-
return `# Observable Plot ${version}\n\nPackage: \`@observablehq/plot@${version}\`. Source: [v${version}](${source}).\n\nThis reference combines selected upstream documentation for static charts and maps. Introductory and site pages, interaction helpers, and the Auto and Tip marks are omitted. Vue components and plot fences are retained as source examples. Use the table of contents to find API signatures and examples; links to omitted pages lead to the tagged upstream documentation.\n\n## Table of contents\n\n${contents}\n\n---\n\n${combined}\n\n<!-- setup-data-project:observable-plot:${version}:complete -->\n`;
|
|
89
|
-
}
|
|
90
|
-
function proseLines(content, transform) {
|
|
91
|
-
let fence;
|
|
92
|
-
let script = false;
|
|
93
|
-
return content.split("\n").map((line, number) => {
|
|
94
|
-
const marker = line.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
95
|
-
if (fence) {
|
|
96
|
-
if (marker?.[1][0] === fence.character &&
|
|
97
|
-
marker[1].length >= fence.length && /^ {0,3}(?:`+|~+)\s*$/.test(line))
|
|
98
|
-
fence = undefined;
|
|
99
|
-
return line;
|
|
100
|
-
}
|
|
101
|
-
if (marker) {
|
|
102
|
-
fence = { character: marker[1][0], length: marker[1].length };
|
|
103
|
-
return line;
|
|
104
|
-
}
|
|
105
|
-
if (/^\s*<script\b/.test(line))
|
|
106
|
-
script = true;
|
|
107
|
-
if (script) {
|
|
108
|
-
if (/<\/script>/.test(line))
|
|
109
|
-
script = false;
|
|
110
|
-
return line;
|
|
111
|
-
}
|
|
112
|
-
return transform(line, number);
|
|
113
|
-
}).join("\n");
|
|
114
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAIA,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UA6C/D"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createFolderStructure = createFolderStructure;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const prompts_1 = require("@clack/prompts");
|
|
7
|
-
function createFolderStructure(selectedPackages) {
|
|
8
|
-
const sdaFolder = "sda";
|
|
9
|
-
const folders = ["data", "helpers", "output", "tests"];
|
|
10
|
-
if (!(0, node_fs_1.existsSync)(sdaFolder)) {
|
|
11
|
-
(0, node_fs_1.mkdirSync)(sdaFolder, { recursive: true });
|
|
12
|
-
}
|
|
13
|
-
for (const folder of folders) {
|
|
14
|
-
const path = (0, node_path_1.join)(sdaFolder, folder);
|
|
15
|
-
if (!(0, node_fs_1.existsSync)(path)) {
|
|
16
|
-
(0, node_fs_1.mkdirSync)(path, { recursive: true });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const mainTsPath = (0, node_path_1.join)(sdaFolder, "main.ts");
|
|
20
|
-
let mainTsContent = 'console.log("Hello simple-data-analysis!");\n';
|
|
21
|
-
if (selectedPackages.includes("@nshiab/simple-data-analysis") ||
|
|
22
|
-
selectedPackages.includes("@nshiab/simple-data-analysis-core")) {
|
|
23
|
-
const pkg = selectedPackages.includes("@nshiab/simple-data-analysis")
|
|
24
|
-
? "@nshiab/simple-data-analysis"
|
|
25
|
-
: "@nshiab/simple-data-analysis-core";
|
|
26
|
-
mainTsContent = `import { SimpleDB } from "${pkg}";
|
|
27
|
-
|
|
28
|
-
const sdb = new SimpleDB();
|
|
29
|
-
const table = sdb.newTable();
|
|
30
|
-
|
|
31
|
-
await table
|
|
32
|
-
.loadArray([{ message: "Hello simple-data-analysis!" }])
|
|
33
|
-
.log();
|
|
34
|
-
|
|
35
|
-
await sdb.close();
|
|
36
|
-
`;
|
|
37
|
-
}
|
|
38
|
-
if ((0, node_fs_1.lstatSync)(mainTsPath, { throwIfNoEntry: false }) === undefined) {
|
|
39
|
-
(0, node_fs_1.writeFileSync)(mainTsPath, mainTsContent);
|
|
40
|
-
prompts_1.log.info(`Created ${mainTsPath}`);
|
|
41
|
-
}
|
|
42
|
-
return sdaFolder;
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOzD,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACxC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QA+LvD"}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureAgents = ensureAgents;
|
|
4
|
-
const prompts_1 = require("@clack/prompts");
|
|
5
|
-
const ensureManagedSection_js_1 = require("./ensureManagedSection.js");
|
|
6
|
-
const packageRegistry_js_1 = require("./packageRegistry.js");
|
|
7
|
-
function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docsMapping)) {
|
|
8
|
-
let journalismFunctions = "";
|
|
9
|
-
let sdaClassesAndMethods = "";
|
|
10
|
-
let sdaDocsPath = "";
|
|
11
|
-
let sdaReadmePath = "";
|
|
12
|
-
let sdaLibraryName = "";
|
|
13
|
-
const journalismFunctionsByPackage = new Map();
|
|
14
|
-
for (const [pkg, docs] of Object.entries(docsMapping)) {
|
|
15
|
-
const pkgConfig = packageRegistry_js_1.SUPPORTED_PACKAGES.find((p) => p.value === pkg);
|
|
16
|
-
const pkgType = pkgConfig?.type || "other";
|
|
17
|
-
const doc = docs.llm;
|
|
18
|
-
if (doc === undefined)
|
|
19
|
-
continue;
|
|
20
|
-
if (pkgType === "journalism") {
|
|
21
|
-
const repoName = pkg.split("/")[1];
|
|
22
|
-
const functions = doc
|
|
23
|
-
.split("\n")
|
|
24
|
-
.filter((line) => line.trim().startsWith("#"))
|
|
25
|
-
.filter((line) => {
|
|
26
|
-
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
27
|
-
return depth === 2;
|
|
28
|
-
})
|
|
29
|
-
.map((line) => line.replace(/^#+\s+/, "").trim());
|
|
30
|
-
journalismFunctionsByPackage.set(pkg, functions);
|
|
31
|
-
journalismFunctions += `\n### ${repoName}\n\n`;
|
|
32
|
-
journalismFunctions += functions.map((name) => `- ${name}`).join("\n") +
|
|
33
|
-
"\n";
|
|
34
|
-
}
|
|
35
|
-
else if (pkgType === "sda") {
|
|
36
|
-
const repoName = pkg.split("/")[1];
|
|
37
|
-
sdaDocsPath = `./docs/${repoName}/llm.md`;
|
|
38
|
-
sdaReadmePath = docs.readme === undefined
|
|
39
|
-
? ""
|
|
40
|
-
: `./docs/${repoName}/README.md`;
|
|
41
|
-
sdaLibraryName = pkgConfig?.label || repoName;
|
|
42
|
-
sdaClassesAndMethods = doc
|
|
43
|
-
.split("\n")
|
|
44
|
-
.filter((line) => line.trim().startsWith("#"))
|
|
45
|
-
.filter((line) => {
|
|
46
|
-
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
47
|
-
if (depth === 2)
|
|
48
|
-
return true;
|
|
49
|
-
if (depth !== 4)
|
|
50
|
-
return false;
|
|
51
|
-
const heading = line.replace(/^#+\s+/, "").replaceAll("`", "")
|
|
52
|
-
.trim();
|
|
53
|
-
return heading !== "Parameters";
|
|
54
|
-
})
|
|
55
|
-
.map((line) => {
|
|
56
|
-
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
57
|
-
if (depth === 2) {
|
|
58
|
-
return "\n" + line.replace(/^#+\s+/, "").trim();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return line.replace(/^#+\s+/, " - ")
|
|
62
|
-
.replaceAll("`", "");
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
.join("\n");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const configFile = runtime === "deno" ? "deno.json" : "package.json";
|
|
69
|
-
const runSdaOnce = runtime === "deno"
|
|
70
|
-
? "deno run -A --env --check sda/main.ts"
|
|
71
|
-
: runtime === "bun"
|
|
72
|
-
? "bun run sda/main.ts"
|
|
73
|
-
: "node --env-file-if-exists=.env --experimental-strip-types sda/main.ts";
|
|
74
|
-
const runClean = runtime === "deno" ? "deno task clean" : "npm run clean";
|
|
75
|
-
const runAllTests = runtime === "deno"
|
|
76
|
-
? "deno task all-tests"
|
|
77
|
-
: runtime === "bun"
|
|
78
|
-
? "bun run all-tests"
|
|
79
|
-
: "npm run all-tests";
|
|
80
|
-
const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
|
|
81
|
-
const importExamples = installedPackageConfigs.flatMap((pkg) => {
|
|
82
|
-
if (pkg.type === "sda") {
|
|
83
|
-
return [`import { SimpleDB } from "${pkg.value}";`];
|
|
84
|
-
}
|
|
85
|
-
const functionName = journalismFunctionsByPackage.get(pkg.value)
|
|
86
|
-
?.map((name) => name.replaceAll("`", ""))
|
|
87
|
-
.find((name) => /^[A-Za-z_$][\w$]*$/.test(name));
|
|
88
|
-
return functionName
|
|
89
|
-
? [`import { ${functionName} } from "${pkg.value}";`]
|
|
90
|
-
: [];
|
|
91
|
-
});
|
|
92
|
-
let libraryGuidance = "";
|
|
93
|
-
if (installedPackageConfigs.length > 0) {
|
|
94
|
-
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.value}"`)
|
|
95
|
-
.join(", ");
|
|
96
|
-
const libraryNoun = installedPackageConfigs.length === 1
|
|
97
|
-
? "library"
|
|
98
|
-
: "libraries";
|
|
99
|
-
libraryGuidance = `
|
|
100
|
-
Always prioritize the installed ${libraryNames} ${libraryNoun} when relevant.
|
|
101
|
-
`;
|
|
102
|
-
const documentationGuidance = installedPackageConfigs.flatMap((pkg) => {
|
|
103
|
-
const docs = docsMapping[pkg.value];
|
|
104
|
-
if (!docs)
|
|
105
|
-
return [];
|
|
106
|
-
if (docs.plot) {
|
|
107
|
-
return [
|
|
108
|
-
"- `@observablehq/plot`: use Observable Plot to create charts and maps " +
|
|
109
|
-
"with `writeChart` and `writeMap`. Import with " +
|
|
110
|
-
'`import { plot } from "@observablehq/plot";`. ' +
|
|
111
|
-
"Documentation and examples at `./docs/observable-plot/llm.md`",
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
const repoName = pkg.value.split("/")[1];
|
|
115
|
-
const availableDocs = [
|
|
116
|
-
docs.readme === undefined
|
|
117
|
-
? ""
|
|
118
|
-
: `overview and practical examples at \`./docs/${repoName}/README.md\``,
|
|
119
|
-
docs.llm === undefined
|
|
120
|
-
? ""
|
|
121
|
-
: `complete API documentation at \`./docs/${repoName}/llm.md\``,
|
|
122
|
-
].filter(Boolean);
|
|
123
|
-
return availableDocs.length === 0
|
|
124
|
-
? []
|
|
125
|
-
: [`- \`${pkg.value}\`: ${availableDocs.join("; ")}`];
|
|
126
|
-
});
|
|
127
|
-
if (documentationGuidance.length > 0) {
|
|
128
|
-
libraryGuidance += `
|
|
129
|
-
The \`docs/\` folder contains long, exhaustive library references. Search for the relevant methods or topics, then read only the matching sections and any related definitions or examples you need.
|
|
130
|
-
|
|
131
|
-
The following documentation was fetched for the exact installed library versions. Consult it when relevant:
|
|
132
|
-
|
|
133
|
-
${documentationGuidance.join("\n")}
|
|
134
|
-
`;
|
|
135
|
-
}
|
|
136
|
-
if (importExamples.length > 0) {
|
|
137
|
-
libraryGuidance += `APIs can be imported like this:
|
|
138
|
-
\`\`\`typescript
|
|
139
|
-
${importExamples.join("\n")}
|
|
140
|
-
\`\`\`
|
|
141
|
-
`;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
let content = `Always verify if there is a ${configFile} file in the root of the project and familiarize yourself with the scripts available in it and the libraries already installed in the project.
|
|
145
|
-
|
|
146
|
-
Run \`sda/main.ts\` with \`${runSdaOnce}\`. Do not use the \`sda\` task for agent-driven checks because it runs in watch mode and will keep waiting for file changes.
|
|
147
|
-
|
|
148
|
-
Before handing off your work, always run \`${runAllTests}\`, even if no tests have been added yet. Fix any errors or warnings it reports.
|
|
149
|
-
|
|
150
|
-
The \`clean\` task (e.g. \`${runClean}\`) removes caches and other temporary files. Do not run it routinely. Cached results can be especially valuable for computationally expensive operations or API calls. If you are unsure whether the caches should be removed, ask the user first.
|
|
151
|
-
|
|
152
|
-
Always use "sda/main.ts" as the entry point.
|
|
153
|
-
|
|
154
|
-
If you need to create other TypeScript files, create them in the "sda/helpers" folder. Prioritize the use of helper functions to keep the code well organized and maintainable, with one helper function per file, with the file named after the function. Prioritize default exports for helper functions.
|
|
155
|
-
|
|
156
|
-
Put tests in the "sda/tests" folder. Write focused tests for reusable helpers and important data transformations when appropriate. When testing a helper from "sda/helpers/functionName.ts", name its test file "sda/tests/functionName.test.ts".
|
|
157
|
-
|
|
158
|
-
If you need to download data, always put the files in the "sda/data" folder, which is ignored by Git.
|
|
159
|
-
|
|
160
|
-
If you need to output data to a file, always put the file in the "sda/output" folder, which is also ignored by Git.
|
|
161
|
-
${libraryGuidance}`;
|
|
162
|
-
if (journalismFunctions !== "") {
|
|
163
|
-
content += `
|
|
164
|
-
Here are the functions available in the "journalism" libraries. If one of the functions might be relevant, search its complete API documentation in the corresponding \`./docs/<library-name>/llm.md\` file to properly use it.
|
|
165
|
-
${journalismFunctions}`;
|
|
166
|
-
}
|
|
167
|
-
if (sdaClassesAndMethods !== "") {
|
|
168
|
-
const readmeGuidance = sdaReadmePath === ""
|
|
169
|
-
? ""
|
|
170
|
-
: ` An overview and practical examples are available at "${sdaReadmePath}".`;
|
|
171
|
-
content += `
|
|
172
|
-
Here are the classes and their methods available in the "${sdaLibraryName}" library.${readmeGuidance} If one of the classes or methods might be relevant, search the complete API documentation at "${sdaDocsPath}" to properly use it.
|
|
173
|
-
|
|
174
|
-
Most data-loading and transformation methods are synchronous, chainable builders. Await the final asynchronous observer or export method, such as \`log()\`, \`getData()\`, or \`writeData()\`, to execute the queued operations. If a chain ends without an observer, call \`run()\`. Always call \`await sdb.close()\` when the database is no longer needed. Methods that return an answer or export to an external service can be asynchronous, so verify their documentation before calling them.
|
|
175
|
-
${sdaClassesAndMethods}`;
|
|
176
|
-
}
|
|
177
|
-
const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
|
|
178
|
-
path: "AGENTS.md",
|
|
179
|
-
name: "agents",
|
|
180
|
-
content,
|
|
181
|
-
createContent: (managedSection) => managedSection,
|
|
182
|
-
});
|
|
183
|
-
if (status === "created") {
|
|
184
|
-
prompts_1.log.info("Created AGENTS.md");
|
|
185
|
-
}
|
|
186
|
-
else if (status === "updated") {
|
|
187
|
-
prompts_1.log.info("Updated AGENTS.md");
|
|
188
|
-
}
|
|
189
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureEnvFile.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureEnvFile.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,SAK5B"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureEnvFile = ensureEnvFile;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const prompts_1 = require("@clack/prompts");
|
|
6
|
-
function ensureEnvFile() {
|
|
7
|
-
if ((0, node_fs_1.lstatSync)(".env", { throwIfNoEntry: false }) === undefined) {
|
|
8
|
-
(0, node_fs_1.writeFileSync)(".env", "");
|
|
9
|
-
prompts_1.log.info("Created .env");
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureGitignore.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureGitignore.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,4DAC4B,CAAC;AAE5D,wBAAgB,eAAe,SA0B9B"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GITIGNORE_SENTINEL = void 0;
|
|
4
|
-
exports.ensureGitignore = ensureGitignore;
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const prompts_1 = require("@clack/prompts");
|
|
7
|
-
const gitignoreEntries_js_1 = require("./gitignoreEntries.js");
|
|
8
|
-
exports.GITIGNORE_SENTINEL = "# Added by setup-data-project. Do not remove this line.";
|
|
9
|
-
function ensureGitignore() {
|
|
10
|
-
const path = ".gitignore";
|
|
11
|
-
const stats = (0, node_fs_1.lstatSync)(path, { throwIfNoEntry: false });
|
|
12
|
-
if (stats?.isSymbolicLink()) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const content = stats === undefined ? "" : (0, node_fs_1.readFileSync)(path, "utf-8");
|
|
16
|
-
const hasSentinel = content.split("\n").some((line) => line.trim() === exports.GITIGNORE_SENTINEL);
|
|
17
|
-
if (hasSentinel) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const separator = content === ""
|
|
21
|
-
? ""
|
|
22
|
-
: content.endsWith("\n")
|
|
23
|
-
? "\n"
|
|
24
|
-
: "\n\n";
|
|
25
|
-
const block = `${exports.GITIGNORE_SENTINEL}\n${gitignoreEntries_js_1.GITIGNORE_ENTRIES.join("\n")}\n`;
|
|
26
|
-
(0, node_fs_1.writeFileSync)(path, content + separator + block);
|
|
27
|
-
prompts_1.log.info(`${stats === undefined ? "Created" : "Updated"} ${path}`);
|
|
28
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
interface ManagedSectionOptions {
|
|
2
|
-
path: string;
|
|
3
|
-
name: string;
|
|
4
|
-
content: string;
|
|
5
|
-
createContent: (section: string) => string;
|
|
6
|
-
}
|
|
7
|
-
export declare function ensureManagedSection(options: ManagedSectionOptions): "created" | "updated" | "unchanged" | "missing-markers";
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=ensureManagedSection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureManagedSection.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureManagedSection.ts"],"names":[],"mappings":"AAGA,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5C;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,iBAAiB,CAwCzD"}
|