mirror of
https://github.com/moebooru/moebooru
synced 2025-08-22 09:57:31 +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
|
||||
run: ./script/gh-action-prepare
|
||||
|
||||
- name: Lint assets
|
||||
run: npm run lint
|
||||
|
||||
- name: Build assets
|
||||
run: bundle exec rails assets:precompile
|
||||
|
||||
|
@ -5,4 +5,5 @@
|
||||
//= require jquery/dist/jquery
|
||||
//= require timeago/jquery.timeago
|
||||
|
||||
jQuery.noConflict()
|
||||
/* global jQuery */
|
||||
jQuery.noConflict();
|
||||
|
58
build.js
58
build.js
@ -1,14 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import babel from '@babel/core'
|
||||
import { createHash } from 'crypto'
|
||||
import esbuild from 'esbuild'
|
||||
import coffeeScriptPlugin from 'esbuild-coffeescript'
|
||||
import { lessLoader } from 'esbuild-plugin-less'
|
||||
import fsPromises from 'fs/promises'
|
||||
import glob from 'glob'
|
||||
import babel from '@babel/core';
|
||||
import { createHash } from 'crypto';
|
||||
import esbuild from 'esbuild';
|
||||
import coffeeScriptPlugin from 'esbuild-coffeescript';
|
||||
import { lessLoader } from 'esbuild-plugin-less';
|
||||
import fsPromises from 'fs/promises';
|
||||
import glob from 'glob';
|
||||
|
||||
const outdir = 'app/assets/builds'
|
||||
const outdir = 'app/assets/builds';
|
||||
|
||||
const plugins = [
|
||||
coffeeScriptPlugin({
|
||||
@ -25,8 +25,8 @@ const plugins = [
|
||||
name: 'babel',
|
||||
setup (build) {
|
||||
build.onEnd(async () => {
|
||||
const esbuildFilepath = `${outdir}/application.js`
|
||||
const inputSourceMap = JSON.parse(await fsPromises.readFile(`${esbuildFilepath}.map`))
|
||||
const esbuildFilepath = `${outdir}/application.js`;
|
||||
const inputSourceMap = JSON.parse(await fsPromises.readFile(`${esbuildFilepath}.map`));
|
||||
const options = {
|
||||
inputSourceMap,
|
||||
minified: true,
|
||||
@ -34,23 +34,23 @@ const plugins = [
|
||||
['@babel/preset-env']
|
||||
],
|
||||
sourceMaps: true
|
||||
}
|
||||
const esbuildOutput = await fsPromises.readFile(esbuildFilepath)
|
||||
const result = await babel.transformAsync(esbuildOutput, options)
|
||||
const filename = 'application.jsout'
|
||||
const outfileBabel = `${outdir}/${filename}`
|
||||
};
|
||||
const esbuildOutput = await fsPromises.readFile(esbuildFilepath);
|
||||
const result = await babel.transformAsync(esbuildOutput, options);
|
||||
const filename = 'application.jsout';
|
||||
const outfileBabel = `${outdir}/${filename}`;
|
||||
result.map.sources = result.map.sources
|
||||
// CoffeeScript sourcemap and Esbuild sourcemap combined generates duplicated source paths
|
||||
.map((path) => path.replace(/\.\.\/\.\.\/javascript(\/.+)?\/app\/javascript\//, '../app/javascript/'))
|
||||
const resultMap = JSON.stringify(result.map)
|
||||
const resultMapHash = createHash('sha256').update(resultMap).digest('hex')
|
||||
.map((path) => path.replace(/\.\.\/\.\.\/javascript(\/.+)?\/app\/javascript\//, '../app/javascript/'));
|
||||
const resultMap = JSON.stringify(result.map);
|
||||
const resultMapHash = createHash('sha256').update(resultMap).digest('hex');
|
||||
|
||||
return Promise.all([
|
||||
// add hash so it matches sprocket output
|
||||
fsPromises.writeFile(outfileBabel, `${result.code}\n//# sourceMappingURL=${filename}-${resultMapHash}.map`),
|
||||
fsPromises.writeFile(`${outfileBabel}.map`, JSON.stringify(result.map))
|
||||
])
|
||||
})
|
||||
]);
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -58,29 +58,29 @@ const plugins = [
|
||||
setup (build) {
|
||||
build.onEnd(async (result) => {
|
||||
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 = {
|
||||
watch: args.includes('--watch'),
|
||||
analyze: args.includes('--analyze')
|
||||
}
|
||||
};
|
||||
const watch = options.watch
|
||||
? {
|
||||
onRebuild (error) {
|
||||
if (error == null) {
|
||||
console.log('Rebuild succeeded')
|
||||
console.log('Rebuild succeeded');
|
||||
}
|
||||
}
|
||||
}
|
||||
: false
|
||||
: false;
|
||||
|
||||
esbuild.build({
|
||||
bundle: true,
|
||||
@ -94,4 +94,4 @@ esbuild.build({
|
||||
sourcemap: 'external',
|
||||
watch
|
||||
}).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",
|
||||
"js-cookie": "^3.0.1",
|
||||
"mousetrap": "^1.6.5",
|
||||
"semistandard": "^17.0.0",
|
||||
"timeago": "^1.6.7"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "./build.js"
|
||||
"build": "./build.js",
|
||||
"lint": "semistandard *.js app/javascript/**/*.js app/assets/javascripts/*.js"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user