@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 +1 -1
- package/dist/cli.js +42 -16
- package/dist/core/write.js +19 -9
- package/dist/index.js +1 -5
- package/dist/package.js +88 -0
- package/dist/utils/pkg.d.ts +1 -1
- package/dist/utils/pkg.js +4 -7
- package/package.json +19 -18
- package/dist/package.json.js +0 -11
package/LICENSE
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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 {};
|
package/dist/core/write.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { existsSync
|
|
2
|
-
import { mkdir
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
package/dist/package.js
ADDED
|
@@ -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.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const description: string, name: string, version: string;
|
package/dist/utils/pkg.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.
|
|
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/
|
|
37
|
+
"homepage": "https://github.com/dephub-js/write#readme",
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/dephub-js/write.git"
|
|
41
41
|
},
|
|
42
42
|
"bugs": {
|
|
43
|
-
"url": "https://github.com/
|
|
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/
|
|
50
|
-
"@dephub/
|
|
49
|
+
"@dephub/command": "^3.0.0",
|
|
50
|
+
"@dephub/logger": "^1.2.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@dephub/
|
|
54
|
-
"@dephub/
|
|
55
|
-
"@dephub/
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"vite": "^
|
|
61
|
-
"vite-plugin-dts": "^
|
|
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
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"lint
|
|
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"
|
package/dist/package.json.js
DELETED