@mastra/deployer 0.3.0-alpha.4 → 0.3.0-alpha.5

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.
@@ -80,8 +80,9 @@ export declare abstract class Bundler extends MastraBundler {
80
80
  }>;
81
81
  protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
82
82
  protected copyPublic(mastraDir: string, outputDirectory: string): Promise<void>;
83
- protected getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>): Promise<InputOptions>;
84
- protected _bundle(serverFile: string, mastraEntryFile: string, outputDirectory: string, bundleLocation?: string): Promise<void>;
83
+ protected getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
84
+ getToolsInputOptions(toolsPaths: string[]): Promise<Record<string, string>>;
85
+ protected _bundle(serverFile: string, mastraEntryFile: string, outputDirectory: string, toolsPaths?: string[], bundleLocation?: string): Promise<void>;
85
86
  }
86
87
 
87
88
  declare function createBundler(inputOptions: InputOptions, outputOptions: Partial<OutputOptions> & {
@@ -80,8 +80,9 @@ export declare abstract class Bundler extends MastraBundler {
80
80
  }>;
81
81
  protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
82
82
  protected copyPublic(mastraDir: string, outputDirectory: string): Promise<void>;
83
- protected getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>): Promise<InputOptions>;
84
- protected _bundle(serverFile: string, mastraEntryFile: string, outputDirectory: string, bundleLocation?: string): Promise<void>;
83
+ protected getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
84
+ getToolsInputOptions(toolsPaths: string[]): Promise<Record<string, string>>;
85
+ protected _bundle(serverFile: string, mastraEntryFile: string, outputDirectory: string, toolsPaths?: string[], bundleLocation?: string): Promise<void>;
85
86
  }
86
87
 
