-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
2,833 additions
and
735 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,98 @@ | ||
console.time('build'); | ||
|
||
const { exec } = require('child_process'); | ||
const { existsSync, rmSync } = require('fs'); | ||
const { copy } = require('fs-extra'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
const util = require('util'); | ||
|
||
const execAsync = util.promisify(exec); | ||
if (existsSync('out')) rmSync('out', { recursive: true, force: true }); | ||
|
||
copy('src', 'out/extension').then(() => { | ||
execAsync('tsc -p config/tsconfig.json').then(() => { | ||
let tsFiles = glob.sync('out/extension/**/*.ts'); | ||
tsFiles.forEach(tsFile => { | ||
let jsFile = path.normalize(path.join('out', 'js', path.relative('out/extension', tsFile))).replace(/\.ts$/, '.js'); | ||
if (existsSync(jsFile)) { | ||
rmSync(tsFile, { force: true }); | ||
copy(jsFile, tsFile.replace(/\.ts$/, '.js')); | ||
} | ||
}); | ||
|
||
console.timeEnd('build'); | ||
}); | ||
import { exec } from 'child_process'; | ||
import CleanCSS from 'clean-css'; | ||
import { existsSync, rmSync } from 'fs'; | ||
import { copy, remove } from 'fs-extra'; | ||
import { readFile, writeFile } from 'fs/promises'; | ||
import { glob } from 'glob'; | ||
import { minify as HtmlMinify } from 'html-minifier-terser'; | ||
import { join, normalize, relative } from 'path'; | ||
import { minify } from 'terser'; | ||
import { promisify } from 'util'; | ||
import manifest from './src/manifest.json' assert { type: 'json' }; | ||
|
||
const execAsync = promisify(exec); | ||
|
||
async function build() { | ||
console.time(`- ${manifest.name} v${manifest.version} was built and minified in`); | ||
|
||
// Removing "out" if exists | ||
if (existsSync('out')) { | ||
rmSync('out', { recursive: true, force: true }); | ||
console.log(`- Removed "out" folder`); | ||
} | ||
|
||
// Copying everything from "src" to "out/extension" and compiling TS | ||
await Promise.all([ | ||
copy('src', 'out/extension').then(() => console.log(`- Copied contents of "src" to "out/extension"`)), | ||
execAsync('tsc -p config/tsconfig.json').then(() => console.log(`- Compiled TypeScript`)) | ||
]); | ||
|
||
// Replacing TS files from "out/extension" with files from "out/js" | ||
// Also minifying everying | ||
const tsFiles = glob.sync('out/extension/**/*.ts'); | ||
const cssFiles = glob.sync('out/extension/**/*.css'); | ||
const htmlFiles = glob.sync('out/extension/**/*.html'); | ||
|
||
await Promise.all([ | ||
...tsFiles.map(async tsFile => { | ||
if (tsFile.endsWith('global.d.ts')) return; | ||
|
||
const jsFile = normalize(join('out', 'js', relative('out/extension', tsFile))).replace(/\.ts$/, '.js'); | ||
|
||
// Read the JS file | ||
const data = await readFile(jsFile, { encoding: 'utf8' }); | ||
|
||
// Minimize | ||
const result = await minify(data); | ||
if (!result.code) throw new Error(`Failed to minify ${jsFile}`); | ||
|
||
// Write the minified code to the new file | ||
await writeFile(tsFile.replace(/\.ts$/, '.js'), result.code); | ||
console.log(`- Written (minified) ${tsFile.replace(/\.ts$/, '.js')}`); | ||
}), | ||
...cssFiles.map(async cssFile => { | ||
// Read the CSS file | ||
const data = await readFile(cssFile, { encoding: 'utf8' }); | ||
|
||
// Minimize | ||
const result = new CleanCSS().minify(data).styles; | ||
|
||
// Write the minified CSS to the same file | ||
await writeFile(cssFile, result); | ||
console.log(`- Written (minified) ${cssFile}`); | ||
}), | ||
...htmlFiles.map(async htmlFile => { | ||
// Read the HTML file | ||
const data = await readFile(htmlFile, { encoding: 'utf8' }); | ||
|
||
// Minimize | ||
const result = await HtmlMinify(data, { collapseWhitespace: true, minifyCSS: true, minifyJS: true }); | ||
|
||
// Write the minified HTML to the same file | ||
await writeFile(htmlFile, result); | ||
console.log(`- Written (minified) ${htmlFile}`); | ||
}), | ||
// Removing "out/extension/**/*.ts" | ||
...tsFiles.map(tsFile => remove(tsFile).then(() => console.log(`- Removed ${tsFile}`))) | ||
]); | ||
|
||
// Removing "out/js" | ||
await remove('out/js').then(() => console.log(`- Removed "out/js" folder`)); | ||
|
||
// Copy all files from "out/extension" to "out" | ||
await copy('out/extension', 'out', { overwrite: true }).then(() => console.log(`- Moved everything from "out/extension" to "out"`)); | ||
|
||
// Remove the "out/extension" folder | ||
await remove('out/extension').then(() => console.log(`- Removed "out/extenson"`)); | ||
|
||
console.log(); | ||
console.timeEnd(`- ${manifest.name} v${manifest.version} was built and minified in`); | ||
} | ||
|
||
build().catch(e => { | ||
if (e.stdout) { | ||
console.log(e.stdout); | ||
} else { | ||
console.log(e); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"watch": ["src"], | ||
"watch": ["src", "build.js"], | ||
"ext": "*", | ||
"exec": "node build.js" | ||
"exec": "cls && node --disable-warning=ExperimentalWarning build.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
{ | ||
"name": "anilist-to-aniwave", | ||
"version": "7.0.0", | ||
"description": "Adds a button on AniList anime pages that searches the anime on AniWave.", | ||
"name": "anilist-watcher", | ||
"version": "8.0.0", | ||
"description": "Adds a button on AniList anime and manga pages to quickly open media on popular streaming and reading sites.", | ||
"scripts": { | ||
"watch": "nodemon --config config/nodemon.json", | ||
"build": "node build.js" | ||
"build": "node build.js --disable-warning ExperimentalWarning" | ||
}, | ||
"keywords": [], | ||
"author": "sans._.", | ||
"license": "ISC", | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/chrome": "^0.0.246", | ||
"nodemon": "^3.0.1" | ||
"@types/clean-css": "^4.2.11", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/html-minifier-terser": "^7.0.2", | ||
"@types/node": "20.14.8", | ||
"nodemon": "^3.1.4" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^11.1.1", | ||
"glob": "^10.3.10", | ||
"typescript": "^5.2.2" | ||
"clean-css": "^5.3.3", | ||
"fs-extra": "^11.2.0", | ||
"glob": "^10.4.5", | ||
"html-minifier-terser": "^7.2.0", | ||
"htmlparser2": "^9.1.0", | ||
"terser": "^5.32.0", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
Oops, something went wrong.