-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-link.js
101 lines (78 loc) · 2.45 KB
/
create-link.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var replace = require("replace");
var ncp = require('ncp').ncp;
var mv = require('mv');
var fs = require('fs');
var archiver = require('archiver');
ncp.limit = 16;
if(!process.argv || process.argv.length != 4) {
console.log("Please run with two arguments: Name and URL");
return;
}
var name = process.argv[2];
if (/^http:\/\//.exec(process.argv[3]) || /^https:\/\//.exec(process.argv[3])) {
var url = process.argv[3];
} else {
console.log('not a valid url!')
}
console.log("Building link for " + name + " @ " + url);
var source = "Generic.app";
//Change "links/" to be a random directory or user hash, so they can download again
// Put in a directory to preserve the Name.app for zipping purposes
//var nameDir = name + "/" + name;
var nameDir = name;
var destination = nameDir + ".app";
//fs.mkdirSync(name);
ncp(source, destination, function (err) {
if (err) {
return console.error(err);
}
//Replace URL
replace({
regex: "genericURL",
replacement: url,
paths: [nameDir + '.app/Contents/Resources/AppSettings.plist'],
recursive: true,
silent: true,
});
//Replace instances of link title
replace({
regex: "Generic",
replacement: name,
paths: [nameDir + '.app/Contents/Info.plist'],
recursive: true,
silent: true,
});
//Rename the file
mv(nameDir + '.app/Contents/MacOS/Generic', nameDir + '.app/Contents/MacOS/' + name, function(err) {
if (err) {
return console.error(err);
}
mv('icon.icns', nameDir + '.app/Contents/Resources/appIcon.icns', function(err) {
if (err) {
return console.error(err);
}
//zip up contents at this point
//TODO put this online :P
/*
var output = fs.createWriteStream(name + ".zip");
var zipArchive = archiver('zip');
output.on('close', function() {
console.log('done with the zip', name);
});
zipArchive.pipe(output);
var srcDirectory = name;
*/
// zipArchive.bulk([
// { src: [ '**/*' ], cwd: srcDirectory, expand: true }
// ]);
/*
zipArchive.finalize(function(err, bytes) {
if(err) {
throw err;
}
console.log('done:', base, bytes);
});
*/
});
});
});