@dephub/write 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 Estarlin R
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # @dephub/write 📝
2
+
3
+ > A utility for writing files with automatic directory creation in Node.js and browsers.
4
+
5
+ [![NPM version](https://img.shields.io/npm/v/@dephub/write.svg?style=flat)](https://npmjs.org/package/@dephub/write)
6
+ [![ESM-only](https://img.shields.io/badge/ESM-only-brightgreen?style=flat)](https://nodejs.org/)
7
+ [![Node.js version](https://img.shields.io/badge/node-%3E%3D22.5.0-brightgreen.svg)](https://nodejs.org/)
8
+
9
+ ---
10
+
11
+ ## Features ✨
12
+
13
+ - 📄 **Simple File Writing** - Write content to files with one function call
14
+ - 🗂️ **Automatic Directories** - Creates parent directories if they don't exist
15
+ - 🎯 **TypeScript Ready** - Full type safety with zero configuration
16
+ - 🌐 **Universal** - Works in Node.js and browser environments
17
+ - ⚡ **Lightweight** - Minimal dependencies, focused functionality
18
+
19
+ ---
20
+
21
+ ## Installation 📦
22
+
23
+ ```bash
24
+ npm install @dephub/write
25
+ # or
26
+ pnpm add @dephub/write
27
+ # or
28
+ yarn add @dephub/write
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Usage 🎯
34
+
35
+ ### Programmatic API
36
+
37
+ ```typescript
38
+ import { writeFile } from '@dephub/write';
39
+
40
+ // Write simple content
41
+ await writeFile('output.txt', 'Hello World!');
42
+
43
+ // Write multi-line content
44
+ await writeFile(
45
+ 'README.md',
46
+ `
47
+ # My Project
48
+
49
+ This is a sample README file.
50
+
51
+ ## Features
52
+ - Feature 1
53
+ - Feature 2
54
+ `.trim(),
55
+ );
56
+
57
+ // Write JSON data
58
+ await writeFile(
59
+ 'config.json',
60
+ JSON.stringify(
61
+ {
62
+ name: 'my-app',
63
+ version: '1.0.0',
64
+ },
65
+ null,
66
+ 2,
67
+ ),
68
+ );
69
+ ```
70
+
71
+ ### CLI Usage
72
+
73
+ ```bash
74
+ # Quick one-time usage (no installation):
75
+ npx @dephub/write output.txt "Hello World"
76
+
77
+ # Write from stdin
78
+ echo "File content" | npx @dephub/write output.txt
79
+
80
+ # For frequent usage, install globally:
81
+ npm install -g @dephub/write
82
+ write output.txt "Hello World"
83
+
84
+ # Or use with package managers:
85
+ pnpm dlx @dephub/write output.txt "Hello World"
86
+ yarn dlx @dephub/write output.txt "Hello World"
87
+ ```
88
+
89
+ ---
90
+
91
+ ## API Reference 📚
92
+
93
+ ### `writeFile(filePath, content)`
94
+
95
+ Writes content to a file, creating directories if needed.
96
+
97
+ **Parameters:**
98
+
99
+ - `filePath` (string) - Full path to the file including filename
100
+ - `content` (string) - Content to write to the file
101
+
102
+ **Returns:** `Promise<void>`
103
+
104
+ **Example:**
105
+
106
+ ```typescript
107
+ import { writeFile } from '@dephub/write';
108
+
109
+ await writeFile('dist/bundle.js', 'console.log("Hello")');
110
+ await writeFile('src/config.json', JSON.stringify(config, null, 2));
111
+ ```
112
+
113
+ ---
114
+
115
+ ## License 📄
116
+
117
+ MIT License – see [LICENSE](LICENSE) for details.
118
+
119
+ **Author:** Estarlin R ([estarlincito.com](https://estarlincito.com))
package/dist/cli.js ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import { cli as o } from "@dephub/cli";
3
+ import { error as r, success as s } from "@dephub/log";
4
+ import { writeFile as a } from "./core/write.js";
5
+ import { name as d, version as c, description as m } from "./utils/pkg.js";
6
+ o.name(d.split("/")[1] ?? "write").version(c).description(m).argument("<filepath>", "Path where the file will be written").argument("[content]", "Content to write (if not provided, reads from stdin)").action(async ({ args: n }) => {
7
+ const [e, i] = n;
8
+ try {
9
+ let t = i;
10
+ i || (t = await p(), t || (r("No content provided and stdin is empty"), process.exit(1))), await a(e, t), s(`Written to ${e}`);
11
+ } catch (t) {
12
+ r(`Failed to write to ${e}: ${t.message}`), process.exit(1);
13
+ }
14
+ });
15
+ const p = () => new Promise((n, e) => {
16
+ let i = "";
17
+ process.stdin.setEncoding("utf8"), process.stdin.on("data", (t) => i += t), process.stdin.on("end", () => n(i.trim())), process.stdin.on("error", e), process.stdin.isTTY && setTimeout(() => n(""), 100);
18
+ });
19
+ await o.run();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Writes content to a file, creating directories if needed
3
+ * @param filePath - Full path to the file including filename
4
+ * @param content - Content to write to the file
5
+ * @example
6
+ * ```typescript
7
+ * await writeFile('dist/app.js', 'console.log("hello")');
8
+ * await writeFile('src/components/Button.tsx', componentCode);
9
+ * ```
10
+ */
11
+ export declare const writeFile: (filePath: string, content: string) => Promise<void>;
@@ -0,0 +1,10 @@
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
10
+ };
@@ -0,0 +1,2 @@
1
+ export { writeFile } from './core/write.js';
2
+ export { writeFile as default } from './core/write.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { writeFile as r, writeFile as t } from "./core/write.js";
2
+ export {
3
+ r as default,
4
+ t as writeFile
5
+ };
@@ -0,0 +1,11 @@
1
+ const t = "@dephub/write", i = "1.0.0", 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
+ };
@@ -0,0 +1 @@
1
+ export declare const version: string, description: string, name: string;
@@ -0,0 +1,7 @@
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
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@dephub/write",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "File writing utility with automatic directory creation for Node.js",
6
+ "types": "./dist/index.d.ts",
7
+ "main": "./dist/index.js",
8
+ "bin": {
9
+ "write": "./dist/cli.js"
10
+ },
11
+ "keywords": [
12
+ "file",
13
+ "write",
14
+ "filesystem",
15
+ "typescript",
16
+ "node",
17
+ "esm",
18
+ "utility",
19
+ "directory",
20
+ "creation",
21
+ "dephub"
22
+ ],
23
+ "author": {
24
+ "name": "Estarlin R",
25
+ "email": "dev@estarlincito.com",
26
+ "url": "https://estarlincito.com"
27
+ },
28
+ "engines": {
29
+ "node": ">=22.5.0"
30
+ },
31
+ "files": [
32
+ "LICENSE",
33
+ "README.md",
34
+ "dist"
35
+ ],
36
+ "license": "MIT",
37
+ "homepage": "https://github.com/dephubjs/write#readme",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/dephubjs/write.git",
41
+ "directory": "packages/write"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/dephubjs/write/issues"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "dependencies": {
50
+ "@dephub/log": "^1.0.0",
51
+ "@dephub/cli": "^1.0.0"
52
+ },
53
+ "scripts": {
54
+ "release": "pnpm publish",
55
+ "check-types": "tsc --noEmit --skipLibCheck",
56
+ "lint": "lint . --max-warnings 0",
57
+ "lint:fix": "lint . --fix",
58
+ "clean": "rm -rf dist",
59
+ "build": "vite build",
60
+ "dev": "vite build -w --mode development"
61
+ }
62
+ }