@airmoney-degn/airmoney-cli 0.9.0 → 0.10.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.
File without changes
package/dist/cli/serve.js CHANGED
@@ -62,55 +62,62 @@ function getSimulatorDir() {
62
62
  const base = path_1.default.resolve(__dirname, '..', '..');
63
63
  return path_1.default.join(base, 'public', 'simulator');
64
64
  }
65
- async function serveCommand(port, noBrowser, locationFolder, appUrl) {
66
- const actualPort = port || 3334;
67
- // Attempt loading metadata (not strictly necessary for just sim, but we keep logic)
68
- // locationFolder
65
+ async function serveCommand(noBrowser, locationFolder, appUrl) {
66
+ const simulatorPort = 4041;
67
+ const simulatorExpress = (0, express_ws_1.default)((0, express_1.default)()).app;
68
+ simulatorExpress.use((0, cors_1.default)());
69
+ simulatorExpress.use(express_1.default.json());
70
+ let simulatorClient;
71
+ simulatorExpress.ws('/ws', function (ws, req) {
72
+ simulatorClient = ws;
73
+ ws.on('message', function (msg) {
74
+ console.log(msg);
75
+ });
76
+ console.log('socket', req.body);
77
+ });
78
+ const simulatorDir = getSimulatorDir();
79
+ simulatorExpress.use('/simulator', express_1.default.static(simulatorDir));
80
+ ////////////////////////////////////////////////////////////////
69
81
  let projectFolder = process.cwd();
70
82
  if (locationFolder != undefined) {
71
83
  projectFolder = path_1.default.join(process.cwd(), locationFolder);
72
84
  }
73
85
  const metadata = (0, metadata_1.loadMetadata)();
74
86
  if (!metadata) {
75
- // Not a fatal exit, but let's log a note
76
87
  console.log('[Warning] No metadata found. Skipping some possible checks.');
77
88
  }
78
- const ex = (0, express_1.default)();
79
- const ws = (0, express_ws_1.default)(ex);
80
- const app = ws.app;
81
- app.use((0, cors_1.default)());
82
- // We'll serve any local working directory as /app
83
- if (locationFolder) {
84
- app.use('/app', express_1.default.static(projectFolder));
85
- }
86
- app.use(express_1.default.json());
87
- let simulatorClient;
88
- app.ws('/ws', function (ws, req) {
89
- simulatorClient = ws;
90
- ws.on('message', function (msg) {
91
- console.log(msg);
89
+ if (appUrl != undefined) {
90
+ const proxyMiddleware = (0, http_proxy_middleware_1.createProxyMiddleware)({
91
+ xfwd: true,
92
+ target: appUrl,
93
+ changeOrigin: true,
94
+ pathFilter: '/',
92
95
  });
93
- console.log('socket', req.body);
94
- });
95
- const simulatorDir = getSimulatorDir();
96
- // Our primary route is the simulator's index.html
97
- app.get('/simulator', (_req, res) => {
98
- const indexHtml = path_1.default.join(simulatorDir, 'index.html');
99
- res.sendFile(indexHtml);
100
- });
101
- // Device image route
102
- app.get('/assets/device.png', (_req, res) => {
103
- const devicePngPath = path_1.default.join(simulatorDir, 'assets/device.png');
104
- res.sendFile(devicePngPath);
105
- });
106
- // JS bundle route (the index.umd.js in assets)
107
- app.get('/assets/device.umd.js', (_req, res) => {
108
- const deviceUmdPath = path_1.default.join(simulatorDir, 'assets/index.umd.js');
109
- res.sendFile(deviceUmdPath);
96
+ simulatorExpress.use('/', proxyMiddleware);
97
+ }
98
+ else {
99
+ simulatorExpress.use('/', express_1.default.static(projectFolder));
100
+ }
101
+ const simulatorServer = simulatorExpress.listen(simulatorPort, () => {
102
+ const url = `http://localhost:${simulatorPort}/simulator`;
103
+ console.log(`Starting simulator server at ${url}`);
104
+ if (!noBrowser) {
105
+ (0, open_1.default)(url)
106
+ .then(() => {
107
+ // success opening URL
108
+ })
109
+ .catch(err => {
110
+ console.error('Failed to open web browser', err);
111
+ });
112
+ }
110
113
  });
111
- app.post('/', async (req, res) => {
114
+ ////////////////////////////////////////////////////////////////
115
+ const airmoneyServicePort = 4040;
116
+ const airmoneyServiceExpress = (0, express_1.default)();
117
+ airmoneyServiceExpress.use((0, cors_1.default)());
118
+ airmoneyServiceExpress.use(express_1.default.json());
119
+ airmoneyServiceExpress.post('/', async (req, res) => {
112
120
  let rpcReq = req.body;
113
- console.log(rpcReq);
114
121
  let event;
115
122
  let simulator = true;
116
123
  switch (rpcReq.method) {
@@ -142,33 +149,11 @@ async function serveCommand(port, noBrowser, locationFolder, appUrl) {
142
149
  return;
143
150
  }
144
151
  });
145
- if (appUrl != undefined) {
146
- const proxyMiddleware = (0, http_proxy_middleware_1.createProxyMiddleware)({
147
- xfwd: true,
148
- target: appUrl,
149
- changeOrigin: true,
150
- pathFilter: '/',
151
- });
152
- app.use('/', proxyMiddleware);
153
- app.use('/app', (req, res, next) => {
154
- req.url = req.url.replace('/app', '/');
155
- next('route');
156
- });
157
- }
158
- // Start server
159
- const server = app.listen(actualPort, () => {
160
- const url = `http://localhost:${actualPort}/simulator`;
161
- console.log(`Starting server at ${url}`);
162
- if (!noBrowser) {
163
- (0, open_1.default)(url)
164
- .then(() => {
165
- // success opening URL
166
- })
167
- .catch(err => {
168
- console.error('Failed to open web browser', err);
169
- });
170
- }
152
+ const airmoneyServiceServer = airmoneyServiceExpress.listen(airmoneyServicePort, () => {
153
+ const url = `http://localhost:${airmoneyServicePort}`;
154
+ console.log(`Starting airmoney service server at ${url}`);
171
155
  });
156
+ ////////////////////////////////////////////////////////////////
172
157
  const cryptoServiceBin = `${process.platform}-${process.arch}`;
173
158
  const bin = path_1.default.join(__dirname, '..', 'bin', cryptoServiceBin);
174
159
  if (!(0, fs_1.existsSync)(bin)) {
package/dist/cli/setup.js CHANGED
File without changes
File without changes
File without changes
package/dist/darwin-arm64 CHANGED
File without changes
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ const program = new commander_1.Command();
14
14
  program
15
15
  .name('airmoney-cli')
16
16
  .description('airmoney-cli is a command-line interface tool designed to facilitate the development and management of decentralized applications (DApps) for Airmoney.')
17
- .version('0.8.1');
17
+ .version("0.10.1");
18
18
  program
19
19
  .command('setup')
20
20
  .description('Setup env with userAddress, apiKey, rpc')
@@ -39,13 +39,11 @@ program
39
39
  program
40
40
  .command('serve')
41
41
  .description('Serve locally in the simulator')
42
- .option('-p, --port <number>', 'Port', '4040')
43
42
  .option('-f, --index-app-path <string>', 'path for the index.html', './')
44
43
  .option('--no-browser', 'stop browser from being open')
45
44
  .option('-u, --app-url <string>', 'url where the app is running')
46
45
  .action(async (opts) => {
47
- let { portArg, indexAppPath, browser, appUrl } = opts;
48
- const port = parseInt(portArg, 10) || 4040;
46
+ let { indexAppPath, browser, appUrl } = opts;
49
47
  if (indexAppPath == './') {
50
48
  indexAppPath = undefined;
51
49
  }
@@ -53,7 +51,7 @@ program
53
51
  console.error('both --index-app-path and --app-url must not be used simuntaniusly');
54
52
  return;
55
53
  }
56
- await (0, serve_1.serveCommand)(port, !browser, indexAppPath, appUrl);
54
+ await (0, serve_1.serveCommand)(!browser, indexAppPath, appUrl);
57
55
  });
58
56
  program
59
57
  .command('wallet')
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@airmoney-degn/airmoney-cli",
3
+ "version": "0.10.0",
4
+ "description": "airmoney-cli is a command-line interface tool designed to facilitate the development and management of decentralized applications (DApps) for Airmoney.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "bin": {
9
+ "airmoney-cli": "./dist/index.js"
10
+ },
11
+ "scripts": {
12
+ "format": "prettier --write \"src/**/*\"",
13
+ "start": "tsc && cp -r bin/ dist/ && chmod -R +x dist && node dist/index.js",
14
+ "build": "tsc && cp -r bin/ dist/ && chmod -R +x dist",
15
+ "release": "npm run build && npm publish"
16
+ },
17
+ "keywords": [
18
+ "CLI"
19
+ ],
20
+ "author": "Hadi Hosseini <help@degn.com>",
21
+ "license": "MIT",
22
+ "files": [
23
+ "dist/**/*",
24
+ "public/simulator/**/*"
25
+ ],
26
+ "dependencies": {
27
+ "@solana/signers": "2.1.1",
28
+ "@solana/web3.js": "1.98.2",
29
+ "base64-js": "^1.5.1",
30
+ "bs58": "5.0.0",
31
+ "commander": "^11.0.0",
32
+ "cors": "^2.8.5",
33
+ "dotenv": "^16.3.1",
34
+ "ethers": "6.14.3",
35
+ "expres": "^0.0.5",
36
+ "express": "^4.21.2",
37
+ "express-http-proxy": "^2.1.1",
38
+ "express-ws": "^5.0.2",
39
+ "form-data": "^4.0.0",
40
+ "http-proxy-middleware": "^3.0.3",
41
+ "inquirer": "^8.0.0",
42
+ "md5": "^2.3.0",
43
+ "node-fetch": "^2.6.7",
44
+ "open": "^8.4.0",
45
+ "tar": "^6.1.13",
46
+ "websocket": "^1.0.35",
47
+ "ws": "^8.18.1"
48
+ },
49
+ "devDependencies": {
50
+ "@airmoney-degn/controller-sdk": "^5.4.1",
51
+ "@types/bs58": "5.0.0",
52
+ "@types/cors": "^2.8.17",
53
+ "@types/express": "^5.0.0",
54
+ "@types/express-http-proxy": "^1.6.6",
55
+ "@types/express-ws": "^3.0.5",
56
+ "@types/inquirer": "^8.1.3",
57
+ "@types/md5": "^2.3.2",
58
+ "@types/node": "^18.19.70",
59
+ "@types/node-fetch": "^2.6.12",
60
+ "@types/tar": "^6.1.13",
61
+ "@types/websocket": "^1.0.10",
62
+ "prettier": "^3.6.1",
63
+ "typescript": "^5.0.4"
64
+ }
65
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createCommand = createCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const types_1 = require("../types");
40
+ const child_process_1 = require("child_process");
41
+ /**
42
+ * Command for creating a new project.
43
+ * Now no longer requires userId + apiKey from caller;
44
+ * it will read them from environment variables:
45
+ * process.env.DEVELOPER_ADDRESS
46
+ * process.env.API_KEY
47
+ */
48
+ async function createCommand(name, network, template, locationFolder) {
49
+ // read from env (the .env was placed in config by `setup`).
50
+ const userId = process.env.DEVELOPER_ADDRESS || '';
51
+ const apiKey = process.env.API_KEY || '';
52
+ if (!userId || !apiKey) {
53
+ console.error("Missing user or API key from env. Did you run 'airmoney-cli setup'?");
54
+ process.exit(1);
55
+ }
56
+ const identifier = `com.degn.${name}`;
57
+ console.log(`Initializing project: ${name} (network=${network})`);
58
+ console.log(`Using .env user: ${userId}`);
59
+ const folderName = locationFolder || name;
60
+ const projectPath = path.join(process.cwd(), folderName);
61
+ if (template) {
62
+ console.log('cloning project');
63
+ (0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/Air-Money/airmoney-dapp-quickstart ${folderName}`);
64
+ if (fs.lstatSync(path.join(projectPath, '.git')).isDirectory()) {
65
+ fs.rmdirSync(path.join(projectPath, '.git'));
66
+ }
67
+ else {
68
+ fs.rmSync(path.join(projectPath, '.git'));
69
+ }
70
+ }
71
+ else {
72
+ fs.mkdirSync(projectPath, { recursive: true });
73
+ // replicate Rust logic
74
+ const indexHtml = `
75
+ <html>
76
+ <head>
77
+ <title>Sample ${name}</title>
78
+ </head>
79
+ <body>
80
+ <p>Hello from ${name}</p>
81
+ </body>
82
+ </html>
83
+ `.trim();
84
+ fs.writeFileSync(path.join(projectPath, 'index.html'), indexHtml, 'utf8');
85
+ // assets
86
+ const assetsDir = path.join(projectPath, 'assets');
87
+ fs.mkdirSync(assetsDir, { recursive: true });
88
+ fs.writeFileSync(path.join(assetsDir, 'main.js'), '// sample main.js\n', 'utf8');
89
+ fs.writeFileSync(path.join(assetsDir, 'style.css'), '/* sample style.css */\n', 'utf8');
90
+ }
91
+ // metadata
92
+ const pkg = (0, types_1.createPackage)(name, identifier);
93
+ const metaStr = JSON.stringify(pkg, null, 2);
94
+ fs.writeFileSync(path.join(projectPath, 'metadata.json'), metaStr, 'utf8');
95
+ console.log(`Project '${name}' created successfully.`);
96
+ console.log(`\nNext steps:`);
97
+ console.log(` cd ${name}`);
98
+ if (template) {
99
+ console.log(' npm install');
100
+ console.log(` npm run serve`);
101
+ }
102
+ else {
103
+ console.log(' airmoney-cli serve');
104
+ }
105
+ }
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.serveCommand = serveCommand;
40
+ const path_1 = __importDefault(require("path"));
41
+ const open_1 = __importDefault(require("open"));
42
+ // var cors = require('cors')
43
+ // import * as cors from "cors"
44
+ const cors_1 = __importDefault(require("cors"));
45
+ const express_1 = __importDefault(require("express"));
46
+ const express_ws_1 = __importDefault(require("express-ws"));
47
+ const metadata_1 = require("../util/metadata");
48
+ const server_1 = require("../util/server");
49
+ const http_proxy_middleware_1 = require("http-proxy-middleware");
50
+ const ChildProcess = __importStar(require("child_process"));
51
+ const fs_1 = require("fs");
52
+ const env_1 = require("../util/env");
53
+ /**
54
+ * Helper to get the path to the "public/simulator" folder
55
+ * from the distributed code. We use __dirname, then move
56
+ * up two levels to the project root, then into public/simulator.
57
+ */
58
+ function getSimulatorDir() {
59
+ // after tsc compile, serve.js is in dist/cli/
60
+ // we step up two dirs to get back to the project root
61
+ // then go into public/simulator
62
+ const base = path_1.default.resolve(__dirname, '..', '..');
63
+ return path_1.default.join(base, 'public', 'simulator');
64
+ }
65
+ async function serveCommand(noBrowser, locationFolder, appUrl) {
66
+ const simulatorPort = 4041;
67
+ const simulatorExpress = (0, express_ws_1.default)((0, express_1.default)()).app;
68
+ simulatorExpress.use((0, cors_1.default)());
69
+ simulatorExpress.use(express_1.default.json());
70
+ let simulatorClient;
71
+ simulatorExpress.ws('/ws', function (ws, req) {
72
+ simulatorClient = ws;
73
+ ws.on('message', function (msg) {
74
+ console.log(msg);
75
+ });
76
+ console.log('socket', req.body);
77
+ });
78
+ const simulatorDir = getSimulatorDir();
79
+ simulatorExpress.use('/simulator', express_1.default.static(simulatorDir));
80
+ ////////////////////////////////////////////////////////////////
81
+ let projectFolder = process.cwd();
82
+ if (locationFolder != undefined) {
83
+ projectFolder = path_1.default.join(process.cwd(), locationFolder);
84
+ }
85
+ const metadata = (0, metadata_1.loadMetadata)();
86
+ if (!metadata) {
87
+ console.log('[Warning] No metadata found. Skipping some possible checks.');
88
+ }
89
+ if (appUrl != undefined) {
90
+ const proxyMiddleware = (0, http_proxy_middleware_1.createProxyMiddleware)({
91
+ xfwd: true,
92
+ target: appUrl,
93
+ changeOrigin: true,
94
+ pathFilter: '/',
95
+ });
96
+ simulatorExpress.use('/', proxyMiddleware);
97
+ }
98
+ else {
99
+ simulatorExpress.use('/', express_1.default.static(projectFolder));
100
+ }
101
+ const simulatorServer = simulatorExpress.listen(simulatorPort, () => {
102
+ const url = `http://localhost:${simulatorPort}/simulator`;
103
+ console.log(`Starting simulator server at ${url}`);
104
+ if (!noBrowser) {
105
+ (0, open_1.default)(url)
106
+ .then(() => {
107
+ // success opening URL
108
+ })
109
+ .catch(err => {
110
+ console.error('Failed to open web browser', err);
111
+ });
112
+ }
113
+ });
114
+ ////////////////////////////////////////////////////////////////
115
+ const airmoneyServicePort = 4040;
116
+ const airmoneyServiceExpress = (0, express_1.default)();
117
+ airmoneyServiceExpress.use((0, cors_1.default)());
118
+ airmoneyServiceExpress.use(express_1.default.json());
119
+ airmoneyServiceExpress.post('/', async (req, res) => {
120
+ let rpcReq = req.body;
121
+ let event;
122
+ let simulator = true;
123
+ switch (rpcReq.method) {
124
+ case 'setImage':
125
+ case 'setAnimate':
126
+ event = (0, server_1.displayImage)(rpcReq, metadata.name);
127
+ break;
128
+ }
129
+ if (simulator) {
130
+ if (event != null) {
131
+ if (simulatorClient) {
132
+ simulatorClient.send(JSON.stringify(event));
133
+ res.status(200).json({ success: true });
134
+ return;
135
+ }
136
+ else {
137
+ console.log('Warning: No simulator client connected');
138
+ res.status(503).json({ error: 'Simulator not connected' });
139
+ return;
140
+ }
141
+ }
142
+ else {
143
+ res.status(500).json({ error: 'Failed to process request' });
144
+ return;
145
+ }
146
+ }
147
+ else {
148
+ res.json({ jsonrpc: '2.0', result: event, id: 1 });
149
+ return;
150
+ }
151
+ });
152
+ const airmoneyServiceServer = airmoneyServiceExpress.listen(airmoneyServicePort, () => {
153
+ const url = `http://localhost:${airmoneyServicePort}`;
154
+ console.log(`Starting airmoney service server at ${url}`);
155
+ });
156
+ ////////////////////////////////////////////////////////////////
157
+ const cryptoServiceBin = `${process.platform}-${process.arch}`;
158
+ const bin = path_1.default.join(__dirname, '..', 'bin', cryptoServiceBin);
159
+ if (!(0, fs_1.existsSync)(bin)) {
160
+ console.log('crypto service not found at ' + bin);
161
+ }
162
+ else {
163
+ ChildProcess.exec(bin, { env: { SECURE_STORAGE: (0, env_1.configDir)() } });
164
+ }
165
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.setupCommand = setupCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const env_1 = require("../util/env");
40
+ async function setupCommand(network, userId, apiKey) {
41
+ const dir = (0, env_1.configDir)();
42
+ if (!dir)
43
+ return;
44
+ // ensure directory
45
+ fs.mkdirSync(dir, { recursive: true });
46
+ const envPath = path.join(dir, '.env');
47
+ try {
48
+ fs.writeFileSync(envPath, `DEVELOPER_ADDRESS=${userId}\nAPI_KEY=${apiKey}\nRPC=${network}\n`, 'utf8');
49
+ console.log(`.env created at ${envPath}`);
50
+ }
51
+ catch (err) {
52
+ console.error(`error when writing .env to ${envPath}`);
53
+ console.error(err);
54
+ process.exit(1);
55
+ }
56
+ }