1 | var fs = require('fs')
|
2 | var cons = require('./console').Console
|
3 | var _process = process
|
4 |
|
5 |
|
6 |
|
7 | function replaceVar(str, key, value){
|
8 | str = str.replace('$' + key, value);
|
9 | str = str.replace('${' + key + '}', value);
|
10 |
|
11 | return str;
|
12 | }
|
13 |
|
14 |
|
15 | function procs(procdata){
|
16 |
|
17 | var processes = {};
|
18 |
|
19 | procdata.toString().split(/\n/).forEach(function(line){
|
20 | if(!line || line[0] === '#') return;
|
21 |
|
22 | var tuple = /^([A-Za-z0-9_-]+):\s*(.+)$/m.exec(line);
|
23 |
|
24 | var prockey = tuple[1].trim();
|
25 | var command = tuple[2].trim();
|
26 |
|
27 | if(!prockey)
|
28 | return cons.Warn('Syntax Error in Procfile, Line %d: No Prockey Found',i+1);
|
29 |
|
30 | if(!command)
|
31 | return cons.Warn('Syntax Error in Procfile, Line %d: No Command Found',i+1);
|
32 |
|
33 | processes[prockey]=command;
|
34 | });
|
35 |
|
36 | return processes;
|
37 | }
|
38 |
|
39 |
|
40 | function loadProc(path){
|
41 |
|
42 | try{
|
43 | var data = fs.readFileSync(path);
|
44 | return procs(data);
|
45 | }catch(e){
|
46 | cons.Warn('No Procfile Found')
|
47 | if(fs.existsSync('package.json')){
|
48 | cons.Alert("package.json file found - trying 'npm start'")
|
49 | return procs("web: npm start");
|
50 | }else{
|
51 | cons.Error("No Procfile found in Current Directory - See nf --help");
|
52 | return;
|
53 | }
|
54 | }
|
55 |
|
56 | }
|
57 |
|
58 | module.exports.loadProc = loadProc
|
59 | module.exports.procs = procs
|