-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheroku_prep.js
61 lines (41 loc) · 1.69 KB
/
heroku_prep.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
/*
* heroku_prep.js
* Prepares a default angular-7 package.js file so it so a Angular App can be served on Heroku
*
*/
const package_file = require('./package');
const fs = require('fs');
const writeOutTheFile = (filename, data) => {
fs.writeFile(filename, data, (err) =>{
if(err) {
return console.log(err);
}
console.log(`The ${filename} was saved!`);
});
};
const app_name = package_file.name;
const server_template = `
//Install express server
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files from the dist directory
app.use(express.static(__dirname + '/dist'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);`;
// Read in the package.json
package_file.dependencies["@angular/cli"] = package_file.devDependencies["@angular/cli"];
package_file.dependencies["@angular/compiler-cli"] = package_file.devDependencies["@angular/compiler-cli"];
package_file.dependencies["typescript"]= package_file.devDependencies["typescript"];
package_file.scripts["build"] = "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build %config%";
package_file["engines"] = {"node":"18.x", "npm":"9.x"};
package_file.devDependencies["enhanced-resolve"]="^5.8.0";
package_file.dependencies["express"] = "^4.17.1";
package_file.dependencies["path"] = "^0.12.7";
package_file.scripts["start"] = "node server.js";
// Output the files
writeOutTheFile('server.js', server_template);
writeOutTheFile('package.json_2', JSON.stringify(package_file, null, 2));