mirror of
https://github.com/heyman/heynote.git
synced 2024-11-21 15:33:14 +01:00
Avoid code duplication by auto building the GUESSLANG_LANGUAGES list in langdetect-worker.js from the src/editor/languages.js:LANGUAGES list.
This commit is contained in:
parent
d591d7ddb1
commit
a7e0f53c35
@ -1,31 +1,6 @@
|
|||||||
importScripts("guesslang.min.js")
|
importScripts("guesslang.min.js")
|
||||||
|
|
||||||
GUESSLANG_LANGUAGES = [
|
GUESSLANG_LANGUAGES = ["json","py","html","sql","md","java","php","css","xml","cpp","rs","cs","rb","sh","yaml","toml","go","clj","erl","js","ts","swift","kt","groovy","ps1"]
|
||||||
"json",
|
|
||||||
"py",
|
|
||||||
"js",
|
|
||||||
"ts",
|
|
||||||
"html",
|
|
||||||
"sql",
|
|
||||||
"java",
|
|
||||||
"cpp",
|
|
||||||
"php",
|
|
||||||
"css",
|
|
||||||
"xml",
|
|
||||||
"rs",
|
|
||||||
"md",
|
|
||||||
"cs",
|
|
||||||
"rb",
|
|
||||||
"sh",
|
|
||||||
"yaml",
|
|
||||||
"go",
|
|
||||||
"clj",
|
|
||||||
"erl",
|
|
||||||
"toml",
|
|
||||||
"swift",
|
|
||||||
"kt",
|
|
||||||
"groovy",
|
|
||||||
]
|
|
||||||
|
|
||||||
const guessLang = new self.GuessLang()
|
const guessLang = new self.GuessLang()
|
||||||
|
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"allowSyntheticDefaultImports": true
|
"allowSyntheticDefaultImports": true
|
||||||
},
|
},
|
||||||
"include": ["vite.config.ts", "package.json", "electron", "shared-utils"]
|
"include": ["vite.config.mjs", "package.json", "electron", "shared-utils"]
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import * as fs from 'node:fs'
|
||||||
import { rmSync } from 'node:fs'
|
import { rmSync } from 'node:fs'
|
||||||
import { join } from 'node:path'
|
import { join } from 'node:path'
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
@ -9,6 +10,7 @@ import pkg from './package.json'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
import { keyHelpStr } from "./shared-utils/key-helper";
|
import { keyHelpStr } from "./shared-utils/key-helper";
|
||||||
|
import { LANGUAGES } from "./src/editor/languages"
|
||||||
|
|
||||||
rmSync('dist-electron', { recursive: true, force: true })
|
rmSync('dist-electron', { recursive: true, force: true })
|
||||||
|
|
||||||
@ -16,8 +18,6 @@ const isDevelopment = process.env.NODE_ENV === "development" || !!process.env.VS
|
|||||||
const isProduction = process.env.NODE_ENV === "production"
|
const isProduction = process.env.NODE_ENV === "production"
|
||||||
|
|
||||||
const updateReadmeKeybinds = async () => {
|
const updateReadmeKeybinds = async () => {
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const readmePath = path.resolve(__dirname, 'README.md')
|
const readmePath = path.resolve(__dirname, 'README.md')
|
||||||
let readme = fs.readFileSync(readmePath, 'utf-8')
|
let readme = fs.readFileSync(readmePath, 'utf-8')
|
||||||
const keybindsRegex = /^(### What are the default keyboard shortcuts\?\s*).*?^(```\s+#)/gms
|
const keybindsRegex = /^(### What are the default keyboard shortcuts\?\s*).*?^(```\s+#)/gms
|
||||||
@ -32,11 +32,20 @@ ${keyHelpStr('darwin')}
|
|||||||
\`\`\`
|
\`\`\`
|
||||||
${keyHelpStr('win32')}
|
${keyHelpStr('win32')}
|
||||||
$2`
|
$2`
|
||||||
|
|
||||||
readme = readme.replace(keybindsRegex, shortcuts)
|
readme = readme.replace(keybindsRegex, shortcuts)
|
||||||
fs.writeFileSync(readmePath, readme)
|
fs.writeFileSync(readmePath, readme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateGuesslangLanguagesInWebWorker = async () => {
|
||||||
|
const langDetectWorkerPath = path.resolve(__dirname, 'public', 'langdetect-worker.js')
|
||||||
|
let workerFileContents = fs.readFileSync(langDetectWorkerPath, 'utf-8')
|
||||||
|
const langListRegex = /^GUESSLANG_LANGUAGES = \[[^\]]+\]/gms
|
||||||
|
const newLangList = JSON.stringify(LANGUAGES.map(l => l.guesslang).filter(l => l !== null))
|
||||||
|
workerFileContents = workerFileContents.replace(langListRegex, `GUESSLANG_LANGUAGES = ${newLangList}`)
|
||||||
|
fs.writeFileSync(langDetectWorkerPath, workerFileContents)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
resolve: {
|
resolve: {
|
||||||
@ -48,6 +57,7 @@ export default defineConfig({
|
|||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
updateReadmeKeybinds(),
|
updateReadmeKeybinds(),
|
||||||
|
updateGuesslangLanguagesInWebWorker(),
|
||||||
electron([
|
electron([
|
||||||
{
|
{
|
||||||
// Main-Process entry file of the Electron App.
|
// Main-Process entry file of the Electron App.
|
Loading…
Reference in New Issue
Block a user