@dephub/write 1.0.1 → 1.0.3

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright (c) 2025 Estarlin R
3
+ Copyright (c) 2025-2026 Estarlin R
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/cli.js CHANGED
@@ -1,19 +1,45 @@
1
1
  #!/usr/bin/env node
2
- import { cli as o } from "@dephub/cli";
3
- import { logger as n } from "@dephub/logger";
4
- import { writeFile as s } from "./core/write.js";
5
- import { name as a, version as d, description as c } from "./utils/pkg.js";
6
- o.name(a.split("/")[1] ?? "write").version(d).description(c).argument("<filepath>", "Path where the file will be written").argument("[content]", "Content to write (if not provided, reads from stdin)").action(async ({ args: r }) => {
7
- const [e, i] = r;
8
- try {
9
- let t = i;
10
- i || (t = await m(), t || (n.error("No content provided and stdin is empty"), process.exit(1))), await s(e, t), n.success(`Written to ${e}`);
11
- } catch (t) {
12
- n.error(`Failed to write to ${e}: ${t.message}`), process.exit(1);
13
- }
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
+ }
14
23
  });
15
- const m = () => new Promise((r, e) => {
16
- let i = "";
17
- process.stdin.setEncoding("utf8"), process.stdin.on("data", (t) => i += t), process.stdin.on("end", () => r(i.trim())), process.stdin.on("error", e), process.stdin.isTTY && setTimeout(() => r(""), 100);
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);
18
34
  });
19
- await o.run();
35
+ try {
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;
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 { existsSync } from "node:fs";
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 (!existsSync(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,88 @@
1
+ // package.json
2
+ var name = "@dephub/write";
3
+ var type = "module";
4
+ var version = "1.0.3";
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 lint && pnpm check && pnpm build",
11
+ "release": "pnpm publish",
12
+ "docs": "lineo md 'src/**/*.ts' --outFile code.md --outDir temp",
13
+ "check": "tsc --noEmit --skipLibCheck",
14
+ "lint": "eslint . --fix --max-warnings 0",
15
+ "fmt": "prettier --write .",
16
+ "clean": "rm -rf dist",
17
+ "build": "vite build",
18
+ "dev": "vite build -w --mode development"
19
+ };
20
+ var keywords = [
21
+ "file",
22
+ "write",
23
+ "filesystem",
24
+ "typescript",
25
+ "node",
26
+ "esm",
27
+ "utility",
28
+ "directory",
29
+ "creation",
30
+ "dephub"
31
+ ];
32
+ var author = {
33
+ "name": "Estarlin R",
34
+ "email": "dev@estarlincito.com",
35
+ "url": "https://estarlincito.com"
36
+ };
37
+ var engines = { "node": ">=22.5.0" };
38
+ var files = [
39
+ "LICENSE",
40
+ "README.md",
41
+ "dist"
42
+ ];
43
+ var homepage = "https://github.com/dephub-js/write#readme";
44
+ var repository = {
45
+ "type": "git",
46
+ "url": "https://github.com/dephub-js/write.git"
47
+ };
48
+ var bugs = { "url": "https://github.com/dephub-js/write/issues" };
49
+ var publishConfig = { "access": "public" };
50
+ var packageManager = "pnpm@10.30.3";
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": "^1.0.2",
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.5",
64
+ "vite-plugin-dts": "^5.1.2"
65
+ };
66
+ var package_default = {
67
+ name,
68
+ type,
69
+ version,
70
+ description,
71
+ types,
72
+ main,
73
+ bin,
74
+ scripts,
75
+ keywords,
76
+ author,
77
+ engines,
78
+ files,
79
+ license: "MIT",
80
+ homepage,
81
+ repository,
82
+ bugs,
83
+ publishConfig,
84
+ packageManager,
85
+ dependencies,
86
+ devDependencies
87
+ };
88
+ export { author, bin, bugs, package_default as default, dependencies, description, devDependencies, engines, files, homepage, keywords, main, name, packageManager, publishConfig, repository, scripts, type, types, version };
@@ -1 +1 @@
1
- export declare const version: string, description: string, name: string;
1
+ export declare const description: string, name: string, version: string;
package/dist/utils/pkg.js CHANGED
@@ -1,7 +1,4 @@
1
- import o from "../package.json.js";
2
- const { version: e, description: i, name: n } = o ?? {};
3
- export {
4
- i as description,
5
- n as name,
6
- e 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.1",
4
+ "version": "1.0.3",
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",
@@ -34,37 +34,38 @@
34
34
  "dist"
35
35
  ],
36
36
  "license": "MIT",
37
- "homepage": "https://github.com/estarlincito/dephub-write#readme",
37
+ "homepage": "https://github.com/dephub-js/write#readme",
38
38
  "repository": {
39
39
  "type": "git",
40
- "url": "https://github.com/estarlincito/dephub-write.git"
40
+ "url": "https://github.com/dephub-js/write.git"
41
41
  },
42
42
  "bugs": {
43
- "url": "https://github.com/estarlincito/dephub-write/issues"
43
+ "url": "https://github.com/dephub-js/write/issues"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@dephub/logger": "^1.1.0",
50
- "@dephub/cli": "^1.0.0"
49
+ "@dephub/command": "^3.0.0",
50
+ "@dephub/logger": "^1.2.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@dephub/lint": "^1.0.0",
54
- "@dephub/lint-ts": "^1.0.0",
55
- "@dephub/glob": "^1.0.0",
56
- "@dephub/path": "^1.0.0",
57
- "@types/node": "^24.3.1",
58
- "typescript": "^5.9.2",
59
- "eslint": "^9.37.0",
60
- "vite": "^7.1.4",
61
- "vite-plugin-dts": "^4.5.4"
53
+ "@dephub/eslint-ts": "^1.0.5",
54
+ "@dephub/glob": "^1.0.2",
55
+ "@dephub/path": "^1.0.2",
56
+ "@types/node": "^26.6.6",
57
+ "eslint": "^10.14.0",
58
+ "prettier": "^3.9.10",
59
+ "typescript": "6.0.3",
60
+ "vite": "^8.3.5",
61
+ "vite-plugin-dts": "^5.1.2"
62
62
  },
63
63
  "scripts": {
64
64
  "release": "pnpm publish",
65
- "check-types": "tsc --noEmit --skipLibCheck",
66
- "lint": "lint . --max-warnings 0",
67
- "lint:fix": "lint . --fix",
65
+ "docs": "lineo md 'src/**/*.ts' --outFile code.md --outDir temp",
66
+ "check": "tsc --noEmit --skipLibCheck",
67
+ "lint": "eslint . --fix --max-warnings 0",
68
+ "fmt": "prettier --write .",
68
69
  "clean": "rm -rf dist",
69
70
  "build": "vite build",
70
71
  "dev": "vite build -w --mode development"
@@ -1,11 +0,0 @@
1
- const t = "@dephub/write", i = "1.0.1", 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
- };