@dephub/write 1.0.2 → 1.0.4

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/dist/cli.js CHANGED
@@ -1,23 +1,45 @@
1
1
  #!/usr/bin/env node
2
- import { Command as s, CommandError as a } from "@dephub/command";
3
- import { logger as o } from "@dephub/logger";
4
- import { writeFile as d } from "./core/write.js";
5
- import { name as m, version as c, description as p } from "./utils/pkg.js";
6
- const i = new s().name(m.split("/")[1] ?? "write").version(c).description(p).argument("filePath", "Path where the file will be written").argument("content", "Content to write (if not provided, reads from stdin)").handler(async ({ args: { content: r, filePath: t } }) => {
7
- try {
8
- let e = r;
9
- r || (e = await f(), e || (o.error("No content provided and stdin is empty"), process.exit(1))), await d(t, e), o.success(`Written to ${t}`);
10
- } catch (e) {
11
- o.error(`Failed to write to ${t}: ${e.message}`), process.exit(1);
12
- }
13
- }), f = () => new Promise((r, t) => {
14
- let e = "";
15
- process.stdin.setEncoding("utf8"), process.stdin.on("data", (n) => e += n), process.stdin.on("end", () => r(e.trim())), process.stdin.on("error", t), process.stdin.isTTY && setTimeout(() => r(""), 100);
2
+ import { writeFile } from "./core/write.js";
3
+ import { description, name, version } from "./utils/pkg.js";
4
+ import { Command, CommandError } from "@dephub/command";
5
+ import { logger } from "@dephub/logger";
6
+ // src/cli.ts
7
+ var cmd = new Command().name(name.split("/")[1] ?? "write").version(version).description(description).argument("filePath", "Path where the file will be written").argument("content", "Content to write (if not provided, reads from stdin)").handler(async ({ args: { content, filePath } }) => {
8
+ try {
9
+ let finalContent = content;
10
+ if (!content) {
11
+ finalContent = await readStdin();
12
+ if (!finalContent) {
13
+ logger.error("No content provided and stdin is empty");
14
+ process.exit(1);
15
+ }
16
+ }
17
+ await writeFile(filePath, finalContent);
18
+ logger.success(`Written to ${filePath}`);
19
+ } catch (err) {
20
+ logger.error(`Failed to write to ${filePath}: ${err.message}`);
21
+ process.exit(1);
22
+ }
23
+ });
24
+ /**
25
+ * Reads content from stdin
26
+ */
27
+ var readStdin = () => new Promise((resolve, reject) => {
28
+ let data = "";
29
+ process.stdin.setEncoding("utf8");
30
+ process.stdin.on("data", (chunk) => data += chunk);
31
+ process.stdin.on("end", () => resolve(data.trim()));
32
+ process.stdin.on("error", reject);
33
+ if (process.stdin.isTTY) setTimeout(() => resolve(""), 100);
16
34
  });
17
35
  try {
18
- await i.run();
19
- } catch (r) {
20
- throw r instanceof a && (o.error(`
21
- Error: ${r.message}
22
- `), i.help(), process.exit(1)), r;
36
+ await cmd.run();
37
+ } catch (err) {
38
+ if (err instanceof CommandError) {
39
+ logger.error(`\nError: ${err.message}\n`);
40
+ cmd.help();
41
+ process.exit(1);
42
+ }
43
+ throw err;
23
44
  }
45
+ export {};
@@ -1,10 +1,20 @@
1
- import { existsSync as e } from "node:fs";
2
- import { mkdir as o, writeFile as m } from "node:fs/promises";
3
- import a from "node:path";
4
- const p = async (i, t) => {
5
- const r = a.dirname(i);
6
- e(r) || await o(r, { recursive: !0 }), await m(i, t);
7
- };
8
- export {
9
- p as writeFile
1
+ import { canAccess } from "../utils/access.js";
2
+ import { mkdir, writeFile as writeFile$1 } from "node:fs/promises";
3
+ import path from "node:path";
4
+ // src/core/write.ts
5
+ /**
6
+ * Writes content to a file, creating directories if needed
7
+ * @param filePath - Full path to the file including filename
8
+ * @param content - Content to write to the file
9
+ * @example
10
+ * ```typescript
11
+ * await writeFile('dist/app.js', 'console.log("hello")');
12
+ * await writeFile('src/components/Button.tsx', componentCode);
13
+ * ```
14
+ */
15
+ var writeFile = async (filePath, content) => {
16
+ const dir = path.dirname(filePath);
17
+ if (!await canAccess(dir)) await mkdir(dir, { recursive: true });
18
+ await writeFile$1(filePath, content);
10
19
  };
20
+ export { writeFile };
package/dist/index.js CHANGED
@@ -1,5 +1 @@
1
- import { writeFile as r, writeFile as t } from "./core/write.js";
2
- export {
3
- r as default,
4
- t as writeFile
5
- };
1
+ export { writeFile as default, writeFile } from "./core/write.js";
@@ -0,0 +1,92 @@
1
+ // package.json
2
+ var name = "@dephub/write";
3
+ var type = "module";
4
+ var version = "1.0.4";
5
+ var description = "File writing utility with automatic directory creation for Node.js";
6
+ var types = "./dist/index.d.ts";
7
+ var main = "./dist/index.js";
8
+ var bin = { "write": "./dist/cli.js" };
9
+ var scripts = {
10
+ "prepublishOnly": "pnpm check && pnpm test && pnpm build",
11
+ "release": "pnpm publish",
12
+ "docs": "lineo md 'src/**/*.ts' --outFile code.md --outDir temp",
13
+ "test": "node --test",
14
+ "check": "pnpm fmt && pnpm lint && pnpm check-types",
15
+ "check-types": "tsc --noEmit --skipLibCheck",
16
+ "lint": "eslint . --fix --max-warnings 0",
17
+ "fmt": "prettier --write .",
18
+ "clean": "rm -rf dist",
19
+ "build": "vite build",
20
+ "dev": "vite build -w --mode development"
21
+ };
22
+ var keywords = [
23
+ "file",
24
+ "write",
25
+ "filesystem",
26
+ "typescript",
27
+ "node",
28
+ "esm",
29
+ "utility",
30
+ "directory",
31
+ "creation",
32
+ "dephub"
33
+ ];
34
+ var author = {
35
+ "name": "Estarlin R",
36
+ "email": "dev@estarlincito.com",
37
+ "url": "https://estarlincito.com"
38
+ };
39
+ var files = [
40
+ "LICENSE",
41
+ "README.md",
42
+ "dist"
43
+ ];
44
+ var homepage = "https://github.com/dephub-js/write#readme";
45
+ var repository = {
46
+ "type": "git",
47
+ "url": "https://github.com/dephub-js/write.git"
48
+ };
49
+ var bugs = { "url": "https://github.com/dephub-js/write/issues" };
50
+ var publishConfig = { "access": "public" };
51
+ var dependencies = {
52
+ "@dephub/command": "^3.0.0",
53
+ "@dephub/logger": "^1.2.0"
54
+ };
55
+ var devDependencies = {
56
+ "@dephub/eslint-ts": "^1.0.5",
57
+ "@dephub/glob": "^1.0.2",
58
+ "@dephub/path": "^2.0.0",
59
+ "@types/node": "^26.6.6",
60
+ "eslint": "^10.14.0",
61
+ "prettier": "^3.9.10",
62
+ "typescript": "6.0.3",
63
+ "vite": "^8.3.6",
64
+ "vite-plugin-dts": "^5.1.2"
65
+ };
66
+ var imports = { "#/*": "./src/*" };
67
+ var engines = { "node": ">=24.0.0" };
68
+ var packageManager = "pnpm@10.30.3";
69
+ var package_default = {
70
+ name,
71
+ type,
72
+ version,
73
+ description,
74
+ types,
75
+ main,
76
+ bin,
77
+ scripts,
78
+ keywords,
79
+ author,
80
+ files,
81
+ license: "MIT",
82
+ homepage,
83
+ repository,
84
+ bugs,
85
+ publishConfig,
86
+ dependencies,
87
+ devDependencies,
88
+ imports,
89
+ engines,
90
+ packageManager
91
+ };
92
+ export { author, bin, bugs, package_default as default, dependencies, description, devDependencies, engines, files, homepage, imports, keywords, main, name, packageManager, publishConfig, repository, scripts, type, types, version };
@@ -0,0 +1,2 @@
1
+ import { PathLike } from 'node:fs';
2
+ export declare function canAccess(path: PathLike): Promise<boolean>;
@@ -0,0 +1,11 @@
1
+ import { access, constants } from "node:fs/promises";
2
+ // src/utils/access.ts
3
+ async function canAccess(path) {
4
+ try {
5
+ await access(path, constants.R_OK | constants.W_OK);
6
+ return true;
7
+ } catch {
8
+ return false;
9
+ }
10
+ }
11
+ export { canAccess };
package/dist/utils/pkg.js CHANGED
@@ -1,7 +1,4 @@
1
- import o from "../package.json.js";
2
- const { description: e, name: i, version: n } = o ?? {};
3
- export {
4
- e as description,
5
- i as name,
6
- n as version
7
- };
1
+ import package_default from "../package.js";
2
+ // src/utils/pkg.ts
3
+ var { description, name, version } = package_default ?? {};
4
+ export { description, name, version };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dephub/write",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "File writing utility with automatic directory creation for Node.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.js",
@@ -25,9 +25,6 @@
25
25
  "email": "dev@estarlincito.com",
26
26
  "url": "https://estarlincito.com"
27
27
  },
28
- "engines": {
29
- "node": ">=22.5.0"
30
- },
31
28
  "files": [
32
29
  "LICENSE",
33
30
  "README.md",
@@ -46,23 +43,31 @@
46
43
  "access": "public"
47
44
  },
48
45
  "dependencies": {
49
- "@dephub/command": "^1.0.1",
46
+ "@dephub/command": "^3.0.0",
50
47
  "@dephub/logger": "^1.2.0"
51
48
  },
52
49
  "devDependencies": {
53
- "@dephub/eslint-ts": "^1.0.2",
50
+ "@dephub/eslint-ts": "^1.0.5",
54
51
  "@dephub/glob": "^1.0.2",
55
- "@dephub/path": "^1.0.2",
56
- "@types/node": "^25.3.3",
57
- "eslint": "^10.0.2",
58
- "prettier": "^3.8.1",
59
- "typescript": "^5.9.3",
60
- "vite": "^7.3.1",
61
- "vite-plugin-dts": "^4.5.4"
52
+ "@dephub/path": "^2.0.0",
53
+ "@types/node": "^26.6.6",
54
+ "eslint": "^10.14.0",
55
+ "prettier": "^3.9.10",
56
+ "typescript": "6.0.3",
57
+ "vite": "^8.3.6",
58
+ "vite-plugin-dts": "^5.1.2"
59
+ },
60
+ "imports": {
61
+ "#/*": "./src/*"
62
+ },
63
+ "engines": {
64
+ "node": ">=24.0.0"
62
65
  },
63
66
  "scripts": {
64
67
  "release": "pnpm publish",
65
68
  "docs": "lineo md 'src/**/*.ts' --outFile code.md --outDir temp",
69
+ "test": "node --test",
70
+ "check": "pnpm fmt && pnpm lint && pnpm check-types",
66
71
  "check-types": "tsc --noEmit --skipLibCheck",
67
72
  "lint": "eslint . --fix --max-warnings 0",
68
73
  "fmt": "prettier --write .",
@@ -1,11 +0,0 @@
1
- const t = "@dephub/write", i = "1.0.2", o = "File writing utility with automatic directory creation for Node.js", e = {
2
- name: t,
3
- version: i,
4
- description: o
5
- };
6
- export {
7
- e as default,
8
- o as description,
9
- t as name,
10
- i as version
11
- };