diff --git a/.eslintrc.js b/.eslintrc.js index c1136e0c455..cdd83f050f8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,12 @@ module.exports = { "no-console": "off", "no-invalid-this": "off", "no-shadow": "warn", + "brace-style": "off", + "wrap-iife": "off", + "space-before-function-paren": "off", + "indent": "off", + "@typescript-eslint/indent": "off", + "@typescript-eslint/member-delimiter-style": "off", }, "globals": { "$": false, diff --git a/.gitattributes b/.gitattributes index eba1110b579..ce9b094c52a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,6 @@ # Auto detect text files and perform LF normalization -* text=auto \ No newline at end of file +* text=auto +*.js text eol=lf +*.jsx text eol=lf +*.ts text eol=lf +*.tsx text eol=lf diff --git a/gulpfile.js b/gulpfile.js index d532d2f9b8f..a447e2a2171 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,57 +7,66 @@ const gulp = require("gulp"); "./tasks/download-default-extensions", "./tasks/nls-check", "./tasks/eslint", + "./tasks/format", "./tasks/npm-install", "./tasks/test", "./tasks/watch", "./tasks/webpack", - "./tasks/write-config" + "./tasks/write-config", ].forEach((taskfile) => { require(taskfile); }); +gulp.task( + "install", + gulp.series( + "write-config:dist", + "npm-download-default-extensions", + "npm-install-source", + "webpack-browser-dependencies" + ) +); -gulp.task("install", gulp.series( - "write-config:dist", - "npm-download-default-extensions", - "npm-install-source", - "webpack-browser-dependencies" -)); - -gulp.task("build", gulp.series( - "npm-install-dist", - "npm-install-extensions-dist" -)); +gulp.task("build", gulp.series("npm-install-dist", "npm-install-extensions-dist")); // task: optimize - optimize contents of dist folder -gulp.task("optimize-common", gulp.series( - // "eslint:src", - // "clean", - // "targethtml", - // "useminPrepare", - // "htmlmin", - // "requirejs", - // "concat", - // "cssmin", - // "uglify", - // "copy:dist", - // "cleanempty", - // "usemin", - "build-config" - // "clean:node_modules_test_dir" -)); +gulp.task( + "optimize-common", + gulp.series( + // "eslint:src", + // "clean", + // "targethtml", + // "useminPrepare", + // "htmlmin", + // "requirejs", + // "concat", + // "cssmin", + // "uglify", + // "copy:dist", + // "cleanempty", + // "usemin", + "build-config" + // "clean:node_modules_test_dir" + ) +); // task: optimize -gulp.task("optimize", gulp.series( - // "write-config:dist", - "optimize-common" -)); +gulp.task( + "optimize", + gulp.series( + // "write-config:dist", + "optimize-common" + ) +); // task: optimize-prerelease -gulp.task("optimize-prerelease", gulp.series( - // "write-config:prerelease", - "optimize-common" -)); +gulp.task( + "optimize-prerelease", + gulp.series( + // "write-config:prerelease", + "optimize-common" + ) +); -gulp.task("test", gulp.parallel("eslint", "nls-check")); +gulp.task("test", gulp.parallel("eslint", "nls-check", "format-check")); gulp.task("default", gulp.series("test")); diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 385bd456229..f5dcb60d08c 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -63,6 +63,7 @@ "glob": "^7.1.4", "gulp": "^4.0.2", "gulp-eslint-new": "^2.3.0", + "gulp-prettier": "^5.0.0", "gulp-rename": "^2.0.0", "gulp-watch": "^5.0.1", "iconv-lite": "^0.6.3", @@ -9774,6 +9775,46 @@ "node": "^12.20 || ^14.13 || >=16" } }, + "node_modules/gulp-prettier": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/gulp-prettier/-/gulp-prettier-5.0.0.tgz", + "integrity": "sha512-2TbsdXnO/zMLYwD5In8w1CwMn0fw2HOfCnD55+D+0AUczqvP8vEgwS82tEIqj4EsWnOS9+kLPclsGYkkpxxtcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "plugin-error": "^2.0.0", + "prettier": "^3.0.0", + "through2": "^4.0.2" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/gulp-prettier/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/gulp-prettier/node_modules/through2": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/through2/-/through2-4.0.2.tgz", + "integrity": "sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==", + "dev": true, + "license": "MIT", + "dependencies": { + "readable-stream": "3" + } + }, "node_modules/gulp-rename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/gulp-rename/-/gulp-rename-2.0.0.tgz", @@ -17040,6 +17081,22 @@ "node": ">=0.10.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-hrtime": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", @@ -28842,6 +28899,39 @@ "vinyl-fs": "^4.0.0" } }, + "gulp-prettier": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/gulp-prettier/-/gulp-prettier-5.0.0.tgz", + "integrity": "sha512-2TbsdXnO/zMLYwD5In8w1CwMn0fw2HOfCnD55+D+0AUczqvP8vEgwS82tEIqj4EsWnOS9+kLPclsGYkkpxxtcg==", + "dev": true, + "requires": { + "plugin-error": "^2.0.0", + "prettier": "^3.0.0", + "through2": "^4.0.2" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "through2": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/through2/-/through2-4.0.2.tgz", + "integrity": "sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==", + "dev": true, + "requires": { + "readable-stream": "3" + } + } + } + }, "gulp-rename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/gulp-rename/-/gulp-rename-2.0.0.tgz", @@ -33805,6 +33895,12 @@ "resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz", "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=" }, + "prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true + }, "pretty-hrtime": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", diff --git a/package.json b/package.json index 09a9bd23ba9..e6ed8180442 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,8 @@ "tslint:app": "tslint -c tslint.json --project app/tsconfig.json -t stylish", "tslint:src": "tslint -c src/tslint.json --project src/tsconfig.json -t stylish", "tslint": "npm run tslint:app && npm run tslint:src", + "lint": "npm run tslint && gulp eslint", + "format": "gulp format", "dev": "concurrently --kill-others \"gulp watch\" \"tsc --watch --project src\" \"npm run webpack -- --watch\"", "start": "electron .", "pack": "npm run build-optimized && electron-builder --dir", @@ -175,6 +177,7 @@ "glob": "^7.1.4", "gulp": "^4.0.2", "gulp-eslint-new": "^2.3.0", + "gulp-prettier": "^5.0.0", "gulp-rename": "^2.0.0", "gulp-watch": "^5.0.1", "iconv-lite": "^0.6.3", diff --git a/src/config.json b/src/config.json index dc663d6b217..1f1cb497107 100644 --- a/src/config.json +++ b/src/config.json @@ -132,6 +132,8 @@ "tslint:app": "tslint -c tslint.json --project app/tsconfig.json -t stylish", "tslint:src": "tslint -c src/tslint.json --project src/tsconfig.json -t stylish", "tslint": "npm run tslint:app && npm run tslint:src", + "lint": "npm run tslint && gulp eslint", + "format": "gulp format", "dev": "concurrently --kill-others \"gulp watch\" \"tsc --watch --project src\" \"npm run webpack -- --watch\"", "start": "electron .", "pack": "npm run build-optimized && electron-builder --dir", @@ -203,6 +205,7 @@ "glob": "^7.1.4", "gulp": "^4.0.2", "gulp-eslint-new": "^2.3.0", + "gulp-prettier": "^5.0.0", "gulp-rename": "^2.0.0", "gulp-watch": "^5.0.1", "iconv-lite": "^0.6.3", diff --git a/tasks/eslint.js b/tasks/eslint.js index 8f55efe3ff2..6f5db7905ce 100644 --- a/tasks/eslint.js +++ b/tasks/eslint.js @@ -49,6 +49,7 @@ const meta = { "tasks/**/*.ts" ] }; +exports.meta = meta; function eslintTask(files) { // To automatically fix issues add `fix: true` to the eslint options and diff --git a/tasks/format.js b/tasks/format.js new file mode 100644 index 00000000000..d32137f836d --- /dev/null +++ b/tasks/format.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 - present The quadre code authors. All rights reserved. + * @license MIT + * + */ + +"use strict"; + +const gulp = require("gulp"); +const prettier = require("gulp-prettier"); +// const { meta } = require("./eslint"); + +const options = { + printWidth: 100, + tabWidth: 4, + semi: true, + trailingComma: "es5", +}; + +function getGlobs() { + const globs = [ + "gulpfile.js", + // ...meta.app, + // ...meta.src, + // ...meta.test, + // ...meta.build, + ]; + return globs; +} + +function format() { + return gulp + .src(getGlobs()) + .pipe(prettier(options)) + .pipe(gulp.dest((file) => file.base)); +} + +format.description = "Format the source code"; + +gulp.task("format", format); + +function validate() { + return gulp.src(getGlobs()).pipe(prettier.check(options)); +} + +format.description = "Format the source code"; + +gulp.task("format-check", validate); diff --git a/tslint.json b/tslint.json index 0a6fd876aab..e07fe6581dc 100644 --- a/tslint.json +++ b/tslint.json @@ -18,6 +18,7 @@ "variable-name": false, "no-implicit-dependencies": [true, "dev"], "no-console": false, - "max-classes-per-file": false + "max-classes-per-file": false, + "one-line": false } } diff --git a/webpack.dev.ts b/webpack.dev.ts index 35c9811571c..493a88047f2 100644 --- a/webpack.dev.ts +++ b/webpack.dev.ts @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2024 - present The quadre code authors. All rights reserved. + * @license MIT + * + */ + import path from "node:path"; import { Configuration } from "webpack"; import TranspilePlugin from "transpile-webpack-plugin";