-
Notifications
You must be signed in to change notification settings - Fork 6
/
copyFromSaveoff.js
62 lines (54 loc) · 2.3 KB
/
copyFromSaveoff.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
//Program to copy files from the saveoff source control files into the newly created WeVoteCordova directory
/*jshint esversion: 6 */
/*jslint node: true */
/*global process, __dirname */
const path = require('path');
const fs = require('fs-extra');
const { rimrafSync } = require('rimraf');
console.log('__dirname', __dirname);
if (!__dirname.endsWith('/WeVoteCordovaSaveoff')) {
console.log('copyFromSaveoff must be run from the WeVoteCordovaSaveoff directory');
process.exit();
}
if (!fs.existsSync('../WeVoteCordova')) {
console.log('copyFromSaveoff must have a destination WeVoteCordova directory to copy from. Did you run "cordova create WeVoteCordova us.wevote.wevotecordova WeVoteCordova"?');
process.exit();
}
const destinationDir = path.join(__dirname, "../WeVoteCordova");
fs.copy(path.resolve(__dirname,'./res'), path.resolve(destinationDir, './res'), function(error) {
if (error) {
console.log('Failed to copy the res dir', error);
} else {
console.log("Copied the /res dir from ../WeVoteCordovaSaveoff");
}
});
fs.copy(path.resolve(__dirname, './docs'), path.resolve(destinationDir, './docs'), function(error) {
if (error) {
console.log('Failed to copy the docs dir', error);
} else {
console.log("Copied the /docs dir from ../WeVoteCordovaSaveoff");
}
});
console.log('dest dir ', path.resolve(destinationDir, './www'));
if (fs.existsSync(path.resolve(destinationDir, './www'))) {
console.log('after if exists')
rimrafSync('../WeVoteCordova/www');
console.log('Removed scaffolding directory: WeVoteCordova/www')
fs.mkdir(path.resolve(destinationDir, './www'), (err) => {
if (err) {
return console.error(err);
}
console.log('../WeVoteCordova/www Directory created successfully');
const filesToCopy = ['./config.xml','./www/index.html', './.gitignore', './buildSymLinks.js', './copyFromSaveoff.js', './package.json', './package-lock.json','README.md'];
filesToCopy.forEach(file => {
// console.log(path.resolve(__dirname, file), ' -------------> ', path.resolve(destinationDir, file) );
fs.copy(path.resolve(__dirname, file), path.resolve(destinationDir, file), (err) => {
if (err) {
console.error('Failed to copy ', err);
} else {
console.log(file + ' copied successfully');
}
});
});
});
}