Skip to content

Commit

Permalink
New build system
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOnlyBinary committed Nov 12, 2023
1 parent 02cbf67 commit ac952a9
Show file tree
Hide file tree
Showing 26 changed files with 4,806 additions and 4,323 deletions.
2 changes: 1 addition & 1 deletion .browserslistrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
> 1%
last 2 versions
not ie <= 8
not dead
5 changes: 2 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build/*.js
config/*.js
tests/unit/coverage/
/dist/
/tests/coverage/
111 changes: 85 additions & 26 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
const rulesDirPlugin = require('eslint-plugin-rulesdir');

rulesDirPlugin.RULES_DIR = 'build/eslint/rules/';
const utils = require('./build/utils');

module.exports = {
root: true,

env: {
browser: true,
es6: true,
node: true,
},

parser: 'vue-eslint-parser',

parserOptions: {
parser: '@babel/eslint-parser',
ecmaVersion: 2020,
extraFileExtensions: ['.vue'],
sourceType: 'module',
},

plugins: ['@kiwiirc', 'jsdoc'],

extends: [
'plugin:vue/recommended',
'plugin:vue/vue3-recommended',
'eslint:recommended',
'@vue/airbnb',
'standard',
],
env: {
browser: true,

settings: {
'import/resolver': {
alias: {
map: [
['@', utils.pathResolve('src')],
],
extensions: ['.js', '.vue', '.json'],
},
},
},
// required to lint *.vue files
plugins: [
'rulesdir',
'vue',
],
// add your custom rules here

rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'rulesdir/class-name-prefix': 'warn',
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',

'@kiwiirc/class-name-prefix': 'warn',

'class-methods-use-this': 0,
'comma-dangle': ['error', {
arrays: 'always-multiline',
Expand All @@ -36,10 +54,16 @@ module.exports = {
}],
'import/extensions': 0,
'import/no-cycle': 0,
'import/no-extraneous-dependencies': 0,
'import/no-unresolved': 0,
'import/no-unresolved': [2, {
ignore: [
// These files will not exist if lint is run before the first build
'/res/locales/available\\.json$',
'/static/locales/\\S+\\.json$',
],
}],
'import/prefer-default-export': 0,
'indent': ['error', 4],
// 'max-len': ['error', { code: 120 }],
'max-classes-per-file': 0,
'no-continue': 0,
'no-else-return': 0,
Expand All @@ -57,9 +81,23 @@ module.exports = {
'prefer-template': 0,
'quote-props': ['error', 'consistent-as-needed'],
'semi': ['error', 'always'],
'space-before-function-paren': ['error', 'never'],
'strict': 0,
'space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
}],
'vue/component-definition-name-casing': 0,
'vue/html-indent': ['error', 4],
// 'vue/max-len': [
// 'error',
// {
// code: 120,
// template: 120,
// tabWidth: 4,
// comments: 120,
// },
// ],
'vue/max-attributes-per-line': 0,
'vue/multi-word-component-names': 0,
'vue/multiline-html-element-content-newline': 0,
Expand All @@ -77,14 +115,35 @@ module.exports = {
'vuejs-accessibility/interactive-supports-focus': 0,
'vuejs-accessibility/label-has-for': 0,
'vuejs-accessibility/mouse-events-have-key-events': 0,

// TODO vue3
'multiline-ternary': 0,
'vue/comma-dangle': 0,
'vue/key-spacing': 0,
'vue/no-template-target-blank': 0,
'vue/object-curly-newline': 0,
'vue/object-curly-spacing': 0,
'vue/operator-linebreak': 0,
'vue/quote-props': 0,
'vue/space-infix-ops': 0,
'vue/v-on-event-hyphenation': 0,
},
overrides: [{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)',
],
env: {
jest: true,
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)',
],
env: {
jest: true,
},
},
}],
{
files: ['webpack.config.js', 'build/**/*.js'],
rules: {
'import/no-extraneous-dependencies': 0,
'no-console': 0,
},
},
],
};
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
printWidth: 120,
printWidth: 100,
quoteProps: 'consistent',
semi: true,
singleQuote: true,
Expand Down
34 changes: 30 additions & 4 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
module.exports = {
extends: ['stylelint-config-standard', 'stylelint-config-recommended-vue'],
extends: ['stylelint-config-standard', 'stylelint-config-standard-scss', 'stylelint-config-recess-order'],
overrides: [
{
files: ['**/*.html'],
files: ['**/*.vue', '**/*.html'],
customSyntax: 'postcss-html',
},
],
rules: {
'alpha-value-notation': null,
'color-function-notation': null,
'declaration-block-no-redundant-longhand-properties': null,
'declaration-no-important': true,
'indentation': 4,
'media-feature-range-notation': null,
'no-descending-specificity': null,
'no-empty-first-line': null,
'number-max-precision': null,
'order/properties-order': null,
'property-no-vendor-prefix': null,
'scss/at-rule-no-unknown': [
true,
{
ignoreAtRules: [
'each',
'else',
'extends',
'for',
'function',
'if',
'ignores',
'include',
'media',
'mixin',
'return',
'use',

// Font Awesome 4
'fa-font-path',
],
},
],
'scss/double-slash-comment-empty-line-before': null,
'scss/double-slash-comment-whitespace-inside': null,
'selector-class-pattern': null,
'shorthand-property-no-redundant-values': null,
'string-quotes': 'single',
},
};
15 changes: 2 additions & 13 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
presets: [
[
'@vue/cli-plugin-babel/preset',
'@babel/preset-env',
{
useBuiltIns: 'entry',
modules: 'commonjs',
Expand All @@ -10,16 +10,5 @@ module.exports = {
],
],
plugins: [['@babel/plugin-transform-runtime', { corejs: 3, useESModules: true }]],
env: {
test: {
plugins: [
[
'istanbul',
{
exclude: ['**/*.spec.js'],
},
],
],
},
},
exclude: [/core-js/],
};
132 changes: 132 additions & 0 deletions build/commands/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const webpack = require('webpack');
const minimist = require('minimist');
const ora = require('ora');
const chalk = require('chalk');
const cliui = require('cliui');
const { rimraf } = require('rimraf');

const utils = require('../utils');
const webpackConfigFunc = require('../../webpack.config');

const argv = minimist(process.argv.slice(2));
const webpackConfig = webpackConfigFunc({}, argv);
const spinner = ora();

console.log();
spinner.text = `Building for ${webpackConfig.mode}...`;
spinner.start();

rimraf(utils.pathResolve('dist')).then(() => {
webpack(webpackConfig, (wpErr, stats) => {
spinner.stop();
console.log();

if (wpErr) {
console.error(wpErr);
console.log();
process.exit(1);
}

if (stats.hasErrors()) {
process.exit(1);
}

const getCompressedAsset = (asset, type) => {
if (!Array.isArray(asset.related)) {
return undefined;
}
return asset.related.find((relAsset) => relAsset.type === type);
};

const isJS = (val) => /\.js$/.test(val);
const isCSS = (val) => /\.css$/.test(val);
const assetSorter = (a, b) => {
if (isJS(a.name) && isCSS(b.name)) {
return -1;
}
if (isCSS(a.name) && isJS(b.name)) {
return 1;
}
return b.size - a.size;
};

const data = stats.toJson();
const files = Object.values(data.assetsByChunkName).flat();

const out = [
// Column headers
['File', 'Size', 'Gzip', 'Brotli'],
];
const totals = {
size: 0,
gzip: 0,
brotli: 0,
};

data.assets.sort(assetSorter).forEach((asset) => {
if (!asset.emitted) {
return;
}

const gzipAsset = getCompressedAsset(asset, 'gzipped');
const brotliAsset = getCompressedAsset(asset, 'brotliCompressed');

totals.size += asset.size;
totals.gzip += gzipAsset ? gzipAsset.size : asset.size;
totals.brotli += brotliAsset ? brotliAsset.size : asset.size;

if (files.includes(asset.name)) {
out.push([
asset.name,
utils.formatSize(asset.size),
gzipAsset ? utils.formatSize(gzipAsset.size) : '',
brotliAsset ? utils.formatSize(brotliAsset.size) : '',
]);
}
});

out.push([
'Totals (including assets)',
utils.formatSize(totals.size),
utils.formatSize(totals.gzip),
utils.formatSize(totals.brotli),
]);

const colWidths = out.reduce((acc, row) => {
row.forEach((col, idx) => {
acc[idx] = Math.max(acc[idx] || 0, col.length + 4);
});
return acc;
}, []);

const table = cliui();
out.forEach((row, rowIdx) => {
table.div(
...row.map((col, colIdx) => ({
text: (rowIdx === 0 || (rowIdx === out.length - 1 && colIdx === 0))
? chalk.cyan.bold(col)
: col,
width: colWidths[colIdx],
padding: (rowIdx === 0 || rowIdx === out.length - 2)
? [0, 0, 1, 3]
: [0, 0, 0, 3],
}))
);
});

console.log(table.toString());
console.log();
console.log();
console.log(
chalk.bgGreen.black(' DONE '),
`Build Complete. The ${chalk.cyan('dist')} directory is ready to be deployed`
);
console.log();
});
}).catch((rmErr) => {
spinner.stop();
console.log();
console.error(rmErr);
console.log();
process.exit(1);
});
Loading

0 comments on commit ac952a9

Please sign in to comment.