-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
58 lines (48 loc) · 1.84 KB
/
index.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
'use strict';
const fs = require('fs');
const path = require('path');
const transforms = require('./build/transforms.json');
const TRANSFORM_PATH = '/lib/transforms';
const transformVersionDirs = fs.readdirSync(path.join(__dirname, TRANSFORM_PATH));
let transformFiles = [];
// We are going to add the order from the transforms.json file
// First let's create a map based on the file name
const transformsOrdered = transforms.reduce((acc, current) => {
// Only get the order for copy's
if (current.copy) {
current.copy.forEach(prop => {
if (prop.type === 'transform' && prop.order) {
acc[prop.outputPath] = prop.order;
}
});
}
return acc;
}, {});
function getTransforms(versionDir) {
const dirPath = path.join(__dirname, `${TRANSFORM_PATH}/${versionDir}`);
if(fs.lstatSync(dirPath).isDirectory()) {
const transformDirs = fs.readdirSync(dirPath);
transformDirs.forEach((transformDir) => {
const innerDirPath = path.join(__dirname, `${TRANSFORM_PATH}/${versionDir}/${transformDir}`);
const transforms = fs.readdirSync(innerDirPath);
transforms.forEach((transformFile) => {
if(transformFile.indexOf('-test.js') === -1) {
const version = versionDir.charAt(versionDir.length - 1);
const transform = {
name: `${transformDir}/${transformFile}`,
fileName: `${transformDir}/${transformFile}`,
file: path.join(__dirname, `${TRANSFORM_PATH}/${versionDir}/${transformDir}/${transformFile}`),
version
};
// If this
if (transformsOrdered[transform.fileName]) {
transform.order = transformsOrdered[transform.fileName];
}
transformFiles.push(transform);
}
});
});
}
}
transformVersionDirs.forEach((dir) => {getTransforms(dir)});
module.exports = transformFiles;