@nshiab/setup-data-project 1.0.36 → 1.0.38
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.map +1 -1
- package/esm/helpers/ensureAgents.js +35 -15
- package/esm/helpers/ensureReadme.d.ts.map +1 -1
- package/esm/helpers/ensureReadme.js +3 -1
- package/package.json +1 -1
- package/script/helpers/ensureAgents.d.ts.map +1 -1
- package/script/helpers/ensureAgents.js +35 -15
- package/script/helpers/ensureReadme.d.ts.map +1 -1
- package/script/helpers/ensureReadme.js +3 -1
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QAgJvD"}
|
|
@@ -6,21 +6,23 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
|
|
|
6
6
|
let sdaClassesAndMethods = "";
|
|
7
7
|
let sdaDocsPath = "";
|
|
8
8
|
let sdaLibraryName = "";
|
|
9
|
+
const journalismFunctionsByPackage = new Map();
|
|
9
10
|
for (const [pkg, doc] of Object.entries(docsMapping)) {
|
|
10
11
|
const pkgConfig = SUPPORTED_PACKAGES.find((p) => p.value === pkg);
|
|
11
12
|
const pkgType = pkgConfig?.type || "other";
|
|
12
13
|
if (pkgType === "journalism") {
|
|
13
14
|
const repoName = pkg.split("/")[1];
|
|
14
|
-
|
|
15
|
-
journalismFunctions += doc
|
|
15
|
+
const functions = doc
|
|
16
16
|
.split("\n")
|
|
17
17
|
.filter((line) => line.trim().startsWith("#"))
|
|
18
18
|
.filter((line) => {
|
|
19
19
|
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
20
|
-
return depth
|
|
20
|
+
return depth === 2;
|
|
21
21
|
})
|
|
22
|
-
.map((line) => line.replace(/^#+\s+/, "").trim())
|
|
23
|
-
|
|
22
|
+
.map((line) => line.replace(/^#+\s+/, "").trim());
|
|
23
|
+
journalismFunctionsByPackage.set(pkg, functions);
|
|
24
|
+
journalismFunctions += `\n### ${repoName}\n\n`;
|
|
25
|
+
journalismFunctions += functions.join("\n") + "\n";
|
|
24
26
|
}
|
|
25
27
|
else if (pkgType === "sda") {
|
|
26
28
|
const repoName = pkg.split("/")[1];
|
|
@@ -31,7 +33,13 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
|
|
|
31
33
|
.filter((line) => line.trim().startsWith("#"))
|
|
32
34
|
.filter((line) => {
|
|
33
35
|
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
34
|
-
|
|
36
|
+
if (depth === 2)
|
|
37
|
+
return true;
|
|
38
|
+
if (depth !== 4)
|
|
39
|
+
return false;
|
|
40
|
+
const heading = line.replace(/^#+\s+/, "").replaceAll("`", "")
|
|
41
|
+
.trim();
|
|
42
|
+
return heading !== "Parameters";
|
|
35
43
|
})
|
|
36
44
|
.map((line) => {
|
|
37
45
|
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
@@ -39,8 +47,7 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
|
|
|
39
47
|
return "\n" + line.replace(/^#+\s+/, "").trim();
|
|
40
48
|
}
|
|
41
49
|
else {
|
|
42
|
-
return line.replace(/^#+\s
|
|
43
|
-
.replace(/^#+\s+/, " - ")
|
|
50
|
+
return line.replace(/^#+\s+/, " - ")
|
|
44
51
|
.replaceAll("`", "");
|
|
45
52
|
}
|
|
46
53
|
})
|
|
@@ -60,21 +67,34 @@ export function ensureAgents(docsMapping, runtime, installedPackages = Object.ke
|
|
|
60
67
|
? "bun run all-tests"
|
|
61
68
|
: "npm run all-tests";
|
|
62
69
|
const installedPackageConfigs = getInstalledPackageConfigs(installedPackages);
|
|
63
|
-
const importExamples = installedPackageConfigs.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const importExamples = installedPackageConfigs.flatMap((pkg) => {
|
|
71
|
+
if (pkg.type === "sda") {
|
|
72
|
+
return [`import { SimpleDB } from "${pkg.value}";`];
|
|
73
|
+
}
|
|
74
|
+
const functionName = journalismFunctionsByPackage.get(pkg.value)
|
|
75
|
+
?.map((name) => name.replaceAll("`", ""))
|
|
76
|
+
.find((name) => /^[A-Za-z_$][\w$]*$/.test(name));
|
|
77
|
+
return functionName
|
|
78
|
+
? [`import { ${functionName} } from "${pkg.value}";`]
|
|
79
|
+
: [];
|
|
67
80
|
});
|
|
68
81
|
let libraryGuidance = "";
|
|
69
82
|
if (installedPackageConfigs.length > 0) {
|
|
70
|
-
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.
|
|
83
|
+
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.value}"`)
|
|
71
84
|
.join(", ");
|
|
85
|
+
const libraryNoun = installedPackageConfigs.length === 1
|
|
86
|
+
? "library"
|
|
87
|
+
: "libraries";
|
|
72
88
|
libraryGuidance = `
|
|
73
|
-
Always prioritize the installed ${libraryNames}
|
|
89
|
+
Always prioritize the installed ${libraryNames} ${libraryNoun} when relevant.
|
|
90
|
+
`;
|
|
91
|
+
if (importExamples.length > 0) {
|
|
92
|
+
libraryGuidance += `APIs can be imported with named imports like this:
|
|
74
93
|
\`\`\`typescript
|
|
75
94
|
${importExamples.join("\n")}
|
|
76
95
|
\`\`\`
|
|
77
96
|
`;
|
|
97
|
+
}
|
|
78
98
|
}
|
|
79
99
|
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.
|
|
80
100
|
|
|
@@ -88,7 +108,7 @@ Always use "sda/main.ts" as the entry point.
|
|
|
88
108
|
|
|
89
109
|
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.
|
|
90
110
|
|
|
91
|
-
Put tests in the "sda/tests" folder. Write focused tests for reusable helpers and important data transformations when appropriate.
|
|
111
|
+
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".
|
|
92
112
|
|
|
93
113
|
If you need to download data, always put the files in the "sda/data" folder, which is ignored by Git.
|
|
94
114
|
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QA4DjC"}
|
|
@@ -37,11 +37,13 @@ Here's the recommended workflow:
|
|
|
37
37
|
ignored by Git.
|
|
38
38
|
- Use the \`sda/main.ts\` file to process your raw data. Write the
|
|
39
39
|
results to the \`sda/output\` folder, which is also ignored by Git.
|
|
40
|
+
- Put your tests in the \`sda/tests\` folder.
|
|
40
41
|
|
|
41
|
-
When working on your project, use the following
|
|
42
|
+
When working on your project, use the following commands:
|
|
42
43
|
|
|
43
44
|
- \`${runCommand} sda\` will watch your \`sda/main.ts\` and its dependencies.
|
|
44
45
|
Whenever you save changes, the data will be reprocessed.
|
|
46
|
+
- \`${runCommand} all-tests\` will run the project's test command.
|
|
45
47
|
- \`${runCommand} clean\` will remove cache and temporary files, if present.
|
|
46
48
|
|
|
47
49
|
Have fun!`,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QAgJvD"}
|
|
@@ -9,21 +9,23 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
|
|
|
9
9
|
let sdaClassesAndMethods = "";
|
|
10
10
|
let sdaDocsPath = "";
|
|
11
11
|
let sdaLibraryName = "";
|
|
12
|
+
const journalismFunctionsByPackage = new Map();
|
|
12
13
|
for (const [pkg, doc] of Object.entries(docsMapping)) {
|
|
13
14
|
const pkgConfig = packageRegistry_js_1.SUPPORTED_PACKAGES.find((p) => p.value === pkg);
|
|
14
15
|
const pkgType = pkgConfig?.type || "other";
|
|
15
16
|
if (pkgType === "journalism") {
|
|
16
17
|
const repoName = pkg.split("/")[1];
|
|
17
|
-
|
|
18
|
-
journalismFunctions += doc
|
|
18
|
+
const functions = doc
|
|
19
19
|
.split("\n")
|
|
20
20
|
.filter((line) => line.trim().startsWith("#"))
|
|
21
21
|
.filter((line) => {
|
|
22
22
|
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
23
|
-
return depth
|
|
23
|
+
return depth === 2;
|
|
24
24
|
})
|
|
25
|
-
.map((line) => line.replace(/^#+\s+/, "").trim())
|
|
26
|
-
|
|
25
|
+
.map((line) => line.replace(/^#+\s+/, "").trim());
|
|
26
|
+
journalismFunctionsByPackage.set(pkg, functions);
|
|
27
|
+
journalismFunctions += `\n### ${repoName}\n\n`;
|
|
28
|
+
journalismFunctions += functions.join("\n") + "\n";
|
|
27
29
|
}
|
|
28
30
|
else if (pkgType === "sda") {
|
|
29
31
|
const repoName = pkg.split("/")[1];
|
|
@@ -34,7 +36,13 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
|
|
|
34
36
|
.filter((line) => line.trim().startsWith("#"))
|
|
35
37
|
.filter((line) => {
|
|
36
38
|
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
37
|
-
|
|
39
|
+
if (depth === 2)
|
|
40
|
+
return true;
|
|
41
|
+
if (depth !== 4)
|
|
42
|
+
return false;
|
|
43
|
+
const heading = line.replace(/^#+\s+/, "").replaceAll("`", "")
|
|
44
|
+
.trim();
|
|
45
|
+
return heading !== "Parameters";
|
|
38
46
|
})
|
|
39
47
|
.map((line) => {
|
|
40
48
|
const depth = line.match(/^#+/)?.[0].length || 0;
|
|
@@ -42,8 +50,7 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
|
|
|
42
50
|
return "\n" + line.replace(/^#+\s+/, "").trim();
|
|
43
51
|
}
|
|
44
52
|
else {
|
|
45
|
-
return line.replace(/^#+\s
|
|
46
|
-
.replace(/^#+\s+/, " - ")
|
|
53
|
+
return line.replace(/^#+\s+/, " - ")
|
|
47
54
|
.replaceAll("`", "");
|
|
48
55
|
}
|
|
49
56
|
})
|
|
@@ -63,21 +70,34 @@ function ensureAgents(docsMapping, runtime, installedPackages = Object.keys(docs
|
|
|
63
70
|
? "bun run all-tests"
|
|
64
71
|
: "npm run all-tests";
|
|
65
72
|
const installedPackageConfigs = (0, packageRegistry_js_1.getInstalledPackageConfigs)(installedPackages);
|
|
66
|
-
const importExamples = installedPackageConfigs.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
const importExamples = installedPackageConfigs.flatMap((pkg) => {
|
|
74
|
+
if (pkg.type === "sda") {
|
|
75
|
+
return [`import { SimpleDB } from "${pkg.value}";`];
|
|
76
|
+
}
|
|
77
|
+
const functionName = journalismFunctionsByPackage.get(pkg.value)
|
|
78
|
+
?.map((name) => name.replaceAll("`", ""))
|
|
79
|
+
.find((name) => /^[A-Za-z_$][\w$]*$/.test(name));
|
|
80
|
+
return functionName
|
|
81
|
+
? [`import { ${functionName} } from "${pkg.value}";`]
|
|
82
|
+
: [];
|
|
70
83
|
});
|
|
71
84
|
let libraryGuidance = "";
|
|
72
85
|
if (installedPackageConfigs.length > 0) {
|
|
73
|
-
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.
|
|
86
|
+
const libraryNames = installedPackageConfigs.map((pkg) => `"${pkg.value}"`)
|
|
74
87
|
.join(", ");
|
|
88
|
+
const libraryNoun = installedPackageConfigs.length === 1
|
|
89
|
+
? "library"
|
|
90
|
+
: "libraries";
|
|
75
91
|
libraryGuidance = `
|
|
76
|
-
Always prioritize the installed ${libraryNames}
|
|
92
|
+
Always prioritize the installed ${libraryNames} ${libraryNoun} when relevant.
|
|
93
|
+
`;
|
|
94
|
+
if (importExamples.length > 0) {
|
|
95
|
+
libraryGuidance += `APIs can be imported with named imports like this:
|
|
77
96
|
\`\`\`typescript
|
|
78
97
|
${importExamples.join("\n")}
|
|
79
98
|
\`\`\`
|
|
80
99
|
`;
|
|
100
|
+
}
|
|
81
101
|
}
|
|
82
102
|
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.
|
|
83
103
|
|
|
@@ -91,7 +111,7 @@ Always use "sda/main.ts" as the entry point.
|
|
|
91
111
|
|
|
92
112
|
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.
|
|
93
113
|
|
|
94
|
-
Put tests in the "sda/tests" folder. Write focused tests for reusable helpers and important data transformations when appropriate.
|
|
114
|
+
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".
|
|
95
115
|
|
|
96
116
|
If you need to download data, always put the files in the "sda/data" folder, which is ignored by Git.
|
|
97
117
|
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QA4DjC"}
|
|
@@ -40,11 +40,13 @@ Here's the recommended workflow:
|
|
|
40
40
|
ignored by Git.
|
|
41
41
|
- Use the \`sda/main.ts\` file to process your raw data. Write the
|
|
42
42
|
results to the \`sda/output\` folder, which is also ignored by Git.
|
|
43
|
+
- Put your tests in the \`sda/tests\` folder.
|
|
43
44
|
|
|
44
|
-
When working on your project, use the following
|
|
45
|
+
When working on your project, use the following commands:
|
|
45
46
|
|
|
46
47
|
- \`${runCommand} sda\` will watch your \`sda/main.ts\` and its dependencies.
|
|
47
48
|
Whenever you save changes, the data will be reprocessed.
|
|
49
|
+
- \`${runCommand} all-tests\` will run the project's test command.
|
|
48
50
|
- \`${runCommand} clean\` will remove cache and temporary files, if present.
|
|
49
51
|
|
|
50
52
|
Have fun!`,
|