This repository was archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathdeploy-ftp.js
74 lines (70 loc) · 2.08 KB
/
deploy-ftp.js
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
65
66
67
68
69
70
71
72
73
74
// Load modules
const fs = require('fs-extra');
const prompt = require('prompt');
const FTP = require('ftp-deploy');
const path = require('./helper/path');
const log = require('./helper/logger');
// Check if PWA was build before
const pwaFolder = path.project('pwa');
if (!fs.pathExistsSync(pwaFolder)) {
log.error('Folder /pwa not found. Please run build process before.');
process.exit(0);
}
// Load app configuration
const configFile = path.app('config.json');
let config = {};
try {
config = fs.readJsonSync(configFile);
log.success('Loaded app config file.');
} catch (e) {
log.error('Failed to load app config file.');
}
// Ask for FTP credentials
log.warning('Please enter your FTP credentials for the deployment.');
log.warning('If default values are shown, you can press enter to confirm.');
const schema = {
properties: {
host: {
description: 'FTP Host',
default: config.ftp.defaultHost,
required: true,
},
port: {
description: 'FTP Port',
default: config.ftp.defaultPort !== '' ? config.ftp.defaultPort : 21,
},
remoteRoot: {
description: 'FTP Upload Path',
default: config.ftp.defaultPathOnServer !== '' ? config.ftp.defaultPathOnServer : '/',
},
user: {
description: 'FTP User Name',
default: config.ftp.defaultUserName,
required: true,
},
password: {
description: 'FTP Password',
default: config.ftp.defaultPassword,
hidden: true,
replace: '*',
required: true,
},
},
};
prompt.start();
prompt.get(schema, (error, promptedValues) => {
// Copy and adjust configuration
const ftpConfig = JSON.parse(JSON.stringify(promptedValues));
ftpConfig.localRoot = pwaFolder;
ftpConfig.include = ['**/*', '*', '.*'];
ftpConfig.exclude = [];
ftpConfig.deleteRemote = false;
ftpConfig.forcePasv = true;
// Connect to FTP server
log.warning('Deploying PWA to the FTP server - this may take a while ...');
const ftp = new FTP();
ftp.deploy(ftpConfig, (err) => {
if (err) log.error('FTP deployment failed.');
log.success('Completed FTP deployment.');
});
});