From cc01174298ec31efe2980b80bd649043d5d3eda5 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Wed, 12 Jun 2024 10:20:18 -0400 Subject: [PATCH] updateproject and add prettier scripts --- .pre-commit-config.yaml | 30 ++++++++++++++++++++ .prettierrc | 3 ++ arches_lingo/locale/messages.pot | 0 eslint.config.mjs | 5 ++-- package.json | 2 ++ webpack/webpack-utils/find-file.js | 8 ++++-- webpack/webpack.common.js | 44 ++++++++++++++++++------------ 7 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .prettierrc create mode 100644 arches_lingo/locale/messages.pot diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..4eecb24f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +--- +repos: + + - repo: https://github.com/psf/black + rev: 24.4.2 + hooks: + - id: black + args: [--quiet] + exclude: node_modules + + - repo: local + hooks: + - id: prettier + name: prettier + entry: npm run prettier:fix + language: system + files: arches_lingo/src + - id: eslint + name: eslint + entry: npm run eslint:fix + language: system + files: arches_lingo/src + - id: typescript + name: typescript + entry: npm run ts:check + language: system + types: [ + "ts", + "vue", + ] diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..c4d8ac54 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleAttributePerLine": true +} diff --git a/arches_lingo/locale/messages.pot b/arches_lingo/locale/messages.pot new file mode 100644 index 00000000..e69de29b diff --git a/eslint.config.mjs b/eslint.config.mjs index 4c919b1c..ab51240a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -2,6 +2,7 @@ import js from "@eslint/js"; import pluginVue from 'eslint-plugin-vue'; import tseslint from 'typescript-eslint'; +import eslintConfigPrettier from "eslint-config-prettier"; import vueESLintParser from 'vue-eslint-parser'; @@ -9,6 +10,7 @@ export default [ js.configs.recommended, ...pluginVue.configs['flat/recommended'], ...tseslint.configs.recommended, + eslintConfigPrettier, { "languageOptions": { "globals": { @@ -36,7 +38,6 @@ export default [ }, "rules": { "semi": ["error", "always"], - "vue/html-indent": ["error", 4] }, }, -] \ No newline at end of file +]; \ No newline at end of file diff --git a/package.json b/package.json index a32aa32c..01d478bb 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,8 @@ "eslint:watch": "nodemon --watch . --ext ts,vue --exec npm run --silent eslint:check", "gettext:extract": "vue-gettext-extract", "gettext:compile": "vue-gettext-compile", + "prettier:check": "prettier arches_lingo/src --check", + "prettier:fix": "prettier arches_lingo/src --write", "ts:check": "vue-tsc --noEmit", "ts:watch": "vue-tsc --watch --noEmit", "start": "cross-env NODE_OPTIONS=--max-old-space-size=2048 webpack serve --config ./webpack/webpack.config.dev.js", diff --git a/webpack/webpack-utils/find-file.js b/webpack/webpack-utils/find-file.js index c6c79365..0ee07cb1 100644 --- a/webpack/webpack-utils/find-file.js +++ b/webpack/webpack-utils/find-file.js @@ -1,12 +1,16 @@ const fs = require('fs'); const Path = require('path'); -function findFile(path, target) { +function findFile(path, target, excludedDirectories) { + if (!excludedDirectories) { + excludedDirectories = []; + } + for (const name of fs.readdirSync(path)) { const filePath = Path.join(path, name); const stat = fs.lstatSync(filePath); - if (stat.isDirectory() && name !== 'node_modules') { + if (stat.isDirectory() && !excludedDirectories.includes(name)) { const result = findFile(filePath, target); if (result) { return result; diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 30367bfb..4e638f92 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -435,7 +435,12 @@ module.exports = () => { if (serverAddress.charAt(serverAddress.length - 1) === '/') { serverAddress = serverAddress.slice(0, -1) } + resp = await fetch(serverAddress + templatePath); + + if (resp.status === 500) { + throw new Error(); + } } catch (e) { failureCount += 1; @@ -447,22 +452,27 @@ module.exports = () => { } } else { - console.error( - '\x1b[31m%s\x1b[0m', // red - `"${templatePath}" has failed to load! Falling back to un-rendered file.` - ); - resp = { - text: () => ( - new Promise((resolve, _reject) => { - /* - if run in a test environment, failures will return a empty string which will - still allow the bundle to build. - */ - - resolve(isTestEnvironment ? '' : content); - }) - ) - }; + if (!isTestEnvironment) { + loaderContext.emitError(`Unable to fetch ${templatePath} from the Django server.`) + } + else { + console.warn( + '\x1b[31m%s\x1b[0m', // red + `"${templatePath}" has failed to load! Test environment detected, falling back to un-rendered file.` + ); + resp = { + text: () => ( + new Promise((resolve, _reject) => { + /* + if run in a test environment, failures will return a empty string which will + still allow the bundle to build. + */ + + resolve(isTestEnvironment ? '' : content); + }) + ) + }; + } } }; @@ -489,7 +499,7 @@ module.exports = () => { }; // BEGIN get data from `settings.py` - const settingsFilePath = findFile(Path.dirname(__dirname), 'settings.py') + const settingsFilePath = findFile(Path.dirname(__dirname), 'settings.py', ["node_modules", "build"]); const runPythonScript = (pythonCommand) => { let projectSettings = spawn(pythonCommand, [settingsFilePath]);