Skip to content

Commit

Permalink
updateproject and add prettier scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 12, 2024
1 parent 605b4cd commit cc01174
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 21 deletions.
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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",
]
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleAttributePerLine": true
}
Empty file.
5 changes: 3 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
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';

export default [
js.configs.recommended,
...pluginVue.configs['flat/recommended'],
...tseslint.configs.recommended,
eslintConfigPrettier,
{
"languageOptions": {
"globals": {
Expand Down Expand Up @@ -36,7 +38,6 @@ export default [
},
"rules": {
"semi": ["error", "always"],
"vue/html-indent": ["error", 4]
},
},
]
];
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions webpack/webpack-utils/find-file.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
44 changes: 27 additions & 17 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
})
)
};
}
}
};

Expand All @@ -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]);
Expand Down

0 comments on commit cc01174

Please sign in to comment.