87
88
  declare function createBundler(inputOptions: InputOptions, outputOptions: Partial<OutputOptions> & {
@@ -4,8 +4,7 @@ var chunkYSFP3CY7_cjs = require('../chunk-YSFP3CY7.cjs');
4
4
  var chunk2ZPQX6BX_cjs = require('../chunk-2ZPQX6BX.cjs');
5
5
  var chunkLA6Y6GAB_cjs = require('../chunk-LA6Y6GAB.cjs');
6
6
  var chunkAE4CVAPK_cjs = require('../chunk-AE4CVAPK.cjs');
7
- var chunkNCROGJGB_cjs = require('../chunk-NCROGJGB.cjs');
8
- var chunkTHU6NH7X_cjs = require('../chunk-THU6NH7X.cjs');
7
+ var chunkRPH27LI6_cjs = require('../chunk-RPH27LI6.cjs');
9
8
 
10
9
 
11
10
 
@@ -37,11 +36,11 @@ Object.defineProperty(exports, "getBundlerInputOptions", {
37
36
  enumerable: true,
38
37
  get: function () { return chunkAE4CVAPK_cjs.getInputOptions; }
39
38
  });
40
- Object.defineProperty(exports, "FileService", {
39
+ Object.defineProperty(exports, "Deps", {
41
40
  enumerable: true,
42
- get: function () { return chunkNCROGJGB_cjs.FileService; }
41
+ get: function () { return chunkRPH27LI6_cjs.Deps; }
43
42
  });
44
- Object.defineProperty(exports, "Deps", {
43
+ Object.defineProperty(exports, "FileService", {
45
44
  enumerable: true,
46
- get: function () { return chunkTHU6NH7X_cjs.Deps; }
45
+ get: function () { return chunkRPH27LI6_cjs.FileService; }
47
46
  });
@@ -2,5 +2,4 @@ export { createWatcher, getServerOptions, getInputOptions as getWatcherInputOpti
2
2
  export { writeTelemetryConfig } from '../chunk-4AYFLP6G.js';
3
3
  export { analyzeBundle } from '../chunk-USZDOFES.js';
4
4
  export { createBundler, getInputOptions as getBundlerInputOptions } from '../chunk-IKPL4RGG.js';
5
- export { FileService } from '../chunk-DYQ225MJ.js';
6
- export { Deps } from '../chunk-P7ZN2KUE.js';
5
+ export { Deps, FileService } from '../chunk-OJI4SKSV.js';
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkBDAX7X52_cjs = require('../chunk-BDAX7X52.cjs');
3
+ var chunkKSYXZYYB_cjs = require('../chunk-KSYXZYYB.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "Bundler", {
8
8
  enumerable: true,
9
- get: function () { return chunkBDAX7X52_cjs.Bundler; }
9
+ get: function () { return chunkKSYXZYYB_cjs.Bundler; }
10
10
  });
@@ -1 +1 @@
1
- export { Bundler } from '../chunk-UUEHIAGW.js';
1
+ export { Bundler } from '../chunk-54TB2QKS.js';
@@ -1,14 +1,14 @@
1
1
  import { writeTelemetryConfig } from './chunk-4AYFLP6G.js';
2
2
  import { analyzeBundle } from './chunk-USZDOFES.js';
3
3
  import { createBundler, getInputOptions } from './chunk-IKPL4RGG.js';
4
- import { DepsService } from './chunk-P7ZN2KUE.js';
4
+ import { DepsService, FileService } from './chunk-OJI4SKSV.js';
5
5
  import { existsSync } from 'node:fs';
6
6
  import { writeFile, stat } from 'node:fs/promises';
7
7
  import { join, dirname } from 'node:path';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { MastraBundler } from '@mastra/core/bundler';
10
10
  import virtual from '@rollup/plugin-virtual';
11
- import { emptyDir, ensureDir, copy, readJSON } from 'fs-extra/esm';
11
+ import fsExtra, { emptyDir, ensureDir, copy, readJSON } from 'fs-extra/esm';
12
12
  import resolveFrom from 'resolve-from';
13
13
 
14
14
  var Bundler = class extends MastraBundler {
@@ -82,22 +82,46 @@ var Bundler = class extends MastraBundler {
82
82
  }
83
83
  await copy(publicDir, join(outputDirectory, this.outputDir));
84
84
  }
85
- async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
85
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
86
86
  const inputOptions = await getInputOptions(mastraEntryFile, analyzedBundleInfo, "node");
87
87
  const isVirtual = serverFile.includes("\n") || existsSync(serverFile);
88
+ const toolsInputOptions = await this.getToolsInputOptions(toolsPaths);
88
89
  if (isVirtual) {
89
- inputOptions.input = { index: "#entry" };
90
+ inputOptions.input = { index: "#entry", ...toolsInputOptions };
90
91
  if (Array.isArray(inputOptions.plugins)) {
91
92
  inputOptions.plugins.unshift(virtual({ "#entry": serverFile }));
92
93
  } else {
93
94
  inputOptions.plugins = [virtual({ "#entry": serverFile })];
94
95
  }
95
96
  } else {
96
- inputOptions.input = { index: serverFile };
97
+ inputOptions.input = { index: serverFile, ...toolsInputOptions };
97
98
  }
98
99
  return inputOptions;
99
100
  }
100
- async _bundle(serverFile, mastraEntryFile, outputDirectory, bundleLocation = join(outputDirectory, this.outputDir)) {
101
+ async getToolsInputOptions(toolsPaths) {
102
+ const inputs = {};
103
+ for (const toolPath of toolsPaths) {
104
+ if (await fsExtra.pathExists(toolPath)) {
105
+ const fileService = new FileService();
106
+ const entryFile = fileService.getFirstExistingFile([
107
+ join(toolPath, "index.ts"),
108
+ join(toolPath, "index.js"),
109
+ toolPath
110
+ // if toolPath itself is a file
111
+ ]);
112
+ if (!entryFile || (await stat(entryFile)).isDirectory()) {
113
+ this.logger.warn(`No entry file found in ${toolPath}, skipping...`);
114
+ continue;
115
+ }
116
+ const uniqueToolID = crypto.randomUUID();
117
+ inputs[`tools/${uniqueToolID}`] = entryFile;
118
+ } else {
119
+ this.logger.warn(`Tool path ${toolPath} does not exist, skipping...`);
120
+ }
121
+ }
122
+ return inputs;
123
+ }
124
+ async _bundle(serverFile, mastraEntryFile, outputDirectory, toolsPaths = [], bundleLocation = join(outputDirectory, this.outputDir)) {
101
125
  this.logger.info("Start bundling Mastra");
102
126
  const analyzedBundleInfo = await analyzeBundle(
103
127
  serverFile,
@@ -123,7 +147,12 @@ var Bundler = class extends MastraBundler {
123
147
  await this.writePackageJson(join(outputDirectory, this.outputDir), dependenciesToInstall);
124
148
  await this.writeInstrumentationFile(join(outputDirectory, this.outputDir));
125
149
  this.logger.info("Bundling Mastra application");
126
- const inputOptions = await this.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
150
+ const inputOptions = await this.getBundlerOptions(
151
+ serverFile,
152
+ mastraEntryFile,
153
+ analyzedBundleInfo,
154
+ toolsPaths
155
+ );
127
156
  const bundler = await this.createBundler(inputOptions, {
128
157
  dir: bundleLocation,
129
158
  manualChunks: {
@@ -131,6 +160,11 @@ var Bundler = class extends MastraBundler {
131
160
  }
132
161
  });
133
162
  await bundler.write();
163
+ const toolsInputOptions = Array.from(Object.keys(inputOptions.input || {})).filter((key) => key.startsWith("tools/")).map((key) => `./${key}.mjs`);
164
+ await writeFile(
165
+ join(outputDirectory, this.outputDir, "tools.mjs"),
166
+ `export const tools = ${JSON.stringify(toolsInputOptions)};`
167
+ );
134
168
  this.logger.info("Bundling Mastra done");
135
169
  this.logger.info("Copying public files");
136
170
  await this.copyPublic(dirname(mastraEntryFile), outputDirectory);
@@ -3,20 +3,21 @@
3
3
  var chunk2ZPQX6BX_cjs = require('./chunk-2ZPQX6BX.cjs');
4
4
  var chunkLA6Y6GAB_cjs = require('./chunk-LA6Y6GAB.cjs');
5
5
  var chunkAE4CVAPK_cjs = require('./chunk-AE4CVAPK.cjs');
6
- var chunkTHU6NH7X_cjs = require('./chunk-THU6NH7X.cjs');
6
+ var chunkRPH27LI6_cjs = require('./chunk-RPH27LI6.cjs');
7
7
  var fs = require('fs');
8
8
  var promises = require('fs/promises');
9
9
  var path = require('path');
10
10
  var url = require('url');
11
11
  var bundler = require('@mastra/core/bundler');
12
12
  var virtual = require('@rollup/plugin-virtual');
13
- var esm = require('fs-extra/esm');
13
+ var fsExtra = require('fs-extra/esm');
14
14
  var resolveFrom = require('resolve-from');
15
15
 
16
16
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
17
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
18
 
19
19
  var virtual__default = /*#__PURE__*/_interopDefault(virtual);
20
+ var fsExtra__default = /*#__PURE__*/_interopDefault(fsExtra);
20
21
  var resolveFrom__default = /*#__PURE__*/_interopDefault(resolveFrom);
21
22
 
22
23
  var Bundler = class extends bundler.MastraBundler {
@@ -26,18 +27,18 @@ var Bundler = class extends bundler.MastraBundler {
26
27
  super({ name, component });
27
28
  }
28
29
  async prepare(outputDirectory) {
29
- await esm.emptyDir(outputDirectory);
30
- await esm.ensureDir(path.join(outputDirectory, this.analyzeOutputDir));
31
- await esm.ensureDir(path.join(outputDirectory, this.outputDir));
30
+ await fsExtra.emptyDir(outputDirectory);
31
+ await fsExtra.ensureDir(path.join(outputDirectory, this.analyzeOutputDir));
32
+ await fsExtra.ensureDir(path.join(outputDirectory, this.outputDir));
32
33
  }
33
34
  async writeInstrumentationFile(outputDirectory) {
34
35
  const instrumentationFile = path.join(outputDirectory, "instrumentation.mjs");
35
- const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-BDAX7X52.cjs', document.baseURI).href))));
36
- await esm.copy(path.join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
36
+ const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-KSYXZYYB.cjs', document.baseURI).href))));
37
+ await fsExtra.copy(path.join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
37
38
  }
38
39
  async writePackageJson(outputDirectory, dependencies) {
39
40
  this.logger.debug(`Writing project's package.json`);
40
- await esm.ensureDir(outputDirectory);
41
+ await fsExtra.ensureDir(outputDirectory);
41
42
  const pkgPath = path.join(outputDirectory, "package.json");
42
43
  const dependenciesMap = /* @__PURE__ */ new Map();
43
44
  for (const [key, value] of dependencies.entries()) {
@@ -77,7 +78,7 @@ var Bundler = class extends bundler.MastraBundler {
77
78
  return await chunkLA6Y6GAB_cjs.analyzeBundle(entry, mastraFile, path.join(outputDirectory, this.analyzeOutputDir), "node", this.logger);
78
79
  }
79
80
  async installDependencies(outputDirectory, rootDir = process.cwd()) {
80
- const deps = new chunkTHU6NH7X_cjs.DepsService(rootDir);
81
+ const deps = new chunkRPH27LI6_cjs.DepsService(rootDir);
81
82
  deps.__setLogger(this.logger);
82
83
  await deps.install({ dir: path.join(outputDirectory, this.outputDir) });
83
84
  }
@@ -88,24 +89,48 @@ var Bundler = class extends bundler.MastraBundler {
88
89
  } catch {
89
90
  return;
90
91
  }
91
- await esm.copy(publicDir, path.join(outputDirectory, this.outputDir));
92
+ await fsExtra.copy(publicDir, path.join(outputDirectory, this.outputDir));
92
93
  }
93
- async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
94
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
94
95
  const inputOptions = await chunkAE4CVAPK_cjs.getInputOptions(mastraEntryFile, analyzedBundleInfo, "node");
95
96
  const isVirtual = serverFile.includes("\n") || fs.existsSync(serverFile);
97
+ const toolsInputOptions = await this.getToolsInputOptions(toolsPaths);
96
98
  if (isVirtual) {
97
- inputOptions.input = { index: "#entry" };
99
+ inputOptions.input = { index: "#entry", ...toolsInputOptions };
98
100
  if (Array.isArray(inputOptions.plugins)) {
99
101
  inputOptions.plugins.unshift(virtual__default.default({ "#entry": serverFile }));
100
102
  } else {
101
103
  inputOptions.plugins = [virtual__default.default({ "#entry": serverFile })];
102
104
  }
103
105
  } else {
104
- inputOptions.input = { index: serverFile };
106
+ inputOptions.input = { index: serverFile, ...toolsInputOptions };
105
107
  }
106
108
  return inputOptions;
107
109
  }
108
- async _bundle(serverFile, mastraEntryFile, outputDirectory, bundleLocation = path.join(outputDirectory, this.outputDir)) {
110
+ async getToolsInputOptions(toolsPaths) {
111
+ const inputs = {};
112
+ for (const toolPath of toolsPaths) {
113
+ if (await fsExtra__default.default.pathExists(toolPath)) {
114
+ const fileService = new chunkRPH27LI6_cjs.FileService();
115
+ const entryFile = fileService.getFirstExistingFile([
116
+ path.join(toolPath, "index.ts"),
117
+ path.join(toolPath, "index.js"),
118
+ toolPath
119
+ // if toolPath itself is a file
120
+ ]);
121
+ if (!entryFile || (await promises.stat(entryFile)).isDirectory()) {
122
+ this.logger.warn(`No entry file found in ${toolPath}, skipping...`);
123
+ continue;
124
+ }
125
+ const uniqueToolID = crypto.randomUUID();
126
+ inputs[`tools/${uniqueToolID}`] = entryFile;
127
+ } else {
128
+ this.logger.warn(`Tool path ${toolPath} does not exist, skipping...`);
129
+ }
130
+ }
131
+ return inputs;
132
+ }
133
+ async _bundle(serverFile, mastraEntryFile, outputDirectory, toolsPaths = [], bundleLocation = path.join(outputDirectory, this.outputDir)) {
109
134
  this.logger.info("Start bundling Mastra");
110
135
  const analyzedBundleInfo = await chunkLA6Y6GAB_cjs.analyzeBundle(
111
136
  serverFile,
@@ -119,7 +144,7 @@ var Bundler = class extends bundler.MastraBundler {
119
144
  for (const dep of analyzedBundleInfo.externalDependencies) {
120
145
  try {
121
146
  const pkgPath = resolveFrom__default.default(mastraEntryFile, `${dep}/package.json`);
122
- const pkg = await esm.readJSON(pkgPath);
147
+ const pkg = await fsExtra.readJSON(pkgPath);
123
148
  dependenciesToInstall.set(dep, pkg.version);
124
149
  } catch {
125
150
  dependenciesToInstall.set(dep, "latest");
@@ -131,7 +156,12 @@ var Bundler = class extends bundler.MastraBundler {
131
156
  await this.writePackageJson(path.join(outputDirectory, this.outputDir), dependenciesToInstall);
132
157
  await this.writeInstrumentationFile(path.join(outputDirectory, this.outputDir));
133
158
  this.logger.info("Bundling Mastra application");
134
- const inputOptions = await this.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
159
+ const inputOptions = await this.getBundlerOptions(
160
+ serverFile,
161
+ mastraEntryFile,
162
+ analyzedBundleInfo,
163
+ toolsPaths
164
+ );
135
165
  const bundler = await this.createBundler(inputOptions, {
136
166
  dir: bundleLocation,
137
167
  manualChunks: {
@@ -139,6 +169,11 @@ var Bundler = class extends bundler.MastraBundler {
139
169
  }
140
170
  });
141
171
  await bundler.write();
172
+ const toolsInputOptions = Array.from(Object.keys(inputOptions.input || {})).filter((key) => key.startsWith("tools/")).map((key) => `./${key}.mjs`);
173
+ await promises.writeFile(
174
+ path.join(outputDirectory, this.outputDir, "tools.mjs"),
175
+ `export const tools = ${JSON.stringify(toolsInputOptions)};`
176
+ );
142
177
  this.logger.info("Bundling Mastra done");
143
178
  this.logger.info("Copying public files");
144
179
  await this.copyPublic(path.dirname(mastraEntryFile), outputDirectory);
@@ -1,11 +1,12 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { Transform } from 'stream';
3
- import fs from 'fs';
3
+ import * as fs3 from 'fs';
4
+ import fs3__default from 'fs';
4
5
  import fsPromises from 'fs/promises';
5
6
  import path, { dirname } from 'path';
6
7
  import { fileURLToPath } from 'url';
7
8
  import { MastraBase } from '@mastra/core/base';
8
- import { readJSON, writeJSON, ensureFile } from 'fs-extra/esm';
9
+ import fsExtra, { readJSON, writeJSON, ensureFile } from 'fs-extra/esm';
9
10
 
10
11
  // src/deploy/log.ts
11
12
  var createPinoStream = (logger) => {
@@ -65,7 +66,7 @@ var Deps = class extends MastraBase {
65
66
  findLockFile(dir) {
66
67
  const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
67
68
  for (const file of lockFiles) {
68
- if (fs.existsSync(path.join(dir, file))) {
69
+ if (fs3__default.existsSync(path.join(dir, file))) {
69
70
  return file;
70
71
  }
71
72
  }
@@ -232,5 +233,111 @@ ${Object.entries(config.supportedArchitectures).map(([key, value]) => ` ${key}:
232
233
  };
233
234
  var DepsService = class extends Deps {
234
235
  };
236
+ var EnvService = class {
237
+ };
238
+ var FileEnvService = class extends EnvService {
239
+ filePath;
240
+ constructor(filePath) {
241
+ super();
242
+ this.filePath = filePath;
243
+ }
244
+ readFile(filePath) {
245
+ return new Promise((resolve, reject) => {
246
+ fs3.readFile(filePath, "utf8", (err, data) => {
247
+ if (err) reject(err);
248
+ else resolve(data);
249
+ });
250
+ });
251
+ }
252
+ writeFile({ filePath, data }) {
253
+ return new Promise((resolve, reject) => {
254
+ fs3.writeFile(filePath, data, "utf8", (err) => {
255
+ if (err) reject(err);
256
+ else resolve();
257
+ });
258
+ });
259
+ }
260
+ async updateEnvData({
261
+ key,
262
+ value,
263
+ filePath = this.filePath,
264
+ data
265
+ }) {
266
+ const regex = new RegExp(`^${key}=.*$`, "m");
267
+ if (data.match(regex)) {
268
+ data = data.replace(regex, `${key}=${value}`);
269
+ } else {
270
+ data += `
271
+ ${key}=${value}`;
272
+ }
273
+ await this.writeFile({ filePath, data });
274
+ console.log(`${key} set to ${value} in ENV file.`);
275
+ return data;
276
+ }
277
+ async getEnvValue(key) {
278
+ try {
279
+ const data = await this.readFile(this.filePath);
280
+ const regex = new RegExp(`^${key}=(.*)$`, "m");
281
+ const match = data.match(regex);
282
+ return match?.[1] || null;
283
+ } catch (err) {
284
+ console.error(`Error reading ENV value: ${err}`);
285
+ return null;
286
+ }
287
+ }
288
+ async setEnvValue(key, value) {
289
+ try {
290
+ const data = await this.readFile(this.filePath);
291
+ await this.updateEnvData({ key, value, data });
292
+ } catch (err) {
293
+ console.error(`Error writing ENV value: ${err}`);
294
+ }
295
+ }
296
+ };
297
+ var FileService = class {
298
+ /**
299
+ *
300
+ * @param inputFile the file in the starter files directory to copy
301
+ * @param outputFilePath the destination path
302
+ * @param replaceIfExists flag to replace if it exists
303
+ * @returns
304
+ */
305
+ async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
306
+ const __filename = fileURLToPath(import.meta.url);
307
+ const __dirname = path.dirname(__filename);
308
+ const filePath = path.resolve(__dirname, "..", "starter-files", inputFile);
309
+ const fileString = fs3__default.readFileSync(filePath, "utf8");
310
+ if (fs3__default.existsSync(outputFilePath) && !replaceIfExists) {
311
+ console.log(`${outputFilePath} already exists`);
312
+ return false;
313
+ }
314
+ await fsExtra.outputFile(outputFilePath, fileString);
315
+ return true;
316
+ }
317
+ async setupEnvFile({ dbUrl }) {
318
+ const envPath = path.join(process.cwd(), ".env.development");
319
+ await fsExtra.ensureFile(envPath);
320
+ const fileEnvService = new FileEnvService(envPath);
321
+ await fileEnvService.setEnvValue("DB_URL", dbUrl);
322
+ }
323
+ getFirstExistingFile(files) {
324
+ for (const f of files) {
325
+ if (fs3__default.existsSync(f)) {
326
+ return f;
327
+ }
328
+ }
329
+ throw new Error("Missing required file, checked the following paths: " + files.join(", "));
330
+ }
331
+ replaceValuesInFile({
332
+ filePath,
333
+ replacements
334
+ }) {
335
+ let fileContent = fs3__default.readFileSync(filePath, "utf8");
336
+ replacements.forEach(({ search, replace }) => {
337
+ fileContent = fileContent.replaceAll(search, replace);
338
+ });
339
+ fs3__default.writeFileSync(filePath, fileContent);
340
+ }
341
+ };
235
342
 
236
- export { Deps, DepsService, createChildProcessLogger, createPinoStream };
343
+ export { Deps, DepsService, EnvService, FileService, createChildProcessLogger, createPinoStream };
@@ -2,19 +2,38 @@
2
2
 
3
3
  var child_process = require('child_process');
4
4
  var stream = require('stream');
5
- var fs = require('fs');
5
+ var fs3 = require('fs');
6
6
  var fsPromises = require('fs/promises');
7
7
  var path = require('path');
8
8
  var url = require('url');
9
9
  var base = require('@mastra/core/base');
10
- var esm = require('fs-extra/esm');
10
+ var fsExtra = require('fs-extra/esm');
11
11
 
12
12
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
- var fs__default = /*#__PURE__*/_interopDefault(fs);
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
16
34
  var fsPromises__default = /*#__PURE__*/_interopDefault(fsPromises);
17
35
  var path__default = /*#__PURE__*/_interopDefault(path);
36
+ var fsExtra__default = /*#__PURE__*/_interopDefault(fsExtra);
18
37
 
19
38
  // src/deploy/log.ts
20
39
  var createPinoStream = (logger) => {
@@ -74,7 +93,7 @@ var Deps = class extends base.MastraBase {
74
93
  findLockFile(dir) {
75
94
  const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
76
95
  for (const file of lockFiles) {
77
- if (fs__default.default.existsSync(path__default.default.join(dir, file))) {
96
+ if (fs3__namespace.default.existsSync(path__default.default.join(dir, file))) {
78
97
  return file;
79
98
  }
80
99
  }
@@ -101,7 +120,7 @@ var Deps = class extends base.MastraBase {
101
120
  }
102
121
  async writePnpmConfig(dir, options) {
103
122
  const packageJsonPath = path__default.default.join(dir, "package.json");
104
- const packageJson = await esm.readJSON(packageJsonPath);
123
+ const packageJson = await fsExtra.readJSON(packageJsonPath);
105
124
  packageJson.pnpm = {
106
125
  ...packageJson.pnpm,
107
126
  supportedArchitectures: {
@@ -110,7 +129,7 @@ var Deps = class extends base.MastraBase {
110
129
  libc: options.libc || []
111
130
  }
112
131
  };
113
- await esm.writeJSON(packageJsonPath, packageJson, { spaces: 2 });
132
+ await fsExtra.writeJSON(packageJsonPath, packageJson, { spaces: 2 });
114
133
  }
115
134
  async writeYarnConfig(dir, options) {
116
135
  const yarnrcPath = path__default.default.join(dir, ".yarnrc.yml");
@@ -148,7 +167,7 @@ ${Object.entries(config.supportedArchitectures).map(([key, value]) => ` ${key}:
148
167
  }
149
168
  break;
150
169
  case "yarn":
151
- await esm.ensureFile(path__default.default.join(dir, "yarn.lock"));
170
+ await fsExtra.ensureFile(path__default.default.join(dir, "yarn.lock"));
152
171
  if (architecture) {
153
172
  await this.writeYarnConfig(dir, architecture);
154
173
  }
@@ -202,7 +221,7 @@ ${Object.entries(config.supportedArchitectures).map(([key, value]) => ` ${key}:
202
221
  } catch {
203
222
  return "No package.json file found in the current directory";
204
223
  }
205
- const packageJson = await esm.readJSON(packageJsonPath);
224
+ const packageJson = await fsExtra.readJSON(packageJsonPath);
206
225
  for (const dependency of dependencies) {
207
226
  if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
208
227
  return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
@@ -217,32 +236,140 @@ ${Object.entries(config.supportedArchitectures).map(([key, value]) => ` ${key}:
217
236
  async getProjectName() {
218
237
  try {
219
238
  const packageJsonPath = path__default.default.join(this.rootDir, "package.json");
220
- const pkg = await esm.readJSON(packageJsonPath);
239
+ const pkg = await fsExtra.readJSON(packageJsonPath);
221
240
  return pkg.name;
222
241
  } catch (err) {
223
242
  throw err;
224
243
  }
225
244
  }
226
245
  async getPackageVersion() {
227
- const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-THU6NH7X.cjs', document.baseURI).href)));
246
+ const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-RPH27LI6.cjs', document.baseURI).href)));
228
247
  const __dirname = path.dirname(__filename);
229
248
  const pkgJsonPath = path__default.default.join(__dirname, "..", "..", "package.json");
230
- const content = await esm.readJSON(pkgJsonPath);
249
+ const content = await fsExtra.readJSON(pkgJsonPath);
231
250
  return content.version;
232
251
  }
233
252
  async addScriptsToPackageJson(scripts) {
234
- const packageJson = await esm.readJSON("package.json");
253
+ const packageJson = await fsExtra.readJSON("package.json");
235
254
  packageJson.scripts = {
236
255
  ...packageJson.scripts,
237
256
  ...scripts
238
257
  };
239
- await esm.writeJSON("package.json", packageJson, { spaces: 2 });
258
+ await fsExtra.writeJSON("package.json", packageJson, { spaces: 2 });
240
259
  }
241
260
  };
242
261
  var DepsService = class extends Deps {
243
262
  };
263
+ var EnvService = class {
264
+ };
265
+ var FileEnvService = class extends EnvService {
266
+ filePath;
267
+ constructor(filePath) {
268
+ super();
269
+ this.filePath = filePath;
270
+ }
271
+ readFile(filePath) {
272
+ return new Promise((resolve, reject) => {
273
+ fs3__namespace.readFile(filePath, "utf8", (err, data) => {
274
+ if (err) reject(err);
275
+ else resolve(data);
276
+ });
277
+ });
278
+ }
279
+ writeFile({ filePath, data }) {
280
+ return new Promise((resolve, reject) => {
281
+ fs3__namespace.writeFile(filePath, data, "utf8", (err) => {
282
+ if (err) reject(err);
283
+ else resolve();
284
+ });
285
+ });
286
+ }
287
+ async updateEnvData({
288
+ key,
289
+ value,
290
+ filePath = this.filePath,
291
+ data
292
+ }) {
293
+ const regex = new RegExp(`^${key}=.*$`, "m");
294
+ if (data.match(regex)) {
295
+ data = data.replace(regex, `${key}=${value}`);
296
+ } else {
297
+ data += `
298
+ ${key}=${value}`;
299
+ }
300
+ await this.writeFile({ filePath, data });
301
+ console.log(`${key} set to ${value} in ENV file.`);
302
+ return data;
303
+ }
304
+ async getEnvValue(key) {
305
+ try {
306
+ const data = await this.readFile(this.filePath);
307
+ const regex = new RegExp(`^${key}=(.*)$`, "m");
308
+ const match = data.match(regex);
309
+ return match?.[1] || null;
310
+ } catch (err) {
311
+ console.error(`Error reading ENV value: ${err}`);
312
+ return null;
313
+ }
314
+ }
315
+ async setEnvValue(key, value) {
316
+ try {
317
+ const data = await this.readFile(this.filePath);
318
+ await this.updateEnvData({ key, value, data });
319
+ } catch (err) {
320
+ console.error(`Error writing ENV value: ${err}`);
321
+ }
322
+ }
323
+ };
324
+ var FileService = class {
325
+ /**
326
+ *
327
+ * @param inputFile the file in the starter files directory to copy
328
+ * @param outputFilePath the destination path
329
+ * @param replaceIfExists flag to replace if it exists
330
+ * @returns
331
+ */
332
+ async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
333
+ const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-RPH27LI6.cjs', document.baseURI).href)));
334
+ const __dirname = path__default.default.dirname(__filename);
335
+ const filePath = path__default.default.resolve(__dirname, "..", "starter-files", inputFile);
336
+ const fileString = fs3__namespace.default.readFileSync(filePath, "utf8");
337
+ if (fs3__namespace.default.existsSync(outputFilePath) && !replaceIfExists) {
338
+ console.log(`${outputFilePath} already exists`);
339
+ return false;
340
+ }
341
+ await fsExtra__default.default.outputFile(outputFilePath, fileString);
342
+ return true;
343
+ }
344
+ async setupEnvFile({ dbUrl }) {
345
+ const envPath = path__default.default.join(process.cwd(), ".env.development");
346
+ await fsExtra__default.default.ensureFile(envPath);
347
+ const fileEnvService = new FileEnvService(envPath);
348
+ await fileEnvService.setEnvValue("DB_URL", dbUrl);
349
+ }
350
+ getFirstExistingFile(files) {
351
+ for (const f of files) {
352
+ if (fs3__namespace.default.existsSync(f)) {
353
+ return f;
354
+ }
355
+ }
356
+ throw new Error("Missing required file, checked the following paths: " + files.join(", "));
357
+ }
358
+ replaceValuesInFile({
359
+ filePath,
360
+ replacements
361
+ }) {
362
+ let fileContent = fs3__namespace.default.readFileSync(filePath, "utf8");
363
+ replacements.forEach(({ search, replace }) => {
364
+ fileContent = fileContent.replaceAll(search, replace);
365
+ });
366
+ fs3__namespace.default.writeFileSync(filePath, fileContent);
367
+ }
368
+ };
244
369
 
245
370
  exports.Deps = Deps;
246
371
  exports.DepsService = DepsService;
372
+ exports.EnvService = EnvService;
373
+ exports.FileService = FileService;
247
374
  exports.createChildProcessLogger = createChildProcessLogger;
248
375
  exports.createPinoStream = createPinoStream;
package/dist/index.cjs CHANGED
@@ -1,9 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkBDAX7X52_cjs = require('./chunk-BDAX7X52.cjs');
3
+ var chunkKSYXZYYB_cjs = require('./chunk-KSYXZYYB.cjs');
4
4
  var chunk2ZPQX6BX_cjs = require('./chunk-2ZPQX6BX.cjs');
5
- var chunkNCROGJGB_cjs = require('./chunk-NCROGJGB.cjs');
6
- var chunkTHU6NH7X_cjs = require('./chunk-THU6NH7X.cjs');
5
+ var chunkRPH27LI6_cjs = require('./chunk-RPH27LI6.cjs');
7
6
  var babel = require('@babel/core');
8
7
  var rollup = require('rollup');
9
8
  var esbuild = require('rollup-plugin-esbuild');
@@ -34,8 +33,8 @@ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
34
33
  var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
35
34
 
36
35
  // src/deploy/base.ts
37
- var Deployer = class extends chunkBDAX7X52_cjs.Bundler {
38
- deps = new chunkTHU6NH7X_cjs.DepsService();
36
+ var Deployer = class extends chunkKSYXZYYB_cjs.Bundler {
37
+ deps = new chunkRPH27LI6_cjs.DepsService();
39
38
  constructor(args) {
40
39
  super(args.name, "DEPLOYER");
41
40
  this.deps.__setLogger(this.logger);
@@ -43,7 +42,7 @@ var Deployer = class extends chunkBDAX7X52_cjs.Bundler {
43
42
  getEnvFiles() {
44
43
  const possibleFiles = [".env.production", ".env.local", ".env"];
45
44
  try {
46
- const fileService = new chunkNCROGJGB_cjs.FileService();
45
+ const fileService = new chunkRPH27LI6_cjs.FileService();
47
46
  const envFile = fileService.getFirstExistingFile(possibleFiles);
48
47
  return Promise.resolve([envFile]);
49
48
  } catch {
@@ -171,21 +170,21 @@ async function getDeployer(entryFile, outputDir) {
171
170
  return (await import(`file:${outputDir}/deployer.mjs`)).deployer;
172
171
  }
173
172
 
174
- Object.defineProperty(exports, "FileService", {
173
+ Object.defineProperty(exports, "Deps", {
175
174
  enumerable: true,
176
- get: function () { return chunkNCROGJGB_cjs.FileService; }
175
+ get: function () { return chunkRPH27LI6_cjs.Deps; }
177
176
  });
178
- Object.defineProperty(exports, "Deps", {
177
+ Object.defineProperty(exports, "FileService", {
179
178
  enumerable: true,
180
- get: function () { return chunkTHU6NH7X_cjs.Deps; }
179
+ get: function () { return chunkRPH27LI6_cjs.FileService; }
181
180
  });
182
181
  Object.defineProperty(exports, "createChildProcessLogger", {
183
182
  enumerable: true,
184
- get: function () { return chunkTHU6NH7X_cjs.createChildProcessLogger; }
183
+ get: function () { return chunkRPH27LI6_cjs.createChildProcessLogger; }
185
184
  });
186
185
  Object.defineProperty(exports, "createPinoStream", {
187
186
  enumerable: true,
188
- get: function () { return chunkTHU6NH7X_cjs.createPinoStream; }
187
+ get: function () { return chunkRPH27LI6_cjs.createPinoStream; }
189
188
  });
190
189
  exports.Deployer = Deployer;
191
190
  exports.getDeployer = getDeployer;
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
- import { Bundler } from './chunk-UUEHIAGW.js';
1
+ import { Bundler } from './chunk-54TB2QKS.js';
2
2
  import { recursiveRemoveNonReferencedNodes } from './chunk-4AYFLP6G.js';
3
- import { FileService } from './chunk-DYQ225MJ.js';
4
- export { FileService } from './chunk-DYQ225MJ.js';
5
- import { DepsService } from './chunk-P7ZN2KUE.js';
6
- export { Deps, createChildProcessLogger, createPinoStream } from './chunk-P7ZN2KUE.js';
3
+ import { DepsService, FileService } from './chunk-OJI4SKSV.js';
4
+ export { Deps, FileService, createChildProcessLogger, createPinoStream } from './chunk-OJI4SKSV.js';
7
5
  import * as babel from '@babel/core';
8
6
  import babel__default from '@babel/core';
9
7
  import { rollup } from 'rollup';
@@ -3,6 +3,7 @@
3
3
  var crypto = require('crypto');
4
4
  var promises = require('fs/promises');
5
5
  var path = require('path');
6
+ var posix = require('path/posix');
6
7
  var url = require('url');
7
8
  var http = require('http');
8
9
  var http2 = require('http2');
@@ -32,6 +33,7 @@ var voice = require('@mastra/server/handlers/voice');
32
33
  var workflows = require('@mastra/server/handlers/workflows');
33
34
  var streaming = require('hono/streaming');
34
35
 
36
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
35
37
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
36
38
 
37
39
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
@@ -1849,10 +1851,12 @@ var html2 = `
1849
1851
  async function createHonoServer(mastra, options = {}) {
1850
1852
  const app = new hono.Hono();
1851
1853
  const server = mastra.getServer();
1852
- const mastraToolsPaths = process.env.MASTRA_TOOLS_PATH;
1854
+ const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
1855
+ const mastraToolsPaths = (await import(url.pathToFileURL(posix.join(__dirname, "tools.mjs")).href)).tools;
1853
1856
  const toolImports = mastraToolsPaths ? await Promise.all(
1854
- mastraToolsPaths.split(",").map(async (toolPath) => {
1855
- return import(url.pathToFileURL(toolPath).href);
1857
+ // @ts-ignore
1858
+ mastraToolsPaths.map(async (toolPath) => {
1859
+ return import(url.pathToFileURL(posix.join(__dirname, toolPath)).href);
1856
1860
  })
1857
1861
  ) : [];
1858
1862
  const tools = toolImports.reduce((acc, toolModule) => {
@@ -3829,7 +3833,7 @@ async function createHonoServer(mastra, options = {}) {
3829
3833
  return await next();
3830
3834
  }
3831
3835
  if (options?.playground) {
3832
- const indexHtml = await promises.readFile(path.join(process.cwd(), "./playground/index.html"), "utf-8");
3836
+ const indexHtml = await promises.readFile(posix.join(process.cwd(), "./playground/index.html"), "utf-8");
3833
3837
  return c2.newResponse(indexHtml, 200, { "Content-Type": "text/html" });
3834
3838
  }
3835
3839
  return c2.newResponse(html2, 200, { "Content-Type": "text/html" });
@@ -1,7 +1,8 @@
1
1
  import crypto, { randomUUID } from 'crypto';
2
2
  import { readFile } from 'fs/promises';
3
- import { join } from 'path';
4
- import { pathToFileURL } from 'url';
3
+ import { dirname } from 'path';
4
+ import { join } from 'path/posix';
5
+ import { fileURLToPath, pathToFileURL } from 'url';
5
6
  import { createServer } from 'http';
6
7
  import { Http2ServerRequest } from 'http2';
7
8
  import { Readable } from 'stream';
@@ -1843,10 +1844,12 @@ var html2 = `
1843
1844
  async function createHonoServer(mastra, options = {}) {
1844
1845
  const app = new Hono();
1845
1846
  const server = mastra.getServer();
1846
- const mastraToolsPaths = process.env.MASTRA_TOOLS_PATH;
1847
+ const __dirname = dirname(fileURLToPath(import.meta.url));
1848
+ const mastraToolsPaths = (await import(pathToFileURL(join(__dirname, "tools.mjs")).href)).tools;
1847
1849
  const toolImports = mastraToolsPaths ? await Promise.all(
1848
- mastraToolsPaths.split(",").map(async (toolPath) => {
1849
- return import(pathToFileURL(toolPath).href);
1850
+ // @ts-ignore
1851
+ mastraToolsPaths.map(async (toolPath) => {
1852
+ return import(pathToFileURL(join(__dirname, toolPath)).href);
1850
1853
  })
1851
1854
  ) : [];
1852
1855
  const tools = toolImports.reduce((acc, toolModule) => {
@@ -1,19 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkNCROGJGB_cjs = require('../chunk-NCROGJGB.cjs');
4
- var chunkTHU6NH7X_cjs = require('../chunk-THU6NH7X.cjs');
3
+ var chunkRPH27LI6_cjs = require('../chunk-RPH27LI6.cjs');
5
4
 
6
5
 
7
6
 
8
- Object.defineProperty(exports, "EnvService", {
7
+ Object.defineProperty(exports, "DepsService", {
9
8
  enumerable: true,
10
- get: function () { return chunkNCROGJGB_cjs.EnvService; }
9
+ get: function () { return chunkRPH27LI6_cjs.DepsService; }
11
10
  });
12
- Object.defineProperty(exports, "FileService", {
11
+ Object.defineProperty(exports, "EnvService", {
13
12
  enumerable: true,
14
- get: function () { return chunkNCROGJGB_cjs.FileService; }
13
+ get: function () { return chunkRPH27LI6_cjs.EnvService; }
15
14
  });
16
- Object.defineProperty(exports, "DepsService", {
15
+ Object.defineProperty(exports, "FileService", {
17
16
  enumerable: true,
18
- get: function () { return chunkTHU6NH7X_cjs.DepsService; }
17
+ get: function () { return chunkRPH27LI6_cjs.FileService; }
19
18
  });
@@ -1,2 +1 @@
1
- export { EnvService, FileService } from '../chunk-DYQ225MJ.js';
2
- export { DepsService } from '../chunk-P7ZN2KUE.js';
1
+ export { DepsService, EnvService, FileService } from '../chunk-OJI4SKSV.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer",
3
- "version": "0.3.0-alpha.4",
3
+ "version": "0.3.0-alpha.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -105,8 +105,8 @@
105
105
  "rollup-plugin-node-externals": "^8.0.0",
106
106
  "typescript-paths": "^1.5.1",
107
107
  "zod": "^3.24.2",
108
- "@mastra/core": "^0.9.0-alpha.3",
109
- "@mastra/server": "^2.0.0-alpha.3"
108
+ "@mastra/core": "^0.9.0-alpha.4",
109
+ "@mastra/server": "^2.0.0-alpha.4"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@hono/node-server": "^1.13.8",
@@ -1,115 +0,0 @@
1
- import * as fs2 from 'fs';
2
- import fs2__default from 'fs';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
- import fsExtra from 'fs-extra/esm';
6
-
7
- // src/services/env.ts
8
- var EnvService = class {
9
- };
10
- var FileEnvService = class extends EnvService {
11
- filePath;
12
- constructor(filePath) {
13
- super();
14
- this.filePath = filePath;
15
- }
16
- readFile(filePath) {
17
- return new Promise((resolve, reject) => {
18
- fs2.readFile(filePath, "utf8", (err, data) => {
19
- if (err) reject(err);
20
- else resolve(data);
21
- });
22
- });
23
- }
24
- writeFile({ filePath, data }) {
25
- return new Promise((resolve, reject) => {
26
- fs2.writeFile(filePath, data, "utf8", (err) => {
27
- if (err) reject(err);
28
- else resolve();
29
- });
30
- });
31
- }
32
- async updateEnvData({
33
- key,
34
- value,
35
- filePath = this.filePath,
36
- data
37
- }) {
38
- const regex = new RegExp(`^${key}=.*$`, "m");
39
- if (data.match(regex)) {
40
- data = data.replace(regex, `${key}=${value}`);
41
- } else {
42
- data += `
43
- ${key}=${value}`;
44
- }
45
- await this.writeFile({ filePath, data });
46
- console.log(`${key} set to ${value} in ENV file.`);
47
- return data;
48
- }
49
- async getEnvValue(key) {
50
- try {
51
- const data = await this.readFile(this.filePath);
52
- const regex = new RegExp(`^${key}=(.*)$`, "m");
53
- const match = data.match(regex);
54
- return match?.[1] || null;
55
- } catch (err) {
56
- console.error(`Error reading ENV value: ${err}`);
57
- return null;
58
- }
59
- }
60
- async setEnvValue(key, value) {
61
- try {
62
- const data = await this.readFile(this.filePath);
63
- await this.updateEnvData({ key, value, data });
64
- } catch (err) {
65
- console.error(`Error writing ENV value: ${err}`);
66
- }
67
- }
68
- };
69
- var FileService = class {
70
- /**
71
- *
72
- * @param inputFile the file in the starter files directory to copy
73
- * @param outputFilePath the destination path
74
- * @param replaceIfExists flag to replace if it exists
75
- * @returns
76
- */
77
- async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
78
- const __filename = fileURLToPath(import.meta.url);
79
- const __dirname = path.dirname(__filename);
80
- const filePath = path.resolve(__dirname, "..", "starter-files", inputFile);
81
- const fileString = fs2__default.readFileSync(filePath, "utf8");
82
- if (fs2__default.existsSync(outputFilePath) && !replaceIfExists) {
83
- console.log(`${outputFilePath} already exists`);
84
- return false;
85
- }
86
- await fsExtra.outputFile(outputFilePath, fileString);
87
- return true;
88
- }
89
- async setupEnvFile({ dbUrl }) {
90
- const envPath = path.join(process.cwd(), ".env.development");
91
- await fsExtra.ensureFile(envPath);
92
- const fileEnvService = new FileEnvService(envPath);
93
- await fileEnvService.setEnvValue("DB_URL", dbUrl);
94
- }
95
- getFirstExistingFile(files) {
96
- for (const f of files) {
97
- if (fs2__default.existsSync(f)) {
98
- return f;
99
- }
100
- }
101
- throw new Error("Missing required file, checked the following paths: " + files.join(", "));
102
- }
103
- replaceValuesInFile({
104
- filePath,
105
- replacements
106
- }) {
107
- let fileContent = fs2__default.readFileSync(filePath, "utf8");
108
- replacements.forEach(({ search, replace }) => {
109
- fileContent = fileContent.replaceAll(search, replace);
110
- });
111
- fs2__default.writeFileSync(filePath, fileContent);
112
- }
113
- };
114
-
115
- export { EnvService, FileService };
@@ -1,142 +0,0 @@
1
- 'use strict';
2
-
3
- var fs2 = require('fs');
4
- var path = require('path');
5
- var url = require('url');
6
- var fsExtra = require('fs-extra/esm');
7
-
8
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- function _interopNamespace(e) {
12
- if (e && e.__esModule) return e;
13
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () { return e[k]; }
21
- });
22
- }
23
- });
24
- }
25
- n.default = e;
26
- return Object.freeze(n);
27
- }
28
-
29
- var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
30
- var path__default = /*#__PURE__*/_interopDefault(path);
31
- var fsExtra__default = /*#__PURE__*/_interopDefault(fsExtra);
32
-
33
- // src/services/env.ts
34
- var EnvService = class {
35
- };
36
- var FileEnvService = class extends EnvService {
37
- filePath;
38
- constructor(filePath) {
39
- super();
40
- this.filePath = filePath;
41
- }
42
- readFile(filePath) {
43
- return new Promise((resolve, reject) => {
44
- fs2__namespace.readFile(filePath, "utf8", (err, data) => {
45
- if (err) reject(err);
46
- else resolve(data);
47
- });
48
- });
49
- }
50
- writeFile({ filePath, data }) {
51
- return new Promise((resolve, reject) => {
52
- fs2__namespace.writeFile(filePath, data, "utf8", (err) => {
53
- if (err) reject(err);
54
- else resolve();
55
- });
56
- });
57
- }
58
- async updateEnvData({
59
- key,
60
- value,
61
- filePath = this.filePath,
62
- data
63
- }) {
64
- const regex = new RegExp(`^${key}=.*$`, "m");
65
- if (data.match(regex)) {
66
- data = data.replace(regex, `${key}=${value}`);
67
- } else {
68
- data += `
69
- ${key}=${value}`;
70
- }
71
- await this.writeFile({ filePath, data });
72
- console.log(`${key} set to ${value} in ENV file.`);
73
- return data;
74
- }
75
- async getEnvValue(key) {
76
- try {
77
- const data = await this.readFile(this.filePath);
78
- const regex = new RegExp(`^${key}=(.*)$`, "m");
79
- const match = data.match(regex);
80
- return match?.[1] || null;
81
- } catch (err) {
82
- console.error(`Error reading ENV value: ${err}`);
83
- return null;
84
- }
85
- }
86
- async setEnvValue(key, value) {
87
- try {
88
- const data = await this.readFile(this.filePath);
89
- await this.updateEnvData({ key, value, data });
90
- } catch (err) {
91
- console.error(`Error writing ENV value: ${err}`);
92
- }
93
- }
94
- };
95
- var FileService = class {
96
- /**
97
- *
98
- * @param inputFile the file in the starter files directory to copy
99
- * @param outputFilePath the destination path
100
- * @param replaceIfExists flag to replace if it exists
101
- * @returns
102
- */
103
- async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
104
- const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-NCROGJGB.cjs', document.baseURI).href)));
105
- const __dirname = path__default.default.dirname(__filename);
106
- const filePath = path__default.default.resolve(__dirname, "..", "starter-files", inputFile);
107
- const fileString = fs2__namespace.default.readFileSync(filePath, "utf8");
108
- if (fs2__namespace.default.existsSync(outputFilePath) && !replaceIfExists) {
109
- console.log(`${outputFilePath} already exists`);
110
- return false;
111
- }
112
- await fsExtra__default.default.outputFile(outputFilePath, fileString);
113
- return true;
114
- }
115
- async setupEnvFile({ dbUrl }) {
116
- const envPath = path__default.default.join(process.cwd(), ".env.development");
117
- await fsExtra__default.default.ensureFile(envPath);
118
- const fileEnvService = new FileEnvService(envPath);
119
- await fileEnvService.setEnvValue("DB_URL", dbUrl);
120
- }
121
- getFirstExistingFile(files) {
122
- for (const f of files) {
123
- if (fs2__namespace.default.existsSync(f)) {
124
- return f;
125
- }
126
- }
127
- throw new Error("Missing required file, checked the following paths: " + files.join(", "));
128
- }
129
- replaceValuesInFile({
130
- filePath,
131
- replacements
132
- }) {
133
- let fileContent = fs2__namespace.default.readFileSync(filePath, "utf8");
134
- replacements.forEach(({ search, replace }) => {
135
- fileContent = fileContent.replaceAll(search, replace);
136
- });
137
- fs2__namespace.default.writeFileSync(filePath, fileContent);
138
- }
139
- };
140
-
141
- exports.EnvService = EnvService;
142
- exports.FileService = FileService;