@nshiab/setup-data-project 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -24
- package/dist/main.mjs +849 -0
- package/dist/main.mjs.map +1 -0
- package/package.json +29 -18
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/helpers/createFolderStructure.d.ts +0 -2
- package/esm/helpers/createFolderStructure.d.ts.map +0 -1
- package/esm/helpers/createFolderStructure.js +0 -40
- package/esm/helpers/ensureAgents.d.ts +0 -3
- package/esm/helpers/ensureAgents.d.ts.map +0 -1
- package/esm/helpers/ensureAgents.js +0 -176
- package/esm/helpers/ensureEnvFile.d.ts +0 -2
- package/esm/helpers/ensureEnvFile.d.ts.map +0 -1
- package/esm/helpers/ensureEnvFile.js +0 -8
- package/esm/helpers/ensureGitignore.d.ts +0 -3
- package/esm/helpers/ensureGitignore.d.ts.map +0 -1
- package/esm/helpers/ensureGitignore.js +0 -24
- package/esm/helpers/ensureManagedSection.d.ts +0 -9
- package/esm/helpers/ensureManagedSection.d.ts.map +0 -1
- package/esm/helpers/ensureManagedSection.js +0 -33
- package/esm/helpers/ensureReadme.d.ts +0 -2
- package/esm/helpers/ensureReadme.d.ts.map +0 -1
- package/esm/helpers/ensureReadme.js +0 -61
- package/esm/helpers/fetchPackageDocs.d.ts +0 -8
- package/esm/helpers/fetchPackageDocs.d.ts.map +0 -1
- package/esm/helpers/fetchPackageDocs.js +0 -75
- package/esm/helpers/getInstalledPackageVersions.d.ts +0 -2
- package/esm/helpers/getInstalledPackageVersions.d.ts.map +0 -1
- package/esm/helpers/getInstalledPackageVersions.js +0 -91
- package/esm/helpers/getProjectTasks.d.ts +0 -6
- package/esm/helpers/getProjectTasks.d.ts.map +0 -1
- package/esm/helpers/getProjectTasks.js +0 -17
- package/esm/helpers/getRuntime.d.ts +0 -5
- package/esm/helpers/getRuntime.d.ts.map +0 -1
- package/esm/helpers/getRuntime.js +0 -19
- package/esm/helpers/gitignoreEntries.d.ts +0 -2
- package/esm/helpers/gitignoreEntries.d.ts.map +0 -1
- package/esm/helpers/gitignoreEntries.js +0 -10
- package/esm/helpers/installPackages.d.ts +0 -7
- package/esm/helpers/installPackages.d.ts.map +0 -1
- package/esm/helpers/installPackages.js +0 -59
- package/esm/helpers/packageOptions.d.ts +0 -6
- package/esm/helpers/packageOptions.d.ts.map +0 -1
- package/esm/helpers/packageOptions.js +0 -6
- package/esm/helpers/packageRegistry.d.ts +0 -9
- package/esm/helpers/packageRegistry.d.ts.map +0 -1
- package/esm/helpers/packageRegistry.js +0 -84
- package/esm/helpers/projectManifest.d.ts +0 -12
- package/esm/helpers/projectManifest.d.ts.map +0 -1
- package/esm/helpers/projectManifest.js +0 -80
- package/esm/helpers/syncPackageDocs.d.ts +0 -3
- package/esm/helpers/syncPackageDocs.d.ts.map +0 -1
- package/esm/helpers/syncPackageDocs.js +0 -46
- package/esm/main.d.ts +0 -3
- package/esm/main.d.ts.map +0 -1
- package/esm/main.js +0 -94
- package/esm/package.json +0 -3
- package/script/_dnt.shims.d.ts +0 -2
- package/script/_dnt.shims.d.ts.map +0 -1
- package/script/_dnt.shims.js +0 -60
- package/script/helpers/createFolderStructure.d.ts +0 -2
- package/script/helpers/createFolderStructure.d.ts.map +0 -1
- package/script/helpers/createFolderStructure.js +0 -43
- package/script/helpers/ensureAgents.d.ts +0 -3
- package/script/helpers/ensureAgents.d.ts.map +0 -1
- package/script/helpers/ensureAgents.js +0 -179
- package/script/helpers/ensureEnvFile.d.ts +0 -2
- package/script/helpers/ensureEnvFile.d.ts.map +0 -1
- package/script/helpers/ensureEnvFile.js +0 -11
- package/script/helpers/ensureGitignore.d.ts +0 -3
- package/script/helpers/ensureGitignore.d.ts.map +0 -1
- package/script/helpers/ensureGitignore.js +0 -28
- package/script/helpers/ensureManagedSection.d.ts +0 -9
- package/script/helpers/ensureManagedSection.d.ts.map +0 -1
- package/script/helpers/ensureManagedSection.js +0 -36
- package/script/helpers/ensureReadme.d.ts +0 -2
- package/script/helpers/ensureReadme.d.ts.map +0 -1
- package/script/helpers/ensureReadme.js +0 -64
- package/script/helpers/fetchPackageDocs.d.ts +0 -8
- package/script/helpers/fetchPackageDocs.d.ts.map +0 -1
- package/script/helpers/fetchPackageDocs.js +0 -78
- package/script/helpers/getInstalledPackageVersions.d.ts +0 -2
- package/script/helpers/getInstalledPackageVersions.d.ts.map +0 -1
- package/script/helpers/getInstalledPackageVersions.js +0 -94
- package/script/helpers/getProjectTasks.d.ts +0 -6
- package/script/helpers/getProjectTasks.d.ts.map +0 -1
- package/script/helpers/getProjectTasks.js +0 -20
- package/script/helpers/getRuntime.d.ts +0 -5
- package/script/helpers/getRuntime.d.ts.map +0 -1
- package/script/helpers/getRuntime.js +0 -59
- package/script/helpers/gitignoreEntries.d.ts +0 -2
- package/script/helpers/gitignoreEntries.d.ts.map +0 -1
- package/script/helpers/gitignoreEntries.js +0 -13
- package/script/helpers/installPackages.d.ts +0 -7
- package/script/helpers/installPackages.d.ts.map +0 -1
- package/script/helpers/installPackages.js +0 -96
- package/script/helpers/packageOptions.d.ts +0 -6
- package/script/helpers/packageOptions.d.ts.map +0 -1
- package/script/helpers/packageOptions.js +0 -9
- package/script/helpers/packageRegistry.d.ts +0 -9
- package/script/helpers/packageRegistry.d.ts.map +0 -1
- package/script/helpers/packageRegistry.js +0 -88
- package/script/helpers/projectManifest.d.ts +0 -12
- package/script/helpers/projectManifest.d.ts.map +0 -1
- package/script/helpers/projectManifest.js +0 -84
- package/script/helpers/syncPackageDocs.d.ts +0 -3
- package/script/helpers/syncPackageDocs.d.ts.map +0 -1
- package/script/helpers/syncPackageDocs.js +0 -49
- package/script/main.d.ts +0 -3
- package/script/main.d.ts.map +0 -1
- package/script/main.js +0 -99
- package/script/package.json +0 -3
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { log } from "@clack/prompts";
|
|
2
|
-
import { ensureManagedSection } from "./ensureManagedSection.js";
|
|
3
|
-
import { getInstalledPackageConfigs } from "./packageRegistry.js";
|
|
4
|
-
export function ensureReadme(runtime, installedPackages = []) {
|
|
5
|
-
let runCommand = "npm run";
|
|
6
|
-
if (runtime === "deno") {
|
|
7
|
-
runCommand = "deno task";
|
|
8
|
-
}
|
|
9
|
-
else if (runtime === "bun") {
|
|
10
|
-
runCommand = "bun run";
|
|
11
|
-
}
|
|
12
|
-
const installedPackageConfigs = getInstalledPackageConfigs(installedPackages);
|
|
13
|
-
const hasSdaCore = installedPackageConfigs.some((pkg) => pkg.value === "@nshiab/simple-data-analysis-core");
|
|
14
|
-
const hasFullSda = installedPackageConfigs.some((pkg) => pkg.value === "@nshiab/simple-data-analysis");
|
|
15
|
-
const hasJournalism = installedPackageConfigs.some((pkg) => pkg.type === "journalism");
|
|
16
|
-
const libraryLinks = [
|
|
17
|
-
hasSdaCore
|
|
18
|
-
? "[simple-data-analysis-core](https://github.com/nshiab/simple-data-analysis-core)"
|
|
19
|
-
: "",
|
|
20
|
-
hasFullSda
|
|
21
|
-
? "[simple-data-analysis](https://github.com/nshiab/simple-data-analysis)"
|
|
22
|
-
: "",
|
|
23
|
-
hasJournalism ? "[journalism](https://github.com/nshiab/journalism)" : "",
|
|
24
|
-
].filter(Boolean);
|
|
25
|
-
const librarySection = libraryLinks.length === 0
|
|
26
|
-
? ""
|
|
27
|
-
: `It has installed ${libraryLinks.join(" and ")} ${libraryLinks.length === 1 ? "library" : "libraries"}, along with
|
|
28
|
-
up-to-date documentation and AI agent instructions.`;
|
|
29
|
-
const status = ensureManagedSection({
|
|
30
|
-
path: "README.md",
|
|
31
|
-
name: "libraries",
|
|
32
|
-
content: librarySection,
|
|
33
|
-
createContent: (managedSection) => `This repository was created with
|
|
34
|
-
[setup-data-project](https://github.com/nshiab/setup-data-project/).
|
|
35
|
-
|
|
36
|
-
${managedSection}
|
|
37
|
-
|
|
38
|
-
Here's the recommended workflow:
|
|
39
|
-
|
|
40
|
-
- Put your raw data in the \`sda/data\` folder. Note that this folder is
|
|
41
|
-
ignored by Git.
|
|
42
|
-
- Use the \`sda/main.ts\` file to process your raw data. Write the
|
|
43
|
-
results to the \`sda/output\` folder, which is also ignored by Git.
|
|
44
|
-
- Put your tests in the \`sda/tests\` folder.
|
|
45
|
-
|
|
46
|
-
When working on your project, use the following commands:
|
|
47
|
-
|
|
48
|
-
- \`${runCommand} sda\` will watch your \`sda/main.ts\` and its dependencies.
|
|
49
|
-
Whenever you save changes, the data will be reprocessed.
|
|
50
|
-
- \`${runCommand} all-tests\` will run the project's test command.
|
|
51
|
-
- \`${runCommand} clean\` will remove cache and temporary files, if present.
|
|
52
|
-
|
|
53
|
-
Have fun!`,
|
|
54
|
-
});
|
|
55
|
-
if (status === "created") {
|
|
56
|
-
log.info("Created README.md");
|
|
57
|
-
}
|
|
58
|
-
else if (status === "updated") {
|
|
59
|
-
log.info("Updated README.md");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchPackageDocs.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAiBD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,WAAW,CAAC,CA4DtB"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { log, spinner } from "@clack/prompts";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
const PACKAGE_DOCUMENTS = [
|
|
5
|
-
{
|
|
6
|
-
remoteName: "README.md",
|
|
7
|
-
localName: "README.md",
|
|
8
|
-
key: "readme",
|
|
9
|
-
label: "README",
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
remoteName: "llm.md",
|
|
13
|
-
localName: "llm.md",
|
|
14
|
-
key: "llm",
|
|
15
|
-
label: "API documentation",
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
export async function fetchPackageDocs(pkg, version, options = {}) {
|
|
19
|
-
const repoName = pkg.split("/")[1];
|
|
20
|
-
const docsDirectory = join("docs", repoName);
|
|
21
|
-
mkdirSync(docsDirectory, { recursive: true });
|
|
22
|
-
const sFetch = spinner();
|
|
23
|
-
if (!options.silent) {
|
|
24
|
-
sFetch.start(`Fetching documentation for ${pkg}@${version}...`);
|
|
25
|
-
}
|
|
26
|
-
const fetchedDocuments = await Promise.all(PACKAGE_DOCUMENTS.map(async (document) => {
|
|
27
|
-
const localPath = join(docsDirectory, document.localName);
|
|
28
|
-
try {
|
|
29
|
-
const url = "https://raw.githubusercontent.com/nshiab/" + repoName +
|
|
30
|
-
`/refs/tags/v${version}/${document.remoteName}`;
|
|
31
|
-
const response = await fetch(url);
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
warnAboutFailedFetch(pkg, version, document.label, localPath);
|
|
34
|
-
return { key: document.key, content: undefined };
|
|
35
|
-
}
|
|
36
|
-
const content = await response.text();
|
|
37
|
-
writeFileSync(localPath, content);
|
|
38
|
-
return { key: document.key, content };
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
warnAboutFailedFetch(pkg, version, document.label, localPath);
|
|
42
|
-
console.error(error);
|
|
43
|
-
return { key: document.key, content: undefined };
|
|
44
|
-
}
|
|
45
|
-
}));
|
|
46
|
-
const docs = {};
|
|
47
|
-
for (const document of fetchedDocuments) {
|
|
48
|
-
if (document.content !== undefined) {
|
|
49
|
-
docs[document.key] = document.content;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const savedCount = fetchedDocuments.filter((document) => document.content !== undefined)
|
|
53
|
-
.length;
|
|
54
|
-
if (!options.silent) {
|
|
55
|
-
if (savedCount === PACKAGE_DOCUMENTS.length) {
|
|
56
|
-
sFetch.stop(`✅ Documentation for ${pkg}@${version} saved!`);
|
|
57
|
-
}
|
|
58
|
-
else if (savedCount > 0) {
|
|
59
|
-
sFetch.stop(`⚠️ Some documentation for ${pkg}@${version} could not be fetched.`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
sFetch.stop(`❌ Failed to fetch documentation for ${pkg}@${version}.`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return docs;
|
|
66
|
-
}
|
|
67
|
-
function warnAboutFailedFetch(pkg, version, label, localPath) {
|
|
68
|
-
const existingFileGuidance = existsSync(localPath)
|
|
69
|
-
? ` The existing file at ${localPath} was preserved, but it may not ` +
|
|
70
|
-
"match the installed version. Double-check it before relying on it, or " +
|
|
71
|
-
"remove it."
|
|
72
|
-
: "";
|
|
73
|
-
log.warn(`Could not fetch ${label} for ${pkg}@${version} from its GitHub tag.` +
|
|
74
|
-
existingFileGuidance);
|
|
75
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getInstalledPackageVersions.d.ts","sourceRoot":"","sources":["../../src/helpers/getInstalledPackageVersions.ts"],"names":[],"mappings":"AAKA,wBAAgB,2BAA2B,CACzC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuBxB"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
export function getInstalledPackageVersions(packageSpecifiers) {
|
|
4
|
-
const denoLock = readJsonFile("deno.lock");
|
|
5
|
-
const packageLock = readJsonFile("package-lock.json");
|
|
6
|
-
const bunLock = existsSync("bun.lock")
|
|
7
|
-
? readFileSync("bun.lock", "utf-8")
|
|
8
|
-
: undefined;
|
|
9
|
-
const versions = {};
|
|
10
|
-
for (const [pkg, specifier] of Object.entries(packageSpecifiers)) {
|
|
11
|
-
const version = specifier.startsWith("jsr:")
|
|
12
|
-
? getDenoLockVersion(pkg, specifier, denoLock) ??
|
|
13
|
-
getExactVersion(specifier)
|
|
14
|
-
: getNodeModulesVersion(pkg) ??
|
|
15
|
-
getPackageLockVersion(pkg, packageLock) ??
|
|
16
|
-
getBunLockVersion(pkg, bunLock) ??
|
|
17
|
-
getExactVersion(specifier);
|
|
18
|
-
if (version !== undefined) {
|
|
19
|
-
versions[pkg] = version;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return versions;
|
|
23
|
-
}
|
|
24
|
-
function getNodeModulesVersion(pkg) {
|
|
25
|
-
const packageJson = readJsonFile(join("node_modules", ...pkg.split("/"), "package.json"));
|
|
26
|
-
return typeof packageJson?.version === "string"
|
|
27
|
-
? getExactVersion(packageJson.version)
|
|
28
|
-
: undefined;
|
|
29
|
-
}
|
|
30
|
-
function getDenoLockVersion(pkg, specifier, lock) {
|
|
31
|
-
if (!lock || !specifier.startsWith("jsr:"))
|
|
32
|
-
return undefined;
|
|
33
|
-
const specifiers = asObject(lock.specifiers);
|
|
34
|
-
if (!specifiers)
|
|
35
|
-
return undefined;
|
|
36
|
-
const directVersion = specifiers[specifier];
|
|
37
|
-
if (typeof directVersion === "string")
|
|
38
|
-
return getExactVersion(directVersion);
|
|
39
|
-
const prefix = `jsr:${pkg}@`;
|
|
40
|
-
const matchingVersions = Object.entries(specifiers)
|
|
41
|
-
.filter(([key, value]) => key.startsWith(prefix) && typeof value === "string")
|
|
42
|
-
.flatMap(([, value]) => {
|
|
43
|
-
const version = getExactVersion(value);
|
|
44
|
-
return version === undefined ? [] : [version];
|
|
45
|
-
});
|
|
46
|
-
const uniqueVersions = [...new Set(matchingVersions)];
|
|
47
|
-
return uniqueVersions.length === 1 ? uniqueVersions[0] : undefined;
|
|
48
|
-
}
|
|
49
|
-
function getPackageLockVersion(pkg, lock) {
|
|
50
|
-
if (!lock)
|
|
51
|
-
return undefined;
|
|
52
|
-
const packages = asObject(lock.packages);
|
|
53
|
-
const packageEntry = packages
|
|
54
|
-
? asObject(packages[`node_modules/${pkg}`])
|
|
55
|
-
: undefined;
|
|
56
|
-
if (typeof packageEntry?.version === "string") {
|
|
57
|
-
return getExactVersion(packageEntry.version);
|
|
58
|
-
}
|
|
59
|
-
const dependencies = asObject(lock.dependencies);
|
|
60
|
-
const dependencyEntry = dependencies
|
|
61
|
-
? asObject(dependencies[pkg])
|
|
62
|
-
: undefined;
|
|
63
|
-
return typeof dependencyEntry?.version === "string"
|
|
64
|
-
? getExactVersion(dependencyEntry.version)
|
|
65
|
-
: undefined;
|
|
66
|
-
}
|
|
67
|
-
function getBunLockVersion(pkg, lock) {
|
|
68
|
-
if (!lock)
|
|
69
|
-
return undefined;
|
|
70
|
-
const escapedPackage = pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
71
|
-
const match = lock.match(new RegExp(`"${escapedPackage}"\\s*:\\s*\\[\\s*"${escapedPackage}@(\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?)"`));
|
|
72
|
-
return match?.[1];
|
|
73
|
-
}
|
|
74
|
-
function getExactVersion(specifier) {
|
|
75
|
-
return specifier.match(/(?:^|@)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/)?.[1];
|
|
76
|
-
}
|
|
77
|
-
function readJsonFile(path) {
|
|
78
|
-
if (!existsSync(path))
|
|
79
|
-
return undefined;
|
|
80
|
-
try {
|
|
81
|
-
return asObject(JSON.parse(readFileSync(path, "utf-8")));
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function asObject(value) {
|
|
88
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
89
|
-
? value
|
|
90
|
-
: undefined;
|
|
91
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getProjectTasks.d.ts","sourceRoot":"","sources":["../../src/helpers/getProjectTasks.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe;;;;EAgB9B"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getRuntime } from "./getRuntime.js";
|
|
2
|
-
export function getProjectTasks() {
|
|
3
|
-
const runtime = getRuntime();
|
|
4
|
-
return {
|
|
5
|
-
sda: runtime === "deno"
|
|
6
|
-
? "deno run -A --env --watch --check sda/main.ts"
|
|
7
|
-
: runtime === "bun"
|
|
8
|
-
? "bun run --watch sda/main.ts"
|
|
9
|
-
: "node --env-file-if-exists=.env --watch --experimental-strip-types sda/main.ts",
|
|
10
|
-
"all-tests": runtime === "deno"
|
|
11
|
-
? "deno fmt --check sda && deno lint && deno check sda/main.ts && deno test -A --permit-no-files"
|
|
12
|
-
: runtime === "bun"
|
|
13
|
-
? "bun test --pass-with-no-tests"
|
|
14
|
-
: "node --env-file-if-exists=.env --experimental-strip-types --test",
|
|
15
|
-
clean: "rm -rf .sda-cache .journalism-cache .tmp",
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRuntime.d.ts","sourceRoot":"","sources":["../../src/helpers/getRuntime.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;CAazB,CAAC;AAEF,wBAAgB,UAAU,4BAEzB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
export const runtimeConfig = {
|
|
4
|
-
getRuntime: () => {
|
|
5
|
-
if (typeof process !== "undefined" &&
|
|
6
|
-
process?.versions?.node &&
|
|
7
|
-
!process?.versions?.deno) {
|
|
8
|
-
return "node";
|
|
9
|
-
}
|
|
10
|
-
if ("Bun" in dntShim.dntGlobalThis)
|
|
11
|
-
return "bun";
|
|
12
|
-
if ("Deno" in dntShim.dntGlobalThis)
|
|
13
|
-
return "deno";
|
|
14
|
-
return "node";
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
export function getRuntime() {
|
|
18
|
-
return runtimeConfig.getRuntime();
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gitignoreEntries.d.ts","sourceRoot":"","sources":["../../src/helpers/gitignoreEntries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAS7B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"installPackages.d.ts","sourceRoot":"","sources":["../../src/helpers/installPackages.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa;;CAEzB,CAAC;AASF,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAAC,IAAI,CAAC,CAmDf"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { spinner } from "@clack/prompts";
|
|
2
|
-
import * as childProcess from "node:child_process";
|
|
3
|
-
import { getRuntime } from "./getRuntime.js";
|
|
4
|
-
export const commandRunner = {
|
|
5
|
-
exec: childProcess.exec,
|
|
6
|
-
};
|
|
7
|
-
// Temporary: remove this bypass after the 2.0 release window.
|
|
8
|
-
// https://github.com/nshiab/setup-data-project/issues/15
|
|
9
|
-
const PACKAGES_WITH_FRESH_DENO_RELEASES = new Set([
|
|
10
|
-
"@nshiab/simple-data-analysis-core",
|
|
11
|
-
"@nshiab/simple-data-analysis",
|
|
12
|
-
]);
|
|
13
|
-
export async function installPackages(selectedPackages, options = {}) {
|
|
14
|
-
const runtime = getRuntime();
|
|
15
|
-
for (const selectedPackage of selectedPackages) {
|
|
16
|
-
const packagesToInstall = [selectedPackage];
|
|
17
|
-
if (selectedPackage === "@nshiab/simple-data-analysis" ||
|
|
18
|
-
selectedPackage === "@nshiab/journalism-dataviz") {
|
|
19
|
-
packagesToInstall.push("@observablehq/plot");
|
|
20
|
-
}
|
|
21
|
-
for (const pkg of packagesToInstall) {
|
|
22
|
-
const s = spinner();
|
|
23
|
-
const isObservablePlot = pkg === "@observablehq/plot";
|
|
24
|
-
const minimumDependencyAgeOption = PACKAGES_WITH_FRESH_DENO_RELEASES.has(pkg) ? " --min-dep-age=0" : "";
|
|
25
|
-
const installCmd = runtime === "deno"
|
|
26
|
-
? (isObservablePlot
|
|
27
|
-
? "deno add npm:" + pkg
|
|
28
|
-
: "deno add" + minimumDependencyAgeOption + " jsr:" +
|
|
29
|
-
pkg)
|
|
30
|
-
: runtime === "bun"
|
|
31
|
-
? "bun add " + pkg
|
|
32
|
-
: "npm install " + pkg;
|
|
33
|
-
if (!options.silent) {
|
|
34
|
-
s.start("Installing " + pkg + " via " + runtime + "...");
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
await new Promise((resolve, reject) => {
|
|
38
|
-
commandRunner.exec(installCmd, (error) => {
|
|
39
|
-
if (error) {
|
|
40
|
-
reject(error);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
resolve();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
if (!options.silent) {
|
|
48
|
-
s.stop("✅ " + pkg + " installed!");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
if (!options.silent) {
|
|
53
|
-
s.stop("❌ Failed to install " + pkg + ".");
|
|
54
|
-
}
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"packageOptions.d.ts","sourceRoot":"","sources":["../../src/helpers/packageOptions.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe;;;;GAIzB,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export interface PackageConfig {
|
|
2
|
-
value: string;
|
|
3
|
-
label: string;
|
|
4
|
-
type: "sda" | "journalism" | "other";
|
|
5
|
-
hint?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const SUPPORTED_PACKAGES: PackageConfig[];
|
|
8
|
-
export declare function getInstalledPackageConfigs(installedPackages: string[]): PackageConfig[];
|
|
9
|
-
//# sourceMappingURL=packageRegistry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,84 +0,0 @@
|
|
|
1
|
-
export const SUPPORTED_PACKAGES = [
|
|
2
|
-
{
|
|
3
|
-
value: "@nshiab/simple-data-analysis",
|
|
4
|
-
label: "simple-data-analysis",
|
|
5
|
-
type: "sda",
|
|
6
|
-
hint: "All the core functionality, plus methods for dataviz, AI, Google sheets, etc.",
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
value: "@nshiab/simple-data-analysis-core",
|
|
10
|
-
label: "simple-data-analysis-core",
|
|
11
|
-
type: "sda",
|
|
12
|
-
hint: "No fluff. Great for constrained environments, like a cheap server.",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
value: "@nshiab/journalism-ai",
|
|
16
|
-
label: "journalism-ai",
|
|
17
|
-
type: "journalism",
|
|
18
|
-
hint: "Easily use AI local models with Ollama or remote models with Gemini/Vertex.",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
value: "@nshiab/journalism-google",
|
|
22
|
-
label: "journalism-google",
|
|
23
|
-
type: "journalism",
|
|
24
|
-
hint: "Push and retrieve data from Google Sheets, Google Bucket, and more.",
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
value: "@nshiab/journalism-web-scraping",
|
|
28
|
-
label: "journalism-web-scraping",
|
|
29
|
-
type: "journalism",
|
|
30
|
-
hint: "Retrieve data from Statistics Canada tables, HTML table, download files...",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
value: "@nshiab/journalism-finance",
|
|
34
|
-
label: "journalism-finance",
|
|
35
|
-
type: "journalism",
|
|
36
|
-
hint: "Retrieve financial data, calculate Canadian mortgage payments and taxes...",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
value: "@nshiab/journalism-format",
|
|
40
|
-
label: "journalism-format",
|
|
41
|
-
type: "journalism",
|
|
42
|
-
hint: "Easily format dates, numbers, currencies...",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
value: "@nshiab/journalism-climate",
|
|
46
|
-
label: "journalism-climate",
|
|
47
|
-
type: "journalism",
|
|
48
|
-
hint: "Retrieve data from Environment Canada APIs and more.",
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
value: "@nshiab/journalism-dataviz",
|
|
52
|
-
label: "journalism-dataviz",
|
|
53
|
-
type: "journalism",
|
|
54
|
-
hint: "Render charts/maps with Observable Plot or directly in the terminal.",
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
value: "@nshiab/journalism-geo",
|
|
58
|
-
label: "journalism-geo",
|
|
59
|
-
type: "journalism",
|
|
60
|
-
hint: "Calculate distances, transform 2D coordinates to 3D, wrangle GeoTIFF files...",
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
value: "@nshiab/journalism-statistics",
|
|
64
|
-
label: "journalism-statistics",
|
|
65
|
-
type: "journalism",
|
|
66
|
-
hint: "Functions for statistical tests, clustering, random path generation...",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
value: "@nshiab/journalism-web",
|
|
70
|
-
label: "journalism-web",
|
|
71
|
-
type: "journalism",
|
|
72
|
-
hint: "Web related functions, including downloading data as CSV, extracting ZIP files to URLs...",
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
value: "@nshiab/journalism-extras",
|
|
76
|
-
label: "journalism-extras",
|
|
77
|
-
type: "journalism",
|
|
78
|
-
hint: "Functions to zip/unzip, sleep, reencode files, create nested directories...",
|
|
79
|
-
},
|
|
80
|
-
];
|
|
81
|
-
export function getInstalledPackageConfigs(installedPackages) {
|
|
82
|
-
const installedSet = new Set(installedPackages);
|
|
83
|
-
return SUPPORTED_PACKAGES.filter((pkg) => installedSet.has(pkg.value));
|
|
84
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
getInstalledPackageSpecifiers(): Record<string, string>;
|
|
9
|
-
updateTasks(tasks: Record<string, string>): void;
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=projectManifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;IAIhC,6BAA6B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAoBvD,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAcjD"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
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");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
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");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _ProjectManifest_path, _ProjectManifest_taskKey, _ProjectManifest_dependencyKeys, _ProjectManifest_config;
|
|
13
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
-
export class ProjectManifest {
|
|
15
|
-
constructor(path, taskKey, dependencyKeys, config) {
|
|
16
|
-
_ProjectManifest_path.set(this, void 0);
|
|
17
|
-
_ProjectManifest_taskKey.set(this, void 0);
|
|
18
|
-
_ProjectManifest_dependencyKeys.set(this, void 0);
|
|
19
|
-
_ProjectManifest_config.set(this, void 0);
|
|
20
|
-
__classPrivateFieldSet(this, _ProjectManifest_path, path, "f");
|
|
21
|
-
__classPrivateFieldSet(this, _ProjectManifest_taskKey, taskKey, "f");
|
|
22
|
-
__classPrivateFieldSet(this, _ProjectManifest_dependencyKeys, dependencyKeys, "f");
|
|
23
|
-
__classPrivateFieldSet(this, _ProjectManifest_config, config, "f");
|
|
24
|
-
}
|
|
25
|
-
static open(runtime) {
|
|
26
|
-
if (existsSync("deno.json")) {
|
|
27
|
-
return new ProjectManifest("deno.json", "tasks", ["imports"], readManifest("deno.json"));
|
|
28
|
-
}
|
|
29
|
-
if (existsSync("package.json")) {
|
|
30
|
-
return new ProjectManifest("package.json", "scripts", ["dependencies", "devDependencies"], readManifest("package.json"));
|
|
31
|
-
}
|
|
32
|
-
return runtime === "deno"
|
|
33
|
-
? new ProjectManifest("deno.json", "tasks", ["imports"], { tasks: {} })
|
|
34
|
-
: new ProjectManifest("package.json", "scripts", ["dependencies", "devDependencies"], { name: "data-project", type: "module", scripts: {} });
|
|
35
|
-
}
|
|
36
|
-
reload() {
|
|
37
|
-
__classPrivateFieldSet(this, _ProjectManifest_config, readManifest(__classPrivateFieldGet(this, _ProjectManifest_path, "f")), "f");
|
|
38
|
-
}
|
|
39
|
-
getInstalledPackages() {
|
|
40
|
-
return Object.keys(this.getInstalledPackageSpecifiers());
|
|
41
|
-
}
|
|
42
|
-
getInstalledPackageSpecifiers() {
|
|
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
|
-
for (const [name, specifier] of Object.entries(dependencies)) {
|
|
49
|
-
if (typeof specifier === "string") {
|
|
50
|
-
installed[name] = specifier;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return installed;
|
|
56
|
-
}
|
|
57
|
-
updateTasks(tasks) {
|
|
58
|
-
const currentTasks = __classPrivateFieldGet(this, _ProjectManifest_config, "f")[__classPrivateFieldGet(this, _ProjectManifest_taskKey, "f")];
|
|
59
|
-
const existingTasks = currentTasks && typeof currentTasks === "object" &&
|
|
60
|
-
!Array.isArray(currentTasks)
|
|
61
|
-
? currentTasks
|
|
62
|
-
: {};
|
|
63
|
-
__classPrivateFieldGet(this, _ProjectManifest_config, "f")[__classPrivateFieldGet(this, _ProjectManifest_taskKey, "f")] = { ...existingTasks, ...tasks };
|
|
64
|
-
writeFileSync(__classPrivateFieldGet(this, _ProjectManifest_path, "f"), JSON.stringify(__classPrivateFieldGet(this, _ProjectManifest_config, "f"), null, 2) + "\n", "utf-8");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
_ProjectManifest_path = new WeakMap(), _ProjectManifest_taskKey = new WeakMap(), _ProjectManifest_dependencyKeys = new WeakMap(), _ProjectManifest_config = new WeakMap();
|
|
68
|
-
function readManifest(path) {
|
|
69
|
-
try {
|
|
70
|
-
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
71
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
72
|
-
throw new SyntaxError("the root value must be a JSON object");
|
|
73
|
-
}
|
|
74
|
-
return parsed;
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
const detail = error instanceof Error ? ` ${error.message}` : "";
|
|
78
|
-
throw new Error(`Failed to parse ${path}.${detail}`, { cause: error });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncPackageDocs.d.ts","sourceRoot":"","sources":["../../src/helpers/syncPackageDocs.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG3E,wBAAsB,eAAe,CACnC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CA+CtC"}
|