Skip to content

Commit

Permalink
✨ 将dnt-monorepo的构建脚本迁移到denokit项目下
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaubee committed Oct 12, 2024
1 parent d96e487 commit ce4ee14
Show file tree
Hide file tree
Showing 20 changed files with 617 additions and 388 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

## Packages

The following list contains links to the Standard Library's packages and
documentation:
The following list contains links to the Standard Library's packages and documentation:

| Package | Latest version |
| ----------------------------------- | ------------------------------------------------------------------------- |
Expand All @@ -14,6 +13,5 @@ documentation:

## Releases

Package versions >=1.0.0 follow [Semantic Versioning](https://semver.org/), and
package versions <1.0.0 follow
Package versions >=1.0.0 follow [Semantic Versioning](https://semver.org/), and package versions <1.0.0 follow
[this proposal](https://github.com/semver/semver/pull/923).
13 changes: 4 additions & 9 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
".npm"
],
"fmt": {
"lineWidth": 120
"lineWidth": 120,
"useTabs": false,
"indentWidth": 4
},
"lint": {
"rules": {
Expand All @@ -31,12 +33,5 @@
"ban-ts-comment"
]
}
},
"imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
"@std/fs": "jsr:@std/fs@^1.0.4",
"@std/path": "jsr:@std/path@^1.0.6",
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"zx": "npm:zx@^8.1.9"
}
}
}
73 changes: 28 additions & 45 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions denokit/.import_map.npm.478ebf82-bf2b-45ab-ba51-9ee264f75d16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
"@std/collections": "jsr:@std/collections@^1.0.8",
"@std/fmt": "jsr:@std/fmt@^1.0.2",
"@std/fs": "jsr:@std/fs@^1.0.4",
"@std/jsonc": "jsr:@std/jsonc@^1.0.1",
"@std/path": "jsr:@std/path@^1.0.6",
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"@gaubee/flow": "npm:@gaubee/flow@*",
"@gaubee/util": "npm:@gaubee/util@*",
"@gaubee/denokit": "npm:@gaubee/denokit@*"
}
}
18 changes: 13 additions & 5 deletions denokit/deno.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"name": "@gaubee/denokit",
"version": "0.1.0",
"exports":{
"./shell":"./src/shell.ts",
"version": "0.2.0",
"exports": {
"./config_file": "./src/config_file.ts",
"./dnt_monorepo": "./src/dnt_monorepo.ts",
"./shell": "./src/shell.ts",
".": "./src/index.ts"
},
"imports": {
"@std/fmt": "jsr:@std/fmt@^1.0.2"
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
"@std/collections": "jsr:@std/collections@^1.0.8",
"@std/fmt": "jsr:@std/fmt@^1.0.2",
"@std/fs": "jsr:@std/fs@^1.0.4",
"@std/jsonc": "jsr:@std/jsonc@^1.0.1",
"@std/path": "jsr:@std/path@^1.0.6",
"@std/yaml": "jsr:@std/yaml@^1.0.5"
}
}
}
2 changes: 1 addition & 1 deletion denokit/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"private": true
}
}
58 changes: 58 additions & 0 deletions denokit/src/config_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as JSONC from "@std/jsonc";
import * as YAML from "@std/yaml";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
const normalize_path = (path: string) => path.startsWith("file://") ? fileURLToPath(path) : path;

/**
* read json or jsonc file
*/
export const readJson = <T extends object = any>(path: string, defaultValue?: () => T): T => {
try {
return JSONC.parse(fs.readFileSync(normalize_path(path), "utf8")) as T;
} catch (e) {
if (defaultValue) {
return defaultValue();
}
throw e;
}
};
/**
* write json file
*/
export const writeJson = <T extends object>(
path: string,
data: T,
options?: {
replacer: (this: any, key: string, value: any) => any;
space?: number | string;
},
): void => {
fs.writeFileSync(normalize_path(path), JSON.stringify(data, options?.replacer, options?.space ?? 2));
};

/**
* read yaml file
*/
export const readYaml = <T extends object = any>(path: string, defaultValue?: () => T): T => {
try {
return YAML.parse(fs.readFileSync(normalize_path(path), "utf8")) as T;
} catch (e) {
if (defaultValue) {
return defaultValue();
}
throw e;
}
};

/**
* write yaml file
* @returns
*/
export const writeYaml = <T extends object>(
path: string,
data: T,
options?: YAML.StringifyOptions,
): void => {
fs.writeFileSync(normalize_path(path), YAML.stringify(data, options));
};
Loading

0 comments on commit ce4ee14

Please sign in to comment.