Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
build: organiza scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ferreira-tb committed Jun 19, 2023
1 parent 840092e commit 7e37eff
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 111 deletions.
25 changes: 9 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,23 @@
"license": "MIT",
"main": "dist/ares.js",
"scripts": {
"type-check": "vue-tsc --noEmit",
"clear": "node scripts/clear.mjs",
"build": "npm run type-check && npm run clear && run-p build:* && run-s script:*",
"build": "npm run type-check && npm run clear && run-p build:* && npm run fix",
"build:browser": "vite build --config browser.config.ts",
"build:panel": "vite build --config panel.config.ts",
"build:rollup": "rollup --config rollup.config.ts --configPlugin typescript={tsconfig:'tsconfig.rollup.json'}",
"build:ui": "vite build --config ui.config.ts",
"build:win": "vite build --config windows.config.ts",
"script:css": "node scripts/css.mjs",
"script:html": "node scripts/html.mjs",
"script:fonts": "node scripts/fonts.mjs",
"start": "npm run build && electron .",
"start:browser": "npm run build:browser && npm run script:html && electron .",
"start:panel": "npm run build:panel && npm run script:html && electron .",
"start:rollup": "npm run build:rollup && electron .",
"start:ui": "npm run build:ui && npm run script:html && npm run script:fonts && electron .",
"start:win": "npm run build:win && npm run script:html && electron .",
"forge:start": "electron-forge start",
"forge:package": "npm run build && electron-forge package",
"forge:make": "npm run build && electron-forge make",
"clear": "node scripts/clear-dist.mjs",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
"taze": "npx taze -w"
"fix": "node scripts/fix-files.mjs",
"forge:start": "electron-forge start",
"forge:package": "npm run build && electron-forge package",
"forge:make": "npm run build && electron-forge make",
"start": "npm run build && electron .",
"taze": "npx taze -w",
"type-check": "vue-tsc --noEmit"
},
"dependencies": {
"@tb-dev/kronos": "^1.0.1",
Expand Down
11 changes: 3 additions & 8 deletions scripts/clear.mjs → scripts/clear-dist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

try {
const startTime = Date.now();

console.log('Limpando diretório de distribuição...');

const distDir = path.resolve(__dirname, '../dist');
await fs.rm(distDir, { recursive: true, force: true });

console.log(`Fim dos trabalhos. Tempo total: ${Date.now() - startTime}ms.`);


} catch (err) {
if (err instanceof Error) console.error(err);
console.error(err);
process.exit(1);
};
23 changes: 0 additions & 23 deletions scripts/css.mjs

This file was deleted.

48 changes: 48 additions & 0 deletions scripts/fix-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

try {
const distDir = path.resolve(__dirname, '../dist');
const assetsDir = path.join(distDir, 'assets');

// HTML
const panel = path.join(distDir, 'panel.html');
const windows = path.join(distDir, 'windows.html');
const ui = path.join(distDir, 'ui.html');
await Promise.all([panel, windows, ui].map(html));

// CSS
const style = path.join(distDir, 'style.css');
const browser = path.join(distDir, 'browser.css');
await fs.rename(style, browser);

// Fontes
const regex = /url\s*\(\/?fonts/g;
const replacement = 'url(../fonts';

const files = await fs.readdir(assetsDir);
const cssFiles = files.filter((file) => {
return path.extname(file) === '.css' && file.startsWith('ui');
});

for (const file of cssFiles) {
const cssFile = path.join(assetsDir, file);
let fileContent = await fs.readFile(cssFile, { encoding: 'utf-8' });
fileContent = fileContent.replace(regex, replacement);
await fs.writeFile(cssFile, fileContent, { encoding: 'utf-8' });
};

} catch (err) {
console.error(err);
process.exit(1);
};

async function html(file) {
let content = await fs.readFile(file, { encoding: 'utf-8' });
content = content.replace(/\"\/assets\//g, '\"assets\/');
await fs.writeFile(file, content, { encoding: 'utf-8' });
};
31 changes: 0 additions & 31 deletions scripts/fonts.mjs

This file was deleted.

33 changes: 0 additions & 33 deletions scripts/html.mjs

This file was deleted.

0 comments on commit 7e37eff

Please sign in to comment.