mirror of
https://github.com/penpot/penpot.git
synced 2025-06-24 20:16:59 +02:00
💄 Reformat affected JS files
This commit is contained in:
parent
3efd5cb9e8
commit
ecbedf847f
28 changed files with 720 additions and 285 deletions
|
@ -34,7 +34,9 @@ async function findFiles(basePath, predicate, options = {}) {
|
|||
return true;
|
||||
};
|
||||
|
||||
let files = await fs.readdir(basePath, { recursive: options.recursive ?? false });
|
||||
let files = await fs.readdir(basePath, {
|
||||
recursive: options.recursive ?? false,
|
||||
});
|
||||
files = files.map((path) => ph.join(basePath, path));
|
||||
|
||||
return files;
|
||||
|
@ -232,7 +234,9 @@ async function readTranslations() {
|
|||
lang = lang[0];
|
||||
}
|
||||
|
||||
const content = await fs.readFile(`./translations/${filename}`, { encoding: "utf-8" });
|
||||
const content = await fs.readFile(`./translations/${filename}`, {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
|
||||
lang = lang.toLowerCase();
|
||||
|
||||
|
@ -291,15 +295,23 @@ async function generateSvgSprite(files, prefix) {
|
|||
}
|
||||
|
||||
async function generateSvgSprites() {
|
||||
await fs.mkdir("resources/public/images/sprites/symbol/", { recursive: true });
|
||||
await fs.mkdir("resources/public/images/sprites/symbol/", {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
const icons = await findFiles("resources/images/icons/", isSvgFile);
|
||||
const iconsSprite = await generateSvgSprite(icons, "icon-");
|
||||
await fs.writeFile("resources/public/images/sprites/symbol/icons.svg", iconsSprite);
|
||||
await fs.writeFile(
|
||||
"resources/public/images/sprites/symbol/icons.svg",
|
||||
iconsSprite,
|
||||
);
|
||||
|
||||
const cursors = await findFiles("resources/images/cursors/", isSvgFile);
|
||||
const cursorsSprite = await generateSvgSprite(icons, "cursor-");
|
||||
await fs.writeFile("resources/public/images/sprites/symbol/cursors.svg", cursorsSprite);
|
||||
await fs.writeFile(
|
||||
"resources/public/images/sprites/symbol/cursors.svg",
|
||||
cursorsSprite,
|
||||
);
|
||||
}
|
||||
|
||||
async function generateTemplates() {
|
||||
|
@ -310,15 +322,23 @@ async function generateTemplates() {
|
|||
const manifest = await readShadowManifest();
|
||||
let content;
|
||||
|
||||
const iconsSprite = await fs.readFile("resources/public/images/sprites/symbol/icons.svg", "utf8");
|
||||
const cursorsSprite = await fs.readFile("resources/public/images/sprites/symbol/cursors.svg", "utf8");
|
||||
const iconsSprite = await fs.readFile(
|
||||
"resources/public/images/sprites/symbol/icons.svg",
|
||||
"utf8",
|
||||
);
|
||||
const cursorsSprite = await fs.readFile(
|
||||
"resources/public/images/sprites/symbol/cursors.svg",
|
||||
"utf8",
|
||||
);
|
||||
const partials = {
|
||||
"../public/images/sprites/symbol/icons.svg": iconsSprite,
|
||||
"../public/images/sprites/symbol/cursors.svg": cursorsSprite,
|
||||
};
|
||||
|
||||
const pluginRuntimeUri =
|
||||
process.env.PENPOT_PLUGIN_DEV === "true" ? "http://localhost:4200" : "./plugins-runtime";
|
||||
process.env.PENPOT_PLUGIN_DEV === "true"
|
||||
? "http://localhost:4200"
|
||||
: "./plugins-runtime";
|
||||
|
||||
content = await renderTemplate(
|
||||
"resources/templates/index.mustache",
|
||||
|
@ -411,7 +431,10 @@ export async function copyAssets() {
|
|||
|
||||
await syncDirs("resources/images/", "resources/public/images/");
|
||||
await syncDirs("resources/fonts/", "resources/public/fonts/");
|
||||
await syncDirs("resources/plugins-runtime/", "resources/public/plugins-runtime/");
|
||||
await syncDirs(
|
||||
"resources/plugins-runtime/",
|
||||
"resources/public/plugins-runtime/",
|
||||
);
|
||||
|
||||
const end = process.hrtime(start);
|
||||
log.info("done: copy assets", `(${ppt(end)})`);
|
||||
|
|
|
@ -17,18 +17,21 @@ async function compileFile(path) {
|
|||
const name = ph.basename(path, ".scss");
|
||||
const dest = `${dir}${ph.sep}${name}.css`;
|
||||
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const result = await compiler.compileAsync(path, {
|
||||
loadPaths: ["node_modules/animate.css", "resources/styles/common/", "resources/styles"],
|
||||
sourceMap: false
|
||||
loadPaths: [
|
||||
"node_modules/animate.css",
|
||||
"resources/styles/common/",
|
||||
"resources/styles",
|
||||
],
|
||||
sourceMap: false,
|
||||
});
|
||||
// console.dir(result);
|
||||
resolve({
|
||||
inputPath: path,
|
||||
outputPath: dest,
|
||||
css: result.css
|
||||
css: result.css,
|
||||
});
|
||||
} catch (cause) {
|
||||
// console.error(cause);
|
||||
|
@ -56,7 +59,7 @@ function configureModulesProcessor(options) {
|
|||
});
|
||||
}
|
||||
|
||||
function configureProcessor(options={}) {
|
||||
function configureProcessor(options = {}) {
|
||||
const processors = [];
|
||||
|
||||
if (options.modules) {
|
||||
|
@ -78,7 +81,7 @@ async function postProcessFile(data, options) {
|
|||
});
|
||||
|
||||
return Object.assign(data, {
|
||||
css: result.css
|
||||
css: result.css,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -87,11 +90,14 @@ async function compile(path, options) {
|
|||
return await postProcessFile(result, options);
|
||||
}
|
||||
|
||||
wpool.worker({
|
||||
compileSass: compile
|
||||
}, {
|
||||
onTerminate: async (code) => {
|
||||
// log.info("worker: terminate");
|
||||
await compiler.dispose();
|
||||
}
|
||||
});
|
||||
wpool.worker(
|
||||
{
|
||||
compileSass: compile,
|
||||
},
|
||||
{
|
||||
onTerminate: async (code) => {
|
||||
// log.info("worker: terminate");
|
||||
await compiler.dispose();
|
||||
},
|
||||
},
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@ import log from "fancy-log";
|
|||
import * as h from "./_helpers.js";
|
||||
|
||||
await h.compileStyles();
|
||||
await h.copyAssets()
|
||||
await h.compileSvgSprites()
|
||||
await h.copyAssets();
|
||||
await h.compileSvgSprites();
|
||||
await h.compileTemplates();
|
||||
await h.compilePolyfills();
|
||||
|
|
|
@ -9,7 +9,10 @@ const port = 3000;
|
|||
|
||||
app.use(compression());
|
||||
|
||||
const staticPath = path.join(fileURLToPath(import.meta.url), "../../resources/public");
|
||||
const staticPath = path.join(
|
||||
fileURLToPath(import.meta.url),
|
||||
"../../resources/public",
|
||||
);
|
||||
app.use(express.static(staticPath));
|
||||
|
||||
app.listen(port, () => {
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
const fs = require('fs').promises;
|
||||
const fs = require("fs").promises;
|
||||
const gt = require("gettext-parser");
|
||||
const path = require('path');
|
||||
const util = require('node:util');
|
||||
const execFile = util.promisify(require('node:child_process').execFile);
|
||||
const path = require("path");
|
||||
const util = require("node:util");
|
||||
const execFile = util.promisify(require("node:child_process").execFile);
|
||||
|
||||
|
||||
async function processMsgId(msgId){
|
||||
return execFile('grep', ['-r', '-o', msgId, './src'])
|
||||
.catch(()=> { return msgId})
|
||||
async function processMsgId(msgId) {
|
||||
return execFile("grep", ["-r", "-o", msgId, "./src"]).catch(() => {
|
||||
return msgId;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function processFile(f) {
|
||||
const content = await fs.readFile(f);
|
||||
const data = gt.po.parse(content, "utf-8")
|
||||
const translations = data.translations[''];
|
||||
const data = gt.po.parse(content, "utf-8");
|
||||
const translations = data.translations[""];
|
||||
const badIds = [];
|
||||
|
||||
for (const property in translations) {
|
||||
const data = await processMsgId(translations[property].msgid);
|
||||
if (data!=null && data.stdout === undefined){
|
||||
badIds.push(data)
|
||||
if (data != null && data.stdout === undefined) {
|
||||
badIds.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,63 +27,77 @@ async function processFile(f) {
|
|||
}
|
||||
|
||||
async function cleanFile(f, badIds) {
|
||||
console.log ("\n\nDoing automatic cleanup")
|
||||
console.log("\n\nDoing automatic cleanup");
|
||||
|
||||
const content = await fs.readFile(f);
|
||||
const data = gt.po.parse(content, "utf-8");
|
||||
const translations = data.translations[''];
|
||||
const translations = data.translations[""];
|
||||
const keys = Object.keys(translations);
|
||||
|
||||
for (const key of keys) {
|
||||
property = translations[key];
|
||||
if (badIds.includes(property.msgid)){
|
||||
console.log ('----> deleting', property.msgid)
|
||||
delete data.translations[''][key];
|
||||
if (badIds.includes(property.msgid)) {
|
||||
console.log("----> deleting", property.msgid);
|
||||
delete data.translations[""][key];
|
||||
}
|
||||
}
|
||||
|
||||
const buff = gt.po.compile(data, {sort: true});
|
||||
const buff = gt.po.compile(data, { sort: true });
|
||||
await fs.writeFile(f, buff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function findExecutionTimeTranslations() {
|
||||
const { stdout } = await execFile('grep', ['-r', '-h', '-F', '(tr (', './src']);
|
||||
const { stdout } = await execFile("grep", [
|
||||
"-r",
|
||||
"-h",
|
||||
"-F",
|
||||
"(tr (",
|
||||
"./src",
|
||||
]);
|
||||
console.log(stdout);
|
||||
}
|
||||
|
||||
async function welcome() {
|
||||
console.log ('####################################################################')
|
||||
console.log ('# UNUSED TRANSLATIONS FINDER #')
|
||||
console.log ('####################################################################')
|
||||
console.log ('\n');
|
||||
console.log ('DISCLAIMER: Some translations are only available at execution time.')
|
||||
console.log (' This finder can\'t process them, so there can be')
|
||||
console.log (' false positives.\n')
|
||||
console.log (' If you want to do an automatic clean anyway,')
|
||||
console.log (' call the script with:')
|
||||
console.log (' npm run find-unused-translations -- --clean')
|
||||
console.log (' For example:');
|
||||
console.log ('--------------------------------------------------------------------');
|
||||
console.log(
|
||||
"####################################################################",
|
||||
);
|
||||
console.log(
|
||||
"# UNUSED TRANSLATIONS FINDER #",
|
||||
);
|
||||
console.log(
|
||||
"####################################################################",
|
||||
);
|
||||
console.log("\n");
|
||||
console.log(
|
||||
"DISCLAIMER: Some translations are only available at execution time.",
|
||||
);
|
||||
console.log(" This finder can't process them, so there can be");
|
||||
console.log(" false positives.\n");
|
||||
console.log(" If you want to do an automatic clean anyway,");
|
||||
console.log(" call the script with:");
|
||||
console.log(" npm run find-unused-translations -- --clean");
|
||||
console.log(" For example:");
|
||||
console.log(
|
||||
"--------------------------------------------------------------------",
|
||||
);
|
||||
await findExecutionTimeTranslations();
|
||||
console.log ('--------------------------------------------------------------------');
|
||||
console.log(
|
||||
"--------------------------------------------------------------------",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const doCleanup = process.argv.slice(2)[0] == "--clean";
|
||||
|
||||
|
||||
;(async () => {
|
||||
(async () => {
|
||||
await welcome();
|
||||
const target = path.normalize("./translations/en.po");
|
||||
const badIds = await processFile(target);
|
||||
|
||||
if (doCleanup){
|
||||
if (doCleanup) {
|
||||
cleanFile(target, badIds);
|
||||
} else {
|
||||
for (const badId of badIds){
|
||||
for (const badId of badIds) {
|
||||
console.log(badId);
|
||||
}
|
||||
}
|
||||
})()
|
||||
})();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {promises as fs} from 'fs';
|
||||
import gt from 'gettext-parser';
|
||||
import l from 'lodash';
|
||||
import path from 'path';
|
||||
import { promises as fs } from "fs";
|
||||
import gt from "gettext-parser";
|
||||
import l from "lodash";
|
||||
import path from "path";
|
||||
|
||||
async function* getFiles(dir) {
|
||||
const dirents = await fs.readdir(dir, { withFileTypes: true });
|
||||
|
@ -15,7 +15,7 @@ async function* getFiles(dir) {
|
|||
}
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
(async () => {
|
||||
const fileRe = /.+\.po$/;
|
||||
const target = path.normalize("./translations/");
|
||||
const parent = path.join(target, "..");
|
||||
|
@ -24,8 +24,8 @@ async function* getFiles(dir) {
|
|||
const entry = path.relative(parent, f);
|
||||
console.log(`=> processing: ${entry}`);
|
||||
const content = await fs.readFile(f);
|
||||
const data = gt.po.parse(content, "utf-8")
|
||||
const buff = gt.po.compile(data, {sort: true});
|
||||
const data = gt.po.parse(content, "utf-8");
|
||||
const buff = gt.po.compile(data, { sort: true });
|
||||
await fs.writeFile(f, buff);
|
||||
}
|
||||
})()
|
||||
})();
|
||||
|
|
|
@ -11,7 +11,7 @@ let sass = null;
|
|||
|
||||
async function compileSassAll() {
|
||||
const start = process.hrtime();
|
||||
log.info("init: compile styles")
|
||||
log.info("init: compile styles");
|
||||
|
||||
sass = await h.compileSassAll(worker);
|
||||
let output = await h.concatSass(sass);
|
||||
|
@ -24,7 +24,7 @@ async function compileSassAll() {
|
|||
async function compileSass(path) {
|
||||
const start = process.hrtime();
|
||||
log.info("changed:", path);
|
||||
const result = await h.compileSass(worker, path, {modules:true});
|
||||
const result = await h.compileSass(worker, path, { modules: true });
|
||||
sass.index[result.outputPath] = result.css;
|
||||
|
||||
const output = h.concatSass(sass);
|
||||
|
@ -37,12 +37,12 @@ async function compileSass(path) {
|
|||
|
||||
await fs.mkdir("./resources/public/css/", { recursive: true });
|
||||
await compileSassAll();
|
||||
await h.copyAssets()
|
||||
await h.compileSvgSprites()
|
||||
await h.copyAssets();
|
||||
await h.compileSvgSprites();
|
||||
await h.compileTemplates();
|
||||
await h.compilePolyfills();
|
||||
|
||||
log.info("watch: scss src (~)")
|
||||
log.info("watch: scss src (~)");
|
||||
|
||||
h.watch("src", h.isSassFile, async function (path) {
|
||||
if (path.includes("common")) {
|
||||
|
@ -52,30 +52,34 @@ h.watch("src", h.isSassFile, async function (path) {
|
|||
}
|
||||
});
|
||||
|
||||
log.info("watch: scss: resources (~)")
|
||||
log.info("watch: scss: resources (~)");
|
||||
h.watch("resources/styles", h.isSassFile, async function (path) {
|
||||
log.info("changed:", path);
|
||||
await compileSassAll()
|
||||
await compileSassAll();
|
||||
});
|
||||
|
||||
log.info("watch: templates (~)")
|
||||
log.info("watch: templates (~)");
|
||||
h.watch("resources/templates", null, async function (path) {
|
||||
log.info("changed:", path);
|
||||
await h.compileTemplates();
|
||||
});
|
||||
|
||||
log.info("watch: translations (~)")
|
||||
log.info("watch: translations (~)");
|
||||
h.watch("translations", null, async function (path) {
|
||||
log.info("changed:", path);
|
||||
await h.compileTemplates();
|
||||
});
|
||||
|
||||
log.info("watch: assets (~)")
|
||||
h.watch(["resources/images", "resources/fonts", "resources/plugins-runtime"], null, async function (path) {
|
||||
log.info("changed:", path);
|
||||
await h.compileSvgSprites();
|
||||
await h.copyAssets();
|
||||
await h.compileTemplates();
|
||||
});
|
||||
log.info("watch: assets (~)");
|
||||
h.watch(
|
||||
["resources/images", "resources/fonts", "resources/plugins-runtime"],
|
||||
null,
|
||||
async function (path) {
|
||||
log.info("changed:", path);
|
||||
await h.compileSvgSprites();
|
||||
await h.copyAssets();
|
||||
await h.compileTemplates();
|
||||
},
|
||||
);
|
||||
|
||||
worker.terminate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue