@eighty4/c2 0.0.4 → 0.0.5-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/README.md CHANGED
@@ -12,9 +12,6 @@ npm i -g @eighty4/c2
12
12
  c2 -h
13
13
  ```
14
14
 
15
- (tests use `bun:test` so [install Bun](https://bun.sh/docs/installation)
16
- for contributing!)
17
-
18
15
  ## Using the CLI program
19
16
 
20
17
  ```
@@ -1,5 +1,5 @@
1
+ import { readdir, readFile } from 'node:fs/promises'
1
2
  import { evalTemplateExpressions } from './expression.ts'
2
- import { readDirListing, readToString } from './fs.ts'
3
3
 
4
4
  export type AttachmentType = 'cloud-config' | 'x-shellscript'
5
5
 
@@ -14,11 +14,11 @@ export interface Attachment {
14
14
  export async function collectAttachments(
15
15
  dir: string,
16
16
  ): Promise<Array<Attachment>> {
17
- const filenames = await readDirListing(dir)
17
+ const filenames = await readdir(dir)
18
18
  const attachments = await Promise.all(
19
19
  filenames.map(async filename => {
20
20
  const path = `${dir}/${filename}`
21
- const source = await readToString(path)
21
+ const source = await readFile(path, 'utf-8')
22
22
  const type = resolveAttachmentType(filename, source)
23
23
  const content = await evalTemplateExpressions(source)
24
24
  return { content, filename, path, type, source }
package/lib/bin.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { stat } from 'node:fs/promises'
3
4
  import { buildUserData } from './build.ts'
4
5
  import { parseArgs, type ParsedArgs } from './cli.ts'
5
- import { doesDirExist } from './fs.ts'
6
6
  import { startUserDataHttp } from './http.ts'
7
7
 
8
8
  let args: ParsedArgs | undefined
@@ -52,3 +52,11 @@ function errorExit(msg: string): never {
52
52
  function errorText(s: string): string {
53
53
  return `\u001b[1;31m${s}\u001b[0m`
54
54
  }
55
+
56
+ async function doesDirExist(p: string): Promise<boolean> {
57
+ try {
58
+ return (await stat(p)).isDirectory()
59
+ } catch (ignore) {
60
+ return false
61
+ }
62
+ }
package/lib/expression.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { readFile } from 'node:fs/promises'
1
2
  import MagicString from 'magic-string'
2
- import { readToString } from './fs.ts'
3
3
 
4
4
  type TemplateExpression = {
5
5
  index: number
@@ -56,7 +56,7 @@ async function evaluate(expression: string): Promise<string> {
56
56
  }
57
57
  path = `${process.env.HOME}${path.substring(1)}`
58
58
  }
59
- return readToString(path)
59
+ return await readFile(path, 'utf-8')
60
60
  }
61
61
 
62
62
  throw new Error(`unsupported expression: ${expression}`)
package/lib/fs.testing.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { mkdtemp, rm } from 'node:fs/promises'
1
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises'
2
2
  import { tmpdir } from 'node:os'
3
3
  import { join } from 'node:path'
4
4
 
@@ -8,7 +8,7 @@ export async function makeFile(
8
8
  pathPrefix?: string,
9
9
  ): Promise<string> {
10
10
  const p = !!pathPrefix ? join(pathPrefix, path) : path
11
- await Bun.file(p).write(content)
11
+ await writeFile(p, content)
12
12
  return p
13
13
  }
14
14
 
@@ -1,10 +1,10 @@
1
+ import { readdir, readFile } from 'node:fs/promises';
1
2
  import { evalTemplateExpressions } from "./expression.js";
2
- import { readDirListing, readToString } from "./fs.js";
3
3
  export async function collectAttachments(dir) {
4
- const filenames = await readDirListing(dir);
4
+ const filenames = await readdir(dir);
5
5
  const attachments = await Promise.all(filenames.map(async (filename) => {
6
6
  const path = `${dir}/${filename}`;
7
- const source = await readToString(path);
7
+ const source = await readFile(path, 'utf-8');
8
8
  const type = resolveAttachmentType(filename, source);
9
9
  const content = await evalTemplateExpressions(source);
10
10
  return { content, filename, path, type, source };
package/lib_js/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { stat } from 'node:fs/promises';
2
3
  import { buildUserData } from "./build.js";
3
4
  import { parseArgs } from "./cli.js";
4
- import { doesDirExist } from "./fs.js";
5
5
  import { startUserDataHttp } from "./http.js";
6
6
  let args;
7
7
  try {
@@ -44,3 +44,11 @@ function errorExit(msg) {
44
44
  function errorText(s) {
45
45
  return `\u001b[1;31m${s}\u001b[0m`;
46
46
  }
47
+ async function doesDirExist(p) {
48
+ try {
49
+ return (await stat(p)).isDirectory();
50
+ }
51
+ catch (ignore) {
52
+ return false;
53
+ }
54
+ }
@@ -1,5 +1,5 @@
1
+ import { readFile } from 'node:fs/promises';
1
2
  import MagicString from 'magic-string';
2
- import { readToString } from "./fs.js";
3
3
  export async function evalTemplateExpressions(content) {
4
4
  const regex = new RegExp(/\${{\s*(.*)\s*}}/g);
5
5
  let match;
@@ -41,7 +41,7 @@ async function evaluate(expression) {
41
41
  }
42
42
  path = `${process.env.HOME}${path.substring(1)}`;
43
43
  }
44
- return readToString(path);
44
+ return await readFile(path, 'utf-8');
45
45
  }
46
46
  throw new Error(`unsupported expression: ${expression}`);
47
47
  }
@@ -1,9 +1,9 @@
1
- import { mkdtemp, rm } from 'node:fs/promises';
1
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises';
2
2
  import { tmpdir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  export async function makeFile(path, content, pathPrefix) {
5
5
  const p = !!pathPrefix ? join(pathPrefix, path) : path;
6
- await Bun.file(p).write(content);
6
+ await writeFile(p, content);
7
7
  return p;
8
8
  }
9
9
  export async function makeTempDir() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eighty4/c2",
3
- "version": "0.0.4",
3
+ "version": "0.0.5-0",
4
4
  "author": "Adam McKee <adam.be.g84d@gmail.com>",
5
5
  "repository": "https://github.com/eighty4/c2",
6
6
  "homepage": "https://github.com/eighty4/c2",
@@ -29,18 +29,10 @@
29
29
  "types": "./lib_types/api.d.ts"
30
30
  }
31
31
  },
32
- "scripts": {
33
- "build": "tsc",
34
- "fmt": "prettier --write .",
35
- "fmtcheck": "prettier --check .",
36
- "test": "bun test",
37
- "typecheck": "tsc --noEmit"
38
- },
39
32
  "dependencies": {
40
33
  "magic-string": "0.30.17"
41
34
  },
42
35
  "devDependencies": {
43
- "@types/bun": "1.2.5",
44
36
  "@types/node": "^22.14.1",
45
37
  "prettier": "^3.5.3",
46
38
  "typescript": "5.8.2"
@@ -51,5 +43,12 @@
51
43
  "lib_js/*",
52
44
  "lib_types/*",
53
45
  "CHANGELOG.md"
54
- ]
55
- }
46
+ ],
47
+ "scripts": {
48
+ "build": "tsc",
49
+ "fmt": "prettier --write .",
50
+ "fmtcheck": "prettier --check .",
51
+ "test": "node --test \"lib/**/*.spec.ts\"",
52
+ "typecheck": "tsc --noEmit"
53
+ }
54
+ }
package/lib/fs.ts DELETED
@@ -1,17 +0,0 @@
1
- import { readdir, readFile, stat } from 'node:fs/promises'
2
-
3
- export async function doesDirExist(p: string): Promise<boolean> {
4
- try {
5
- return (await stat(p)).isDirectory()
6
- } catch (ignore) {
7
- return false
8
- }
9
- }
10
-
11
- export async function readDirListing(p: string): Promise<Array<string>> {
12
- return readdir(p)
13
- }
14
-
15
- export async function readToString(p: string): Promise<string> {
16
- return readFile(p, 'utf8')
17
- }
package/lib_js/fs.js DELETED
@@ -1,15 +0,0 @@
1
- import { readdir, readFile, stat } from 'node:fs/promises';
2
- export async function doesDirExist(p) {
3
- try {
4
- return (await stat(p)).isDirectory();
5
- }
6
- catch (ignore) {
7
- return false;
8
- }
9
- }
10
- export async function readDirListing(p) {
11
- return readdir(p);
12
- }
13
- export async function readToString(p) {
14
- return readFile(p, 'utf8');
15
- }
package/lib_types/fs.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare function doesDirExist(p: string): Promise<boolean>;
2
- export declare function readDirListing(p: string): Promise<Array<string>>;
3
- export declare function readToString(p: string): Promise<string>;
4
- //# sourceMappingURL=fs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../lib/fs.ts"],"names":[],"mappings":"AAEA,wBAAsB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAM9D;AAED,wBAAsB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAEtE;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7D"}