Adjust image gen plugin
This commit is contained in:
1 parent
9fddd40ff3
commit
ea5ca1c45d
11 files changed
+35
-31
No files matched your search
@@ -2,21 +2,21 @@
|
|||||||
inputHash: '0536f51fa72c2e4e368ea0e901aadfc1',
|
inputHash: '0536f51fa72c2e4e368ea0e901aadfc1',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/splash-screen_fhd.jpg',
|
outputFilePath: 'images/splash-screen_fhd.jpg',
|
||||||
outputHash: 'b15f3a3f1ccc459cbca12cb828b78d16',
|
outputHash: 'b15f3a3f1ccc459cbca12cb828b78d16',
|
||||||
width: 1920,
|
width: 1920,
|
||||||
height: 1080,
|
height: 1080,
|
||||||
background: '#242424',
|
background: '#242424',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/splash-screen_hd.jpg',
|
outputFilePath: 'images/splash-screen_hd.jpg',
|
||||||
outputHash: '25e9c4220f8a42101d6333e548e33aa8',
|
outputHash: '25e9c4220f8a42101d6333e548e33aa8',
|
||||||
width: 1280,
|
width: 1280,
|
||||||
height: 720,
|
height: 720,
|
||||||
background: '#242424',
|
background: '#242424',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/splash-screen_sd.jpg',
|
outputFilePath: 'images/splash-screen_sd.jpg',
|
||||||
outputHash: 'c54a2f7fa65f443263806962450f2c04',
|
outputHash: 'c54a2f7fa65f443263806962450f2c04',
|
||||||
width: 720,
|
width: 720,
|
||||||
height: 480,
|
height: 480,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
inputHash: "d61131ccc714d8df0b4514ca76883494",
|
inputHash: 'd61131ccc714d8df0b4514ca76883494',
|
||||||
outputs: [],
|
outputs: [],
|
||||||
}
|
}
|
||||||
@@ -2,21 +2,21 @@
|
|||||||
inputHash: '3452c6ea1c84f59aedf5530bf86a7a51',
|
inputHash: '3452c6ea1c84f59aedf5530bf86a7a51',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/channel-poster_fhd.png',
|
outputFilePath: 'images/channel-poster_fhd.png',
|
||||||
outputHash: 'd644a0db84deed0bcc41a41d08a4ef75',
|
outputHash: 'd644a0db84deed0bcc41a41d08a4ef75',
|
||||||
width: 540,
|
width: 540,
|
||||||
height: 405,
|
height: 405,
|
||||||
background: '#FFFFFF',
|
background: '#FFFFFF',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/channel-poster_hd.png',
|
outputFilePath: 'images/channel-poster_hd.png',
|
||||||
outputHash: 'd07a4ffaa021b55528bee91710f4e9d2',
|
outputHash: 'd07a4ffaa021b55528bee91710f4e9d2',
|
||||||
width: 290,
|
width: 290,
|
||||||
height: 218,
|
height: 218,
|
||||||
background: '#FFFFFF',
|
background: '#FFFFFF',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/channel-poster_sd.png',
|
outputFilePath: 'images/channel-poster_sd.png',
|
||||||
outputHash: '66a311c639f89ff009e4624468282b2f',
|
outputHash: '66a311c639f89ff009e4624468282b2f',
|
||||||
width: 246,
|
width: 246,
|
||||||
height: 140,
|
height: 140,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: 'b88a05052cd01cb7a89bd6802418d79e',
|
inputHash: 'b88a05052cd01cb7a89bd6802418d79e',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/filters-black.png',
|
outputFilePath: 'images/icons/filters-black.png',
|
||||||
outputHash: 'f0a7539ae840c00a2d91292f993bb75e',
|
outputHash: 'f0a7539ae840c00a2d91292f993bb75e',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: 'df7918a3b43642f707cc0d9fcfd2d9ee',
|
inputHash: 'df7918a3b43642f707cc0d9fcfd2d9ee',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/filters-white.png',
|
outputFilePath: 'images/icons/filters-white.png',
|
||||||
outputHash: '914e2c8da9772c23c24bebbd39c918f2',
|
outputHash: '914e2c8da9772c23c24bebbd39c918f2',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: '788d5e9ddc5a26953392afa17a85a05c',
|
inputHash: '788d5e9ddc5a26953392afa17a85a05c',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/home.png',
|
outputFilePath: 'images/icons/home.png',
|
||||||
outputHash: '3da3ed864137ace837ef2f96a4e5e13d',
|
outputHash: '3da3ed864137ace837ef2f96a4e5e13d',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: '92a5720049ca36c38c695969534c2bb5',
|
inputHash: '92a5720049ca36c38c695969534c2bb5',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/info.png',
|
outputFilePath: 'images/icons/info.png',
|
||||||
outputHash: '31b5c5c342ded1bc99b3466c2fbaaf09',
|
outputHash: '31b5c5c342ded1bc99b3466c2fbaaf09',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: 'e6318f56ce4c0cc637cf0cc3180a2013',
|
inputHash: 'e6318f56ce4c0cc637cf0cc3180a2013',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/phone.png',
|
outputFilePath: 'images/icons/phone.png',
|
||||||
outputHash: '2d7ece94b64fa5a725adeea5a313cbcf',
|
outputHash: '2d7ece94b64fa5a725adeea5a313cbcf',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: 'dede98d4bf3c835836c82c485600108c',
|
inputHash: 'dede98d4bf3c835836c82c485600108c',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/search.png',
|
outputFilePath: 'images/icons/search.png',
|
||||||
outputHash: '5b5fb4128202a1e074b04ee570bbcf69',
|
outputHash: '5b5fb4128202a1e074b04ee570bbcf69',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
inputHash: '11d4a0bfa1ae239216088d825851ec4a',
|
inputHash: '11d4a0bfa1ae239216088d825851ec4a',
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
outputFilePath: 'src/images/icons/settings.png',
|
outputFilePath: 'images/icons/settings.png',
|
||||||
outputHash: '1b6d024df95af8b002e469453e29a632',
|
outputHash: '1b6d024df95af8b002e469453e29a632',
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
// This plugin converts svg files to png/jpeg files
|
// This plugin converts svg files to png/jpeg files
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CompilerPlugin, ProgramBuilder,
|
CompilerPlugin, FileObj, ProgramBuilder,
|
||||||
} from 'brighterscript';
|
} from 'brighterscript';
|
||||||
import { readFileSync, renameSync, rmSync, writeFileSync } from 'fs';
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
import { existsSync } from 'fs-extra';
|
import { existsSync } from 'fs-extra';
|
||||||
import { globSync } from 'glob';
|
import { globSync } from 'glob';
|
||||||
import md5 from 'crypto-js/md5';
|
import md5 from 'crypto-js/md5';
|
||||||
import { join as joinPath, relative as relativePath } from 'path';
|
import { join as joinPath } from 'path';
|
||||||
import json5 from 'json5';
|
import json5 from 'json5';
|
||||||
const shell = require('shelljs');
|
const shell = require('shelljs');
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ const META_EXT = '.meta.json5';
|
|||||||
export class ImageGenPlugin implements CompilerPlugin {
|
export class ImageGenPlugin implements CompilerPlugin {
|
||||||
public name = 'ImageGenPlugin';
|
public name = 'ImageGenPlugin';
|
||||||
|
|
||||||
beforeProgramCreate(builder: ProgramBuilder) {
|
beforePrepublish(builder: ProgramBuilder, files: FileObj[]) {
|
||||||
// Debug flag
|
// Debug flag
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const debug = !!builder.options.debug;
|
const debug = !!builder.options.debug;
|
||||||
@@ -30,21 +30,20 @@ export class ImageGenPlugin implements CompilerPlugin {
|
|||||||
|
|
||||||
const svgFiles = globSync(`**/*.svg`, { cwd: rootDir });
|
const svgFiles = globSync(`**/*.svg`, { cwd: rootDir });
|
||||||
|
|
||||||
svgFiles.forEach((svg) => {
|
svgFiles.forEach((svgFile) => {
|
||||||
// Web app can use svg files, no need to convert
|
// Web app can use svg files, no need to convert
|
||||||
if (svg.includes('www')) {
|
if (svgFile.includes('www')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const svgFile = relativePath(process.cwd(), joinPath(rootDir, svg));
|
const metafile = joinPath(rootDir, `${svgFile}${META_EXT}`);
|
||||||
const metafile = `${svgFile}${META_EXT}`;
|
|
||||||
if (!existsSync(metafile)) {
|
if (!existsSync(metafile)) {
|
||||||
this.createDefaultMetaFile(svgFile, metafile);
|
this.createDefaultMetaFile(svgFile, metafile);
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta = json5.parse(readFileSync(metafile, 'utf8'));
|
const meta = json5.parse(readFileSync(metafile, 'utf8'));
|
||||||
|
|
||||||
this.generateImages(svgFile, meta, metafile);
|
this.generateImages(svgFile, meta, metafile, rootDir, files);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +61,9 @@ export class ImageGenPlugin implements CompilerPlugin {
|
|||||||
writeFileSync(metafile, json5.stringify(meta, null, 2));
|
writeFileSync(metafile, json5.stringify(meta, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
generateImages(svgFile: string, meta: any, metafile: string) {
|
generateImages(svgFile: string, meta: any, metafile: string, rootDir: string, files: FileObj[]) {
|
||||||
let metaChanged = false;
|
let metaChanged = false;
|
||||||
const inputHash = this.checkFileHash(svgFile, meta.inputHash);
|
const inputHash = this.checkFileHash(joinPath(rootDir, svgFile), meta.inputHash);
|
||||||
if (!inputHash.valid) {
|
if (!inputHash.valid) {
|
||||||
meta.inputHash = inputHash.hash;
|
meta.inputHash = inputHash.hash;
|
||||||
metaChanged = true;
|
metaChanged = true;
|
||||||
@@ -73,14 +72,17 @@ export class ImageGenPlugin implements CompilerPlugin {
|
|||||||
for (var i in meta.outputs) {
|
for (var i in meta.outputs) {
|
||||||
const output = meta.outputs[i];
|
const output = meta.outputs[i];
|
||||||
|
|
||||||
let outputHash = this.checkFileHash(output.outputFilePath, output.outputHash);
|
const outputFilePath = joinPath(rootDir, output.outputFilePath);
|
||||||
|
let outputHash = this.checkFileHash(outputFilePath, output.outputHash);
|
||||||
|
|
||||||
if (inputHash.valid && outputHash.valid) {
|
if (inputHash.valid && outputHash.valid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.generateImage(svgFile, output);
|
this.generateImage(svgFile, output, rootDir);
|
||||||
outputHash = this.checkFileHash(output.outputFilePath, output.outputHash);
|
outputHash = this.checkFileHash(outputFilePath, output.outputHash);
|
||||||
|
|
||||||
|
files.push({ src: outputFilePath, dest: output.outputFilePath })
|
||||||
|
|
||||||
output.outputHash = outputHash.hash;
|
output.outputHash = outputHash.hash;
|
||||||
metaChanged = true;
|
metaChanged = true;
|
||||||
@@ -91,8 +93,10 @@ export class ImageGenPlugin implements CompilerPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateImage(svgFile: string, output: any) {
|
generateImage(svgFile: string, output: any, rootDir: string) {
|
||||||
shell.exec(`node ../tools/convert-image.js --input "${svgFile}" --options '${JSON.stringify(output)}'`)
|
shell.exec(`node ../../tools/convert-image.js --input "${svgFile}" --options '${JSON.stringify(output)}'`, {
|
||||||
|
cwd: rootDir
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
checkFileHash(file: string, hash: string) {
|
checkFileHash(file: string, hash: string) {
|
||||||
|
|||||||
Reference in new issue
Block a user