-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 1.73 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
#!/usr/bin/env node
const _ = require('lodash');
const { resolve: resolvePath } = require('path');
const { writeFileSync } = require('fs');
const zipTheme = require('./lib/zipTheme');
const generateIcons = require('./lib/generateIcons');
const reCreateDir = require('./lib/reCreateDir');
const getVariations = require('./lib/getVariations');
const { DIST_FOLDER } = require('./lib/constants');
const generateFirefoxManifest = require('./lib/firefox/generateFirefoxManifest');
const generateChromeManifest = require('./lib/chrome/generateChromeManifest');
const writeInDist = async ({ version, colorName, hexColor, chromeManifest, chromeFolderName, firefoxManifest, firefoxFolderName }) => {
const promises = _(
[
{ folderName: chromeFolderName, manifest: chromeManifest, shouldAddIcons: true },
{ folderName: firefoxFolderName, manifest: firefoxManifest, shouldAddIcons: false },
])
.map(({ folderName, manifest, shouldAddIcons }) => {
const targetFolderPath = resolvePath(DIST_FOLDER, folderName);
reCreateDir(targetFolderPath);
const targetManifestPath = resolvePath(targetFolderPath, 'manifest.json');
writeFileSync(targetManifestPath, JSON.stringify(manifest, null, 2), 'utf8');
const iconsGenerator = shouldAddIcons ? generateIcons(hexColor, targetFolderPath) : Promise.resolve();
return iconsGenerator.then(() => zipTheme(colorName, targetFolderPath, version));
})
.flatten()
.value();
return Promise.all(promises);
};
reCreateDir(DIST_FOLDER);
_(getVariations())
.map(variation => ({
...variation,
chromeManifest: generateChromeManifest(variation),
firefoxManifest: generateFirefoxManifest(variation),
}))
.each(builtVariation => writeInDist(builtVariation));