-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previous linter `lynt` had vulnerable dependencies that were not addressed for some time. ESLint is better maintained and a popular project. This commit fixes also linting errors from ESLint.
- Loading branch information
1 parent
e34c3b0
commit 26b9c52
Showing
7 changed files
with
2,507 additions
and
6,692 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
env: | ||
browser: true | ||
commonjs: true | ||
es6: true | ||
extends: airbnb-base | ||
globals: | ||
Atomics: readonly | ||
SharedArrayBuffer: readonly | ||
parserOptions: | ||
ecmaVersion: 2018 | ||
rules: { | ||
"no-use-before-define": 0 | ||
} |
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,97 +1,100 @@ | ||
/* eslint-disable no-console */ | ||
|
||
const fs = require('fs'); | ||
const babel = require("@babel/core"); | ||
const path = require("path"); | ||
const babel = require('@babel/core'); | ||
const path = require('path'); | ||
const ClosureCompiler = require('google-closure-compiler').jsCompiler; | ||
const CleanCSS = require('clean-css'); | ||
|
||
const outputFolder = 'dist'; | ||
const inputFile = './src/ez-consent.js'; | ||
const cssFolder = './src/themes/'; | ||
|
||
(async function() { | ||
await deleteFolderRecursiveAsync(outputFolder); | ||
await fs.promises.mkdir(outputFolder, { recursive: true }); | ||
const noModulesCode = (await babel.transformFileAsync(inputFile, { | ||
plugins: ["remove-import-export"] | ||
})).code; | ||
await Promise.all([ | ||
compileWithClosureAsync(noModulesCode, path.join(outputFolder, path.basename(inputFile)), { | ||
compilation_level: 'SIMPLE', | ||
formatting: 'PRETTY_PRINT', | ||
env: 'BROWSER', | ||
debug: true | ||
}), | ||
compileWithClosureAsync(noModulesCode, path.join(outputFolder, removeExtension(path.basename(inputFile)) + ".min.js"), { | ||
compilation_level: 'SIMPLE', | ||
env: 'BROWSER' | ||
}), | ||
minifyCssAsync(cssFolder, path.join(outputFolder, 'themes')) | ||
]); | ||
})().catch(err => { | ||
console.error(err); | ||
process.exit(-1); | ||
(async () => { | ||
await deleteFolderRecursiveAsync(outputFolder); | ||
await fs.promises.mkdir(outputFolder, { recursive: true }); | ||
const noModulesCode = (await babel.transformFileAsync(inputFile, { | ||
plugins: ['remove-import-export'], | ||
})).code; | ||
await Promise.all([ | ||
compileWithClosureAsync(noModulesCode, path.join(outputFolder, path.basename(inputFile)), { | ||
compilation_level: 'SIMPLE', | ||
formatting: 'PRETTY_PRINT', | ||
env: 'BROWSER', | ||
debug: true, | ||
}), | ||
compileWithClosureAsync(noModulesCode, path.join(outputFolder, `${removeExtension(path.basename(inputFile))}.min.js`), { | ||
compilation_level: 'SIMPLE', | ||
env: 'BROWSER', | ||
}), | ||
minifyCssAsync(cssFolder, path.join(outputFolder, 'themes')), | ||
]); | ||
})().catch((err) => { | ||
console.error(err); | ||
process.exit(-1); | ||
}); | ||
|
||
|
||
async function minifyCssAsync(srcDir, targetDir) { | ||
const files = await fs.promises.readdir(srcDir); | ||
const cleanCSS = new CleanCSS(); | ||
return Promise.all(files.map(async (name) => { | ||
const filePath = path.join(srcDir, name); | ||
// Copy as it is | ||
const nonMinifiedTarget = path.join(targetDir, name); | ||
await copyFile(filePath, nonMinifiedTarget); | ||
console.log(`CSS copied to "${nonMinifiedTarget}"`); | ||
// Minify content | ||
const content = await fs.promises.readFile(filePath, 'utf-8'); | ||
const minified = cleanCSS.minify(content).styles; | ||
const targetPath = path.join(targetDir, removeExtension(path.basename(name)) + ".min.css"); | ||
await fs.promises.writeFile(targetPath, minified); | ||
console.log(`CSS minified to "${targetPath}"`); | ||
})); | ||
const files = await fs.promises.readdir(srcDir); | ||
const cleanCSS = new CleanCSS(); | ||
return Promise.all(files.map(async (name) => { | ||
const filePath = path.join(srcDir, name); | ||
// Copy as it is | ||
const nonMinifiedTarget = path.join(targetDir, name); | ||
await copyFile(filePath, nonMinifiedTarget); | ||
console.log(`CSS copied to "${nonMinifiedTarget}"`); | ||
// Minify content | ||
const content = await fs.promises.readFile(filePath, 'utf-8'); | ||
const minified = cleanCSS.minify(content).styles; | ||
const targetPath = path.join(targetDir, `${removeExtension(path.basename(name))}.min.css`); | ||
await fs.promises.writeFile(targetPath, minified); | ||
console.log(`CSS minified to "${targetPath}"`); | ||
})); | ||
} | ||
|
||
async function copyFile(src, dest) { | ||
await fs.promises.mkdir(path.dirname(dest), {recursive: true}); | ||
await fs.promises.copyFile(src, dest); | ||
await fs.promises.mkdir(path.dirname(dest), { recursive: true }); | ||
await fs.promises.copyFile(src, dest); | ||
} | ||
|
||
function removeExtension(str) { | ||
return str.slice(0, -path.extname(str).length); | ||
return str.slice(0, -path.extname(str).length); | ||
} | ||
|
||
async function compileWithClosureAsync(code, output, options) { | ||
return new Promise((resolve, reject) => { | ||
new ClosureCompiler(options).run([{ | ||
path: './', | ||
src: code, | ||
sourceMap: null | ||
}], async (exitCode, stdOut, stdErr) => { | ||
if(stdErr) { | ||
console.error('[ERROR] Google Closure', stdErr); | ||
} | ||
if(exitCode !== 0) { | ||
reject(new Error('Unexpected exit code : ' + exitCode)); | ||
} | ||
for (const fileResult of stdOut) { | ||
console.log(`JS compiled to "${output}", with options: ${JSON.stringify(options)}`); | ||
await fs.promises.writeFile(output, fileResult.src); | ||
} | ||
resolve(); | ||
}); | ||
}) | ||
return new Promise((resolve, reject) => { | ||
new ClosureCompiler(options).run([{ | ||
path: './', | ||
src: code, | ||
sourceMap: null, | ||
}], async (exitCode, stdOut, stdErr) => { | ||
if (stdErr) { | ||
console.error('[ERROR] Google Closure', stdErr); | ||
} | ||
if (exitCode !== 0) { | ||
reject(new Error(`Unexpected exit code : ${exitCode}`)); | ||
} | ||
await Promise.all(stdOut.map(async (fileResult) => { | ||
console.log(`JS compiled to "${output}", with options: ${JSON.stringify(options)}`); | ||
await fs.promises.writeFile(output, fileResult.src); | ||
})); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
async function deleteFolderRecursiveAsync(path) { | ||
if (!fs.existsSync(path)) { | ||
return; | ||
} | ||
for (const entry of await fs.promises.readdir(path)) { | ||
const curPath = path + "/" + entry; | ||
if ((await fs.promises.lstat(curPath)).isDirectory()) | ||
{await deleteFolderRecursiveAsync(curPath);} | ||
else await fs.promises.unlink(curPath); | ||
async function deleteFolderRecursiveAsync(folderPath) { | ||
if (!fs.existsSync(folderPath)) { | ||
return; | ||
} | ||
const directoryContents = await fs.promises.readdir(folderPath); | ||
await Promise.all(directoryContents.map(async (innerFilePath) => { | ||
const innerPath = `${folderPath}/${innerFilePath}`; | ||
if ((await fs.promises.lstat(innerPath)).isDirectory()) { | ||
await deleteFolderRecursiveAsync(innerPath); | ||
} else { | ||
await fs.promises.unlink(innerPath); | ||
} | ||
await fs.promises.rmdir(path); | ||
})); | ||
await fs.promises.rmdir(path); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.