mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
💄 Reformat JS file
This commit is contained in:
parent
7461126d1a
commit
d30eca016e
1 changed files with 52 additions and 48 deletions
|
@ -19,19 +19,22 @@ function getCoreCount() {
|
||||||
return os.cpus().length;
|
return os.cpus().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const __filename = url.fileURLToPath(import.meta.url);
|
|
||||||
export const dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
export const dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
export function startWorker() {
|
export function startWorker() {
|
||||||
return wpool.pool(dirname + "/_worker.js", {
|
return wpool.pool(dirname + "/_worker.js", {
|
||||||
maxWorkers: getCoreCount()
|
maxWorkers: getCoreCount(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findFiles(basePath, predicate, options = {}) {
|
async function findFiles(basePath, predicate, options = {}) {
|
||||||
predicate = predicate ?? function() { return true; }
|
predicate =
|
||||||
|
predicate ??
|
||||||
|
function () {
|
||||||
|
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));
|
files = files.map((path) => ph.join(basePath, path));
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
|
@ -42,8 +45,11 @@ function syncDirs(originPath, destPath) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
proc.exec(command, (cause, stdout) => {
|
proc.exec(command, (cause, stdout) => {
|
||||||
if (cause) { reject(cause); }
|
if (cause) {
|
||||||
else { resolve(); }
|
reject(cause);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -71,14 +77,13 @@ export async function compileSassAll(worker) {
|
||||||
const limitFn = pLimit(4);
|
const limitFn = pLimit(4);
|
||||||
const sourceDir = "src";
|
const sourceDir = "src";
|
||||||
|
|
||||||
let files = await fs.readdir(sourceDir, { recursive: true })
|
let files = await fs.readdir(sourceDir, { recursive: true });
|
||||||
files = files.filter((path) => path.endsWith(".scss"));
|
files = files.filter((path) => path.endsWith(".scss"));
|
||||||
files = files.map((path) => ph.join(sourceDir, path));
|
files = files.map((path) => ph.join(sourceDir, path));
|
||||||
// files = files.slice(0, 10);
|
|
||||||
|
|
||||||
const procs = [
|
const procs = [
|
||||||
compileSass(worker, "resources/styles/main-default.scss", {}),
|
compileSass(worker, "resources/styles/main-default.scss", {}),
|
||||||
compileSass(worker, "resources/styles/debug.scss", {})
|
compileSass(worker, "resources/styles/debug.scss", {}),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let path of files) {
|
for (let path of files) {
|
||||||
|
@ -88,11 +93,14 @@ export async function compileSassAll(worker) {
|
||||||
|
|
||||||
const result = await Promise.all(procs);
|
const result = await Promise.all(procs);
|
||||||
|
|
||||||
return result.reduce((acc, item, index) => {
|
return result.reduce(
|
||||||
|
(acc, item, index) => {
|
||||||
acc.index[item.outputPath] = item.css;
|
acc.index[item.outputPath] = item.css;
|
||||||
acc.items.push(item.outputPath);
|
acc.items.push(item.outputPath);
|
||||||
return acc;
|
return acc;
|
||||||
}, {index:{}, items: []});
|
},
|
||||||
|
{ index: {}, items: [] },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function compare(a, b) {
|
function compare(a, b) {
|
||||||
|
@ -106,7 +114,7 @@ function compare(a, b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function concatSass(data) {
|
export function concatSass(data) {
|
||||||
const output = []
|
const output = [];
|
||||||
|
|
||||||
for (let path of data.items) {
|
for (let path of data.items) {
|
||||||
output.push(data.index[path]);
|
output.push(data.index[path]);
|
||||||
|
@ -118,10 +126,9 @@ export function concatSass(data) {
|
||||||
export async function watch(baseDir, predicate, callback) {
|
export async function watch(baseDir, predicate, callback) {
|
||||||
predicate = predicate ?? (() => true);
|
predicate = predicate ?? (() => true);
|
||||||
|
|
||||||
|
|
||||||
const watcher = new Watcher(baseDir, {
|
const watcher = new Watcher(baseDir, {
|
||||||
persistent: true,
|
persistent: true,
|
||||||
recursive: true
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
watcher.on("change", (path) => {
|
watcher.on("change", (path) => {
|
||||||
|
@ -133,7 +140,7 @@ export async function watch(baseDir, predicate, callback) {
|
||||||
|
|
||||||
async function readShadowManifest() {
|
async function readShadowManifest() {
|
||||||
try {
|
try {
|
||||||
const manifestPath = "resources/public/js/manifest.json"
|
const manifestPath = "resources/public/js/manifest.json";
|
||||||
let content = await fs.readFile(manifestPath, { encoding: "utf8" });
|
let content = await fs.readFile(manifestPath, { encoding: "utf8" });
|
||||||
content = JSON.parse(content);
|
content = JSON.parse(content);
|
||||||
|
|
||||||
|
@ -148,7 +155,6 @@ async function readShadowManifest() {
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
// log.error("error on reading manifest (using default)", cause);
|
|
||||||
return {
|
return {
|
||||||
config: "js/config.js",
|
config: "js/config.js",
|
||||||
polyfills: "js/polyfills.js",
|
polyfills: "js/polyfills.js",
|
||||||
|
@ -167,7 +173,7 @@ async function renderTemplate(path, context={}, partials={}) {
|
||||||
|
|
||||||
context = Object.assign({}, context, {
|
context = Object.assign({}, context, {
|
||||||
ts: ts,
|
ts: ts,
|
||||||
isDebug: process.env.NODE_ENV !== "production"
|
isDebug: process.env.NODE_ENV !== "production",
|
||||||
});
|
});
|
||||||
|
|
||||||
return mustache.render(content, context, partials);
|
return mustache.render(content, context, partials);
|
||||||
|
@ -214,9 +220,8 @@ async function readTranslations() {
|
||||||
// this happens when file does not matches correct
|
// this happens when file does not matches correct
|
||||||
// iso code for the language.
|
// iso code for the language.
|
||||||
["ja_jp", "jpn_JP"],
|
["ja_jp", "jpn_JP"],
|
||||||
// ["fi", "fin_FI"],
|
|
||||||
["uk", "ukr_UA"],
|
["uk", "ukr_UA"],
|
||||||
"ha"
|
"ha",
|
||||||
];
|
];
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
|
@ -261,10 +266,6 @@ async function readTranslations() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// if (key === "modals.delete-font.title") {
|
|
||||||
// console.dir(trdata[key], {depth:10});
|
|
||||||
// console.dir(result[key], {depth:10});
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,12 +275,12 @@ async function readTranslations() {
|
||||||
async function generateSvgSprite(files, prefix) {
|
async function generateSvgSprite(files, prefix) {
|
||||||
const spriter = new SVGSpriter({
|
const spriter = new SVGSpriter({
|
||||||
mode: {
|
mode: {
|
||||||
symbol: { inline: true }
|
symbol: { inline: true },
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let path of files) {
|
for (let path of files) {
|
||||||
const name = `${prefix}${ph.basename(path)}`
|
const name = `${prefix}${ph.basename(path)}`;
|
||||||
const content = await fs.readFile(path, { encoding: "utf-8" });
|
const content = await fs.readFile(path, { encoding: "utf-8" });
|
||||||
spriter.add(name, name, content);
|
spriter.add(name, name, content);
|
||||||
}
|
}
|
||||||
|
@ -315,13 +316,18 @@ async function generateTemplates() {
|
||||||
"../public/images/sprites/symbol/cursors.svg": cursorsSprite,
|
"../public/images/sprites/symbol/cursors.svg": cursorsSprite,
|
||||||
};
|
};
|
||||||
|
|
||||||
const pluginRuntimeUri = (process.env.PENPOT_PLUGIN_DEV === "true") ? "http://localhost:4200" : "./plugins-runtime";
|
const pluginRuntimeUri =
|
||||||
|
process.env.PENPOT_PLUGIN_DEV === "true" ? "http://localhost:4200" : "./plugins-runtime";
|
||||||
|
|
||||||
content = await renderTemplate("resources/templates/index.mustache", {
|
content = await renderTemplate(
|
||||||
|
"resources/templates/index.mustache",
|
||||||
|
{
|
||||||
manifest: manifest,
|
manifest: manifest,
|
||||||
translations: JSON.stringify(translations),
|
translations: JSON.stringify(translations),
|
||||||
pluginRuntimeUri,
|
pluginRuntimeUri,
|
||||||
}, partials);
|
},
|
||||||
|
partials,
|
||||||
|
);
|
||||||
|
|
||||||
await fs.writeFile("./resources/public/index.html", content);
|
await fs.writeFile("./resources/public/index.html", content);
|
||||||
|
|
||||||
|
@ -351,7 +357,7 @@ export async function compileStyles() {
|
||||||
const worker = startWorker();
|
const worker = startWorker();
|
||||||
const start = process.hrtime();
|
const start = process.hrtime();
|
||||||
|
|
||||||
log.info("init: compile styles")
|
log.info("init: compile styles");
|
||||||
let result = await compileSassAll(worker);
|
let result = await compileSassAll(worker);
|
||||||
result = concatSass(result);
|
result = concatSass(result);
|
||||||
|
|
||||||
|
@ -365,7 +371,7 @@ export async function compileStyles() {
|
||||||
|
|
||||||
export async function compileSvgSprites() {
|
export async function compileSvgSprites() {
|
||||||
const start = process.hrtime();
|
const start = process.hrtime();
|
||||||
log.info("init: compile svgsprite")
|
log.info("init: compile svgsprite");
|
||||||
await generateSvgSprites();
|
await generateSvgSprites();
|
||||||
const end = process.hrtime(start);
|
const end = process.hrtime(start);
|
||||||
log.info("done: compile svgsprite", `(${ppt(end)})`);
|
log.info("done: compile svgsprite", `(${ppt(end)})`);
|
||||||
|
@ -373,7 +379,7 @@ export async function compileSvgSprites() {
|
||||||
|
|
||||||
export async function compileTemplates() {
|
export async function compileTemplates() {
|
||||||
const start = process.hrtime();
|
const start = process.hrtime();
|
||||||
log.info("init: compile templates")
|
log.info("init: compile templates");
|
||||||
await generateTemplates();
|
await generateTemplates();
|
||||||
const end = process.hrtime(start);
|
const end = process.hrtime(start);
|
||||||
log.info("done: compile templates", `(${ppt(end)})`);
|
log.info("done: compile templates", `(${ppt(end)})`);
|
||||||
|
@ -381,8 +387,7 @@ export async function compileTemplates() {
|
||||||
|
|
||||||
export async function compilePolyfills() {
|
export async function compilePolyfills() {
|
||||||
const start = process.hrtime();
|
const start = process.hrtime();
|
||||||
log.info("init: compile polyfills")
|
log.info("init: compile polyfills");
|
||||||
|
|
||||||
|
|
||||||
const files = await findFiles("resources/polyfills/", isJsFile);
|
const files = await findFiles("resources/polyfills/", isJsFile);
|
||||||
let result = [];
|
let result = [];
|
||||||
|
@ -400,7 +405,7 @@ export async function compilePolyfills() {
|
||||||
|
|
||||||
export async function copyAssets() {
|
export async function copyAssets() {
|
||||||
const start = process.hrtime();
|
const start = process.hrtime();
|
||||||
log.info("init: copy assets")
|
log.info("init: copy assets");
|
||||||
|
|
||||||
await syncDirs("resources/images/", "resources/public/images/");
|
await syncDirs("resources/images/", "resources/public/images/");
|
||||||
await syncDirs("resources/fonts/", "resources/public/fonts/");
|
await syncDirs("resources/fonts/", "resources/public/fonts/");
|
||||||
|
@ -409,4 +414,3 @@ export async function copyAssets() {
|
||||||
const end = process.hrtime(start);
|
const end = process.hrtime(start);
|
||||||
log.info("done: copy assets", `(${ppt(end)})`);
|
log.info("done: copy assets", `(${ppt(end)})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue