d3ployer 0.0.3 → 0.0.4
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/defaultTasks.js +22 -37
- package/dist/runner.js +1 -1
- package/package.json +2 -6
package/dist/defaultTasks.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { Exception } from './utils/index.js';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { Exception } from './utils/Exception.js';
|
|
5
4
|
function buildRsyncCommand(server, source, dest, files) {
|
|
6
5
|
const args = ['rsync', '-avz', '--delete', '--progress=info2'];
|
|
7
6
|
// ssh shell
|
|
@@ -29,34 +28,6 @@ function buildRsyncCommand(server, source, dest, files) {
|
|
|
29
28
|
args.push(source, dest);
|
|
30
29
|
return args.join(' ');
|
|
31
30
|
}
|
|
32
|
-
function execRsync(command) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
const child = spawn('sh', ['-c', command], {
|
|
35
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
36
|
-
});
|
|
37
|
-
const stderrChunks = [];
|
|
38
|
-
child.stdout.on('data', (data) => {
|
|
39
|
-
process.stdout.write(data);
|
|
40
|
-
});
|
|
41
|
-
child.stderr.on('data', (data) => {
|
|
42
|
-
stderrChunks.push(data.toString());
|
|
43
|
-
process.stderr.write(data);
|
|
44
|
-
});
|
|
45
|
-
child.on('close', (code) => {
|
|
46
|
-
if (code !== 0) {
|
|
47
|
-
const details = stderrChunks.length
|
|
48
|
-
? `\n${stderrChunks.join('')}`
|
|
49
|
-
: '';
|
|
50
|
-
reject(new Exception(`rsync exited with code ${code} (cmd: ${command})${details}`, 1774741947570));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
resolve();
|
|
54
|
-
});
|
|
55
|
-
child.on('error', (err) => {
|
|
56
|
-
reject(new Exception(`rsync failed: ${command}\n${err.message}`, 1774741947571));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
31
|
const uploadTask = async (ctx, ph) => {
|
|
61
32
|
const files = ctx.config.files;
|
|
62
33
|
if (!files) {
|
|
@@ -70,7 +41,7 @@ const uploadTask = async (ctx, ph) => {
|
|
|
70
41
|
const source = localBase.endsWith('/') ? localBase : localBase + '/';
|
|
71
42
|
await ctx.run(`mkdir -p ${remotePath}`);
|
|
72
43
|
const command = buildRsyncCommand(ctx.server, source, dest, files);
|
|
73
|
-
await
|
|
44
|
+
await ctx.runLocal(command);
|
|
74
45
|
};
|
|
75
46
|
const symlinksTask = async (ctx, ph) => {
|
|
76
47
|
const symlinks = ctx.config.symlinks;
|
|
@@ -87,24 +58,37 @@ const symlinksTask = async (ctx, ph) => {
|
|
|
87
58
|
await ctx.run(`ln -sfn ${target} ${path}`);
|
|
88
59
|
}
|
|
89
60
|
};
|
|
90
|
-
const depInstallTask = async (ctx
|
|
61
|
+
const depInstallTask = async (ctx) => {
|
|
91
62
|
const pm = ctx.server.packageManager ?? ctx.config.packageManager ?? 'npm';
|
|
92
|
-
|
|
63
|
+
let cmd = `${pm}`;
|
|
64
|
+
if (pm === 'npm') {
|
|
65
|
+
cmd += ' install --production';
|
|
66
|
+
}
|
|
67
|
+
else if (pm === 'yarn') {
|
|
68
|
+
cmd += ' install --production';
|
|
69
|
+
}
|
|
70
|
+
else if (pm === 'pnpm') {
|
|
71
|
+
cmd += ' install --prod';
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new Exception(`Unsupported package manager "${pm}"`, 1774823752134);
|
|
75
|
+
}
|
|
93
76
|
await ctx.run(cmd);
|
|
94
77
|
};
|
|
95
78
|
const printDeploymentTask = async (ctx, ph) => {
|
|
79
|
+
await ctx.run('date');
|
|
96
80
|
console.log(chalk.cyan('Deployment directory'), ph.deployPath);
|
|
97
81
|
await ctx.run('ls -la .');
|
|
98
82
|
console.log(chalk.cyan('Directory size'));
|
|
99
83
|
await ctx.run('du -hd 1 .');
|
|
100
84
|
};
|
|
101
|
-
const pm2SetupTask = async (ctx
|
|
102
|
-
const pm2ConfigExists = await ctx.test('test -f pm2.config
|
|
85
|
+
const pm2SetupTask = async (ctx) => {
|
|
86
|
+
const pm2ConfigExists = await ctx.test('test -f pm2.config.*');
|
|
103
87
|
if (!pm2ConfigExists) {
|
|
104
|
-
console.log(chalk.yellow('
|
|
88
|
+
console.log(chalk.yellow('PM2 config not found, skipping setup'));
|
|
105
89
|
return;
|
|
106
90
|
}
|
|
107
|
-
await ctx.run('pm2 start pm2.config
|
|
91
|
+
await ctx.run('pm2 start pm2.config.* --update-env');
|
|
108
92
|
await ctx.run('pm2 save');
|
|
109
93
|
};
|
|
110
94
|
export const defaultTasks = {
|
|
@@ -137,6 +121,7 @@ export const defaultScenarios = {
|
|
|
137
121
|
'symlinks',
|
|
138
122
|
'depInstall',
|
|
139
123
|
'pm2Setup',
|
|
124
|
+
'printDeployment',
|
|
140
125
|
],
|
|
141
126
|
},
|
|
142
127
|
};
|
package/dist/runner.js
CHANGED
|
@@ -140,7 +140,7 @@ function buildTaskContext(serverName, server, ssh, config) {
|
|
|
140
140
|
const result = await execRemote(ssh, cmd, {
|
|
141
141
|
ignoreError: true,
|
|
142
142
|
printOutput: false,
|
|
143
|
-
cwd:
|
|
143
|
+
cwd: server.deployPath,
|
|
144
144
|
initCmd: server.initCmd,
|
|
145
145
|
});
|
|
146
146
|
return result.success;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "d3ployer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,11 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc -p tsconfig.build.json",
|
|
21
|
-
"
|
|
22
|
-
"dev:watch": "tsx --watch src/main.ts",
|
|
23
|
-
"dev:inspect": "tsx --inspect-brk src/main.ts",
|
|
24
|
-
"script": "tsx src/script.ts",
|
|
25
|
-
"deploy": "tsx src/cli.ts",
|
|
21
|
+
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
26
22
|
"test": "mocha --import=tsx",
|
|
27
23
|
"test:inspect": "mocha --import=tsx --inspect-brk",
|
|
28
24
|
"coverage": "c8 mocha --import=tsx",
|