@dephub/write 1.0.2 → 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/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 { 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 };
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.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",
@@ -46,24 +46,24 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@dephub/command": "^1.0.1",
49
+ "@dephub/command": "^3.0.0",
50
50
  "@dephub/logger": "^1.2.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@dephub/eslint-ts": "^1.0.2",
53
+ "@dephub/eslint-ts": "^1.0.5",
54
54
  "@dephub/glob": "^1.0.2",
55
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"
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
65
  "docs": "lineo md 'src/**/*.ts' --outFile code.md --outDir temp",
66
- "check-types": "tsc --noEmit --skipLibCheck",
66
+ "check": "tsc --noEmit --skipLibCheck",
67
67
  "lint": "eslint . --fix --max-warnings 0",
68
68
  "fmt": "prettier --write .",
69
69
  "clean": "rm -rf dist",
@@ -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
- };