@nshiab/setup-data-project 2.0.3 → 3.0.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/README.md +76 -28
- package/dist/main.mjs +849 -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
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureManagedSection = ensureManagedSection;
|
|
4
|
-
const prompts_1 = require("@clack/prompts");
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
function ensureManagedSection(options) {
|
|
7
|
-
const startMarker = `<!-- Do not remove / setup-data-project:${options.name}:start -->`;
|
|
8
|
-
const endMarker = `<!-- Do not remove / setup-data-project:${options.name}:end -->`;
|
|
9
|
-
const trimmedContent = options.content.trim();
|
|
10
|
-
const section = trimmedContent === ""
|
|
11
|
-
? `${startMarker}\n${endMarker}`
|
|
12
|
-
: `${startMarker}\n${trimmedContent}\n${endMarker}`;
|
|
13
|
-
if (!(0, node_fs_1.existsSync)(options.path)) {
|
|
14
|
-
(0, node_fs_1.writeFileSync)(options.path, ensureFinalNewline(options.createContent(section)));
|
|
15
|
-
return "created";
|
|
16
|
-
}
|
|
17
|
-
const currentContent = (0, node_fs_1.readFileSync)(options.path, "utf-8");
|
|
18
|
-
const start = currentContent.indexOf(startMarker);
|
|
19
|
-
const end = currentContent.indexOf(endMarker);
|
|
20
|
-
if (start === -1 || end === -1 || end < start) {
|
|
21
|
-
prompts_1.log.warn(`${options.path} was not updated because its setup-data-project markers ` +
|
|
22
|
-
`were not found. Add ${startMarker} and ${endMarker}, then rerun the ` +
|
|
23
|
-
"script.");
|
|
24
|
-
return "missing-markers";
|
|
25
|
-
}
|
|
26
|
-
const nextContent = currentContent.slice(0, start) + section +
|
|
27
|
-
currentContent.slice(end + endMarker.length);
|
|
28
|
-
if (nextContent === currentContent) {
|
|
29
|
-
return "unchanged";
|
|
30
|
-
}
|
|
31
|
-
(0, node_fs_1.writeFileSync)(options.path, ensureFinalNewline(nextContent));
|
|
32
|
-
return "updated";
|
|
33
|
-
}
|
|
34
|
-
function ensureFinalNewline(content) {
|
|
35
|
-
return content.endsWith("\n") ? content : content + "\n";
|
|
36
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureReadme.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureReadme.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAAO,QAsEjC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureReadme = ensureReadme;
|
|
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 ensureReadme(runtime, installedPackages = []) {
|
|
8
|
-
let runCommand = "npm run";
|
|
9
|
-
if (runtime === "deno") {
|
|
10
|
-
runCommand = "deno task";
|
|
11
|
-
}
|
|
12
|
-
else if (runtime === "bun") {
|
|
13
|
-
runCommand = "bun run";
|
|
14
|
-
}
|
|
15
|
-
const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
|
|
16
|
-
const hasSdaCore = installedPackageConfigs.some((pkg) => pkg.value === "@nshiab/simple-data-analysis-core");
|
|
17
|
-
const hasFullSda = installedPackageConfigs.some((pkg) => pkg.value === "@nshiab/simple-data-analysis");
|
|
18
|
-
const hasJournalism = installedPackageConfigs.some((pkg) => pkg.type === "journalism");
|
|
19
|
-
const libraryLinks = [
|
|
20
|
-
hasSdaCore
|
|
21
|
-
? "[simple-data-analysis-core](https://github.com/nshiab/simple-data-analysis-core)"
|
|
22
|
-
: "",
|
|
23
|
-
hasFullSda
|
|
24
|
-
? "[simple-data-analysis](https://github.com/nshiab/simple-data-analysis)"
|
|
25
|
-
: "",
|
|
26
|
-
hasJournalism ? "[journalism](https://github.com/nshiab/journalism)" : "",
|
|
27
|
-
].filter(Boolean);
|
|
28
|
-
const librarySection = libraryLinks.length === 0
|
|
29
|
-
? ""
|
|
30
|
-
: `It has installed ${libraryLinks.join(" and ")} ${libraryLinks.length === 1 ? "library" : "libraries"}, along with
|
|
31
|
-
up-to-date documentation and AI agent instructions.`;
|
|
32
|
-
const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
|
|
33
|
-
path: "README.md",
|
|
34
|
-
name: "libraries",
|
|
35
|
-
content: librarySection,
|
|
36
|
-
createContent: (managedSection) => `This repository was created with
|
|
37
|
-
[setup-data-project](https://github.com/nshiab/setup-data-project/).
|
|
38
|
-
|
|
39
|
-
${managedSection}
|
|
40
|
-
|
|
41
|
-
Here's the recommended workflow:
|
|
42
|
-
|
|
43
|
-
- Put your raw data in the \`sda/data\` folder. Note that this folder is
|
|
44
|
-
ignored by Git.
|
|
45
|
-
- Use the \`sda/main.ts\` file to process your raw data. Write the
|
|
46
|
-
results to the \`sda/output\` folder, which is also ignored by Git.
|
|
47
|
-
- Put your tests in the \`sda/tests\` folder.
|
|
48
|
-
|
|
49
|
-
When working on your project, use the following commands:
|
|
50
|
-
|
|
51
|
-
- \`${runCommand} sda\` will watch your \`sda/main.ts\` and its dependencies.
|
|
52
|
-
Whenever you save changes, the data will be reprocessed.
|
|
53
|
-
- \`${runCommand} all-tests\` will run the project's test command.
|
|
54
|
-
- \`${runCommand} clean\` will remove cache and temporary files, if present.
|
|
55
|
-
|
|
56
|
-
Have fun!`,
|
|
57
|
-
});
|
|
58
|
-
if (status === "created") {
|
|
59
|
-
prompts_1.log.info("Created README.md");
|
|
60
|
-
}
|
|
61
|
-
else if (status === "updated") {
|
|
62
|
-
prompts_1.log.info("Updated README.md");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface PackageDocs {
|
|
2
|
-
readme?: string;
|
|
3
|
-
llm?: string;
|
|
4
|
-
plot?: {
|
|
5
|
-
version: string;
|
|
6
|
-
pages: string[];
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export declare function fetchPackageDocs(pkg: string, version: string, options?: {
|
|
10
|
-
silent?: boolean;
|
|
11
|
-
}): Promise<PackageDocs>;
|
|
12
|
-
//# sourceMappingURL=fetchPackageDocs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchPackageDocs.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAC7C;AAiBD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,WAAW,CAAC,CA4DtB"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchPackageDocs = fetchPackageDocs;
|
|
4
|
-
const prompts_1 = require("@clack/prompts");
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const PACKAGE_DOCUMENTS = [
|
|
8
|
-
{
|
|
9
|
-
remoteName: "README.md",
|
|
10
|
-
localName: "README.md",
|
|
11
|
-
key: "readme",
|
|
12
|
-
label: "README",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
remoteName: "llm.md",
|
|
16
|
-
localName: "llm.md",
|
|
17
|
-
key: "llm",
|
|
18
|
-
label: "API documentation",
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
async function fetchPackageDocs(pkg, version, options = {}) {
|
|
22
|
-
const repoName = pkg.split("/")[1];
|
|
23
|
-
const docsDirectory = (0, node_path_1.join)("docs", repoName);
|
|
24
|
-
(0, node_fs_1.mkdirSync)(docsDirectory, { recursive: true });
|
|
25
|
-
const sFetch = (0, prompts_1.spinner)();
|
|
26
|
-
if (!options.silent) {
|
|
27
|
-
sFetch.start(`Fetching documentation for ${pkg}@${version}...`);
|
|
28
|
-
}
|
|
29
|
-
const fetchedDocuments = await Promise.all(PACKAGE_DOCUMENTS.map(async (document) => {
|
|
30
|
-
const localPath = (0, node_path_1.join)(docsDirectory, document.localName);
|
|
31
|
-
try {
|
|
32
|
-
const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
|
|
33
|
-
`/refs/tags/v${version}/${document.remoteName}`;
|
|
34
|
-
const response = await fetch(url);
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
warnAboutFailedFetch(pkg, version, document.label, localPath);
|
|
37
|
-
return { key: document.key, content: undefined };
|
|
38
|
-
}
|
|
39
|
-
const content = await response.text();
|
|
40
|
-
(0, node_fs_1.writeFileSync)(localPath, content);
|
|
41
|
-
return { key: document.key, content };
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
warnAboutFailedFetch(pkg, version, document.label, localPath);
|
|
45
|
-
console.error(error);
|
|
46
|
-
return { key: document.key, content: undefined };
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
49
|
-
const docs = {};
|
|
50
|
-
for (const document of fetchedDocuments) {
|
|
51
|
-
if (document.content !== undefined) {
|
|
52
|
-
docs[document.key] = document.content;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const savedCount = fetchedDocuments.filter((document) => document.content !== undefined)
|
|
56
|
-
.length;
|
|
57
|
-
if (!options.silent) {
|
|
58
|
-
if (savedCount === PACKAGE_DOCUMENTS.length) {
|
|
59
|
-
sFetch.stop(`✅ Documentation for ${pkg}@${version} saved!`);
|
|
60
|
-
}
|
|
61
|
-
else if (savedCount > 0) {
|
|
62
|
-
sFetch.stop(`⚠️ Some documentation for ${pkg}@${version} could not be fetched.`);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
sFetch.stop(`❌ Failed to fetch documentation for ${pkg}@${version}.`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return docs;
|
|
69
|
-
}
|
|
70
|
-
function warnAboutFailedFetch(pkg, version, label, localPath) {
|
|
71
|
-
const existingFileGuidance = (0, node_fs_1.existsSync)(localPath)
|
|
72
|
-
? ` The existing file at ${localPath} was preserved, but it may not ` +
|
|
73
|
-
"match the installed version. Double-check it before relying on it, or " +
|
|
74
|
-
"remove it."
|
|
75
|
-
: "";
|
|
76
|
-
prompts_1.log.warn(`Could not fetch ${label} for ${pkg}@${version} from its GitHub tag.` +
|
|
77
|
-
existingFileGuidance);
|
|
78
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchPlotDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchPlotDocs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACvC,OAAO,CAAC,WAAW,CAAC,CAsCtB"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchPlotDocs = fetchPlotDocs;
|
|
4
|
-
const prompts_1 = require("@clack/prompts");
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const combinePlotDocs_js_1 = require("./combinePlotDocs.js");
|
|
8
|
-
const plotDocPages_js_1 = require("./plotDocPages.js");
|
|
9
|
-
// Publish one reference only after every tagged page has been fetched.
|
|
10
|
-
async function fetchPlotDocs(version, options = {}) {
|
|
11
|
-
const tag = `v${version}`;
|
|
12
|
-
const directory = (0, node_path_1.join)("docs", "observable-plot");
|
|
13
|
-
try {
|
|
14
|
-
let llm;
|
|
15
|
-
if (options.preferStored !== false) {
|
|
16
|
-
try {
|
|
17
|
-
const response = await fetch("https://raw.githubusercontent.com/nshiab/setup-data-project/" +
|
|
18
|
-
`refs/heads/main/docs-cache/observable-plot/${version}/llm.md`);
|
|
19
|
-
if (response.ok) {
|
|
20
|
-
const cached = await response.text();
|
|
21
|
-
if (isStoredReference(cached, version))
|
|
22
|
-
llm = cached;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
// A cache is an optimization. An unavailable cache never blocks the tag.
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (llm === undefined)
|
|
30
|
-
llm = await generateReference(version);
|
|
31
|
-
(0, node_fs_1.mkdirSync)(directory, { recursive: true });
|
|
32
|
-
const temporaryPath = (0, node_path_1.join)(directory, ".llm.md.tmp");
|
|
33
|
-
try {
|
|
34
|
-
(0, node_fs_1.writeFileSync)(temporaryPath, llm);
|
|
35
|
-
(0, node_fs_1.renameSync)(temporaryPath, (0, node_path_1.join)(directory, "llm.md"));
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
(0, node_fs_1.rmSync)(temporaryPath, { force: true });
|
|
39
|
-
}
|
|
40
|
-
return { llm, plot: { version, pages: [...plotDocPages_js_1.PLOT_DOC_PAGES] } };
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
prompts_1.log.warn(`Could not fetch complete Observable Plot documentation for ${tag}. ` +
|
|
44
|
-
"Existing files were preserved, but may not match the installed " +
|
|
45
|
-
"version. Plot documentation will not be included in AGENTS.md. " +
|
|
46
|
-
String(error));
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function generateReference(version) {
|
|
51
|
-
const tag = `v${version}`;
|
|
52
|
-
const pages = plotDocPages_js_1.PLOT_DOC_PAGES;
|
|
53
|
-
const documents = new Map();
|
|
54
|
-
const failed = [];
|
|
55
|
-
// Fetch in small batches to avoid overwhelming GitHub on the first run.
|
|
56
|
-
for (let offset = 0; offset < pages.length; offset += 8) {
|
|
57
|
-
await Promise.all(pages.slice(offset, offset + 8).map(async (page) => {
|
|
58
|
-
try {
|
|
59
|
-
const url = "https://raw.githubusercontent.com/observablehq/plot/" +
|
|
60
|
-
`refs/tags/${tag}/docs/${page}`;
|
|
61
|
-
const response = await fetch(url);
|
|
62
|
-
if (!response.ok)
|
|
63
|
-
throw new Error(`HTTP ${response.status}`);
|
|
64
|
-
const content = await response.text();
|
|
65
|
-
documents.set(page, content);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
failed.push(page);
|
|
69
|
-
}
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
if (failed.length > 0) {
|
|
73
|
-
throw new Error(`Could not fetch ${failed.length} Markdown pages`);
|
|
74
|
-
}
|
|
75
|
-
return (0, combinePlotDocs_js_1.combinePlotDocs)(version, documents);
|
|
76
|
-
}
|
|
77
|
-
function isStoredReference(content, version) {
|
|
78
|
-
const source = `https://github.com/observablehq/plot/tree/v${version}/docs`;
|
|
79
|
-
const metadata = content.split(/\n\s*\n/)[1]?.replace(/\s+/g, " ");
|
|
80
|
-
if (!content.startsWith(`# Observable Plot ${version}\n\n`) ||
|
|
81
|
-
metadata !==
|
|
82
|
-
`Package: \`@observablehq/plot@${version}\`. Source: [v${version}](${source}).` ||
|
|
83
|
-
!content.trimEnd().endsWith(`<!-- setup-data-project:observable-plot:${version}:complete -->`))
|
|
84
|
-
return false;
|
|
85
|
-
// Match actual page sections, not TOC entries. Require every selected page
|
|
86
|
-
// exactly once and some upstream heading/content after its source record.
|
|
87
|
-
const sections = [
|
|
88
|
-
...content.matchAll(/<a id="(plot-[^"]+)"><\/a>\n\n# ([^\n]+\.md)\n\nSource:\s+([^\s]+)\n\n/g),
|
|
89
|
-
];
|
|
90
|
-
if (sections.length !== plotDocPages_js_1.PLOT_DOC_PAGES.length)
|
|
91
|
-
return false;
|
|
92
|
-
const found = new Set();
|
|
93
|
-
for (let index = 0; index < sections.length; index++) {
|
|
94
|
-
const section = sections[index];
|
|
95
|
-
const page = section[2];
|
|
96
|
-
const id = `plot-${page.replace(/\.md$/, "").replaceAll("/", "--")}`;
|
|
97
|
-
if (!plotDocPages_js_1.PLOT_DOC_PAGES.includes(page) || found.has(page) || section[1] !== id ||
|
|
98
|
-
section[3] !== `${source}/${page}`)
|
|
99
|
-
return false;
|
|
100
|
-
const body = content.slice(section.index + section[0].length, sections[index + 1]?.index);
|
|
101
|
-
if (!/^#{1,6}\s+\S/m.test(body))
|
|
102
|
-
return false;
|
|
103
|
-
found.add(page);
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getInstalledPackageVersions.d.ts","sourceRoot":"","sources":["../../src/helpers/getInstalledPackageVersions.ts"],"names":[],"mappings":"AAKA,wBAAgB,2BAA2B,CACzC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0BxB"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInstalledPackageVersions = getInstalledPackageVersions;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
function getInstalledPackageVersions(packageSpecifiers) {
|
|
7
|
-
const denoLock = readJsonFile("deno.lock");
|
|
8
|
-
const packageLock = readJsonFile("package-lock.json");
|
|
9
|
-
const bunLock = (0, node_fs_1.existsSync)("bun.lock")
|
|
10
|
-
? (0, node_fs_1.readFileSync)("bun.lock", "utf-8")
|
|
11
|
-
: undefined;
|
|
12
|
-
const versions = {};
|
|
13
|
-
for (const [pkg, specifier] of Object.entries(packageSpecifiers)) {
|
|
14
|
-
const denoVersion = specifier.startsWith("jsr:") || specifier.startsWith("npm:")
|
|
15
|
-
? getDenoLockVersion(pkg, specifier, denoLock)
|
|
16
|
-
: undefined;
|
|
17
|
-
const version = specifier.startsWith("jsr:")
|
|
18
|
-
? denoVersion ?? getExactVersion(specifier)
|
|
19
|
-
: denoVersion ?? getNodeModulesVersion(pkg) ??
|
|
20
|
-
getPackageLockVersion(pkg, packageLock) ??
|
|
21
|
-
getBunLockVersion(pkg, bunLock) ??
|
|
22
|
-
getExactVersion(specifier);
|
|
23
|
-
if (version !== undefined) {
|
|
24
|
-
versions[pkg] = version;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return versions;
|
|
28
|
-
}
|
|
29
|
-
function getNodeModulesVersion(pkg) {
|
|
30
|
-
const packageJson = readJsonFile((0, node_path_1.join)("node_modules", ...pkg.split("/"), "package.json"));
|
|
31
|
-
return typeof packageJson?.version === "string"
|
|
32
|
-
? getExactVersion(packageJson.version)
|
|
33
|
-
: undefined;
|
|
34
|
-
}
|
|
35
|
-
function getDenoLockVersion(pkg, specifier, lock) {
|
|
36
|
-
if (!lock)
|
|
37
|
-
return undefined;
|
|
38
|
-
const specifiers = asObject(lock.specifiers);
|
|
39
|
-
if (!specifiers)
|
|
40
|
-
return undefined;
|
|
41
|
-
const directVersion = specifiers[specifier];
|
|
42
|
-
if (typeof directVersion === "string")
|
|
43
|
-
return getExactVersion(directVersion);
|
|
44
|
-
const protocol = specifier.startsWith("npm:") ? "npm" : "jsr";
|
|
45
|
-
const prefix = `${protocol}:${pkg}@`;
|
|
46
|
-
const matchingVersions = Object.entries(specifiers)
|
|
47
|
-
.filter(([key, value]) => key.startsWith(prefix) && typeof value === "string")
|
|
48
|
-
.flatMap(([, value]) => {
|
|
49
|
-
const version = getExactVersion(value);
|
|
50
|
-
return version === undefined ? [] : [version];
|
|
51
|
-
});
|
|
52
|
-
const uniqueVersions = [...new Set(matchingVersions)];
|
|
53
|
-
return uniqueVersions.length === 1 ? uniqueVersions[0] : undefined;
|
|
54
|
-
}
|
|
55
|
-
function getPackageLockVersion(pkg, lock) {
|
|
56
|
-
if (!lock)
|
|
57
|
-
return undefined;
|
|
58
|
-
const packages = asObject(lock.packages);
|
|
59
|
-
const packageEntry = packages
|
|
60
|
-
? asObject(packages[`node_modules/${pkg}`])
|
|
61
|
-
: undefined;
|
|
62
|
-
if (typeof packageEntry?.version === "string") {
|
|
63
|
-
return getExactVersion(packageEntry.version);
|
|
64
|
-
}
|
|
65
|
-
const dependencies = asObject(lock.dependencies);
|
|
66
|
-
const dependencyEntry = dependencies
|
|
67
|
-
? asObject(dependencies[pkg])
|
|
68
|
-
: undefined;
|
|
69
|
-
return typeof dependencyEntry?.version === "string"
|
|
70
|
-
? getExactVersion(dependencyEntry.version)
|
|
71
|
-
: undefined;
|
|
72
|
-
}
|
|
73
|
-
function getBunLockVersion(pkg, lock) {
|
|
74
|
-
if (!lock)
|
|
75
|
-
return undefined;
|
|
76
|
-
const escapedPackage = pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
77
|
-
const match = lock.match(new RegExp(`"${escapedPackage}"\\s*:\\s*\\[\\s*"${escapedPackage}@(\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?)"`));
|
|
78
|
-
return match?.[1];
|
|
79
|
-
}
|
|
80
|
-
function getExactVersion(specifier) {
|
|
81
|
-
return specifier.match(/(?:^|@)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/)?.[1];
|
|
82
|
-
}
|
|
83
|
-
function readJsonFile(path) {
|
|
84
|
-
if (!(0, node_fs_1.existsSync)(path))
|
|
85
|
-
return undefined;
|
|
86
|
-
try {
|
|
87
|
-
return asObject(JSON.parse((0, node_fs_1.readFileSync)(path, "utf-8")));
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function asObject(value) {
|
|
94
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
95
|
-
? value
|
|
96
|
-
: undefined;
|
|
97
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getProjectTasks.d.ts","sourceRoot":"","sources":["../../src/helpers/getProjectTasks.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe;;;;EAgB9B"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProjectTasks = getProjectTasks;
|
|
4
|
-
const getRuntime_js_1 = require("./getRuntime.js");
|
|
5
|
-
function getProjectTasks() {
|
|
6
|
-
const runtime = (0, getRuntime_js_1.getRuntime)();
|
|
7
|
-
return {
|
|
8
|
-
sda: runtime === "deno"
|
|
9
|
-
? "deno run -A --env --watch --check sda/main.ts"
|
|
10
|
-
: runtime === "bun"
|
|
11
|
-
? "bun run --watch sda/main.ts"
|
|
12
|
-
: "node --env-file-if-exists=.env --watch --experimental-strip-types sda/main.ts",
|
|
13
|
-
"all-tests": runtime === "deno"
|
|
14
|
-
? "deno fmt --check sda && deno lint && deno check sda/main.ts && deno test -A --permit-no-files"
|
|
15
|
-
: runtime === "bun"
|
|
16
|
-
? "bun test --pass-with-no-tests"
|
|
17
|
-
: "node --env-file-if-exists=.env --experimental-strip-types --test",
|
|
18
|
-
clean: "rm -rf .sda-cache .journalism-cache .tmp",
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRuntime.d.ts","sourceRoot":"","sources":["../../src/helpers/getRuntime.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;CAazB,CAAC;AAEF,wBAAgB,UAAU,4BAEzB"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.runtimeConfig = void 0;
|
|
40
|
-
exports.getRuntime = getRuntime;
|
|
41
|
-
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
42
|
-
const node_process_1 = __importDefault(require("node:process"));
|
|
43
|
-
exports.runtimeConfig = {
|
|
44
|
-
getRuntime: () => {
|
|
45
|
-
if (typeof node_process_1.default !== "undefined" &&
|
|
46
|
-
node_process_1.default?.versions?.node &&
|
|
47
|
-
!node_process_1.default?.versions?.deno) {
|
|
48
|
-
return "node";
|
|
49
|
-
}
|
|
50
|
-
if ("Bun" in dntShim.dntGlobalThis)
|
|
51
|
-
return "bun";
|
|
52
|
-
if ("Deno" in dntShim.dntGlobalThis)
|
|
53
|
-
return "deno";
|
|
54
|
-
return "node";
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
function getRuntime() {
|
|
58
|
-
return exports.runtimeConfig.getRuntime();
|
|
59
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gitignoreEntries.d.ts","sourceRoot":"","sources":["../../src/helpers/gitignoreEntries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAS7B,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GITIGNORE_ENTRIES = void 0;
|
|
4
|
-
exports.GITIGNORE_ENTRIES = [
|
|
5
|
-
"node_modules",
|
|
6
|
-
".tmp",
|
|
7
|
-
".sda-cache",
|
|
8
|
-
".journalism-cache",
|
|
9
|
-
"sda/data",
|
|
10
|
-
"sda/output",
|
|
11
|
-
".env",
|
|
12
|
-
".DS_Store",
|
|
13
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"installPackages.d.ts","sourceRoot":"","sources":["../../src/helpers/installPackages.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa;;CAEzB,CAAC;AAEF,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,IAAI,CAAC,CA8Cf"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.commandRunner = void 0;
|
|
37
|
-
exports.installPackages = installPackages;
|
|
38
|
-
const prompts_1 = require("@clack/prompts");
|
|
39
|
-
const childProcess = __importStar(require("node:child_process"));
|
|
40
|
-
const getRuntime_js_1 = require("./getRuntime.js");
|
|
41
|
-
exports.commandRunner = {
|
|
42
|
-
exec: childProcess.exec,
|
|
43
|
-
};
|
|
44
|
-
async function installPackages(selectedPackages, options = {}) {
|
|
45
|
-
const runtime = (0, getRuntime_js_1.getRuntime)();
|
|
46
|
-
for (const selectedPackage of selectedPackages) {
|
|
47
|
-
const packagesToInstall = [selectedPackage];
|
|
48
|
-
if (selectedPackage === "@nshiab/simple-data-analysis" ||
|
|
49
|
-
selectedPackage === "@nshiab/journalism-dataviz") {
|
|
50
|
-
packagesToInstall.push("@observablehq/plot");
|
|
51
|
-
}
|
|
52
|
-
for (const pkg of packagesToInstall) {
|
|
53
|
-
const s = (0, prompts_1.spinner)();
|
|
54
|
-
const isObservablePlot = pkg === "@observablehq/plot";
|
|
55
|
-
const installCmd = runtime === "deno"
|
|
56
|
-
? (isObservablePlot ? "deno add npm:" + pkg : "deno add jsr:" + pkg)
|
|
57
|
-
: runtime === "bun"
|
|
58
|
-
? "bun add " + pkg
|
|
59
|
-
: "npm install " + pkg;
|
|
60
|
-
if (!options.silent) {
|
|
61
|
-
s.start("Installing " + pkg + " via " + runtime + "...");
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
await new Promise((resolve, reject) => {
|
|
65
|
-
exports.commandRunner.exec(installCmd, (error) => {
|
|
66
|
-
if (error) {
|
|
67
|
-
reject(error);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
resolve();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
if (!options.silent) {
|
|
75
|
-
s.stop("✅ " + pkg + " installed!");
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (!options.silent) {
|
|
80
|
-
s.stop("❌ Failed to install " + pkg + ".");
|
|
81
|
-
}
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|