eser 0.8.1 → 0.8.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/bin.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env -S node
2
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
3
+
4
+ import { main } from "./main.ts";
5
+
6
+ await main();
package/deno.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@eser/cli",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "exports": "./main.ts",
5
5
  "imports": {
6
6
  "@std/cli": "jsr:@std/cli@^1.0.25",
7
- "@std/fmt": "jsr:@std/fmt@^1.0.8"
7
+ "@std/fmt": "jsr:@std/fmt@^1.0.8",
8
+ "@std/path": "jsr:@std/path@^1.1.4"
8
9
  }
9
10
  }
package/main.ts CHANGED
@@ -19,6 +19,7 @@
19
19
  import * as cliParseArgs from "@std/cli/parse-args";
20
20
  import * as standardsRuntime from "@eser/standards/runtime";
21
21
  import { codebaseCommand } from "./commands/codebase/mod.ts";
22
+ import config from "./deno.json" with { type: "json" };
22
23
 
23
24
  type CommandHandler = (
24
25
  args: string[],
@@ -40,7 +41,7 @@ const showHelp = (): void => {
40
41
  console.log("\nRun 'eser <command> --help' for command-specific help.");
41
42
  };
42
43
 
43
- const main = async (): Promise<void> => {
44
+ export const main = async (): Promise<void> => {
44
45
  // @ts-ignore parseArgs doesn't mutate the array, readonly is safe
45
46
  const args = cliParseArgs.parseArgs(standardsRuntime.runtime.process.args, {
46
47
  boolean: ["help", "version"],
@@ -49,7 +50,7 @@ const main = async (): Promise<void> => {
49
50
  });
50
51
 
51
52
  if (args.version) {
52
- console.log("eser 0.8.0");
53
+ console.log(`eser ${config.version}`);
53
54
  return;
54
55
  }
55
56
 
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "eser",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "type": "module",
5
5
  "exports": "./main.ts",
6
6
  "bin": {
7
- "eser": "./main.ts"
7
+ "eser": "./bin.ts"
8
8
  },
9
9
  "dependencies": {
10
- "@eser/codebase": "workspace:*",
11
- "@eser/standards": "workspace:*",
10
+ "@eser/codebase": "npm:@jsr/eser__codebase@^0.8.3",
11
+ "@eser/standards": "npm:@jsr/eser__standards@^0.8.3",
12
12
  "@std/cli": "npm:@jsr/std__cli@^1.0.25",
13
- "@std/fmt": "npm:@jsr/std__fmt@^1.0.8"
13
+ "@std/fmt": "npm:@jsr/std__fmt@^1.0.8",
14
+ "@std/path": "npm:@jsr/std__path@^1.1.4"
14
15
  }
15
16
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@eser/cli",
3
+ "version": "0.8.3",
4
+ "type": "module",
5
+ "exports": "./main.ts",
6
+ "bin": {
7
+ "eser": "./bin.ts"
8
+ },
9
+ "dependencies": {
10
+ "@eser/codebase": "workspace:*",
11
+ "@eser/standards": "workspace:*",
12
+ "@std/cli": "npm:@jsr/std__cli@^1.0.25",
13
+ "@std/fmt": "npm:@jsr/std__fmt@^1.0.8",
14
+ "@std/path": "npm:@jsr/std__path@^1.1.4"
15
+ }
16
+ }
@@ -0,0 +1,123 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+
3
+ /**
4
+ * Prepares package.json for npm publishing.
5
+ *
6
+ * Reads package.json.template, replaces workspace:* dependencies with
7
+ * npm:@jsr/eser__<package>@^<version>, sets name to "eser", and writes
8
+ * the result to package.json.
9
+ *
10
+ * @module
11
+ */
12
+
13
+ import * as path from "@std/path";
14
+
15
+ type PackageJson = {
16
+ name: string;
17
+ version: string;
18
+ type?: string;
19
+ exports?: string | Record<string, string>;
20
+ bin?: Record<string, string>;
21
+ dependencies?: Record<string, string>;
22
+ devDependencies?: Record<string, string>;
23
+ };
24
+
25
+ type DenoJson = {
26
+ name: string;
27
+ version: string;
28
+ };
29
+
30
+ const isWorkspaceDep = (spec: string): boolean => {
31
+ return spec === "workspace:*" || spec.startsWith("workspace:");
32
+ };
33
+
34
+ const extractPackageName = (depName: string): string => {
35
+ // @eser/codebase -> codebase
36
+ const parts = depName.split("/");
37
+ return parts.length > 1 ? parts[1] : depName;
38
+ };
39
+
40
+ const getPackageVersion = async (
41
+ pkgDir: string,
42
+ depName: string,
43
+ ): Promise<string> => {
44
+ const packageName = extractPackageName(depName);
45
+ const denoJsonPath = path.join(pkgDir, "..", packageName, "deno.json");
46
+
47
+ const content = await Deno.readTextFile(denoJsonPath);
48
+ const denoJson = JSON.parse(content) as DenoJson;
49
+
50
+ return denoJson.version;
51
+ };
52
+
53
+ const convertWorkspaceDep = async (
54
+ pkgDir: string,
55
+ depName: string,
56
+ ): Promise<string> => {
57
+ const packageName = extractPackageName(depName);
58
+ const version = await getPackageVersion(pkgDir, depName);
59
+
60
+ // @eser/codebase -> npm:@jsr/eser__codebase@^0.8.0
61
+ return `npm:@jsr/eser__${packageName}@^${version}`;
62
+ };
63
+
64
+ const processDependencies = async (
65
+ pkgDir: string,
66
+ deps: Record<string, string> | undefined,
67
+ ): Promise<Record<string, string> | undefined> => {
68
+ if (deps === undefined) {
69
+ return undefined;
70
+ }
71
+
72
+ const result: Record<string, string> = {};
73
+
74
+ for (const [name, spec] of Object.entries(deps)) {
75
+ if (isWorkspaceDep(spec)) {
76
+ result[name] = await convertWorkspaceDep(pkgDir, name);
77
+ } else {
78
+ result[name] = spec;
79
+ }
80
+ }
81
+
82
+ return result;
83
+ };
84
+
85
+ const main = async (): Promise<void> => {
86
+ const scriptDir = import.meta.dirname;
87
+ if (scriptDir === undefined) {
88
+ throw new Error("Cannot determine script directory");
89
+ }
90
+
91
+ const pkgDir = path.dirname(scriptDir);
92
+ const templatePath = path.join(pkgDir, "package.json.template");
93
+ const outputPath = path.join(pkgDir, "package.json");
94
+
95
+ // Read template
96
+ const templateContent = await Deno.readTextFile(templatePath);
97
+ const pkg = JSON.parse(templateContent) as PackageJson;
98
+
99
+ // Set name to "eser" for npx
100
+ pkg.name = "eser";
101
+
102
+ // Process dependencies
103
+ pkg.dependencies = await processDependencies(pkgDir, pkg.dependencies);
104
+ pkg.devDependencies = await processDependencies(pkgDir, pkg.devDependencies);
105
+
106
+ // Write output
107
+ const outputContent = JSON.stringify(pkg, null, 2) + "\n";
108
+ await Deno.writeTextFile(outputPath, outputContent);
109
+
110
+ // deno-lint-ignore no-console
111
+ console.log(`Generated ${outputPath}`);
112
+ // deno-lint-ignore no-console
113
+ console.log(` name: ${pkg.name}`);
114
+
115
+ if (pkg.dependencies !== undefined) {
116
+ for (const [name, spec] of Object.entries(pkg.dependencies)) {
117
+ // deno-lint-ignore no-console
118
+ console.log(` ${name}: ${spec}`);
119
+ }
120
+ }
121
+ };
122
+
123
+ main();
@@ -0,0 +1,30 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+
3
+ /**
4
+ * Reverts package.json to local development state.
5
+ *
6
+ * Copies package.json.template to package.json to restore workspace:*
7
+ * dependencies for local development.
8
+ *
9
+ * @module
10
+ */
11
+
12
+ import * as path from "@std/path";
13
+
14
+ const main = async (): Promise<void> => {
15
+ const scriptDir = import.meta.dirname;
16
+ if (scriptDir === undefined) {
17
+ throw new Error("Cannot determine script directory");
18
+ }
19
+
20
+ const pkgDir = path.dirname(scriptDir);
21
+ const templatePath = path.join(pkgDir, "package.json.template");
22
+ const outputPath = path.join(pkgDir, "package.json");
23
+
24
+ await Deno.copyFile(templatePath, outputPath);
25
+
26
+ // deno-lint-ignore no-console
27
+ console.log(`Copied ${templatePath} to ${outputPath}`);
28
+ };
29
+
30
+ main();