@ai-digital-factory/asset-manager 0.2.0 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-digital-factory/asset-manager",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,9 +16,6 @@
16
16
  "main": "./dist/index.cjs",
17
17
  "module": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts",
19
- "bin": {
20
- "asset-manager": "./dist/asset-manager.cjs"
21
- },
22
19
  "files": [
23
20
  "dist"
24
21
  ],
@@ -28,17 +25,16 @@
28
25
  "dependencies": {
29
26
  "@aws-sdk/client-s3": "3.1098.0",
30
27
  "@aws-sdk/lib-storage": "3.1098.0",
31
- "commander": "^13.1.0",
32
28
  "mime-types": "^3.0.2"
33
29
  },
34
30
  "devDependencies": {
35
31
  "@types/node": "^22.17.2",
36
32
  "tsup": "^8.5.0",
37
- "@ai-digital-factory/asset-manager-r2": "0.0.2",
38
- "@ai-digital-factory/asset-manager-core": "0.0.2"
33
+ "@ai-digital-factory/asset-manager-core": "0.0.2",
34
+ "@ai-digital-factory/asset-manager-r2": "0.0.2"
39
35
  },
40
36
  "scripts": {
41
- "build": "tsup --config tsup.config.ts && node ../../scripts/build-cli.mjs dist/asset-manager.cjs --packages-external",
37
+ "build": "tsup --config tsup.config.ts",
42
38
  "test": "vitest run",
43
39
  "typecheck": "tsc --project tsconfig.json",
44
40
  "lint": "eslint . --ext ts"
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- // apps/cli/src/index.ts
5
- var import_commander = require("commander");
6
-
7
- // apps/cli/src/env-file.ts
8
- var import_node_fs = require("node:fs");
9
- var import_node_path = require("node:path");
10
- var import_node_url = require("node:url");
11
- function parseEnvFile(contents, path) {
12
- const env = {};
13
- for (const [index, line] of contents.split(/\r?\n/).entries()) {
14
- const trimmedLine = line.trim();
15
- if (!trimmedLine || trimmedLine.startsWith("#")) {
16
- continue;
17
- }
18
- const match = trimmedLine.match(
19
- /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/
20
- );
21
- if (!match) {
22
- throw new Error(`Invalid environment file ${path} at line ${index + 1}`);
23
- }
24
- const [, key, rawValue] = match;
25
- const value = rawValue.trim();
26
- const quote = value[0];
27
- if (quote === '"' || quote === "'") {
28
- if (value.length < 2 || !value.endsWith(quote)) {
29
- throw new Error(
30
- `Invalid environment file ${path} at line ${index + 1}`
31
- );
32
- }
33
- env[key] = value.slice(1, -1);
34
- continue;
35
- }
36
- env[key] = value;
37
- }
38
- return env;
39
- }
40
- function resolveEnvironment(envFile, processEnv = process.env) {
41
- if (!envFile) {
42
- return processEnv;
43
- }
44
- let contents;
45
- try {
46
- contents = (0, import_node_fs.readFileSync)(envFile, "utf-8");
47
- } catch {
48
- throw new Error(`Unable to read environment file: ${envFile}`);
49
- }
50
- return { ...processEnv, ...parseEnvFile(contents, envFile) };
51
- }
52
- function localEnvFilePath(moduleUrl, cwd = process.cwd()) {
53
- const candidates = [
54
- ...moduleUrl ? [(0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(moduleUrl)), "..", ".env")] : [],
55
- (0, import_node_path.join)(cwd, ".env"),
56
- (0, import_node_path.join)(cwd, "apps/cli/.env")
57
- ];
58
- return candidates.find((path) => (0, import_node_fs.existsSync)(path));
59
- }
60
- function loadLocalEnvFile() {
61
- if (process.env.VITEST) {
62
- return;
63
- }
64
- const path = localEnvFilePath();
65
- if (path !== void 0) {
66
- process.loadEnvFile(path);
67
- }
68
- }
69
-
70
- // apps/cli/src/publish-command.ts
71
- var import_asset_manager = require("@ai-digital-factory/asset-manager");
72
-
73
- // apps/cli/src/sdk-env.ts
74
- var assetManagerEnvVars = [
75
- "ASSET_MANAGER_CREDENTIAL",
76
- "ASSET_MANAGER_NAMESPACE"
77
- ];
78
- function missingAssetManagerEnvVars(env = process.env) {
79
- return assetManagerEnvVars.filter((name) => !env[name]);
80
- }
81
- function readAssetManagerConfig(env = process.env) {
82
- const missing = missingAssetManagerEnvVars(env);
83
- if (missing.length > 0) {
84
- throw new Error(
85
- `Missing required environment variable(s): ${missing.join(", ")}`
86
- );
87
- }
88
- return {
89
- credential: env.ASSET_MANAGER_CREDENTIAL,
90
- namespace: env.ASSET_MANAGER_NAMESPACE
91
- };
92
- }
93
-
94
- // apps/cli/src/publish-command.ts
95
- async function runPublish({ filePath, assetPath, env = process.env }, factory = import_asset_manager.createAssetManager) {
96
- const manager = factory(readAssetManagerConfig(env));
97
- return manager.publish({
98
- localPath: filePath,
99
- assetPath
100
- });
101
- }
102
-
103
- // apps/cli/src/index.ts
104
- loadLocalEnvFile();
105
- var program = new import_commander.Command();
106
- program.name("asset-manager").description("Manage digital assets from the command line").version("0.2.0");
107
- program.command("publish").description("Publish a local asset and print its hosted URL").argument("<file-path>", "Path to the local asset file").requiredOption("--asset-path <path>", "Asset Path within the Namespace").option("--env-file <path>", "Path to a dotenv-style configuration file").addHelpText(
108
- "after",
109
- `
110
- Environment variables:
111
- ${assetManagerEnvVars.join("\n ")}`
112
- ).action(
113
- async (filePath, options) => {
114
- try {
115
- const hostedUrl = await runPublish({
116
- filePath,
117
- assetPath: options.assetPath,
118
- env: resolveEnvironment(options.envFile)
119
- });
120
- process.stdout.write(`${hostedUrl}
121
- `);
122
- } catch (error) {
123
- const message = error instanceof Error ? error.message : "Publication failed";
124
- process.stderr.write(`${message}
125
- `);
126
- process.exitCode = 1;
127
- }
128
- }
129
- );
130
- program.parse();