@agent8/deploy 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/bin/agent8.js +51 -11
  2. package/package.json +1 -1
package/bin/agent8.js CHANGED
@@ -11,8 +11,21 @@ const [, , command, fnName, argsString] = process.argv;
11
11
  const envFilePath = path.resolve(process.cwd(), ".env");
12
12
  const deployedFilePath = path.resolve(process.cwd(), ".deployed");
13
13
 
14
+ // Generate random ID for account/verse if needed
15
+ const generateRandomId = () => {
16
+ return crypto.randomBytes(8).toString("hex");
17
+ };
18
+
19
+ let envConfig = {};
20
+
21
+ // Check if .env exists, create if not
14
22
  if (!fs.existsSync(envFilePath)) {
15
- fs.writeFileSync(envFilePath, "");
23
+ console.log("Creating new .env file with generated values");
24
+ const defaultEnv = `VITE_AGENT8_ACCOUNT=${generateRandomId()}\nVITE_AGENT8_VERSE=${generateRandomId()}\n`;
25
+ fs.writeFileSync(envFilePath, defaultEnv);
26
+ envConfig = dotenv.parse(fs.readFileSync(envFilePath));
27
+ } else {
28
+ envConfig = dotenv.parse(fs.readFileSync(envFilePath));
16
29
  }
17
30
 
18
31
  // Load previously deployed file hashes
@@ -26,23 +39,51 @@ if (fs.existsSync(deployedFilePath)) {
26
39
  }
27
40
  }
28
41
 
29
- const envConfig = dotenv.parse(fs.readFileSync(envFilePath));
30
-
31
42
  const endpoint =
32
43
  envConfig.VITE_AGENT8_REMOTE_URL ||
33
44
  "https://verse8-simple-game-backend-609824224664.asia-northeast3.run.app";
34
45
 
46
+ // If account/verse don't exist in .env, add them
35
47
  let verse = envConfig.VITE_AGENT8_VERSE;
36
- let account = envConfig.VITE_AGENT8_ACCOUNT || "0xtest";
37
- let signature = envConfig.VITE_AGENT8_SIGNATURE;
48
+ let account = envConfig.VITE_AGENT8_ACCOUNT;
49
+ let envChanged = false;
38
50
 
39
51
  if (!verse) {
40
- verse = crypto.randomBytes(16).toString("hex"); // Generate a random 32-byte string
41
- fs.appendFileSync(envFilePath, `VITE_AGENT8_VERSE=${verse}\n`);
42
- console.log("Generated random verse and updated .env:", verse);
52
+ verse = generateRandomId();
53
+ envConfig.VITE_AGENT8_VERSE = verse;
54
+ envChanged = true;
55
+ console.log("Generated new verse ID:", verse);
56
+ }
57
+
58
+ if (!account) {
59
+ account = generateRandomId();
60
+ envConfig.VITE_AGENT8_ACCOUNT = account;
61
+ envChanged = true;
62
+ console.log("Generated new account ID:", account);
63
+ }
64
+
65
+ // Save updated .env if needed
66
+ if (envChanged) {
67
+ const envContent = Object.entries(envConfig)
68
+ .map(([key, value]) => `${key}=${value}`)
69
+ .join("\n");
70
+ fs.writeFileSync(envFilePath, envContent);
71
+ console.log("Updated .env file with new values");
72
+ }
73
+
74
+ const accessToken = process.env.V8_ACCESS_TOKEN;
75
+
76
+ // Check if access token exists
77
+ if (!accessToken) {
78
+ console.error("Error: Missing V8_ACCESS_TOKEN environment variable");
79
+ console.error(
80
+ "Please set V8_ACCESS_TOKEN in your environment before deploying"
81
+ );
82
+ process.exit(1);
43
83
  }
44
84
 
45
85
  console.log("Starting deployment to verse:", verse);
86
+ console.log("Account:", account);
46
87
 
47
88
  // Files to upload
48
89
  const filesToUpload = [];
@@ -130,14 +171,13 @@ const uploadPromises = filesToUpload.map((fileInfo) => {
130
171
  form.append("path", uploadPath || "/");
131
172
 
132
173
  return axios
133
- .post(`${endpoint}/verses/${verse}/files`, form, {
174
+ .post(`${endpoint}/verses/${account}-${verse}/files`, form, {
134
175
  headers: {
135
176
  ...form.getHeaders(),
136
- "X-Signature": signature,
177
+ "X-Access-Token": accessToken,
137
178
  },
138
179
  })
139
180
  .then(() => {
140
- // 경로 출력 처리
141
181
  console.log(`Uploaded: ${uploadPath}/${fileName}`);
142
182
  return true;
143
183
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent8/deploy",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "A CLI tool for running agent8 commands",
5
5
  "main": "index.js",
6
6
  "bin": {