@nshiab/setup-data-project 1.0.28 → 1.0.30
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/esm/helpers/ensureAgents.d.ts +1 -1
- package/esm/helpers/ensureAgents.d.ts.map +1 -1
- package/esm/helpers/ensureAgents.js +34 -13
- package/esm/helpers/ensureManagedSection.d.ts +9 -0
- package/esm/helpers/ensureManagedSection.d.ts.map +1 -0
- package/esm/helpers/ensureManagedSection.js +30 -0
- package/esm/helpers/ensureReadme.d.ts +1 -1
- package/esm/helpers/ensureReadme.d.ts.map +1 -1
- package/esm/helpers/ensureReadme.js +26 -12
- package/esm/helpers/gitignoreEntries.d.ts.map +1 -1
- package/esm/helpers/gitignoreEntries.js +1 -0
- package/esm/helpers/installPackagesAndFetchDocs.d.ts +3 -0
- package/esm/helpers/installPackagesAndFetchDocs.d.ts.map +1 -1
- package/esm/helpers/installPackagesAndFetchDocs.js +42 -34
- package/esm/helpers/packageRegistry.d.ts +1 -0
- package/esm/helpers/packageRegistry.d.ts.map +1 -1
- package/esm/helpers/packageRegistry.js +4 -0
- package/esm/helpers/projectManifest.d.ts +11 -0
- package/esm/helpers/projectManifest.d.ts.map +1 -0
- package/esm/helpers/projectManifest.js +73 -0
- package/esm/helpers/syncPackageDocs.d.ts +2 -0
- package/esm/helpers/syncPackageDocs.d.ts.map +1 -0
- package/esm/helpers/syncPackageDocs.js +27 -0
- package/esm/main.js +19 -14
- package/package.json +1 -1
- package/script/helpers/ensureAgents.d.ts +1 -1
- package/script/helpers/ensureAgents.d.ts.map +1 -1
- package/script/helpers/ensureAgents.js +33 -12
- package/script/helpers/ensureManagedSection.d.ts +9 -0
- package/script/helpers/ensureManagedSection.d.ts.map +1 -0
- package/script/helpers/ensureManagedSection.js +33 -0
- package/script/helpers/ensureReadme.d.ts +1 -1
- package/script/helpers/ensureReadme.d.ts.map +1 -1
- package/script/helpers/ensureReadme.js +26 -12
- package/script/helpers/gitignoreEntries.d.ts.map +1 -1
- package/script/helpers/gitignoreEntries.js +1 -0
- package/script/helpers/installPackagesAndFetchDocs.d.ts +3 -0
- package/script/helpers/installPackagesAndFetchDocs.d.ts.map +1 -1
- package/script/helpers/installPackagesAndFetchDocs.js +42 -33
- package/script/helpers/packageRegistry.d.ts +1 -0
- package/script/helpers/packageRegistry.d.ts.map +1 -1
- package/script/helpers/packageRegistry.js +5 -0
- package/script/helpers/projectManifest.d.ts +11 -0
- package/script/helpers/projectManifest.d.ts.map +1 -0
- package/script/helpers/projectManifest.js +77 -0
- package/script/helpers/syncPackageDocs.d.ts +2 -0
- package/script/helpers/syncPackageDocs.d.ts.map +1 -0
- package/script/helpers/syncPackageDocs.js +30 -0
- package/script/main.js +19 -14
- package/esm/helpers/getInstalledPackages.d.ts +0 -2
- package/esm/helpers/getInstalledPackages.d.ts.map +0 -1
- package/esm/helpers/getInstalledPackages.js +0 -29
- package/esm/helpers/updateProjectConfig.d.ts +0 -2
- package/esm/helpers/updateProjectConfig.d.ts.map +0 -1
- package/esm/helpers/updateProjectConfig.js +0 -42
- package/script/helpers/getInstalledPackages.d.ts +0 -2
- package/script/helpers/getInstalledPackages.d.ts.map +0 -1
- package/script/helpers/getInstalledPackages.js +0 -32
- package/script/helpers/updateProjectConfig.d.ts +0 -2
- package/script/helpers/updateProjectConfig.d.ts.map +0 -1
- package/script/helpers/updateProjectConfig.js +0 -45
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureAgents = ensureAgents;
|
|
4
4
|
const prompts_1 = require("@clack/prompts");
|
|
5
|
-
const
|
|
5
|
+
const ensureManagedSection_js_1 = require("./ensureManagedSection.js");
|
|
6
6
|
const packageRegistry_js_1 = require("./packageRegistry.js");
|
|
7
|
-
|
|
7
|
+
function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docsMapping)) {
|
|
8
8
|
let journalismFunctions = "";
|
|
9
9
|
let sdaClassesAndMethods = "";
|
|
10
|
+
let sdaDocsPath = "";
|
|
11
|
+
let sdaLibraryName = "";
|
|
10
12
|
for (const [pkg, doc] of Object.entries(docsMapping)) {
|
|
11
13
|
const pkgConfig = packageRegistry_js_1.SUPPORTED_PACKAGES.find((p) => p.value === pkg);
|
|
12
14
|
const pkgType = pkgConfig?.type || "other";
|
|
@@ -24,6 +26,9 @@ async function ensureAgents(docsMapping, runtime) {
|
|
|
24
26
|
.join("\n") + "\n";
|
|
25
27
|
}
|
|
26
28
|
else if (pkgType === "sda") {
|
|
29
|
+
const repoName = pkg.split("/")[1];
|
|
30
|
+
sdaDocsPath = `./docs/${repoName}.md`;
|
|
31
|
+
sdaLibraryName = pkgConfig?.label || repoName;
|
|
27
32
|
sdaClassesAndMethods = doc
|
|
28
33
|
.split("\n")
|
|
29
34
|
.filter((line) => line.trim().startsWith("#"))
|
|
@@ -48,6 +53,23 @@ async function ensureAgents(docsMapping, runtime) {
|
|
|
48
53
|
const configFile = runtime === "deno" ? "deno.json" : "package.json";
|
|
49
54
|
const runSda = runtime === "deno" ? "deno task sda" : "npm run sda";
|
|
50
55
|
const runClean = runtime === "deno" ? "deno task clean" : "npm run clean";
|
|
56
|
+
const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
|
|
57
|
+
const importExamples = installedPackageConfigs.map((pkg) => {
|
|
58
|
+
const repoName = pkg.value.split("/")[1];
|
|
59
|
+
const identifier = repoName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
60
|
+
return `import * as ${identifier} from "${pkg.value}";`;
|
|
61
|
+
});
|
|
62
|
+
let libraryGuidance = "";
|
|
63
|
+
if (installedPackageConfigs.length > 0) {
|
|
64
|
+
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.label}"`)
|
|
65
|
+
.join(", ");
|
|
66
|
+
libraryGuidance = `
|
|
67
|
+
Always prioritize the installed ${libraryNames} libraries when relevant. They can be imported directly like this:
|
|
68
|
+
\`\`\`typescript
|
|
69
|
+
${importExamples.join("\n")}
|
|
70
|
+
\`\`\`
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
51
73
|
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.
|
|
52
74
|
|
|
53
75
|
Always use "sda" task when available (e.g. \`${runSda}\`).
|
|
@@ -65,13 +87,7 @@ If you need to create other TypeScript files, create them in the "sda/helpers" f
|
|
|
65
87
|
If you need to download data, always put the files in the "sda/data" folder, which is gitignored.
|
|
66
88
|
|
|
67
89
|
If you need to output data to a file, always put the file in the "sda/output" folder.
|
|
68
|
-
|
|
69
|
-
Always prioritize the use of the "journalism" and "simple-data-analysis" libraries when they are installed. These libraries can be used directly like this:
|
|
70
|
-
\`\`\`typescript
|
|
71
|
-
import { formatDate } from "@nshiab/journalism-format";
|
|
72
|
-
import { SimpleDB } from "@nshiab/simple-data-analysis";
|
|
73
|
-
\`\`\`
|
|
74
|
-
`;
|
|
90
|
+
${libraryGuidance}`;
|
|
75
91
|
if (journalismFunctions !== "") {
|
|
76
92
|
content += `
|
|
77
93
|
Here are the functions available in the "journalism" libraries. If one of the function might be relevant, read the complete documentation in the "./docs/" folder to properly use it.
|
|
@@ -79,11 +95,16 @@ ${journalismFunctions}`;
|
|
|
79
95
|
}
|
|
80
96
|
if (sdaClassesAndMethods !== "") {
|
|
81
97
|
content += `
|
|
82
|
-
Here are the classes and their methods available in the "
|
|
98
|
+
Here are the classes and their methods available in the "${sdaLibraryName}" library. If one of the classes or methods might be relevant, read the complete documentation at "${sdaDocsPath}" to properly use it. Remember that almost all methods are asynchronous, so you need to use \`await\` when calling them.
|
|
83
99
|
${sdaClassesAndMethods}`;
|
|
84
100
|
}
|
|
85
|
-
const status =
|
|
86
|
-
|
|
101
|
+
const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
|
|
102
|
+
path: "AGENTS.md",
|
|
103
|
+
name: "agents",
|
|
104
|
+
content,
|
|
105
|
+
createContent: (managedSection) => managedSection,
|
|
106
|
+
});
|
|
107
|
+
if (status === "created" || status === "updated") {
|
|
87
108
|
prompts_1.log.info("Updated AGENTS.md");
|
|
88
109
|
}
|
|
89
110
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAmCzD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 = `<!-- setup-data-project:${options.name}:start -->`;
|
|
8
|
+
const endMarker = `<!-- 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, 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, nextContent);
|
|
32
|
+
return "updated";
|
|
33
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ensureReadme(runtime: string):
|
|
1
|
+
export declare function ensureReadme(runtime: string, installedPackages?: string[]): void;
|
|
2
2
|
//# sourceMappingURL=ensureReadme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureReadme.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureReadme.ts"],"names":[],"mappings":"
|
|
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,QAwDjC"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureReadme = ensureReadme;
|
|
4
4
|
const prompts_1 = require("@clack/prompts");
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const ensureManagedSection_js_1 = require("./ensureManagedSection.js");
|
|
6
|
+
const packageRegistry_js_1 = require("./packageRegistry.js");
|
|
7
|
+
function ensureReadme(runtime, installedPackages = []) {
|
|
7
8
|
let runCommand = "npm run";
|
|
8
9
|
if (runtime === "deno") {
|
|
9
10
|
runCommand = "deno task";
|
|
@@ -11,13 +12,27 @@ async function ensureReadme(runtime) {
|
|
|
11
12
|
else if (runtime === "bun") {
|
|
12
13
|
runCommand = "bun run";
|
|
13
14
|
}
|
|
14
|
-
const
|
|
15
|
+
const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
|
|
16
|
+
const hasSda = installedPackageConfigs.some((pkg) => pkg.type === "sda");
|
|
17
|
+
const hasJournalism = installedPackageConfigs.some((pkg) => pkg.type === "journalism");
|
|
18
|
+
const libraryLinks = [
|
|
19
|
+
hasSda
|
|
20
|
+
? "[simple-data-analysis](https://github.com/nshiab/simple-data-analysis)"
|
|
21
|
+
: "",
|
|
22
|
+
hasJournalism ? "[journalism](https://github.com/nshiab/journalism)" : "",
|
|
23
|
+
].filter(Boolean);
|
|
24
|
+
const librarySection = libraryLinks.length === 0
|
|
25
|
+
? ""
|
|
26
|
+
: `It's installing ${libraryLinks.join(" and ")} libraries, with up-to-date
|
|
27
|
+
documentation and AI agent instructions.`;
|
|
28
|
+
const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
|
|
29
|
+
path: "README.md",
|
|
30
|
+
name: "libraries",
|
|
31
|
+
content: librarySection,
|
|
32
|
+
createContent: (managedSection) => `This repository has been created with
|
|
15
33
|
[setup-data-project](https://github.com/nshiab/setup-data-project/).
|
|
16
34
|
|
|
17
|
-
|
|
18
|
-
[simple-data-analysis](https://github.com/nshiab/simple-data-analysis) and
|
|
19
|
-
[journalism](https://github.com/nshiab/journalism) libraries, with up-to-date
|
|
20
|
-
documentation and AI agent instructions.
|
|
35
|
+
${managedSection}
|
|
21
36
|
|
|
22
37
|
Here's the recommended workflow:
|
|
23
38
|
|
|
@@ -30,12 +45,11 @@ When working on your project, use the following command:
|
|
|
30
45
|
|
|
31
46
|
- \`${runCommand} sda\` will watch your \`sda/main.ts\` and its dependencies. Everytime
|
|
32
47
|
you'll save some changes, the data will be reprocessed.
|
|
33
|
-
- \`${runCommand} clean\` will remove
|
|
34
|
-
if present.
|
|
48
|
+
- \`${runCommand} clean\` will remove cache and temporary files, if present.
|
|
35
49
|
|
|
36
|
-
Have fun
|
|
37
|
-
|
|
38
|
-
if (status === "updated") {
|
|
50
|
+
Have fun!`,
|
|
51
|
+
});
|
|
52
|
+
if (status === "created" || status === "updated") {
|
|
39
53
|
prompts_1.log.info("Updated README.md");
|
|
40
54
|
}
|
|
41
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitignoreEntries.d.ts","sourceRoot":"","sources":["../../src/helpers/gitignoreEntries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"gitignoreEntries.d.ts","sourceRoot":"","sources":["../../src/helpers/gitignoreEntries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAS7B,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export declare const commandRunner: {
|
|
2
2
|
exec: any;
|
|
3
3
|
};
|
|
4
|
+
export declare function fetchPackageDocs(pkg: string, options?: {
|
|
5
|
+
silent?: boolean;
|
|
6
|
+
}): Promise<string | undefined>;
|
|
4
7
|
export declare function installPackagesAndFetchDocs(selectedPackages: string[], options?: {
|
|
5
8
|
silent?: boolean;
|
|
6
9
|
}): Promise<string | void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installPackagesAndFetchDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/installPackagesAndFetchDocs.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa;;CAEzB,CAAC;AAEF,wBAAsB,2BAA2B,CAC/C,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"installPackagesAndFetchDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/installPackagesAndFetchDocs.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa;;CAEzB,CAAC;AAEF,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA4C7B;AAED,wBAAsB,2BAA2B,CAC/C,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA4DxB"}
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.commandRunner = void 0;
|
|
37
|
+
exports.fetchPackageDocs = fetchPackageDocs;
|
|
37
38
|
exports.installPackagesAndFetchDocs = installPackagesAndFetchDocs;
|
|
38
39
|
const prompts_1 = require("@clack/prompts");
|
|
39
40
|
const childProcess = __importStar(require("node:child_process"));
|
|
@@ -43,6 +44,44 @@ const getRuntime_js_1 = require("./getRuntime.js");
|
|
|
43
44
|
exports.commandRunner = {
|
|
44
45
|
exec: childProcess.exec,
|
|
45
46
|
};
|
|
47
|
+
async function fetchPackageDocs(pkg, options = {}) {
|
|
48
|
+
if (!(0, node_fs_1.existsSync)("docs")) {
|
|
49
|
+
(0, node_fs_1.mkdirSync)("docs");
|
|
50
|
+
}
|
|
51
|
+
const sFetch = (0, prompts_1.spinner)();
|
|
52
|
+
if (!options.silent) {
|
|
53
|
+
sFetch.start("Fetching documentation for " + pkg + "...");
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const repoName = pkg.split("/")[1];
|
|
57
|
+
const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
|
|
58
|
+
"/refs/heads/main/llm.md";
|
|
59
|
+
const response = await fetch(url);
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
if (!options.silent) {
|
|
62
|
+
sFetch.stop("⚠️ No documentation (llm.md) found for " + pkg + ".");
|
|
63
|
+
}
|
|
64
|
+
prompts_1.log.warn(`Documentation for ${pkg} could not be refreshed. Rerun the script ` +
|
|
65
|
+
"later to try again.");
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const docContent = await response.text();
|
|
69
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)("docs", repoName + ".md"), docContent);
|
|
70
|
+
if (!options.silent) {
|
|
71
|
+
sFetch.stop("✅ Documentation for " + pkg + " saved!");
|
|
72
|
+
}
|
|
73
|
+
return docContent;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (!options.silent) {
|
|
77
|
+
sFetch.stop("❌ Failed to fetch documentation for " + pkg + ".");
|
|
78
|
+
}
|
|
79
|
+
prompts_1.log.warn(`Documentation for ${pkg} could not be refreshed. Rerun the script ` +
|
|
80
|
+
"later to try again.");
|
|
81
|
+
console.error(error);
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
46
85
|
async function installPackagesAndFetchDocs(selectedPackages, options = {}) {
|
|
47
86
|
const runtime = (0, getRuntime_js_1.getRuntime)();
|
|
48
87
|
if (Array.isArray(selectedPackages) && selectedPackages.length > 0) {
|
|
@@ -89,39 +128,9 @@ async function installPackagesAndFetchDocs(selectedPackages, options = {}) {
|
|
|
89
128
|
throw error;
|
|
90
129
|
}
|
|
91
130
|
}
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
const sFetch = (0, prompts_1.spinner)();
|
|
97
|
-
try {
|
|
98
|
-
if (!options.silent) {
|
|
99
|
-
sFetch.start("Fetching documentation for " + pkg + "...");
|
|
100
|
-
}
|
|
101
|
-
const repoName = pkg.split("/")[1];
|
|
102
|
-
const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
|
|
103
|
-
"/refs/heads/main/llm.md";
|
|
104
|
-
const response = await fetch(url);
|
|
105
|
-
if (response.ok) {
|
|
106
|
-
const docContent = await response.text();
|
|
107
|
-
(0, node_fs_1.writeFileSync)((0, node_path_1.join)("docs", repoName + ".md"), docContent);
|
|
108
|
-
if (!options.silent) {
|
|
109
|
-
sFetch.stop("✅ Documentation for " + pkg + " saved!");
|
|
110
|
-
}
|
|
111
|
-
lastDoc = docContent;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
if (!options.silent) {
|
|
115
|
-
sFetch.stop("⚠️ No documentation (llm.md) found for " + pkg +
|
|
116
|
-
". Skipping doc fetch.");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
if (!options.silent) {
|
|
122
|
-
sFetch.stop("❌ Failed to fetch documentation for " + pkg + ".");
|
|
123
|
-
}
|
|
124
|
-
console.error(error);
|
|
131
|
+
const docContent = await fetchPackageDocs(pkg, options);
|
|
132
|
+
if (docContent !== undefined) {
|
|
133
|
+
lastDoc = docContent;
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
return lastDoc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageRegistry.d.ts","sourceRoot":"","sources":["../../src/helpers/packageRegistry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,YAAY,GAAG,OAAO,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,EAAE,aAAa,EAwF7C,CAAC"}
|
|
1
|
+
{"version":3,"file":"packageRegistry.d.ts","sourceRoot":"","sources":["../../src/helpers/packageRegistry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,YAAY,GAAG,OAAO,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,EAAE,aAAa,EAwF7C,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,iBAAiB,EAAE,MAAM,EAAE,GAC1B,aAAa,EAAE,CAGjB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SUPPORTED_PACKAGES = void 0;
|
|
4
|
+
exports.getInstalledPackageConfigs = getInstalledPackageConfigs;
|
|
4
5
|
exports.SUPPORTED_PACKAGES = [
|
|
5
6
|
{
|
|
6
7
|
value: "@nshiab/simple-data-analysis-core",
|
|
@@ -81,3 +82,7 @@ exports.SUPPORTED_PACKAGES = [
|
|
|
81
82
|
hint: "Functions to zip/unzip, sleep, reencode files, create nested directories...",
|
|
82
83
|
},
|
|
83
84
|
];
|
|
85
|
+
function getInstalledPackageConfigs(installedPackages) {
|
|
86
|
+
const installedSet = new Set(installedPackages);
|
|
87
|
+
return exports.SUPPORTED_PACKAGES.filter((pkg) => installedSet.has(pkg.value));
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Runtime = "deno" | "node" | "bun";
|
|
2
|
+
export declare class ProjectManifest {
|
|
3
|
+
#private;
|
|
4
|
+
private constructor();
|
|
5
|
+
static open(runtime: Runtime): ProjectManifest;
|
|
6
|
+
reload(): void;
|
|
7
|
+
getInstalledPackages(): string[];
|
|
8
|
+
updateTasks(tasks: Record<string, string>): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=projectManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectManifest.d.ts","sourceRoot":"","sources":["../../src/helpers/projectManifest.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAGvC,qBAAa,eAAe;;IAM1B,OAAO;IAYP,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IA6B9C,MAAM,IAAI,IAAI;IAId,oBAAoB,IAAI,MAAM,EAAE;IAgBhC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAUjD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ProjectManifest_path, _ProjectManifest_taskKey, _ProjectManifest_dependencyKeys, _ProjectManifest_config;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProjectManifest = void 0;
|
|
16
|
+
const node_fs_1 = require("node:fs");
|
|
17
|
+
class ProjectManifest {
|
|
18
|
+
constructor(path, taskKey, dependencyKeys, config) {
|
|
19
|
+
_ProjectManifest_path.set(this, void 0);
|
|
20
|
+
_ProjectManifest_taskKey.set(this, void 0);
|
|
21
|
+
_ProjectManifest_dependencyKeys.set(this, void 0);
|
|
22
|
+
_ProjectManifest_config.set(this, void 0);
|
|
23
|
+
__classPrivateFieldSet(this, _ProjectManifest_path, path, "f");
|
|
24
|
+
__classPrivateFieldSet(this, _ProjectManifest_taskKey, taskKey, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _ProjectManifest_dependencyKeys, dependencyKeys, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _ProjectManifest_config, config, "f");
|
|
27
|
+
}
|
|
28
|
+
static open(runtime) {
|
|
29
|
+
if ((0, node_fs_1.existsSync)("deno.json")) {
|
|
30
|
+
return new ProjectManifest("deno.json", "tasks", ["imports"], readManifest("deno.json"));
|
|
31
|
+
}
|
|
32
|
+
if ((0, node_fs_1.existsSync)("package.json")) {
|
|
33
|
+
return new ProjectManifest("package.json", "scripts", ["dependencies", "devDependencies"], readManifest("package.json"));
|
|
34
|
+
}
|
|
35
|
+
return runtime === "deno"
|
|
36
|
+
? new ProjectManifest("deno.json", "tasks", ["imports"], { tasks: {} })
|
|
37
|
+
: new ProjectManifest("package.json", "scripts", ["dependencies", "devDependencies"], { name: "data-project", type: "module", scripts: {} });
|
|
38
|
+
}
|
|
39
|
+
reload() {
|
|
40
|
+
__classPrivateFieldSet(this, _ProjectManifest_config, readManifest(__classPrivateFieldGet(this, _ProjectManifest_path, "f")), "f");
|
|
41
|
+
}
|
|
42
|
+
getInstalledPackages() {
|
|
43
|
+
const installed = [];
|
|
44
|
+
for (const key of __classPrivateFieldGet(this, _ProjectManifest_dependencyKeys, "f")) {
|
|
45
|
+
const dependencies = __classPrivateFieldGet(this, _ProjectManifest_config, "f")[key];
|
|
46
|
+
if (dependencies && typeof dependencies === "object" &&
|
|
47
|
+
!Array.isArray(dependencies)) {
|
|
48
|
+
installed.push(...Object.keys(dependencies));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return installed;
|
|
52
|
+
}
|
|
53
|
+
updateTasks(tasks) {
|
|
54
|
+
const currentTasks = __classPrivateFieldGet(this, _ProjectManifest_config, "f")[__classPrivateFieldGet(this, _ProjectManifest_taskKey, "f")];
|
|
55
|
+
const existingTasks = currentTasks && typeof currentTasks === "object" &&
|
|
56
|
+
!Array.isArray(currentTasks)
|
|
57
|
+
? currentTasks
|
|
58
|
+
: {};
|
|
59
|
+
__classPrivateFieldGet(this, _ProjectManifest_config, "f")[__classPrivateFieldGet(this, _ProjectManifest_taskKey, "f")] = { ...existingTasks, ...tasks };
|
|
60
|
+
(0, node_fs_1.writeFileSync)(__classPrivateFieldGet(this, _ProjectManifest_path, "f"), JSON.stringify(__classPrivateFieldGet(this, _ProjectManifest_config, "f"), null, 2), "utf-8");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ProjectManifest = ProjectManifest;
|
|
64
|
+
_ProjectManifest_path = new WeakMap(), _ProjectManifest_taskKey = new WeakMap(), _ProjectManifest_dependencyKeys = new WeakMap(), _ProjectManifest_config = new WeakMap();
|
|
65
|
+
function readManifest(path) {
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse((0, node_fs_1.readFileSync)(path, "utf-8"));
|
|
68
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
69
|
+
throw new SyntaxError("the root value must be a JSON object");
|
|
70
|
+
}
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const detail = error instanceof Error ? ` ${error.message}` : "";
|
|
75
|
+
throw new Error(`Failed to parse ${path}.${detail}`, { cause: error });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/syncPackageDocs.ts"],"names":[],"mappings":"AAMA,wBAAsB,eAAe,CACnC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,GAAE,MAAM,EAAO,GAClC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0BjC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncPackageDocs = syncPackageDocs;
|
|
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 installPackagesAndFetchDocs_js_1 = require("./installPackagesAndFetchDocs.js");
|
|
8
|
+
const packageRegistry_js_1 = require("./packageRegistry.js");
|
|
9
|
+
async function syncPackageDocs(installedPackages, docsAlreadyRefreshed = []) {
|
|
10
|
+
const installedSet = new Set(installedPackages);
|
|
11
|
+
const refreshedSet = new Set(docsAlreadyRefreshed);
|
|
12
|
+
const docsMapping = {};
|
|
13
|
+
for (const pkg of packageRegistry_js_1.SUPPORTED_PACKAGES) {
|
|
14
|
+
const docPath = (0, node_path_1.join)("docs", pkg.value.split("/")[1] + ".md");
|
|
15
|
+
if (!installedSet.has(pkg.value)) {
|
|
16
|
+
if ((0, node_fs_1.existsSync)(docPath)) {
|
|
17
|
+
(0, node_fs_1.rmSync)(docPath);
|
|
18
|
+
prompts_1.log.info(`Removed stale documentation at ${docPath}.`);
|
|
19
|
+
}
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (!(0, node_fs_1.existsSync)(docPath) && !refreshedSet.has(pkg.value)) {
|
|
23
|
+
await (0, installPackagesAndFetchDocs_js_1.fetchPackageDocs)(pkg.value, { silent: true });
|
|
24
|
+
}
|
|
25
|
+
if ((0, node_fs_1.existsSync)(docPath)) {
|
|
26
|
+
docsMapping[pkg.value] = (0, node_fs_1.readFileSync)(docPath, "utf-8");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return docsMapping;
|
|
30
|
+
}
|
package/script/main.js
CHANGED
|
@@ -7,9 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const prompts_1 = require("@clack/prompts");
|
|
8
8
|
const node_process_1 = __importDefault(require("node:process"));
|
|
9
9
|
const getRuntime_js_1 = require("./helpers/getRuntime.js");
|
|
10
|
-
const getInstalledPackages_js_1 = require("./helpers/getInstalledPackages.js");
|
|
11
10
|
const packageOptions_js_1 = require("./helpers/packageOptions.js");
|
|
12
|
-
const updateProjectConfig_js_1 = require("./helpers/updateProjectConfig.js");
|
|
13
11
|
const ensureGitignore_js_1 = require("./helpers/ensureGitignore.js");
|
|
14
12
|
const ensureReadme_js_1 = require("./helpers/ensureReadme.js");
|
|
15
13
|
const installPackagesAndFetchDocs_js_1 = require("./helpers/installPackagesAndFetchDocs.js");
|
|
@@ -17,12 +15,16 @@ const getProjectTasks_js_1 = require("./helpers/getProjectTasks.js");
|
|
|
17
15
|
const createFolderStructure_js_1 = require("./helpers/createFolderStructure.js");
|
|
18
16
|
const ensureEnvFile_js_1 = require("./helpers/ensureEnvFile.js");
|
|
19
17
|
const ensureAgents_js_1 = require("./helpers/ensureAgents.js");
|
|
18
|
+
const packageRegistry_js_1 = require("./helpers/packageRegistry.js");
|
|
19
|
+
const projectManifest_js_1 = require("./helpers/projectManifest.js");
|
|
20
|
+
const syncPackageDocs_js_1 = require("./helpers/syncPackageDocs.js");
|
|
20
21
|
async function main() {
|
|
21
22
|
const runtime = (0, getRuntime_js_1.getRuntime)();
|
|
22
23
|
console.log();
|
|
23
24
|
(0, prompts_1.intro)(`Hi! 👋 (Running on ${runtime})`);
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const projectManifest = projectManifest_js_1.ProjectManifest.open(runtime);
|
|
26
|
+
projectManifest.updateTasks((0, getProjectTasks_js_1.getProjectTasks)());
|
|
27
|
+
const installedPackages = projectManifest.getInstalledPackages();
|
|
26
28
|
const options = packageOptions_js_1.PACKAGE_OPTIONS.map((opt) => ({
|
|
27
29
|
...opt,
|
|
28
30
|
label: installedPackages.includes(opt.value)
|
|
@@ -61,15 +63,11 @@ async function main() {
|
|
|
61
63
|
packagesToInstall.push(pkg);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
|
-
const docsMapping = {};
|
|
65
66
|
const sInstall = (0, prompts_1.spinner)();
|
|
66
67
|
sInstall.start("Installing packages and fetching documentation...");
|
|
67
68
|
for (const pkg of packagesToInstall) {
|
|
68
69
|
try {
|
|
69
|
-
|
|
70
|
-
if (typeof doc === "string") {
|
|
71
|
-
docsMapping[pkg] = doc;
|
|
72
|
-
}
|
|
70
|
+
await (0, installPackagesAndFetchDocs_js_1.installPackagesAndFetchDocs)([pkg], { silent: true });
|
|
73
71
|
}
|
|
74
72
|
catch (error) {
|
|
75
73
|
sInstall.stop(`❌ Failed to install ${pkg}.`);
|
|
@@ -78,12 +76,19 @@ async function main() {
|
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
78
|
sInstall.stop("✅ Packages installed and documentation fetched.");
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
projectManifest.reload();
|
|
80
|
+
projectManifest.updateTasks((0, getProjectTasks_js_1.getProjectTasks)());
|
|
81
|
+
const finalInstalledPackages = (0, packageRegistry_js_1.getInstalledPackageConfigs)(projectManifest.getInstalledPackages()).map((pkg) => pkg.value);
|
|
82
|
+
const docsMapping = await (0, syncPackageDocs_js_1.syncPackageDocs)(finalInstalledPackages, packagesToInstall);
|
|
83
|
+
await (0, createFolderStructure_js_1.createFolderStructure)(finalInstalledPackages);
|
|
83
84
|
(0, ensureGitignore_js_1.ensureGitignore)();
|
|
84
85
|
await (0, ensureEnvFile_js_1.ensureEnvFile)();
|
|
85
|
-
await (0, ensureReadme_js_1.ensureReadme)(runtime);
|
|
86
|
-
await (0, ensureAgents_js_1.ensureAgents)(docsMapping, runtime);
|
|
86
|
+
await (0, ensureReadme_js_1.ensureReadme)(runtime, finalInstalledPackages);
|
|
87
|
+
await (0, ensureAgents_js_1.ensureAgents)(docsMapping, runtime, finalInstalledPackages);
|
|
87
88
|
(0, prompts_1.outro)("You are all set! 🙌");
|
|
88
89
|
}
|
|
89
|
-
main().catch(
|
|
90
|
+
main().catch((error) => {
|
|
91
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
92
|
+
console.error(`❌ Error: ${message}`);
|
|
93
|
+
node_process_1.default.exitCode = 1;
|
|
94
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getInstalledPackages.d.ts","sourceRoot":"","sources":["../../src/helpers/getInstalledPackages.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CA4B/C"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
export function getInstalledPackages() {
|
|
3
|
-
let configFile = "";
|
|
4
|
-
let depKeys = [];
|
|
5
|
-
if (existsSync("deno.json")) {
|
|
6
|
-
configFile = "deno.json";
|
|
7
|
-
depKeys = ["imports"];
|
|
8
|
-
}
|
|
9
|
-
else if (existsSync("package.json")) {
|
|
10
|
-
configFile = "package.json";
|
|
11
|
-
depKeys = ["dependencies", "devDependencies"];
|
|
12
|
-
}
|
|
13
|
-
if (configFile === "")
|
|
14
|
-
return [];
|
|
15
|
-
try {
|
|
16
|
-
const content = readFileSync(configFile, "utf-8");
|
|
17
|
-
const config = JSON.parse(content);
|
|
18
|
-
const installed = [];
|
|
19
|
-
for (const key of depKeys) {
|
|
20
|
-
if (config[key]) {
|
|
21
|
-
installed.push(...Object.keys(config[key]));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return installed;
|
|
25
|
-
}
|
|
26
|
-
catch (_e) {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateProjectConfig.d.ts","sourceRoot":"","sources":["../../src/helpers/updateProjectConfig.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QA8ChE"}
|