@nshiab/setup-data-project 1.0.28 → 1.0.29
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 +28 -12
- 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/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 +8 -7
- 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 +27 -11
- 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/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 +8 -7
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ensureAgents(docsMapping: Record<string, string>, runtime: string):
|
|
1
|
+
export declare function ensureAgents(docsMapping: Record<string, string>, runtime: string, installedPackages?: string[]): void;
|
|
2
2
|
//# sourceMappingURL=ensureAgents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAkHvD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { log } from "@clack/prompts";
|
|
2
|
-
import {
|
|
3
|
-
import { SUPPORTED_PACKAGES } from "./packageRegistry.js";
|
|
4
|
-
export
|
|
2
|
+
import { ensureManagedSection } from "./ensureManagedSection.js";
|
|
3
|
+
import { getInstalledPackageConfigs, SUPPORTED_PACKAGES, } from "./packageRegistry.js";
|
|
4
|
+
export function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docsMapping)) {
|
|
5
5
|
let journalismFunctions = "";
|
|
6
6
|
let sdaClassesAndMethods = "";
|
|
7
7
|
for (const [pkg, doc] of Object.entries(docsMapping)) {
|
|
@@ -45,6 +45,23 @@ export async function ensureAgents(docsMapping, runtime) {
|
|
|
45
45
|
const configFile = runtime === "deno" ? "deno.json" : "package.json";
|
|
46
46
|
const runSda = runtime === "deno" ? "deno task sda" : "npm run sda";
|
|
47
47
|
const runClean = runtime === "deno" ? "deno task clean" : "npm run clean";
|
|
48
|
+
const installedPackageConfigs = getInstalledPackageConfigs(installedPackages);
|
|
49
|
+
const importExamples = installedPackageConfigs.map((pkg) => {
|
|
50
|
+
const repoName = pkg.value.split("/")[1];
|
|
51
|
+
const identifier = repoName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
52
|
+
return `import * as ${identifier} from "${pkg.value}";`;
|
|
53
|
+
});
|
|
54
|
+
let libraryGuidance = "";
|
|
55
|
+
if (installedPackageConfigs.length > 0) {
|
|
56
|
+
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.label}"`)
|
|
57
|
+
.join(", ");
|
|
58
|
+
libraryGuidance = `
|
|
59
|
+
Always prioritize the installed ${libraryNames} libraries when relevant. They can be imported directly like this:
|
|
60
|
+
\`\`\`typescript
|
|
61
|
+
${importExamples.join("\n")}
|
|
62
|
+
\`\`\`
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
48
65
|
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.
|
|
49
66
|
|
|
50
67
|
Always use "sda" task when available (e.g. \`${runSda}\`).
|
|
@@ -62,13 +79,7 @@ If you need to create other TypeScript files, create them in the "sda/helpers" f
|
|
|
62
79
|
If you need to download data, always put the files in the "sda/data" folder, which is gitignored.
|
|
63
80
|
|
|
64
81
|
If you need to output data to a file, always put the file in the "sda/output" folder.
|
|
65
|
-
|
|
66
|
-
Always prioritize the use of the "journalism" and "simple-data-analysis" libraries when they are installed. These libraries can be used directly like this:
|
|
67
|
-
\`\`\`typescript
|
|
68
|
-
import { formatDate } from "@nshiab/journalism-format";
|
|
69
|
-
import { SimpleDB } from "@nshiab/simple-data-analysis";
|
|
70
|
-
\`\`\`
|
|
71
|
-
`;
|
|
82
|
+
${libraryGuidance}`;
|
|
72
83
|
if (journalismFunctions !== "") {
|
|
73
84
|
content += `
|
|
74
85
|
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,8 +90,13 @@ ${journalismFunctions}`;
|
|
|
79
90
|
Here are the classes and their methods available in the "simple-data-analysis" library. If one of the classes or methods might be relevant, read the complete documentation at "./docs/simple-data-analysis.md" to properly use it. Remember that almost all methods are asynchronous, so you need to use \`await\` when calling them.
|
|
80
91
|
${sdaClassesAndMethods}`;
|
|
81
92
|
}
|
|
82
|
-
const status =
|
|
83
|
-
|
|
93
|
+
const status = ensureManagedSection({
|
|
94
|
+
path: "AGENTS.md",
|
|
95
|
+
name: "agents",
|
|
96
|
+
content,
|
|
97
|
+
createContent: (managedSection) => managedSection,
|
|
98
|
+
});
|
|
99
|
+
if (status === "created" || status === "updated") {
|
|
84
100
|
log.info("Updated AGENTS.md");
|
|
85
101
|
}
|
|
86
102
|
}
|
|
@@ -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,30 @@
|
|
|
1
|
+
import { log } from "@clack/prompts";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
export function ensureManagedSection(options) {
|
|
4
|
+
const startMarker = `<!-- setup-data-project:${options.name}:start -->`;
|
|
5
|
+
const endMarker = `<!-- setup-data-project:${options.name}:end -->`;
|
|
6
|
+
const trimmedContent = options.content.trim();
|
|
7
|
+
const section = trimmedContent === ""
|
|
8
|
+
? `${startMarker}\n${endMarker}`
|
|
9
|
+
: `${startMarker}\n${trimmedContent}\n${endMarker}`;
|
|
10
|
+
if (!existsSync(options.path)) {
|
|
11
|
+
writeFileSync(options.path, options.createContent(section));
|
|
12
|
+
return "created";
|
|
13
|
+
}
|
|
14
|
+
const currentContent = readFileSync(options.path, "utf-8");
|
|
15
|
+
const start = currentContent.indexOf(startMarker);
|
|
16
|
+
const end = currentContent.indexOf(endMarker);
|
|
17
|
+
if (start === -1 || end === -1 || end < start) {
|
|
18
|
+
log.warn(`${options.path} was not updated because its setup-data-project markers ` +
|
|
19
|
+
`were not found. Add ${startMarker} and ${endMarker}, then rerun the ` +
|
|
20
|
+
"script.");
|
|
21
|
+
return "missing-markers";
|
|
22
|
+
}
|
|
23
|
+
const nextContent = currentContent.slice(0, start) + section +
|
|
24
|
+
currentContent.slice(end + endMarker.length);
|
|
25
|
+
if (nextContent === currentContent) {
|
|
26
|
+
return "unchanged";
|
|
27
|
+
}
|
|
28
|
+
writeFileSync(options.path, nextContent);
|
|
29
|
+
return "updated";
|
|
30
|
+
}
|
|
@@ -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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { log } from "@clack/prompts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ensureManagedSection } from "./ensureManagedSection.js";
|
|
3
|
+
import { getInstalledPackageConfigs } from "./packageRegistry.js";
|
|
4
|
+
export function ensureReadme(runtime, installedPackages = []) {
|
|
4
5
|
let runCommand = "npm run";
|
|
5
6
|
if (runtime === "deno") {
|
|
6
7
|
runCommand = "deno task";
|
|
@@ -8,13 +9,27 @@ export async function ensureReadme(runtime) {
|
|
|
8
9
|
else if (runtime === "bun") {
|
|
9
10
|
runCommand = "bun run";
|
|
10
11
|
}
|
|
11
|
-
const
|
|
12
|
+
const installedPackageConfigs = getInstalledPackageConfigs(installedPackages);
|
|
13
|
+
const hasSda = installedPackageConfigs.some((pkg) => pkg.type === "sda");
|
|
14
|
+
const hasJournalism = installedPackageConfigs.some((pkg) => pkg.type === "journalism");
|
|
15
|
+
const libraryLinks = [
|
|
16
|
+
hasSda
|
|
17
|
+
? "[simple-data-analysis](https://github.com/nshiab/simple-data-analysis)"
|
|
18
|
+
: "",
|
|
19
|
+
hasJournalism ? "[journalism](https://github.com/nshiab/journalism)" : "",
|
|
20
|
+
].filter(Boolean);
|
|
21
|
+
const librarySection = libraryLinks.length === 0
|
|
22
|
+
? ""
|
|
23
|
+
: `It's installing ${libraryLinks.join(" and ")} libraries, with up-to-date
|
|
24
|
+
documentation and AI agent instructions.`;
|
|
25
|
+
const status = ensureManagedSection({
|
|
26
|
+
path: "README.md",
|
|
27
|
+
name: "libraries",
|
|
28
|
+
content: librarySection,
|
|
29
|
+
createContent: (managedSection) => `This repository has been created with
|
|
12
30
|
[setup-data-project](https://github.com/nshiab/setup-data-project/).
|
|
13
31
|
|
|
14
|
-
|
|
15
|
-
[simple-data-analysis](https://github.com/nshiab/simple-data-analysis) and
|
|
16
|
-
[journalism](https://github.com/nshiab/journalism) libraries, with up-to-date
|
|
17
|
-
documentation and AI agent instructions.
|
|
32
|
+
${managedSection}
|
|
18
33
|
|
|
19
34
|
Here's the recommended workflow:
|
|
20
35
|
|
|
@@ -27,12 +42,11 @@ When working on your project, use the following command:
|
|
|
27
42
|
|
|
28
43
|
- \`${runCommand} sda\` will watch your \`sda/main.ts\` and its dependencies. Everytime
|
|
29
44
|
you'll save some changes, the data will be reprocessed.
|
|
30
|
-
- \`${runCommand} clean\` will remove
|
|
31
|
-
if present.
|
|
45
|
+
- \`${runCommand} clean\` will remove cache and temporary files, if present.
|
|
32
46
|
|
|
33
|
-
Have fun
|
|
34
|
-
|
|
35
|
-
if (status === "updated") {
|
|
47
|
+
Have fun!`,
|
|
48
|
+
});
|
|
49
|
+
if (status === "created" || status === "updated") {
|
|
36
50
|
log.info("Updated README.md");
|
|
37
51
|
}
|
|
38
52
|
}
|
|
@@ -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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spinner } from "@clack/prompts";
|
|
1
|
+
import { log, spinner } from "@clack/prompts";
|
|
2
2
|
import * as childProcess from "node:child_process";
|
|
3
3
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
@@ -6,6 +6,44 @@ import { getRuntime } from "./getRuntime.js";
|
|
|
6
6
|
export const commandRunner = {
|
|
7
7
|
exec: childProcess.exec,
|
|
8
8
|
};
|
|
9
|
+
export async function fetchPackageDocs(pkg, options = {}) {
|
|
10
|
+
if (!existsSync("docs")) {
|
|
11
|
+
mkdirSync("docs");
|
|
12
|
+
}
|
|
13
|
+
const sFetch = spinner();
|
|
14
|
+
if (!options.silent) {
|
|
15
|
+
sFetch.start("Fetching documentation for " + pkg + "...");
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const repoName = pkg.split("/")[1];
|
|
19
|
+
const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
|
|
20
|
+
"/refs/heads/main/llm.md";
|
|
21
|
+
const response = await fetch(url);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
if (!options.silent) {
|
|
24
|
+
sFetch.stop("⚠️ No documentation (llm.md) found for " + pkg + ".");
|
|
25
|
+
}
|
|
26
|
+
log.warn(`Documentation for ${pkg} could not be refreshed. Rerun the script ` +
|
|
27
|
+
"later to try again.");
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const docContent = await response.text();
|
|
31
|
+
writeFileSync(join("docs", repoName + ".md"), docContent);
|
|
32
|
+
if (!options.silent) {
|
|
33
|
+
sFetch.stop("✅ Documentation for " + pkg + " saved!");
|
|
34
|
+
}
|
|
35
|
+
return docContent;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!options.silent) {
|
|
39
|
+
sFetch.stop("❌ Failed to fetch documentation for " + pkg + ".");
|
|
40
|
+
}
|
|
41
|
+
log.warn(`Documentation for ${pkg} could not be refreshed. Rerun the script ` +
|
|
42
|
+
"later to try again.");
|
|
43
|
+
console.error(error);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
9
47
|
export async function installPackagesAndFetchDocs(selectedPackages, options = {}) {
|
|
10
48
|
const runtime = getRuntime();
|
|
11
49
|
if (Array.isArray(selectedPackages) && selectedPackages.length > 0) {
|
|
@@ -52,39 +90,9 @@ export async function installPackagesAndFetchDocs(selectedPackages, options = {}
|
|
|
52
90
|
throw error;
|
|
53
91
|
}
|
|
54
92
|
}
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
const sFetch = spinner();
|
|
60
|
-
try {
|
|
61
|
-
if (!options.silent) {
|
|
62
|
-
sFetch.start("Fetching documentation for " + pkg + "...");
|
|
63
|
-
}
|
|
64
|
-
const repoName = pkg.split("/")[1];
|
|
65
|
-
const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
|
|
66
|
-
"/refs/heads/main/llm.md";
|
|
67
|
-
const response = await fetch(url);
|
|
68
|
-
if (response.ok) {
|
|
69
|
-
const docContent = await response.text();
|
|
70
|
-
writeFileSync(join("docs", repoName + ".md"), docContent);
|
|
71
|
-
if (!options.silent) {
|
|
72
|
-
sFetch.stop("✅ Documentation for " + pkg + " saved!");
|
|
73
|
-
}
|
|
74
|
-
lastDoc = docContent;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
if (!options.silent) {
|
|
78
|
-
sFetch.stop("⚠️ No documentation (llm.md) found for " + pkg +
|
|
79
|
-
". Skipping doc fetch.");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
if (!options.silent) {
|
|
85
|
-
sFetch.stop("❌ Failed to fetch documentation for " + pkg + ".");
|
|
86
|
-
}
|
|
87
|
-
console.error(error);
|
|
93
|
+
const docContent = await fetchPackageDocs(pkg, options);
|
|
94
|
+
if (docContent !== undefined) {
|
|
95
|
+
lastDoc = docContent;
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
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"}
|
|
@@ -78,3 +78,7 @@ export const SUPPORTED_PACKAGES = [
|
|
|
78
78
|
hint: "Functions to zip/unzip, sleep, reencode files, create nested directories...",
|
|
79
79
|
},
|
|
80
80
|
];
|
|
81
|
+
export function getInstalledPackageConfigs(installedPackages) {
|
|
82
|
+
const installedSet = new Set(installedPackages);
|
|
83
|
+
return SUPPORTED_PACKAGES.filter((pkg) => installedSet.has(pkg.value));
|
|
84
|
+
}
|
|
@@ -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,27 @@
|
|
|
1
|
+
import { log } from "@clack/prompts";
|
|
2
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fetchPackageDocs } from "./installPackagesAndFetchDocs.js";
|
|
5
|
+
import { SUPPORTED_PACKAGES } from "./packageRegistry.js";
|
|
6
|
+
export async function syncPackageDocs(installedPackages, docsAlreadyRefreshed = []) {
|
|
7
|
+
const installedSet = new Set(installedPackages);
|
|
8
|
+
const refreshedSet = new Set(docsAlreadyRefreshed);
|
|
9
|
+
const docsMapping = {};
|
|
10
|
+
for (const pkg of SUPPORTED_PACKAGES) {
|
|
11
|
+
const docPath = join("docs", pkg.value.split("/")[1] + ".md");
|
|
12
|
+
if (!installedSet.has(pkg.value)) {
|
|
13
|
+
if (existsSync(docPath)) {
|
|
14
|
+
rmSync(docPath);
|
|
15
|
+
log.info(`Removed stale documentation at ${docPath}.`);
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (!existsSync(docPath) && !refreshedSet.has(pkg.value)) {
|
|
20
|
+
await fetchPackageDocs(pkg.value, { silent: true });
|
|
21
|
+
}
|
|
22
|
+
if (existsSync(docPath)) {
|
|
23
|
+
docsMapping[pkg.value] = readFileSync(docPath, "utf-8");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return docsMapping;
|
|
27
|
+
}
|
package/esm/main.js
CHANGED
|
@@ -12,6 +12,8 @@ import { getProjectTasks } from "./helpers/getProjectTasks.js";
|
|
|
12
12
|
import { createFolderStructure } from "./helpers/createFolderStructure.js";
|
|
13
13
|
import { ensureEnvFile } from "./helpers/ensureEnvFile.js";
|
|
14
14
|
import { ensureAgents } from "./helpers/ensureAgents.js";
|
|
15
|
+
import { SUPPORTED_PACKAGES } from "./helpers/packageRegistry.js";
|
|
16
|
+
import { syncPackageDocs } from "./helpers/syncPackageDocs.js";
|
|
15
17
|
async function main() {
|
|
16
18
|
const runtime = getRuntime();
|
|
17
19
|
console.log();
|
|
@@ -56,15 +58,11 @@ async function main() {
|
|
|
56
58
|
packagesToInstall.push(pkg);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
const docsMapping = {};
|
|
60
61
|
const sInstall = spinner();
|
|
61
62
|
sInstall.start("Installing packages and fetching documentation...");
|
|
62
63
|
for (const pkg of packagesToInstall) {
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
-
if (typeof doc === "string") {
|
|
66
|
-
docsMapping[pkg] = doc;
|
|
67
|
-
}
|
|
65
|
+
await installPackagesAndFetchDocs([pkg], { silent: true });
|
|
68
66
|
}
|
|
69
67
|
catch (error) {
|
|
70
68
|
sInstall.stop(`❌ Failed to install ${pkg}.`);
|
|
@@ -74,11 +72,14 @@ async function main() {
|
|
|
74
72
|
}
|
|
75
73
|
sInstall.stop("✅ Packages installed and documentation fetched.");
|
|
76
74
|
updateProjectConfig(getProjectTasks());
|
|
75
|
+
const supportedPackageNames = new Set(SUPPORTED_PACKAGES.map((pkg) => pkg.value));
|
|
76
|
+
const finalInstalledPackages = getInstalledPackages().filter((pkg) => supportedPackageNames.has(pkg));
|
|
77
|
+
const docsMapping = await syncPackageDocs(finalInstalledPackages, packagesToInstall);
|
|
77
78
|
await createFolderStructure(packagesToInstall);
|
|
78
79
|
ensureGitignore();
|
|
79
80
|
await ensureEnvFile();
|
|
80
|
-
await ensureReadme(runtime);
|
|
81
|
-
await ensureAgents(docsMapping, runtime);
|
|
81
|
+
await ensureReadme(runtime, finalInstalledPackages);
|
|
82
|
+
await ensureAgents(docsMapping, runtime, finalInstalledPackages);
|
|
82
83
|
outro("You are all set! 🙌");
|
|
83
84
|
}
|
|
84
85
|
main().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function ensureAgents(docsMapping: Record<string, string>, runtime: string):
|
|
1
|
+
export declare function ensureAgents(docsMapping: Record<string, string>, runtime: string, installedPackages?: string[]): void;
|
|
2
2
|
//# sourceMappingURL=ensureAgents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ensureAgents.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureAgents.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAM,EAA6B,QAkHvD"}
|
|
@@ -2,9 +2,9 @@
|
|
|
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
10
|
for (const [pkg, doc] of Object.entries(docsMapping)) {
|
|
@@ -48,6 +48,23 @@ async function ensureAgents(docsMapping, runtime) {
|
|
|
48
48
|
const configFile = runtime === "deno" ? "deno.json" : "package.json";
|
|
49
49
|
const runSda = runtime === "deno" ? "deno task sda" : "npm run sda";
|
|
50
50
|
const runClean = runtime === "deno" ? "deno task clean" : "npm run clean";
|
|
51
|
+
const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
|
|
52
|
+
const importExamples = installedPackageConfigs.map((pkg) => {
|
|
53
|
+
const repoName = pkg.value.split("/")[1];
|
|
54
|
+
const identifier = repoName.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
55
|
+
return `import * as ${identifier} from "${pkg.value}";`;
|
|
56
|
+
});
|
|
57
|
+
let libraryGuidance = "";
|
|
58
|
+
if (installedPackageConfigs.length > 0) {
|
|
59
|
+
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.label}"`)
|
|
60
|
+
.join(", ");
|
|
61
|
+
libraryGuidance = `
|
|
62
|
+
Always prioritize the installed ${libraryNames} libraries when relevant. They can be imported directly like this:
|
|
63
|
+
\`\`\`typescript
|
|
64
|
+
${importExamples.join("\n")}
|
|
65
|
+
\`\`\`
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
51
68
|
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
69
|
|
|
53
70
|
Always use "sda" task when available (e.g. \`${runSda}\`).
|
|
@@ -65,13 +82,7 @@ If you need to create other TypeScript files, create them in the "sda/helpers" f
|
|
|
65
82
|
If you need to download data, always put the files in the "sda/data" folder, which is gitignored.
|
|
66
83
|
|
|
67
84
|
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
|
-
`;
|
|
85
|
+
${libraryGuidance}`;
|
|
75
86
|
if (journalismFunctions !== "") {
|
|
76
87
|
content += `
|
|
77
88
|
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.
|
|
@@ -82,8 +93,13 @@ ${journalismFunctions}`;
|
|
|
82
93
|
Here are the classes and their methods available in the "simple-data-analysis" library. If one of the classes or methods might be relevant, read the complete documentation at "./docs/simple-data-analysis.md" to properly use it. Remember that almost all methods are asynchronous, so you need to use \`await\` when calling them.
|
|
83
94
|
${sdaClassesAndMethods}`;
|
|
84
95
|
}
|
|
85
|
-
const status =
|
|
86
|
-
|
|
96
|
+
const status = (0, ensureManagedSection_js_1.ensureManagedSection)({
|
|
97
|
+
path: "AGENTS.md",
|
|
98
|
+
name: "agents",
|
|
99
|
+
content,
|
|
100
|
+
createContent: (managedSection) => managedSection,
|
|
101
|
+
});
|
|
102
|
+
if (status === "created" || status === "updated") {
|
|
87
103
|
prompts_1.log.info("Updated AGENTS.md");
|
|
88
104
|
}
|
|
89
105
|
}
|
|
@@ -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 @@
|
|
|
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
|
@@ -17,6 +17,8 @@ const getProjectTasks_js_1 = require("./helpers/getProjectTasks.js");
|
|
|
17
17
|
const createFolderStructure_js_1 = require("./helpers/createFolderStructure.js");
|
|
18
18
|
const ensureEnvFile_js_1 = require("./helpers/ensureEnvFile.js");
|
|
19
19
|
const ensureAgents_js_1 = require("./helpers/ensureAgents.js");
|
|
20
|
+
const packageRegistry_js_1 = require("./helpers/packageRegistry.js");
|
|
21
|
+
const syncPackageDocs_js_1 = require("./helpers/syncPackageDocs.js");
|
|
20
22
|
async function main() {
|
|
21
23
|
const runtime = (0, getRuntime_js_1.getRuntime)();
|
|
22
24
|
console.log();
|
|
@@ -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}.`);
|
|
@@ -79,11 +77,14 @@ async function main() {
|
|
|
79
77
|
}
|
|
80
78
|
sInstall.stop("✅ Packages installed and documentation fetched.");
|
|
81
79
|
(0, updateProjectConfig_js_1.updateProjectConfig)((0, getProjectTasks_js_1.getProjectTasks)());
|
|
80
|
+
const supportedPackageNames = new Set(packageRegistry_js_1.SUPPORTED_PACKAGES.map((pkg) => pkg.value));
|
|
81
|
+
const finalInstalledPackages = (0, getInstalledPackages_js_1.getInstalledPackages)().filter((pkg) => supportedPackageNames.has(pkg));
|
|
82
|
+
const docsMapping = await (0, syncPackageDocs_js_1.syncPackageDocs)(finalInstalledPackages, packagesToInstall);
|
|
82
83
|
await (0, createFolderStructure_js_1.createFolderStructure)(packagesToInstall);
|
|
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
90
|
main().catch(console.error);
|