@nshiab/setup-data-project 1.0.30 → 1.0.31

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.
@@ -1,2 +1,2 @@
1
- export declare function createFolderStructure(selectedPackages: string[]): Promise<string>;
1
+ export declare function createFolderStructure(selectedPackages: string[]): string;
2
2
  //# sourceMappingURL=createFolderStructure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAKA,wBAAsB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBA8CrE"}
1
+ {"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UA6C/D"}
@@ -1,8 +1,6 @@
1
- import { existsSync, mkdirSync } from "node:fs";
1
+ import { existsSync, lstatSync, mkdirSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { log } from "@clack/prompts";
4
- import { handleFileConflict } from "./handleFileConflict.js";
5
- export async function createFolderStructure(selectedPackages) {
3
+ export function createFolderStructure(selectedPackages) {
6
4
  const sdaFolder = "sda";
7
5
  const folders = ["data", "helpers", "output"];
8
6
  if (!existsSync(sdaFolder)) {
@@ -34,9 +32,8 @@ await table.logTable();
34
32
  await sdb.done();
35
33
  `;
36
34
  }
37
- const status = await handleFileConflict(mainTsPath, mainTsContent);
38
- if (status === "updated") {
39
- log.info(`Updated ${mainTsPath}`);
35
+ if (lstatSync(mainTsPath, { throwIfNoEntry: false }) === undefined) {
36
+ writeFileSync(mainTsPath, mainTsContent);
40
37
  }
41
38
  return sdaFolder;
42
39
  }
@@ -1,2 +1,2 @@
1
- export declare function ensureEnvFile(): Promise<void>;
1
+ export declare function ensureEnvFile(): void;
2
2
  //# sourceMappingURL=ensureEnvFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensureEnvFile.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureEnvFile.ts"],"names":[],"mappings":"AAGA,wBAAsB,aAAa,kBAKlC"}
1
+ {"version":3,"file":"ensureEnvFile.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureEnvFile.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,SAI5B"}
@@ -1,8 +1,6 @@
1
- import { log } from "@clack/prompts";
2
- import { handleFileConflict } from "./handleFileConflict.js";
3
- export async function ensureEnvFile() {
4
- const status = await handleFileConflict(".env", "");
5
- if (status === "updated") {
6
- log.info("Updated .env");
1
+ import { lstatSync, writeFileSync } from "node:fs";
2
+ export function ensureEnvFile() {
3
+ if (lstatSync(".env", { throwIfNoEntry: false }) === undefined) {
4
+ writeFileSync(".env", "");
7
5
  }
8
6
  }
@@ -1,2 +1,3 @@
1
+ export declare const GITIGNORE_SENTINEL = "# Added by setup-data-project. Do not remove this line.";
1
2
  export declare function ensureGitignore(): void;
2
3
  //# sourceMappingURL=ensureGitignore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensureGitignore.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureGitignore.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,SAqB9B"}
1
+ {"version":3,"file":"ensureGitignore.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureGitignore.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,4DAC4B,CAAC;AAE5D,wBAAgB,eAAe,SA4B9B"}
@@ -1,23 +1,26 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { lstatSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { log } from "@clack/prompts";
3
3
  import { GITIGNORE_ENTRIES } from "./gitignoreEntries.js";
4
+ export const GITIGNORE_SENTINEL = "# Added by setup-data-project. Do not remove this line.";
4
5
  export function ensureGitignore() {
5
6
  const path = ".gitignore";
6
- let content = "";
7
- let exists = false;
8
- if (existsSync(path)) {
9
- content = readFileSync(path, "utf-8");
10
- exists = true;
7
+ const stats = lstatSync(path, { throwIfNoEntry: false });
8
+ if (stats?.isSymbolicLink()) {
9
+ return;
11
10
  }
12
- const lines = content.split("\n").map((l) => l.trim());
13
- const toAdd = GITIGNORE_ENTRIES.filter((e) => !lines.includes(e));
14
- if (toAdd.length > 0) {
15
- const prefix = content.endsWith("\n") || content === "" ? "" : "\n";
16
- const header = "\n# Added by setup-data-project\n";
17
- const newContent = prefix + header + toAdd.join("\n") + "\n";
18
- writeFileSync(path, content + newContent);
19
- if (exists) {
20
- log.info(`Updated ${path}`);
21
- }
11
+ const content = stats === undefined ? "" : readFileSync(path, "utf-8");
12
+ const hasSentinel = content.split("\n").some((line) => line.trim() === GITIGNORE_SENTINEL);
13
+ if (hasSentinel) {
14
+ return;
15
+ }
16
+ const separator = content === ""
17
+ ? ""
18
+ : content.endsWith("\n")
19
+ ? "\n"
20
+ : "\n\n";
21
+ const block = `${GITIGNORE_SENTINEL}\n${GITIGNORE_ENTRIES.join("\n")}\n`;
22
+ writeFileSync(path, content + separator + block);
23
+ if (stats !== undefined) {
24
+ log.info(`Updated ${path}`);
22
25
  }
23
26
  }
package/esm/main.js CHANGED
@@ -75,9 +75,9 @@ async function main() {
75
75
  projectManifest.updateTasks(getProjectTasks());
76
76
  const finalInstalledPackages = getInstalledPackageConfigs(projectManifest.getInstalledPackages()).map((pkg) => pkg.value);
77
77
  const docsMapping = await syncPackageDocs(finalInstalledPackages, packagesToInstall);
78
- await createFolderStructure(finalInstalledPackages);
78
+ createFolderStructure(finalInstalledPackages);
79
79
  ensureGitignore();
80
- await ensureEnvFile();
80
+ ensureEnvFile();
81
81
  await ensureReadme(runtime, finalInstalledPackages);
82
82
  await ensureAgents(docsMapping, runtime, finalInstalledPackages);
83
83
  outro("You are all set! 🙌");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nshiab/setup-data-project",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "Quickly kick off your data project using the simple-data-analysis and journalism libraries.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,2 +1,2 @@
1
- export declare function createFolderStructure(selectedPackages: string[]): Promise<string>;
1
+ export declare function createFolderStructure(selectedPackages: string[]): string;
2
2
  //# sourceMappingURL=createFolderStructure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAKA,wBAAsB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBA8CrE"}
1
+ {"version":3,"file":"createFolderStructure.d.ts","sourceRoot":"","sources":["../../src/helpers/createFolderStructure.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UA6C/D"}
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFolderStructure = createFolderStructure;
4
4
  const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
- const prompts_1 = require("@clack/prompts");
7
- const handleFileConflict_js_1 = require("./handleFileConflict.js");
8
- async function createFolderStructure(selectedPackages) {
6
+ function createFolderStructure(selectedPackages) {
9
7
  const sdaFolder = "sda";
10
8
  const folders = ["data", "helpers", "output"];
11
9
  if (!(0, node_fs_1.existsSync)(sdaFolder)) {
@@ -37,9 +35,8 @@ await table.logTable();
37
35
  await sdb.done();
38
36
  `;
39
37
  }
40
- const status = await (0, handleFileConflict_js_1.handleFileConflict)(mainTsPath, mainTsContent);
41
- if (status === "updated") {
42
- prompts_1.log.info(`Updated ${mainTsPath}`);
38
+ if ((0, node_fs_1.lstatSync)(mainTsPath, { throwIfNoEntry: false }) === undefined) {
39
+ (0, node_fs_1.writeFileSync)(mainTsPath, mainTsContent);
43
40
  }
44
41
  return sdaFolder;
45
42
  }
@@ -1,2 +1,2 @@
1
- export declare function ensureEnvFile(): Promise<void>;
1
+ export declare function ensureEnvFile(): void;
2
2
  //# sourceMappingURL=ensureEnvFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensureEnvFile.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureEnvFile.ts"],"names":[],"mappings":"AAGA,wBAAsB,aAAa,kBAKlC"}
1
+ {"version":3,"file":"ensureEnvFile.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureEnvFile.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,SAI5B"}
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureEnvFile = ensureEnvFile;
4
- const prompts_1 = require("@clack/prompts");
5
- const handleFileConflict_js_1 = require("./handleFileConflict.js");
6
- async function ensureEnvFile() {
7
- const status = await (0, handleFileConflict_js_1.handleFileConflict)(".env", "");
8
- if (status === "updated") {
9
- prompts_1.log.info("Updated .env");
4
+ const node_fs_1 = require("node:fs");
5
+ function ensureEnvFile() {
6
+ if ((0, node_fs_1.lstatSync)(".env", { throwIfNoEntry: false }) === undefined) {
7
+ (0, node_fs_1.writeFileSync)(".env", "");
10
8
  }
11
9
  }
@@ -1,2 +1,3 @@
1
+ export declare const GITIGNORE_SENTINEL = "# Added by setup-data-project. Do not remove this line.";
1
2
  export declare function ensureGitignore(): void;
2
3
  //# sourceMappingURL=ensureGitignore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensureGitignore.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureGitignore.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,SAqB9B"}
1
+ {"version":3,"file":"ensureGitignore.d.ts","sourceRoot":"","sources":["../../src/helpers/ensureGitignore.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,4DAC4B,CAAC;AAE5D,wBAAgB,eAAe,SA4B9B"}
@@ -1,26 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GITIGNORE_SENTINEL = void 0;
3
4
  exports.ensureGitignore = ensureGitignore;
4
5
  const node_fs_1 = require("node:fs");
5
6
  const prompts_1 = require("@clack/prompts");
6
7
  const gitignoreEntries_js_1 = require("./gitignoreEntries.js");
8
+ exports.GITIGNORE_SENTINEL = "# Added by setup-data-project. Do not remove this line.";
7
9
  function ensureGitignore() {
8
10
  const path = ".gitignore";
9
- let content = "";
10
- let exists = false;
11
- if ((0, node_fs_1.existsSync)(path)) {
12
- content = (0, node_fs_1.readFileSync)(path, "utf-8");
13
- exists = true;
11
+ const stats = (0, node_fs_1.lstatSync)(path, { throwIfNoEntry: false });
12
+ if (stats?.isSymbolicLink()) {
13
+ return;
14
14
  }
15
- const lines = content.split("\n").map((l) => l.trim());
16
- const toAdd = gitignoreEntries_js_1.GITIGNORE_ENTRIES.filter((e) => !lines.includes(e));
17
- if (toAdd.length > 0) {
18
- const prefix = content.endsWith("\n") || content === "" ? "" : "\n";
19
- const header = "\n# Added by setup-data-project\n";
20
- const newContent = prefix + header + toAdd.join("\n") + "\n";
21
- (0, node_fs_1.writeFileSync)(path, content + newContent);
22
- if (exists) {
23
- prompts_1.log.info(`Updated ${path}`);
24
- }
15
+ const content = stats === undefined ? "" : (0, node_fs_1.readFileSync)(path, "utf-8");
16
+ const hasSentinel = content.split("\n").some((line) => line.trim() === exports.GITIGNORE_SENTINEL);
17
+ if (hasSentinel) {
18
+ return;
19
+ }
20
+ const separator = content === ""
21
+ ? ""
22
+ : content.endsWith("\n")
23
+ ? "\n"
24
+ : "\n\n";
25
+ const block = `${exports.GITIGNORE_SENTINEL}\n${gitignoreEntries_js_1.GITIGNORE_ENTRIES.join("\n")}\n`;
26
+ (0, node_fs_1.writeFileSync)(path, content + separator + block);
27
+ if (stats !== undefined) {
28
+ prompts_1.log.info(`Updated ${path}`);
25
29
  }
26
30
  }
package/script/main.js CHANGED
@@ -80,9 +80,9 @@ async function main() {
80
80
  projectManifest.updateTasks((0, getProjectTasks_js_1.getProjectTasks)());
81
81
  const finalInstalledPackages = (0, packageRegistry_js_1.getInstalledPackageConfigs)(projectManifest.getInstalledPackages()).map((pkg) => pkg.value);
82
82
  const docsMapping = await (0, syncPackageDocs_js_1.syncPackageDocs)(finalInstalledPackages, packagesToInstall);
83
- await (0, createFolderStructure_js_1.createFolderStructure)(finalInstalledPackages);
83
+ (0, createFolderStructure_js_1.createFolderStructure)(finalInstalledPackages);
84
84
  (0, ensureGitignore_js_1.ensureGitignore)();
85
- await (0, ensureEnvFile_js_1.ensureEnvFile)();
85
+ (0, ensureEnvFile_js_1.ensureEnvFile)();
86
86
  await (0, ensureReadme_js_1.ensureReadme)(runtime, finalInstalledPackages);
87
87
  await (0, ensureAgents_js_1.ensureAgents)(docsMapping, runtime, finalInstalledPackages);
88
88
  (0, prompts_1.outro)("You are all set! 🙌");
@@ -1,5 +0,0 @@
1
- export declare const PROMPT_OVERRIDE: {
2
- select: (config: unknown) => Promise<string | symbol>;
3
- };
4
- export declare function handleFileConflict(path: string, newContent: string): Promise<"created" | "updated" | "skipped">;
5
- //# sourceMappingURL=handleFileConflict.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handleFileConflict.d.ts","sourceRoot":"","sources":["../../src/helpers/handleFileConflict.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,EAAE;IAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CAGvD,CAAC;AAEF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,CAoD5C"}
@@ -1,50 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
- import { isCancel, select } from "@clack/prompts";
3
- import process from "node:process";
4
- export const PROMPT_OVERRIDE = {
5
- select: select,
6
- };
7
- export async function handleFileConflict(path, newContent) {
8
- if (!existsSync(path)) {
9
- writeFileSync(path, newContent);
10
- return "created";
11
- }
12
- // Skip prompt in Deno tests if no override
13
- // @ts-ignore: Deno is not defined in type but present in runtime
14
- if (globalThis.Deno?.args.includes("--internal-test-mode") &&
15
- PROMPT_OVERRIDE.select === select) {
16
- return "skipped";
17
- }
18
- const action = (await PROMPT_OVERRIDE.select({
19
- message: `${path} already exists. What would you like to do?`,
20
- options: [
21
- { value: "skip", label: "Skip", hint: "Keep existing file" },
22
- {
23
- value: "overwrite",
24
- label: "Overwrite",
25
- hint: "Replace with new content",
26
- },
27
- { value: "append", label: "Append", hint: "Add to the end of the file" },
28
- ],
29
- }));
30
- if (isCancel(action)) {
31
- console.log("Operation cancelled.");
32
- process.exit(0);
33
- }
34
- if (action === "skip") {
35
- return "skipped";
36
- }
37
- if (action === "overwrite") {
38
- writeFileSync(path, newContent);
39
- return "updated";
40
- }
41
- if (action === "append") {
42
- const existingContent = readFileSync(path, "utf-8");
43
- const prefix = existingContent.endsWith("\n") || existingContent === ""
44
- ? ""
45
- : "\n";
46
- writeFileSync(path, existingContent + prefix + newContent);
47
- return "updated";
48
- }
49
- return "skipped";
50
- }
@@ -1,5 +0,0 @@
1
- export declare const PROMPT_OVERRIDE: {
2
- select: (config: unknown) => Promise<string | symbol>;
3
- };
4
- export declare function handleFileConflict(path: string, newContent: string): Promise<"created" | "updated" | "skipped">;
5
- //# sourceMappingURL=handleFileConflict.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handleFileConflict.d.ts","sourceRoot":"","sources":["../../src/helpers/handleFileConflict.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,EAAE;IAC5B,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CAGvD,CAAC;AAEF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,CAoD5C"}
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PROMPT_OVERRIDE = void 0;
7
- exports.handleFileConflict = handleFileConflict;
8
- const node_fs_1 = require("node:fs");
9
- const prompts_1 = require("@clack/prompts");
10
- const node_process_1 = __importDefault(require("node:process"));
11
- exports.PROMPT_OVERRIDE = {
12
- select: prompts_1.select,
13
- };
14
- async function handleFileConflict(path, newContent) {
15
- if (!(0, node_fs_1.existsSync)(path)) {
16
- (0, node_fs_1.writeFileSync)(path, newContent);
17
- return "created";
18
- }
19
- // Skip prompt in Deno tests if no override
20
- // @ts-ignore: Deno is not defined in type but present in runtime
21
- if (globalThis.Deno?.args.includes("--internal-test-mode") &&
22
- exports.PROMPT_OVERRIDE.select === prompts_1.select) {
23
- return "skipped";
24
- }
25
- const action = (await exports.PROMPT_OVERRIDE.select({
26
- message: `${path} already exists. What would you like to do?`,
27
- options: [
28
- { value: "skip", label: "Skip", hint: "Keep existing file" },
29
- {
30
- value: "overwrite",
31
- label: "Overwrite",
32
- hint: "Replace with new content",
33
- },
34
- { value: "append", label: "Append", hint: "Add to the end of the file" },
35
- ],
36
- }));
37
- if ((0, prompts_1.isCancel)(action)) {
38
- console.log("Operation cancelled.");
39
- node_process_1.default.exit(0);
40
- }
41
- if (action === "skip") {
42
- return "skipped";
43
- }
44
- if (action === "overwrite") {
45
- (0, node_fs_1.writeFileSync)(path, newContent);
46
- return "updated";
47
- }
48
- if (action === "append") {
49
- const existingContent = (0, node_fs_1.readFileSync)(path, "utf-8");
50
- const prefix = existingContent.endsWith("\n") || existingContent === ""
51
- ? ""
52
- : "\n";
53
- (0, node_fs_1.writeFileSync)(path, existingContent + prefix + newContent);
54
- return "updated";
55
- }
56
- return "skipped";
57
- }