-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.js
executable file
·53 lines (42 loc) · 1.66 KB
/
Project.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
const os = require('os');
const fs = require('fs');
const inquirer = require('inquirer');
const { execSync } = require('child_process');
const homedir = os.homedir();
class Project {
constructor(name, dir) {
this.config_dir = (dir === undefined) ? (homedir + "/.config/the-seed/") : dir;
this.config_filename = "config.json";
if(!fs.existsSync(this.config_dir) || !fs.existsSync(this.config_dir + this.config_filename)) {
console.log(homedir + "/.config/the-seed/config.json not found. Run 'the-seed-config' to initialize.");
return;
}
this.config = JSON.parse(fs.readFileSync(this.config_dir + this.config_filename));
this.dir = this.config.projects.directory + name;
if(fs.existsSync(this.dir)) {
console.log("There is already a project named '" + name + "' in '" + this.config.projects.directory + "'.");
return;
} else {
fs.mkdirSync(this.dir);
const init = execSync('npm init --yes', { cwd: this.dir });
}
this.package = JSON.parse(fs.readFileSync(this.dir + "/package.json"));
this.package.author = this.config.author;
this.package.license = "UNLICENSED";
this.package.name = this.config.projects.scope + "/" + this.package.name;
delete this.package.main;
this.Save();
console.log("New project created in '" + this.dir + "', please modify 'package.json' as necessary.");
}
Save() {
fs.writeFileSync(this.dir + "/package.json", JSON.stringify(this.package, null, 2));
}
ChooseCertificate(certificate) {
this.package.codeSigning = {
"cert": certificate + "/cert.pem",
"key": certificate + "/key.pem"
};
this.Save();
}
}
module.exports = Project;