Skip to content

Commit

Permalink
feature: setup linting and files changed by linting
Browse files Browse the repository at this point in the history
  • Loading branch information
anon-pradip committed Jul 24, 2024
1 parent 8a4e80b commit c4651e5
Show file tree
Hide file tree
Showing 9 changed files with 856 additions and 769 deletions.
37 changes: 37 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"requireConfigFile": false
},
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
"rules": {
"no-var": "error",
"prefer-const": "warn",
"no-console": "off",
"no-debugger": "warn",
"no-undef": "error",
"no-unused-vars": "warn",
"quotes": ["error", "single"],
"semi": ["error", "never"],
"new-cap": 2,
"no-caller": 2,
"dot-notation": 0,
"no-eq-null": 2,
"no-unused-expressions": 0,
"curly": 0,
"eqeqeq": 2,
"wrap-iife": [2, "any"],
"no-use-before-define": [
2,
{
"functions": false
}
]
}
}
44 changes: 36 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm install --frozen-lockfile

- name: EsLint
run: npm run lint

unit-test:
runs-on: ubuntu-latest
needs: lint
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout
uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: 18
- run: |
npm install
npm run test:unit

- name: Install dependencies
run: npm install --frozen-lockfile

- name: Unit test
run: npm run test:unit
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 120,
"tabWidth": 4,
"semi": false,
"bracketSpacing": true,
"proseWrap": "always",
"arrowParens": "always",
"htmlWhitespaceSensitivity": "css"
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ['@babel/preset-env'],
plugins: ['babel-plugin-transform-import-meta']
plugins: ['babel-plugin-transform-import-meta'],
}
91 changes: 51 additions & 40 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const gulp = require('gulp')
const {rollup} = require('rollup')
const eslint = require('gulp-eslint')
const prettier = require('gulp-prettier')
const { rollup } = require('rollup')
const terser = require('@rollup/plugin-terser')
const babel = require('@rollup/plugin-babel').default
const commonjs = require('@rollup/plugin-commonjs')
Expand All @@ -12,50 +14,59 @@ const babelConfig = {
ignore: ['node_modules'],
compact: false,
extensions: ['.js', '.html'],
plugins: [
'transform-html-import-to-string'
plugins: ['transform-html-import-to-string'],
presets: [
[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
modules: false,
},
],
],
presets: [[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
modules: false
}
]],
configFile: false
configFile: false,
}

gulp.task('lint:js', () =>
gulp.src(['./**/*.js', '!node_modules/**', '!plugin/awesoMD/awesoMD*.js']).pipe(eslint()).pipe(eslint.format())
)

gulp.task('format', () =>
gulp.src(['./**/*.js', '!node_modules/**', '!plugin/awesoMD/awesoMD*.js']).pipe(prettier()).pipe(gulp.dest('.'))
)

gulp.task('build-plugins', () => {
return Promise.all([
{ name: 'RevealAwesoMD', input: './plugin/awesoMD/plugin.js', output: './plugin/awesoMD/awesoMD' },
].map( plugin => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: ["node_modules"],
}),
terser()
]
}).then( bundle => {
cache[plugin.input] = bundle.cache;
bundle.write({
file: plugin.output + '.esm.js',
name: plugin.name,
format: 'es'
})
return Promise.all(
[{ name: 'RevealAwesoMD', input: './plugin/awesoMD/plugin.js', output: './plugin/awesoMD/awesoMD' }].map(
(plugin) => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: ['node_modules'],
}),
terser(),
],
}).then((bundle) => {
cache[plugin.input] = bundle.cache
bundle.write({
file: plugin.output + '.esm.js',
name: plugin.name,
format: 'es',
})

bundle.write({
file: plugin.output + '.js',
name: plugin.name,
format: 'umd'
bundle.write({
file: plugin.output + '.js',
name: plugin.name,
format: 'umd',
})
})
});
} ));
}
)
)
})
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
testEnvironment: "node",
testMatch: ["**/__tests__/**/*.js", "**/?(*.)+(spec|test).js"],
moduleFileExtensions: ["js", "json", "jsx", "node"],
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'],
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
collectCoverage: true,
verbose: true,
transform: {
"\\.[j]sx?$": "babel-jest",
}
};
'\\.[j]sx?$': 'babel-jest',
},
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "Revealjs plugin to support markdown with metadata and templates",
"scripts": {
"build": "gulp build-plugins",
"test:unit": "jest"
"test:unit": "jest",
"lint": "gulp lint:js",
"lint:fix": "gulp format"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +32,8 @@
"core-js": "^3.36.1",
"front-matter": "^4.0.2",
"gulp": "^5.0.0",
"gulp-eslint": "^6.0.0",
"gulp-prettier": "^5.0.0",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"marked": "^4.3.0",
Expand Down
Loading

0 comments on commit c4651e5

Please sign in to comment.