-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeploy.js
More file actions
64 lines (50 loc) · 1.99 KB
/
Copy pathdeploy.js
File metadata and controls
64 lines (50 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const ftp = require('basic-ftp');
const path = require('path');
const settings = require('./.ftpdeploy.js');
async function deploy() {
const client = new ftp.Client();
client.ftp.verbose = false;
try {
await client.access({
host: settings.host,
port: settings.port,
user: settings.user,
password: settings.password,
secure: false // set true if using FTPS
});
const localRoot = path.join(__dirname, 'dist');
const remoteRoot = settings.remoteRoot;
// --- PASS 1: Upload JS files ---
await uploadFiltered(client, localRoot, remoteRoot, (file) => {
return file.endsWith('.js') || file.includes('.js.');
});
// --- PASS 2: Upload everything else except excluded ---
await uploadFiltered(client, localRoot, remoteRoot, (file) => {
if (file.endsWith('.js') || file.includes('.js.')) return false;
if (file.startsWith('font/') || file.startsWith('images/')) return false;
return true;
});
console.log('Deploy complete');
} catch (err) {
console.error(err);
}
client.close();
}
const fs = require('fs');
async function uploadFiltered(client, localDir, remoteDir, filterFn, baseDir = localDir) {
const entries = fs.readdirSync(localDir, { withFileTypes: true });
for (const entry of entries) {
const localPath = path.join(localDir, entry.name);
const relativePath = path.relative(baseDir, localPath).replace(/\\/g, '/');
const remotePath = path.posix.join(remoteDir, relativePath);
if (entry.isDirectory()) {
await uploadFiltered(client, localPath, remoteDir, filterFn, baseDir);
} else {
if (!filterFn(relativePath)) continue;
await client.ensureDir(path.dirname(remotePath));
await client.uploadFrom(localPath, remotePath);
console.log(`Uploaded: ${relativePath}`);
}
}
}
deploy();