@nshiab/setup-data-project 2.0.2 → 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 +80 -24
- 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/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 -176
- 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 -8
- package/esm/helpers/fetchPackageDocs.d.ts.map +0 -1
- package/esm/helpers/fetchPackageDocs.js +0 -75
- package/esm/helpers/getInstalledPackageVersions.d.ts +0 -2
- package/esm/helpers/getInstalledPackageVersions.d.ts.map +0 -1
- package/esm/helpers/getInstalledPackageVersions.js +0 -91
- 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 -59
- 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 -9
- package/esm/helpers/packageRegistry.d.ts.map +0 -1
- package/esm/helpers/packageRegistry.js +0 -84
- 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 -46
- package/esm/main.d.ts +0 -3
- package/esm/main.d.ts.map +0 -1
- package/esm/main.js +0 -94
- 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/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 -179
- 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 -8
- package/script/helpers/fetchPackageDocs.d.ts.map +0 -1
- package/script/helpers/fetchPackageDocs.js +0 -78
- package/script/helpers/getInstalledPackageVersions.d.ts +0 -2
- package/script/helpers/getInstalledPackageVersions.d.ts.map +0 -1
- package/script/helpers/getInstalledPackageVersions.js +0 -94
- 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 -96
- 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 -9
- package/script/helpers/packageRegistry.d.ts.map +0 -1
- package/script/helpers/packageRegistry.js +0 -88
- 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 -49
- package/script/main.d.ts +0 -3
- package/script/main.d.ts.map +0 -1
- package/script/main.js +0 -99
- package/script/package.json +0 -3
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { log } from "@clack/prompts";
|
|
2
|
-
import { existsSync, mkdirSync, renameSync, rmSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { fetchPackageDocs } from "./fetchPackageDocs.js";
|
|
5
|
-
import { SUPPORTED_PACKAGES } from "./packageRegistry.js";
|
|
6
|
-
export async function syncPackageDocs(installedPackages, installedVersions) {
|
|
7
|
-
const installedSet = new Set(installedPackages);
|
|
8
|
-
const docsMapping = {};
|
|
9
|
-
for (const pkg of SUPPORTED_PACKAGES) {
|
|
10
|
-
const repoName = pkg.value.split("/")[1];
|
|
11
|
-
const docsDirectory = join("docs", repoName);
|
|
12
|
-
const llmDocsPath = join(docsDirectory, "llm.md");
|
|
13
|
-
const legacyDocsPath = join("docs", repoName + ".md");
|
|
14
|
-
if (!installedSet.has(pkg.value)) {
|
|
15
|
-
for (const path of [docsDirectory, legacyDocsPath]) {
|
|
16
|
-
if (existsSync(path)) {
|
|
17
|
-
rmSync(path, { recursive: true });
|
|
18
|
-
log.info(`Removed stale documentation at ${path}.`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if (existsSync(legacyDocsPath)) {
|
|
24
|
-
if (!existsSync(llmDocsPath)) {
|
|
25
|
-
mkdirSync(docsDirectory, { recursive: true });
|
|
26
|
-
renameSync(legacyDocsPath, llmDocsPath);
|
|
27
|
-
log.info(`Moved documentation to ${llmDocsPath}.`);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
rmSync(legacyDocsPath);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const version = installedVersions[pkg.value];
|
|
34
|
-
if (version === undefined) {
|
|
35
|
-
log.warn(`Could not determine the exact installed version of ${pkg.value}. ` +
|
|
36
|
-
"Existing local documentation was preserved but will not be " +
|
|
37
|
-
"included in AGENTS.md.");
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const docs = await fetchPackageDocs(pkg.value, version, { silent: true });
|
|
41
|
-
if (docs.readme !== undefined || docs.llm !== undefined) {
|
|
42
|
-
docsMapping[pkg.value] = docs;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return docsMapping;
|
|
46
|
-
}
|
package/esm/main.d.ts
DELETED
package/esm/main.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/esm/main.js
DELETED
|
@@ -1,94 +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
|
-
async function main() {
|
|
18
|
-
const runtime = getRuntime();
|
|
19
|
-
console.log();
|
|
20
|
-
intro(`Hi! 👋 (Running on ${runtime})`);
|
|
21
|
-
const projectManifest = ProjectManifest.open(runtime);
|
|
22
|
-
projectManifest.updateTasks(getProjectTasks());
|
|
23
|
-
const installedPackages = projectManifest.getInstalledPackages();
|
|
24
|
-
const options = PACKAGE_OPTIONS.map((opt) => ({
|
|
25
|
-
...opt,
|
|
26
|
-
label: installedPackages.includes(opt.value)
|
|
27
|
-
? `${opt.label} \x1b[2m(installed)\x1b[22m`
|
|
28
|
-
: opt.label,
|
|
29
|
-
}));
|
|
30
|
-
const selectedPackages = (await multiselect({
|
|
31
|
-
message: "Which libraries would you like to install?\n\x1b[2m(space to select, arrows to navigate, enter to confirm)\x1b[22m\n",
|
|
32
|
-
options,
|
|
33
|
-
required: false,
|
|
34
|
-
}));
|
|
35
|
-
if (isCancel(selectedPackages)) {
|
|
36
|
-
cancel("Installation cancelled.");
|
|
37
|
-
process.exit(0);
|
|
38
|
-
}
|
|
39
|
-
const alreadyInstalled = selectedPackages.filter((pkg) => installedPackages.includes(pkg));
|
|
40
|
-
const packagesToInstall = [];
|
|
41
|
-
for (const pkg of selectedPackages) {
|
|
42
|
-
if (alreadyInstalled.includes(pkg)) {
|
|
43
|
-
const action = await select({
|
|
44
|
-
message: `${pkg} is already installed. What would you like to do?`,
|
|
45
|
-
options: [
|
|
46
|
-
{ value: "skip", label: "Keep existing version" },
|
|
47
|
-
{ value: "update", label: "Update to latest" },
|
|
48
|
-
],
|
|
49
|
-
});
|
|
50
|
-
if (isCancel(action)) {
|
|
51
|
-
cancel("Installation cancelled.");
|
|
52
|
-
process.exit(0);
|
|
53
|
-
}
|
|
54
|
-
if (action === "update") {
|
|
55
|
-
packagesToInstall.push(pkg);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
packagesToInstall.push(pkg);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const sInstall = spinner();
|
|
63
|
-
sInstall.start("Installing packages...");
|
|
64
|
-
for (const pkg of packagesToInstall) {
|
|
65
|
-
try {
|
|
66
|
-
await installPackages([pkg], { silent: true });
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
sInstall.stop(`❌ Failed to install ${pkg}.`);
|
|
70
|
-
console.error(error);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
sInstall.stop("✅ Package installation complete.");
|
|
75
|
-
projectManifest.reload();
|
|
76
|
-
projectManifest.updateTasks(getProjectTasks());
|
|
77
|
-
const finalInstalledPackages = getInstalledPackageConfigs(projectManifest.getInstalledPackages()).map((pkg) => pkg.value);
|
|
78
|
-
const finalInstalledVersions = getInstalledPackageVersions(projectManifest.getInstalledPackageSpecifiers());
|
|
79
|
-
const sDocs = spinner();
|
|
80
|
-
sDocs.start("Fetching documentation for installed package versions...");
|
|
81
|
-
const docsMapping = await syncPackageDocs(finalInstalledPackages, finalInstalledVersions);
|
|
82
|
-
sDocs.stop("✅ Documentation synchronization complete.");
|
|
83
|
-
createFolderStructure(finalInstalledPackages);
|
|
84
|
-
ensureGitignore();
|
|
85
|
-
ensureEnvFile();
|
|
86
|
-
await ensureReadme(runtime, finalInstalledPackages);
|
|
87
|
-
await ensureAgents(docsMapping, runtime, finalInstalledPackages);
|
|
88
|
-
outro("You are all set! 🙌");
|
|
89
|
-
}
|
|
90
|
-
main().catch((error) => {
|
|
91
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
92
|
-
console.error(`❌ Error: ${message}`);
|
|
93
|
-
process.exitCode = 1;
|
|
94
|
-
});
|
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":"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,QAqLvD"}
|
|
@@ -1,179 +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
|
-
const repoName = pkg.value.split("/")[1];
|
|
107
|
-
const availableDocs = [
|
|
108
|
-
docs.readme === undefined
|
|
109
|
-
? ""
|
|
110
|
-
: `overview and practical examples at \`./docs/${repoName}/README.md\``,
|
|
111
|
-
docs.llm === undefined
|
|
112
|
-
? ""
|
|
113
|
-
: `complete API documentation at \`./docs/${repoName}/llm.md\``,
|
|
114
|
-
].filter(Boolean);
|
|
115
|
-
return availableDocs.length === 0
|
|
116
|
-
? []
|
|
117
|
-
: [`- \`${pkg.value}\`: ${availableDocs.join("; ")}`];
|
|
118
|
-
});
|
|
119
|
-
if (documentationGuidance.length > 0) {
|
|
120
|
-
libraryGuidance += `
|
|
121
|
-
The following documentation was fetched for the exact installed library versions. Consult it when relevant:
|
|
122
|
-
|
|
123
|
-
${documentationGuidance.join("\n")}
|
|
124
|
-
`;
|
|
125
|
-
}
|
|
126
|
-
if (importExamples.length > 0) {
|
|
127
|
-
libraryGuidance += `APIs can be imported with named imports like this:
|
|
128
|
-
\`\`\`typescript
|
|
129
|
-
${importExamples.join("\n")}
|
|
130
|
-
\`\`\`
|
|
131
|
-
`;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
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.
|
|
135
|
-
|
|
136
|
-
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.
|
|
137
|
-
|
|
138
|
-
Before handing off your work, always run \`${runAllTests}\`, even if no tests have been added yet. Fix any errors or warnings it reports.
|
|
139
|
-
|
|
140
|
-
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.
|
|
141
|
-
|
|
142
|
-
Always use "sda/main.ts" as the entry point.
|
|
143
|
-
|
|
144
|
-
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.
|
|
145
|
-
|
|
146
|
-
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".
|
|
147
|
-
|
|
148
|
-
If you need to download data, always put the files in the "sda/data" folder, which is ignored by Git.
|
|
149
|
-
|
|
150
|
-
If you need to output data to a file, always put the file in the "sda/output" folder, which is also ignored by Git.
|
|
151
|
-
${libraryGuidance}`;
|
|
152
|
-
if (journalismFunctions !== "") {
|
|
153
|
-
content += `
|
|
154
|
-
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.
|
|
155
|
-
${journalismFunctions}`;
|
|
156
|
-
}
|
|
157
|
-
if (sdaClassesAndMethods !== "") {
|
|
158
|
-
const readmeGuidance = sdaReadmePath === ""
|
|
159
|
-
? ""
|
|
160
|
-
: ` An overview and practical examples are available at "${sdaReadmePath}".`;
|
|
161
|
-
content += `
|
|
162
|
-
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.
|
|
163
|
-
|
|
164
|
-
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.
|
|
165
|
-
${sdaClassesAndMethods}`;
|
|
166
|
-
}
|
|
167
|
-
const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
|
|
168
|
-
path: "AGENTS.md",
|
|
169
|
-
name: "agents",
|
|
170
|
-
content,
|
|
171
|
-
createContent: (managedSection) => managedSection,
|
|
172
|
-
});
|
|
173
|
-
if (status === "created") {
|
|
174
|
-
prompts_1.log.info("Created AGENTS.md");
|
|
175
|
-
}
|
|
176
|
-
else if (status === "updated") {
|
|
177
|
-
prompts_1.log.info("Updated AGENTS.md");
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -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"}
|
|
@@ -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
|
-
}
|