genome 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +237 -87
- package/dist/hash.d.ts +67 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/id-indexhash.d.ts +21 -0
- package/dist/id-indexhash.d.ts.map +1 -0
- package/dist/id-multiset.d.ts +6 -0
- package/dist/id-multiset.d.ts.map +1 -0
- package/dist/id-multiset32.d.ts +2 -0
- package/dist/id-multiset32.d.ts.map +1 -0
- package/dist/index.cjs +449 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +272 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +405 -0
- package/dist/index.js.map +1 -0
- package/dist/largeObj.d.ts +119 -0
- package/dist/largeObj.d.ts.map +1 -0
- package/package.json +94 -22
- package/.npmignore +0 -4
- package/bin/genome.js +0 -3
- package/example/app/index.slm +0 -11
- package/example/app/robots.txt +0 -5
- package/example/app/scripts/app.js +0 -7
- package/example/app/styles/print.styl +0 -2
- package/example/app/styles/screen.styl +0 -3
- package/example/dist/index.html +0 -1
- package/example/dist/robots.txt +0 -5
- package/example/dist/scripts/app.js +0 -14
- package/example/dist/styles/print.css +0 -3
- package/example/dist/styles/screen.css +0 -4
- package/example/genomefile.js +0 -102
- package/example/package.json +0 -21
- package/index.js +0 -229
package/index.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var cp = require('fs-cp'),
|
|
4
|
-
fs = require('fs'),
|
|
5
|
-
gaze = require('gaze'),
|
|
6
|
-
glob = require('glob'),
|
|
7
|
-
mkdirp = require('mkdirp'),
|
|
8
|
-
path = require('path');
|
|
9
|
-
|
|
10
|
-
class Genome {
|
|
11
|
-
/**
|
|
12
|
-
* Genome constructor
|
|
13
|
-
*/
|
|
14
|
-
constructor () {
|
|
15
|
-
prototypeString(this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Spawns tasks passed in through command line
|
|
20
|
-
* @return {Promise}
|
|
21
|
-
*/
|
|
22
|
-
run () {
|
|
23
|
-
return this.spawn(process.argv.slice(2));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* genome task runner
|
|
28
|
-
* @param {string | [string]} tasks Tasks to perform
|
|
29
|
-
* @return {Promise} Resolves when all tasks are complete
|
|
30
|
-
*/
|
|
31
|
-
spawn (tasks) {
|
|
32
|
-
var promises = [],
|
|
33
|
-
all;
|
|
34
|
-
|
|
35
|
-
// Accept a string or an array
|
|
36
|
-
if (typeof tasks === 'string') {
|
|
37
|
-
tasks = [tasks];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
tasks.forEach(function(task, index, array) {
|
|
41
|
-
if (this._tasks[task]) {
|
|
42
|
-
console.log(`Doing ${task}...`);
|
|
43
|
-
|
|
44
|
-
promises.push(runGenerator(this._tasks[task]));
|
|
45
|
-
} else {
|
|
46
|
-
console.warn(`'${task}' is not a valid task`);
|
|
47
|
-
}
|
|
48
|
-
}.bind(this));
|
|
49
|
-
|
|
50
|
-
return Promise.all(promises).then(function() {
|
|
51
|
-
console.log('Done ', tasks.join(', '));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return all;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Promise wrapper for setTimout
|
|
59
|
-
* Useful for testing, but should not be necessary in production
|
|
60
|
-
* @param {int} time Passes to setTimeout()
|
|
61
|
-
* @param {anything} params Passes to resolve()
|
|
62
|
-
* @return {promise}
|
|
63
|
-
*/
|
|
64
|
-
wait (time, params) {
|
|
65
|
-
return new Promise(function(resolve) {
|
|
66
|
-
setTimeout(function() {
|
|
67
|
-
resolve(params);
|
|
68
|
-
}, time);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get tasks() {
|
|
73
|
-
return this._tasks;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
set tasks(tasks) {
|
|
77
|
-
this._tasks = tasks;
|
|
78
|
-
|
|
79
|
-
for (let taskName in tasks) {
|
|
80
|
-
this[taskName] = this[taskName] || this.spawn.bind(this, taskName);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Run generator as async function
|
|
87
|
-
* @param {fn} generatorFunc
|
|
88
|
-
* @return {Promise}
|
|
89
|
-
*/
|
|
90
|
-
function runGenerator(generatorFunc) {
|
|
91
|
-
function continuer(verb, arg) {
|
|
92
|
-
var result;
|
|
93
|
-
try {
|
|
94
|
-
result = generator[verb](arg);
|
|
95
|
-
} catch (err) {
|
|
96
|
-
return Promise.reject(err);
|
|
97
|
-
}
|
|
98
|
-
if (result.done) {
|
|
99
|
-
return result.value;
|
|
100
|
-
} else {
|
|
101
|
-
return Promise.resolve(result.value).then(onFulfilled, onRejected);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
var generator = generatorFunc();
|
|
105
|
-
var onFulfilled = continuer.bind(continuer, "next");
|
|
106
|
-
var onRejected = continuer.bind(continuer, "throw");
|
|
107
|
-
return onFulfilled();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Adds string methods and properties
|
|
112
|
-
*/
|
|
113
|
-
function prototypeString(genome) {
|
|
114
|
-
/**
|
|
115
|
-
* Watch file(s)
|
|
116
|
-
* @param {fn, string, [string]} task Function or task to call when files change
|
|
117
|
-
*/
|
|
118
|
-
String.prototype.onChange = function(task) {
|
|
119
|
-
var filename = this;
|
|
120
|
-
console.log(`Watching ${filename}...`);
|
|
121
|
-
|
|
122
|
-
gaze(filename, function(err, watcher) {
|
|
123
|
-
if (err) {
|
|
124
|
-
return console.error(err);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.on('all', function(event, whichFile) {
|
|
128
|
-
console.log(`${whichFile} was ${event}`);
|
|
129
|
-
|
|
130
|
-
if (typeof task === 'function') {
|
|
131
|
-
task(whichFile);
|
|
132
|
-
} else {
|
|
133
|
-
genome.spawn(task);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Process glob string, passing file contents into filter
|
|
141
|
-
* @param {fn} filter File contents get passed into this
|
|
142
|
-
* @param {string} ext Optional, change the extension of the file for output
|
|
143
|
-
* @return {Promise}
|
|
144
|
-
*/
|
|
145
|
-
String.prototype.use = function(filter, ext) {
|
|
146
|
-
var globPath = this;
|
|
147
|
-
|
|
148
|
-
return new Promise(function(resolve) {
|
|
149
|
-
var filenames = glob.sync(globPath),
|
|
150
|
-
files = [];
|
|
151
|
-
|
|
152
|
-
var promises = filenames.map(function(filename) {
|
|
153
|
-
return filename.contents.then(function(contents) {
|
|
154
|
-
var parsedPath = path.parse(filename);
|
|
155
|
-
|
|
156
|
-
if (ext) {
|
|
157
|
-
parsedPath.ext = ext;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
files.push({
|
|
161
|
-
filename: filename,
|
|
162
|
-
path: parsedPath,
|
|
163
|
-
data: filter(contents)
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
Promise
|
|
169
|
-
.all(promises)
|
|
170
|
-
.then(function() {
|
|
171
|
-
resolve(files);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
String.prototype.read = function() {
|
|
177
|
-
var filename = this;
|
|
178
|
-
|
|
179
|
-
return new Promise(function(resolve, reject) {
|
|
180
|
-
fs.readFile(filename, 'utf8', function(err, data) {
|
|
181
|
-
if (err) {
|
|
182
|
-
reject(err);
|
|
183
|
-
} else {
|
|
184
|
-
resolve(data);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
String.prototype.write = function(data) {
|
|
191
|
-
var dest = this;
|
|
192
|
-
|
|
193
|
-
if (data.readable) {
|
|
194
|
-
// If stream
|
|
195
|
-
return cp(data, dest);
|
|
196
|
-
} else if (data.splice) {
|
|
197
|
-
// If array of files
|
|
198
|
-
let promises = data.map(function(file) {
|
|
199
|
-
return path.normalize(`${dest}/${file.path.name}${file.path.ext}`).write(file.data);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
return Promise.all(promises);
|
|
203
|
-
} else {
|
|
204
|
-
// If string
|
|
205
|
-
return new Promise(function(resolve, reject) {
|
|
206
|
-
mkdirp.sync(path.dirname(dest));
|
|
207
|
-
fs.writeFile(dest, data, 'utf8', function(err) {
|
|
208
|
-
if (err) {
|
|
209
|
-
reject(err);
|
|
210
|
-
console.log('err ' , err);
|
|
211
|
-
} else {
|
|
212
|
-
resolve(data);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
Object.defineProperty(String.prototype, 'contents', {
|
|
220
|
-
get: function () {
|
|
221
|
-
return this.read();
|
|
222
|
-
},
|
|
223
|
-
set: function(data) {
|
|
224
|
-
this.write(data);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
module.exports = new Genome();
|