d3ployer 0.0.9 → 0.0.10

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/dist/config.js CHANGED
@@ -68,14 +68,32 @@ export function defineConfig(input) {
68
68
  };
69
69
  }
70
70
  }
71
- return {
72
- rootDir: '',
73
- ...input,
74
- packageManager: {
71
+ let packageManager;
72
+ if (input.packageManager === false) {
73
+ packageManager = false;
74
+ }
75
+ else {
76
+ packageManager = {
75
77
  manager: 'npm',
76
78
  productionOnly: true,
77
79
  ...input.packageManager,
78
- },
80
+ };
81
+ }
82
+ let dockerCompose;
83
+ if (input.dockerCompose === false) {
84
+ dockerCompose = false;
85
+ }
86
+ else {
87
+ dockerCompose = {
88
+ configFiles: undefined,
89
+ ...input.dockerCompose,
90
+ };
91
+ }
92
+ return {
93
+ rootDir: '',
94
+ ...input,
95
+ packageManager,
96
+ dockerCompose,
79
97
  servers,
80
98
  tasks,
81
99
  scenarios,
package/dist/def.d.ts CHANGED
@@ -27,6 +27,9 @@ export interface SymlinkConfig {
27
27
  path: string;
28
28
  target: string;
29
29
  }
30
+ export type DockerComposeConfig = {
31
+ configFiles: string[];
32
+ };
30
33
  export interface LogsConfig {
31
34
  time?: number;
32
35
  }
@@ -86,7 +89,7 @@ export interface DeployerConfig {
86
89
  symlinks?: SymlinkConfig[];
87
90
  packageManager?: PackageManagerConfig | false;
88
91
  pm2?: boolean;
89
- dockerCompose?: boolean;
92
+ dockerCompose?: DockerComposeConfig | false;
90
93
  logs?: LogsConfig | false;
91
94
  tasks?: Record<string, TaskDef>;
92
95
  scenarios?: Record<string, ScenarioDef>;
@@ -146,18 +146,38 @@ const pm2SetupTask = async (ctx) => {
146
146
  await ctx.run('pm2 start pm2.config.* --update-env');
147
147
  await ctx.run('pm2 save');
148
148
  };
149
+ function buildDockerComposeTestCmd(dockerComposeConfig) {
150
+ if (dockerComposeConfig === false) {
151
+ return 'false';
152
+ }
153
+ const configFiles = dockerComposeConfig.configFiles ?? [
154
+ 'docker-compose.yml',
155
+ 'docker-compose.yaml',
156
+ 'compose.yml',
157
+ 'compose.yaml',
158
+ ];
159
+ const testCmdPart = configFiles.map(f => `-f ${f}`);
160
+ return `test ${testCmdPart.join(' -o ')}`;
161
+ }
149
162
  const dockerSetupSkip = async (ctx) => {
150
163
  if (ctx.config.dockerCompose === false) {
151
164
  return 'Docker Compose disabled';
152
165
  }
153
- const composeExists = await ctx.test('test -f docker-compose.yml -o -f docker-compose.yaml -o -f compose.yml -o -f compose.yaml');
166
+ const testCmd = buildDockerComposeTestCmd(ctx.config.dockerCompose);
167
+ const composeExists = await ctx.test(testCmd);
154
168
  if (!composeExists) {
155
169
  return 'Docker Compose config not found';
156
170
  }
157
171
  return false;
158
172
  };
159
173
  const dockerSetupTask = async (ctx) => {
160
- await ctx.run('docker compose up -d --build --remove-orphans');
174
+ if (ctx.config.dockerCompose === false) {
175
+ return;
176
+ }
177
+ const configFiles = ctx.config.dockerCompose?.configFiles ?? [];
178
+ const options = configFiles.map(f => `-f ${f}`).join(' ');
179
+ await ctx.run(`docker compose ${options} down --remove-orphans`);
180
+ await ctx.run(`docker compose ${options} up -d --build`);
161
181
  };
162
182
  const clearTargetTask = async (ctx, ph) => {
163
183
  const confirmed = await confirm({
@@ -177,19 +197,22 @@ const printDeploymentTask = async (ctx, ph) => {
177
197
  console.log(chalk.cyan('Directory size'));
178
198
  await ctx.run('du -hd 1 .');
179
199
  };
180
- const streamLogsSkip = async (ctx) => {
200
+ const logsStreamSkip = async (ctx) => {
181
201
  if (ctx.config.logs === false) {
182
202
  return 'Logs streaming disabled';
183
203
  }
184
204
  const hasPm2 = ctx.config.pm2 !== false && await ctx.test('test -f pm2.config.*');
185
- const hasDocker = ctx.config.dockerCompose !== false
186
- && await ctx.test('test -f docker-compose.yml -o -f docker-compose.yaml -o -f compose.yml -o -f compose.yaml');
205
+ let hasDocker = false;
206
+ if (ctx.config.dockerCompose) {
207
+ const testCmd = buildDockerComposeTestCmd(ctx.config.dockerCompose);
208
+ hasDocker = await ctx.test(testCmd);
209
+ }
187
210
  if (!hasPm2 && !hasDocker) {
188
211
  return 'No PM2 or Docker Compose detected';
189
212
  }
190
213
  return false;
191
214
  };
192
- const streamLogsTask = async (ctx) => {
215
+ const logsStreamTask = async (ctx) => {
193
216
  const logsConfig = {
194
217
  time: 3,
195
218
  ...ctx.config.logs,
@@ -197,8 +220,11 @@ const streamLogsTask = async (ctx) => {
197
220
  const time = logsConfig.time;
198
221
  const hasPm2 = ctx.config.pm2 !== false
199
222
  && await ctx.test('test -f pm2.config.*');
200
- const hasDocker = ctx.config.dockerCompose !== false
201
- && await ctx.test('test -f docker-compose.yml -o -f docker-compose.yaml -o -f compose.yml -o -f compose.yaml');
223
+ let hasDocker = false;
224
+ if (ctx.config.dockerCompose !== false) {
225
+ const testCmd = buildDockerComposeTestCmd(ctx.config.dockerCompose);
226
+ hasDocker = await ctx.test(testCmd);
227
+ }
202
228
  if (hasPm2) {
203
229
  const pm2ConfigRaw = await ctx.run('cat pm2.config.*', { printOutput: false });
204
230
  const nameMatch = pm2ConfigRaw.stdout.match(/name: ['"](?<name>.+?)['"]/);
@@ -206,9 +232,11 @@ const streamLogsTask = async (ctx) => {
206
232
  console.log(chalk.cyan(`Streaming PM2 logs for ${time}s...`));
207
233
  await ctx.run(`timeout ${time} pm2 logs "${name}" || true`, { printOutput: true, ignoreError: true });
208
234
  }
209
- else if (hasDocker) {
235
+ else if (hasDocker && ctx.config.dockerCompose) {
236
+ const configFiles = ctx.config.dockerCompose.configFiles ?? [];
237
+ const options = configFiles.map(f => `-f ${f}`).join(' ');
210
238
  console.log(chalk.cyan(`Streaming Docker Compose logs for ${time}s...`));
211
- await ctx.run(`timeout ${time} docker compose logs --tail=50 -f || true`, {
239
+ await ctx.run(`timeout ${time} docker compose ${options} logs --tail=10 -f || true`, {
212
240
  printOutput: true,
213
241
  ignoreError: true,
214
242
  });
@@ -253,10 +281,10 @@ export const defaultTasks = {
253
281
  name: 'Print deployment info',
254
282
  task: printDeploymentTask,
255
283
  },
256
- streamLogs: {
257
- name: 'Stream logs',
258
- skip: streamLogsSkip,
259
- task: streamLogsTask,
284
+ logsStream: {
285
+ name: 'Logs stream',
286
+ skip: logsStreamSkip,
287
+ task: logsStreamTask,
260
288
  },
261
289
  };
262
290
  export const defaultScenarios = {
@@ -269,7 +297,7 @@ export const defaultScenarios = {
269
297
  'pm2:setup',
270
298
  'docker:setup',
271
299
  'print:deployment',
272
- 'stream:logs',
300
+ 'logs:stream',
273
301
  ],
274
302
  },
275
303
  };
package/dist/runner.js CHANGED
@@ -173,13 +173,6 @@ export function resolveTaskDefs(taskNames, allTasks) {
173
173
  return [name, def];
174
174
  });
175
175
  }
176
- const listrOptions = {
177
- concurrent: false,
178
- renderer: 'simple',
179
- rendererOptions: {
180
- clearOutput: true,
181
- },
182
- };
183
176
  function buildServerListr(serverName, server, config, tasks) {
184
177
  return new Listr([
185
178
  {
@@ -203,7 +196,6 @@ function buildServerListr(serverName, server, config, tasks) {
203
196
  ctx.taskCtx.taskConfig = taskDef.config;
204
197
  return taskDef.task(ctx.taskCtx, ctx.ph);
205
198
  },
206
- options: listrOptions,
207
199
  })),
208
200
  {
209
201
  task: async (ctx) => {
@@ -212,7 +204,10 @@ function buildServerListr(serverName, server, config, tasks) {
212
204
  }
213
205
  },
214
206
  },
215
- ], listrOptions);
207
+ ], {
208
+ concurrent: false,
209
+ renderer: 'simple',
210
+ });
216
211
  }
217
212
  export async function runScenario(config, scenarioName, serverNames) {
218
213
  const scenarioDef = config.scenarios?.[scenarioName];
@@ -226,8 +221,10 @@ export async function runScenario(config, scenarioName, serverNames) {
226
221
  const listr = new Listr(servers.map(([name, server]) => ({
227
222
  title: chalk.bgMagenta.black(` ${name} (${server.host}) `),
228
223
  task: () => buildServerListr(name, server, config, tasks),
229
- options: listrOptions,
230
- })), listrOptions);
224
+ })), {
225
+ concurrent: false,
226
+ renderer: 'simple',
227
+ });
231
228
  await listr.run();
232
229
  }
233
230
  export async function runTask(config, taskName, serverNames) {
@@ -241,7 +238,9 @@ export async function runTask(config, taskName, serverNames) {
241
238
  const listr = new Listr(servers.map(([name, server]) => ({
242
239
  title: chalk.bgMagenta.black(` ${name} (${server.host}) `),
243
240
  task: () => buildServerListr(name, server, config, [[taskName, taskDef]]),
244
- options: listrOptions,
245
- })), listrOptions);
241
+ })), {
242
+ concurrent: false,
243
+ renderer: 'simple',
244
+ });
246
245
  await listr.run();
247
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d3ployer",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {