1 | const chalk = require( 'chalk' );
|
2 | const nconf = require( 'nconf' );
|
3 | const moment = require( 'moment' );
|
4 | const tz = require( 'moment-timezone' );
|
5 | const fs = require( 'fs' );
|
6 | const p = require( 'path' );
|
7 | const app = require( './app' );
|
8 | const util = require( './util' );
|
9 |
|
10 | const config = {
|
11 |
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 | updateName( slug, name ) {
|
18 | nconf.set( `local_projects:${slug}:name`, name );
|
19 | nconf.save();
|
20 | },
|
21 |
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 | updateType( slug, type ) {
|
28 | nconf.set( `local_projects:${slug}:type`, type );
|
29 | nconf.save();
|
30 | },
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 | updateUrl( slug, url ) {
|
38 | nconf.set( `local_projects:${slug}:url`, url );
|
39 | nconf.save();
|
40 | },
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 | updatePath( slug, path ) {
|
48 | nconf.set( `local_projects:${slug}:path`, path );
|
49 | nconf.save();
|
50 | },
|
51 |
|
52 | |
53 |
|
54 |
|
55 |
|
56 | updateLastUpdatedTime( slug ) {
|
57 | const now = moment().tz( 'America/New_York' ).toISOString();
|
58 |
|
59 | nconf.set( `local_projects:${slug}:last_updated`, now );
|
60 | nconf.save();
|
61 | },
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 | updatePorts( slug, ports ) {
|
69 | nconf.set( `local_projects:${slug}:ports`, ports );
|
70 | nconf.save();
|
71 | },
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 | updateContainerNames( slug, containerNames ) {
|
79 | nconf.set( `local_projects:${slug}:containers`, containerNames );
|
80 | nconf.save();
|
81 | },
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 | removePath( slug ) {
|
88 | nconf.remove( `local_projects:${slug}:path` );
|
89 | nconf.save();
|
90 | },
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 | updateLocalProjects( projects ) {
|
97 | nconf.set( 'local_projects', projects );
|
98 | nconf.save();
|
99 | },
|
100 |
|
101 | |
102 |
|
103 |
|
104 | create() {
|
105 |
|
106 | if ( !fs.existsSync( app.configDir ) ) {
|
107 | fs.mkdirSync( app.configDir );
|
108 | }
|
109 |
|
110 |
|
111 | fs.writeFileSync( app.config, '{}' );
|
112 |
|
113 |
|
114 | nconf.file( app.config );
|
115 | nconf.set( 'current_profile', '' );
|
116 | nconf.save();
|
117 | },
|
118 |
|
119 | |
120 |
|
121 |
|
122 |
|
123 | updateCurrentProfile( path ) {
|
124 | nconf.file( app.config );
|
125 | nconf.set( 'current_profile', path );
|
126 | nconf.save();
|
127 | },
|
128 |
|
129 | |
130 |
|
131 |
|
132 | load() {
|
133 | nconf.file( app.config );
|
134 | util.requireKeys( [
|
135 | 'current_profile',
|
136 | ] );
|
137 | },
|
138 |
|
139 | |
140 |
|
141 |
|
142 |
|
143 | async exists() {
|
144 | const exists = await fs.existsSync( app.config );
|
145 |
|
146 | return exists;
|
147 | },
|
148 |
|
149 | };
|
150 |
|
151 | module.exports = config;
|