halife 0.0.1
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/README.md +15 -0
- package/index.js +60 -0
- package/package.json +49 -0
package/README.md
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { finished } from "node:stream/promises";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { program } from "commander";
|
|
8
|
+
import pkg from "./package.json";
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.command("add")
|
|
12
|
+
.description("Add components (e.g., add button card)")
|
|
13
|
+
.argument("[components...]", "Component names to add")
|
|
14
|
+
.option("--all", "Add all components")
|
|
15
|
+
.action(add);
|
|
16
|
+
|
|
17
|
+
program.parse();
|
|
18
|
+
|
|
19
|
+
async function add(components, options) {
|
|
20
|
+
const cwd = process.cwd();
|
|
21
|
+
const packageJSON = path.join(cwd, "package.json");
|
|
22
|
+
if (!(await fs.pathExists(packageJSON))) {
|
|
23
|
+
console.log("Run command in project root.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let addedComponents = [];
|
|
28
|
+
for (const comp of components) {
|
|
29
|
+
const reg = pkg.packages[comp];
|
|
30
|
+
if (!reg) {
|
|
31
|
+
console.log(chalk.red(`NotFound: ${comp}`));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// `${pkg.repository.url}/raw/branch/main/${reg.path}`
|
|
36
|
+
let response = await fetch(
|
|
37
|
+
"https://codeberg.org/Transient/saiyo-wchat-mini/src/branch/main/typings/index.d.ts",
|
|
38
|
+
);
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
console.info(
|
|
41
|
+
chalk.red(
|
|
42
|
+
`Failed to fetch ${comp}: ${response.status} ${response.statusText}`,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const target = path.join(cwd, `${reg.type}s`, reg.path.split("/").pop());
|
|
49
|
+
await fs.ensureDir(path.dirname(target));
|
|
50
|
+
// await fs.writeFile(target, file.content);
|
|
51
|
+
const fileStream = fs.createWriteStream(target);
|
|
52
|
+
const webStream = Readable.fromWeb(response.body);
|
|
53
|
+
await finished(webStream.pipe(fileStream));
|
|
54
|
+
addedComponents.push(comp);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (addedComponents.length) {
|
|
58
|
+
console.log(chalk.green(`Added: ${addedComponents.join(", ")}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "halife",
|
|
3
|
+
"author": {
|
|
4
|
+
"name": "Yaozong Wang",
|
|
5
|
+
"email": "renaud.w@outlook.com"
|
|
6
|
+
},
|
|
7
|
+
"description": "half life has gone",
|
|
8
|
+
"homepage": "https://codeberg.org/y0z0ng/halife.git",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"astro",
|
|
11
|
+
"CSS",
|
|
12
|
+
"HTML",
|
|
13
|
+
"component",
|
|
14
|
+
"layout"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT License",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://codeberg.org/y0z0ng/halife.git"
|
|
20
|
+
},
|
|
21
|
+
"version": "0.0.1",
|
|
22
|
+
"workspaces": [
|
|
23
|
+
"examples/*"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": "index.js",
|
|
27
|
+
"main": "index.js",
|
|
28
|
+
"module": "index.js",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"chalk": "^5.6.2",
|
|
31
|
+
"commander": "^14.0.2",
|
|
32
|
+
"fs-extra": "^11.3.3"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"index.js",
|
|
36
|
+
"package.json",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"packages": {
|
|
40
|
+
"Input": {
|
|
41
|
+
"type": "component",
|
|
42
|
+
"path": "packages/Input.astro"
|
|
43
|
+
},
|
|
44
|
+
"BaseLayout": {
|
|
45
|
+
"type": "layout",
|
|
46
|
+
"path": "packages/BaseLayout.astro"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|