-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.js
179 lines (151 loc) · 3.63 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
const path = require('path');
const _ = require('lodash');
const gulp = require('gulp');
const fs = require('fs');
const chalk = require('chalk');
class UbiquitsProject {
constructor(basePath) {
this.gulp = gulp;
this.basePath = basePath;
this.docsConfig = {
meta: {
gaCode: null
}
};
this.paths = {
source: {
base: './src',
server: {
tsConfig: this.basePath + '/tsconfig.server.json',
},
browser: {
tsConfig: this.basePath + '/tsconfig.browser.json',
},
all: {
tsConfig: this.basePath + '/tsconfig.all.json',
},
docs: {
base: './docs',
root: this.basePath,
templates: 'templates',
partials: 'templates/partials',
}
},
destination: {
lib: './lib',
dist: './dist',
coverage: './coverage',
server: 'dist/server',
browser: 'dist/browser',
docs: './dist-docs'
}
};
this.deploymentConfig = {
docs: {
repo: null,
remote: 'origin',
branch: 'gh-pages',
dir: this.paths.destination.docs
}
};
this.socialConfig = {
github: {
forkMe: true,
star: true
},
twitter: false,
gitter: false
};
this.commandRegistry = [];
}
/**
* Configure the deployment options
* @param config
* @returns {UbiquitsProject}
*/
configureDeployment(config) {
this.deploymentConfig = _.merge(this.deploymentConfig, config);
return this;
}
/**
* Configure the paths
* @param config
* @returns {UbiquitsProject}
*/
configurePaths(config) {
this.paths = _.merge(this.paths, config);
return this;
}
/**
* Configure Documentation options
* @param config
* @returns {UbiquitsProject}
*/
configureDocs(config){
this.docsConfig = _.merge(this.paths, config);
return this;
}
/**
* Configure Social options
* @param config
* @returns {UbiquitsProject}
*/
configureSocial(config){
this.socialConfig = _.merge(this.socialConfig, config);
return this;
}
/**
* Register a single command
* @param commandRegisterFn
* @returns {UbiquitsProject}
*/
registerCommand(commandRegisterFn) {
this.commandRegistry.push(commandRegisterFn);
return this;
}
/**
* Read all the tasks from ./cli/tasks, pushing them into the command registry
*/
readTasks() {
var taskDirectory = path.resolve(__dirname + '/cli/tasks');
fs.readdirSync(taskDirectory).forEach((file) => {
this.commandRegistry.push(require(path.resolve(taskDirectory, file)).task);
});
}
/**
* Resolve a path relative to the base
* @param pathString
* @param relative
* @returns {string}
*/
resolvePath(pathString, relative) {
const normalized = path.normalize(this.basePath + '/' + pathString);
if (!relative) {
return normalized;
}
return path.relative(this.basePath, normalized);
}
/**
* Read tasks from the task dir then iterate over all commands,
* invoking them with vantage and this project instance
* @param vorpal
* @returns {UbiquitsProject}
*/
loadRegisteredCommands(vantage) {
this.readTasks();
this.commandRegistry.forEach((commandRegisterFn) => {
commandRegisterFn(vantage, this);
});
return this;
}
/**
* Extends gutil.log with [project] prefix
*/
log() {
const task = chalk.white('[project]');
Array.prototype.unshift.call(arguments, task);
gutil.log.apply(this, arguments);
}
}
module.exports = {UbiquitsProject};