d3ployer 0.0.3 → 0.0.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.
- package/dist/config.js +5 -1
- package/dist/def.d.ts +7 -2
- package/dist/defaultTasks.js +30 -38
- package/dist/runner.js +1 -1
- package/package.json +2 -6
package/dist/config.js
CHANGED
|
@@ -39,9 +39,13 @@ export function defineConfig(input) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
return {
|
|
42
|
-
packageManager: 'npm',
|
|
43
42
|
rootDir: '',
|
|
44
43
|
...input,
|
|
44
|
+
packageManager: {
|
|
45
|
+
manager: 'npm',
|
|
46
|
+
productionOnly: true,
|
|
47
|
+
...input.packageManager,
|
|
48
|
+
},
|
|
45
49
|
servers,
|
|
46
50
|
tasks,
|
|
47
51
|
scenarios,
|
package/dist/def.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type SSH2Promise from 'ssh2-promise';
|
|
2
2
|
export type AuthMethod = 'key' | 'password' | 'agent';
|
|
3
|
+
export type PackageManager = 'npm' | 'yarn' | 'pnpm';
|
|
4
|
+
export type PackageManagerConfig = {
|
|
5
|
+
manager: PackageManager;
|
|
6
|
+
productionOnly?: boolean;
|
|
7
|
+
};
|
|
3
8
|
export interface ServerConfig {
|
|
4
9
|
host: string;
|
|
5
10
|
port: number;
|
|
@@ -9,7 +14,7 @@ export interface ServerConfig {
|
|
|
9
14
|
password?: string;
|
|
10
15
|
agent?: string;
|
|
11
16
|
deployPath: string;
|
|
12
|
-
packageManager?:
|
|
17
|
+
packageManager?: PackageManagerConfig;
|
|
13
18
|
initCmd?: string;
|
|
14
19
|
}
|
|
15
20
|
export type ServerConfigInput = Partial<ServerConfig> & Pick<ServerConfig, 'host' | 'deployPath'>;
|
|
@@ -68,7 +73,7 @@ export type ScenarioInput = string[] | {
|
|
|
68
73
|
export interface DeployerConfig {
|
|
69
74
|
rootDir: string;
|
|
70
75
|
servers: Record<string, ServerConfig>;
|
|
71
|
-
packageManager?:
|
|
76
|
+
packageManager?: PackageManagerConfig;
|
|
72
77
|
files?: FilesConfig;
|
|
73
78
|
symlinks?: SymlinkConfig[];
|
|
74
79
|
tasks?: Record<string, TaskDef>;
|
package/dist/defaultTasks.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
2
|
import path from 'node:path';
|
|
4
|
-
import { Exception } from './utils/
|
|
3
|
+
import { Exception } from './utils/index.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,44 @@ const symlinksTask = async (ctx, ph) => {
|
|
|
87
58
|
await ctx.run(`ln -sfn ${target} ${path}`);
|
|
88
59
|
}
|
|
89
60
|
};
|
|
90
|
-
const depInstallTask = async (ctx
|
|
91
|
-
const
|
|
92
|
-
|
|
61
|
+
const depInstallTask = async (ctx) => {
|
|
62
|
+
const config = {
|
|
63
|
+
manager: 'npm',
|
|
64
|
+
productionOnly: true,
|
|
65
|
+
...ctx.config.packageManager,
|
|
66
|
+
...ctx.server.packageManager,
|
|
67
|
+
};
|
|
68
|
+
let cmd = `${config.manager} install`;
|
|
69
|
+
if (config.productionOnly) {
|
|
70
|
+
if (config.manager === 'npm') {
|
|
71
|
+
cmd += ' --omit=dev';
|
|
72
|
+
}
|
|
73
|
+
else if (config.manager === 'yarn') {
|
|
74
|
+
cmd += ' --production';
|
|
75
|
+
}
|
|
76
|
+
else if (config.manager === 'pnpm') {
|
|
77
|
+
cmd += ' --prod';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Exception(`Unsupported package manager "${config.manager}"`, 1774823752134);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
93
83
|
await ctx.run(cmd);
|
|
94
84
|
};
|
|
95
85
|
const printDeploymentTask = async (ctx, ph) => {
|
|
86
|
+
await ctx.run('date');
|
|
96
87
|
console.log(chalk.cyan('Deployment directory'), ph.deployPath);
|
|
97
88
|
await ctx.run('ls -la .');
|
|
98
89
|
console.log(chalk.cyan('Directory size'));
|
|
99
90
|
await ctx.run('du -hd 1 .');
|
|
100
91
|
};
|
|
101
|
-
const pm2SetupTask = async (ctx
|
|
102
|
-
const pm2ConfigExists = await ctx.test('test -f pm2.config
|
|
92
|
+
const pm2SetupTask = async (ctx) => {
|
|
93
|
+
const pm2ConfigExists = await ctx.test('test -f pm2.config.*');
|
|
103
94
|
if (!pm2ConfigExists) {
|
|
104
|
-
console.log(chalk.yellow('
|
|
95
|
+
console.log(chalk.yellow('PM2 config not found, skipping setup'));
|
|
105
96
|
return;
|
|
106
97
|
}
|
|
107
|
-
await ctx.run('pm2 start pm2.config
|
|
98
|
+
await ctx.run('pm2 start pm2.config.* --update-env');
|
|
108
99
|
await ctx.run('pm2 save');
|
|
109
100
|
};
|
|
110
101
|
export const defaultTasks = {
|
|
@@ -137,6 +128,7 @@ export const defaultScenarios = {
|
|
|
137
128
|
'symlinks',
|
|
138
129
|
'depInstall',
|
|
139
130
|
'pm2Setup',
|
|
131
|
+
'printDeployment',
|
|
140
132
|
],
|
|
141
133
|
},
|
|
142
134
|
};
|
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.5",
|
|
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",
|