mirror of
https://github.com/moebooru/moebooru
synced 2025-08-22 18:07:25 +00:00
Add basic linter
This commit is contained in:
parent
3c9aa7042e
commit
fd925327a9
3
.github/workflows/tests.yml
vendored
3
.github/workflows/tests.yml
vendored
@ -41,6 +41,9 @@ jobs:
|
|||||||
- name: Setup environment
|
- name: Setup environment
|
||||||
run: ./script/gh-action-prepare
|
run: ./script/gh-action-prepare
|
||||||
|
|
||||||
|
- name: Lint assets
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
- name: Build assets
|
- name: Build assets
|
||||||
run: bundle exec rails assets:precompile
|
run: bundle exec rails assets:precompile
|
||||||
|
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
//= require jquery/dist/jquery
|
//= require jquery/dist/jquery
|
||||||
//= require timeago/jquery.timeago
|
//= require timeago/jquery.timeago
|
||||||
|
|
||||||
jQuery.noConflict()
|
/* global jQuery */
|
||||||
|
jQuery.noConflict();
|
||||||
|
58
build.js
58
build.js
@ -1,14 +1,14 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import babel from '@babel/core'
|
import babel from '@babel/core';
|
||||||
import { createHash } from 'crypto'
|
import { createHash } from 'crypto';
|
||||||
import esbuild from 'esbuild'
|
import esbuild from 'esbuild';
|
||||||
import coffeeScriptPlugin from 'esbuild-coffeescript'
|
import coffeeScriptPlugin from 'esbuild-coffeescript';
|
||||||
import { lessLoader } from 'esbuild-plugin-less'
|
import { lessLoader } from 'esbuild-plugin-less';
|
||||||
import fsPromises from 'fs/promises'
|
import fsPromises from 'fs/promises';
|
||||||
import glob from 'glob'
|
import glob from 'glob';
|
||||||
|
|
||||||
const outdir = 'app/assets/builds'
|
const outdir = 'app/assets/builds';
|
||||||
|
|
||||||
const plugins = [
|
const plugins = [
|
||||||
coffeeScriptPlugin({
|
coffeeScriptPlugin({
|
||||||
@ -25,8 +25,8 @@ const plugins = [
|
|||||||
name: 'babel',
|
name: 'babel',
|
||||||
setup (build) {
|
setup (build) {
|
||||||
build.onEnd(async () => {
|
build.onEnd(async () => {
|
||||||
const esbuildFilepath = `${outdir}/application.js`
|
const esbuildFilepath = `${outdir}/application.js`;
|
||||||
const inputSourceMap = JSON.parse(await fsPromises.readFile(`${esbuildFilepath}.map`))
|
const inputSourceMap = JSON.parse(await fsPromises.readFile(`${esbuildFilepath}.map`));
|
||||||
const options = {
|
const options = {
|
||||||
inputSourceMap,
|
inputSourceMap,
|
||||||
minified: true,
|
minified: true,
|
||||||
@ -34,23 +34,23 @@ const plugins = [
|
|||||||
['@babel/preset-env']
|
['@babel/preset-env']
|
||||||
],
|
],
|
||||||
sourceMaps: true
|
sourceMaps: true
|
||||||
}
|
};
|
||||||
const esbuildOutput = await fsPromises.readFile(esbuildFilepath)
|
const esbuildOutput = await fsPromises.readFile(esbuildFilepath);
|
||||||
const result = await babel.transformAsync(esbuildOutput, options)
|
const result = await babel.transformAsync(esbuildOutput, options);
|
||||||
const filename = 'application.jsout'
|
const filename = 'application.jsout';
|
||||||
const outfileBabel = `${outdir}/${filename}`
|
const outfileBabel = `${outdir}/${filename}`;
|
||||||
result.map.sources = result.map.sources
|
result.map.sources = result.map.sources
|
||||||
// CoffeeScript sourcemap and Esbuild sourcemap combined generates duplicated source paths
|
// CoffeeScript sourcemap and Esbuild sourcemap combined generates duplicated source paths
|
||||||
.map((path) => path.replace(/\.\.\/\.\.\/javascript(\/.+)?\/app\/javascript\//, '../app/javascript/'))
|
.map((path) => path.replace(/\.\.\/\.\.\/javascript(\/.+)?\/app\/javascript\//, '../app/javascript/'));
|
||||||
const resultMap = JSON.stringify(result.map)
|
const resultMap = JSON.stringify(result.map);
|
||||||
const resultMapHash = createHash('sha256').update(resultMap).digest('hex')
|
const resultMapHash = createHash('sha256').update(resultMap).digest('hex');
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
// add hash so it matches sprocket output
|
// add hash so it matches sprocket output
|
||||||
fsPromises.writeFile(outfileBabel, `${result.code}\n//# sourceMappingURL=${filename}-${resultMapHash}.map`),
|
fsPromises.writeFile(outfileBabel, `${result.code}\n//# sourceMappingURL=${filename}-${resultMapHash}.map`),
|
||||||
fsPromises.writeFile(`${outfileBabel}.map`, JSON.stringify(result.map))
|
fsPromises.writeFile(`${outfileBabel}.map`, JSON.stringify(result.map))
|
||||||
])
|
]);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -58,29 +58,29 @@ const plugins = [
|
|||||||
setup (build) {
|
setup (build) {
|
||||||
build.onEnd(async (result) => {
|
build.onEnd(async (result) => {
|
||||||
if (options.analyze) {
|
if (options.analyze) {
|
||||||
const analyzeResult = await esbuild.analyzeMetafile(result.metafile)
|
const analyzeResult = await esbuild.analyzeMetafile(result.metafile);
|
||||||
|
|
||||||
console.log(analyzeResult)
|
console.log(analyzeResult);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
|
|
||||||
const args = process.argv.slice(2)
|
const args = process.argv.slice(2);
|
||||||
const options = {
|
const options = {
|
||||||
watch: args.includes('--watch'),
|
watch: args.includes('--watch'),
|
||||||
analyze: args.includes('--analyze')
|
analyze: args.includes('--analyze')
|
||||||
}
|
};
|
||||||
const watch = options.watch
|
const watch = options.watch
|
||||||
? {
|
? {
|
||||||
onRebuild (error) {
|
onRebuild (error) {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
console.log('Rebuild succeeded')
|
console.log('Rebuild succeeded');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: false
|
: false;
|
||||||
|
|
||||||
esbuild.build({
|
esbuild.build({
|
||||||
bundle: true,
|
bundle: true,
|
||||||
@ -94,4 +94,4 @@ esbuild.build({
|
|||||||
sourcemap: 'external',
|
sourcemap: 'external',
|
||||||
watch
|
watch
|
||||||
}).then(() => console.log('Build succeeded'))
|
}).then(() => console.log('Build succeeded'))
|
||||||
.catch((e) => console.debug(e))
|
.catch((e) => console.debug(e));
|
||||||
|
4843
package-lock.json
generated
4843
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -13,10 +13,12 @@
|
|||||||
"jquery": "^3.6.0",
|
"jquery": "^3.6.0",
|
||||||
"js-cookie": "^3.0.1",
|
"js-cookie": "^3.0.1",
|
||||||
"mousetrap": "^1.6.5",
|
"mousetrap": "^1.6.5",
|
||||||
|
"semistandard": "^17.0.0",
|
||||||
"timeago": "^1.6.7"
|
"timeago": "^1.6.7"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./build.js"
|
"build": "./build.js",
|
||||||
|
"lint": "semistandard *.js app/javascript/**/*.js app/assets/javascripts/*.js"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user