@colyseus/tools 0.15.32 → 0.15.34
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/package.json +1 -1
- package/post-deploy.js +55 -15
package/package.json
CHANGED
package/post-deploy.js
CHANGED
|
@@ -32,20 +32,42 @@ pm2.list(function(err, apps) {
|
|
|
32
32
|
pm2.start(CONFIG_FILE, {...opts}, onAppRunning);
|
|
33
33
|
|
|
34
34
|
} else {
|
|
35
|
-
// reload existing apps
|
|
36
|
-
pm2.reload(CONFIG_FILE, {...opts}, function(err, apps) {
|
|
37
|
-
bailOnErr(err);
|
|
38
|
-
|
|
39
|
-
const name = apps[0].name;
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
//
|
|
37
|
+
// detect if cwd has changed, and restart PM2 if it has
|
|
38
|
+
//
|
|
39
|
+
if (apps[0].pm2_env.pm_cwd !== pm2.cwd) {
|
|
40
|
+
|
|
41
|
+
//
|
|
42
|
+
// remove all and start again with new cwd
|
|
43
|
+
//
|
|
44
|
+
pm2.delete('all', function(err) {
|
|
45
|
+
// force to remove ~/.pm2 folder to avoid conflicts
|
|
46
|
+
fs.rmdirSync(path.join(process.env.HOME, '.pm2'), { recursive: true });
|
|
47
|
+
|
|
48
|
+
// start again
|
|
49
|
+
pm2.start(CONFIG_FILE, { ...opts }, onAppRunning);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
} else {
|
|
53
|
+
//
|
|
54
|
+
// reload existing apps
|
|
55
|
+
//
|
|
56
|
+
pm2.reload(CONFIG_FILE, {...opts}, function(err, apps) {
|
|
57
|
+
bailOnErr(err);
|
|
58
|
+
|
|
59
|
+
const name = apps[0].name;
|
|
60
|
+
|
|
61
|
+
// scale app to use all CPUs available
|
|
62
|
+
if (apps.length !== maxCPU) {
|
|
63
|
+
pm2.scale(name, maxCPU, onAppRunning);
|
|
64
|
+
|
|
65
|
+
} else {
|
|
66
|
+
onAppRunning();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
44
70
|
|
|
45
|
-
} else {
|
|
46
|
-
onAppRunning();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
71
|
}
|
|
50
72
|
});
|
|
51
73
|
|
|
@@ -62,13 +84,14 @@ function updateColyseusBootService() {
|
|
|
62
84
|
const COLYSEUS_CLOUD_BOOT_SERVICE = '/etc/systemd/system/colyseus-boot.service';
|
|
63
85
|
|
|
64
86
|
// ignore if no boot service found
|
|
65
|
-
if (!fs.existsSync(COLYSEUS_CLOUD_BOOT_SERVICE)) {
|
|
87
|
+
if (!fs.existsSync(COLYSEUS_CLOUD_BOOT_SERVICE)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
66
90
|
|
|
67
91
|
const workingDirectory = pm2.cwd;
|
|
68
|
-
const execStart =
|
|
92
|
+
const execStart = `${detectPackageManager()} run colyseus-post-deploy`;
|
|
69
93
|
|
|
70
94
|
const contents = fs.readFileSync(COLYSEUS_CLOUD_BOOT_SERVICE, 'utf8');
|
|
71
|
-
|
|
72
95
|
try {
|
|
73
96
|
fs.writeFileSync(COLYSEUS_CLOUD_BOOT_SERVICE, contents
|
|
74
97
|
.replace(/WorkingDirectory=(.*)/, `WorkingDirectory=${workingDirectory}`)
|
|
@@ -120,6 +143,23 @@ function updateAndReloadNginx() {
|
|
|
120
143
|
});
|
|
121
144
|
}
|
|
122
145
|
|
|
146
|
+
function detectPackageManager() {
|
|
147
|
+
const lockfiles = {
|
|
148
|
+
npm: path.resolve(pm2.cwd, 'package-lock.json'),
|
|
149
|
+
yarn: path.resolve(pm2.cwd, 'yarn.lock'),
|
|
150
|
+
pnpm: path.resolve(pm2.cwd, 'pnpm-lock.yaml'),
|
|
151
|
+
bun: path.resolve(pm2.cwd, 'bun.lockb'),
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
for (const [key, value] of Object.entries(lockfiles)) {
|
|
155
|
+
if (fs.existsSync(value)) {
|
|
156
|
+
return key;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return "npm";
|
|
161
|
+
}
|
|
162
|
+
|
|
123
163
|
function bailOnErr(err) {
|
|
124
164
|
if (err) {
|
|
125
165
|
console.error(err);
|