-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcore-utils.js
137 lines (128 loc) · 3.24 KB
/
core-utils.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
// Modules
const _ = require('lodash');
const path = require('path');
// Default DB cli commands
const mysqlCli = {
service: ':host',
description: 'Drops into a MySQL shell on a database service',
cmd: 'mysql -uroot',
options: {
host: {
description: 'The database service to use',
default: 'database',
alias: ['h'],
},
},
};
const postgresCli = {
service: ':host',
description: 'Drops into a psql shell on a database service',
cmd: 'psql -Upostgres',
user: 'root',
options: {
host: {
description: 'The database service to use',
default: 'database',
alias: ['h'],
},
},
};
/*
* Helper to get DRUSH phar url
*/
const getDrushUrl = version => `https://github.com/drush-ops/drush/releases/download/${version}/drush.phar`;
/*
* Helper to get the correct DB command
*/
exports.getDbTooling = database => {
// Make sure we strip out any version number
database = database.split(':')[0];
// Choose wisely
if (_.includes(['mysql', 'mariadb'], database)) {
return {mysql: mysqlCli};
} else if (database === 'postgres') {
return {psql: postgresCli};
} else if (database === 'mongo') {
return {mongo: {
service: 'database',
description: 'Drop into the mongo shell',
}};
}
};
/*
* Helper to get the phar build command
*/
exports.getDrush = (version, status) => exports.getPhar(
getDrushUrl(version),
'/tmp/drush.phar',
'/usr/local/bin/drush',
status,
);
/*
* Helper to get a phar download and setupcommand
* @TODO: clean this mess up
*/
exports.getPhar = (url, src, dest, check = 'true') => {
// Arrayify the check if needed
if (_.isString(check)) check = [check];
// Phar install command
const pharInstall = [
['curl', url, '-LsS', '-o', src],
['chmod', '+x', src],
['mv', src, dest],
check,
];
// Return
return _.map(pharInstall, cmd => cmd.join(' ')).join(' && ');
};
/*
* Helper to get simple lamp/lemp config defaultz
* NOTE: is it problem that this and lemp has the same class name?
*/
exports.getLampDefaults = (name = 'lamp', via = 'apache') => ({
name,
parent: '_lamp',
config: {
confSrc: __dirname,
database: 'mysql',
php: '7.3',
via,
webroot: '.',
xdebug: false,
},
builder: (parent, config) => class LandoLamp extends parent {
constructor(id, options = {}) {
super(id, _.merge({}, config, options));
}
},
});
/*
* Helper to get service config
*/
exports.getServiceConfig = (options, types = ['php', 'server', 'vhosts']) => {
const config = {};
_.forEach(types, type => {
if (_.has(options, `config.${type}`)) {
config[type] = options.config[type];
} else if (!_.has(options, `config.${type}`) && _.has(options, `defaultFiles.${type}`)) {
if (_.has(options, 'confDest')) {
config[type] = path.join(options.confDest, options.defaultFiles[type]);
}
}
});
return config;
};
/*
* Parse config into raw materials for our factory
*/
exports.parseConfig = (recipe, app) => _.merge({}, _.get(app, 'config.config', {}), {
_app: app,
app: app.name,
confDest: path.join(app._config.userConfRoot, 'config', recipe),
home: app._config.home,
project: app.project,
recipe,
root: app.root,
userConfRoot: app._config.userConfRoot,
});