Skip to content

Commit

Permalink
switch bundler, from parcel to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucaroff committed Aug 18, 2023
1 parent 078700b commit 6fbd1fc
Show file tree
Hide file tree
Showing 13 changed files with 3,834 additions and 3,003 deletions.
4 changes: 2 additions & 2 deletions src/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
color: white;
}
</style>
<link rel="stylesheet" href="./style.css" />
<link rel="stylesheet" href="./src/style.css" />
</head>

<body>
Expand All @@ -19,7 +19,7 @@ <h1 class="title">Cellex</h1>
<p class="subtitle">Monodimensional Cellular Automaton Explorer</p>
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="appRoot"></div>
<script type="module" src="./cellex.ts"></script>
<script type="module" src="./src/cellex.ts"></script>
</div>
</body>
</html>
20 changes: 8 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@
"scripts": {
"check": "tsc --noEmit",
"checkwatch": "tsc --noEmit --watch",
"build": "parcel build src/index.html",
"mcabuild": "parcel build src/index.html --public-url cellex.d",
"dev": "parcel src/index.html"
"build": "vite build",
"mcabuild": "vite build --base /cellex.d",
"dev": "vite"
},
"devDependencies": {
"@rollup/pluginutils": "^5.0.2",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/nearley": "^2.11.1",
"@types/node": "^13.1.1",
"@types/react": "^18.0.2",
"@types/react-dom": "^18.0.2",
"@vitejs/plugin-react": "^4.0.0",
"prettier": "^2.0.5",
"ts-node": "^10.5.0",
"typescript": "^5.0.4"
"typescript": "^5.0.4",
"vite": "^4.3.5"
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"antd": "^5.4.7",
"font-awesome": "^4.7.0",
"js-xxhash": "^1.0.4",
"nearley": "^2.19.1",
"parcel": "^2.8.3",
"parcel-transformer-nearley": "^1.0.4",
"nearley": "^2.20.1",
"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.0.2",
"rehype-react": "^4.0.1",
"remark-parse": "^7.0.2",
"remark-rehype": "^5.0.0",
"unified": "^8.4.2"
},
"alias": {
"process": {
"global": "process"
}
}
}
4 changes: 0 additions & 4 deletions parcel.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/automatonnaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ The following entries all describe rule 110:

- `1d, ns3, 2c, r110`
- `1d,ns3,2c,r110`
- `r110`
- `e110`

They are the compact version of the following entries:

- `1 dimension, neighborhood size 3, 2 colors, rule 110`
- `rule 110`
- `elementary 110`

Cellex handles only monodimensional rules, so rule descriptions beginning by `2d` or `3d` will be rejected.
Expand Down
6 changes: 3 additions & 3 deletions src/patternlang/parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { default as nearley } from "nearley"

import { SideBorder, TopBorder } from "./BorderType"
import patternGrammar from "./patternLanguage.ne"
import sideBorderGrammar from "./sideBorderLanguage.ne"
import topBorderGrammar from "./topBorderLanguage.ne"
import { default as patternGrammar } from "./patternLanguage.ne"
import { default as sideBorderGrammar } from "./sideBorderLanguage.ne"
import { default as topBorderGrammar } from "./topBorderLanguage.ne"

export let createSideBorderParser = () => {
return new nearley.Parser(sideBorderGrammar)
Expand Down
2 changes: 0 additions & 2 deletions src/patternlang/patternLanguage.ne
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const {
pattern,
flag,
group,
visible,
hidden,
patternSet,
} = require('./patternPostprocessor')
%}
Expand Down
6 changes: 2 additions & 4 deletions src/userinterface/markdown/documentation.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import fs from "fs"
import * as React from "react"

import markdownContent from "../../../DOCUMENTATION.md?raw"
import { md2react } from "../../lib/md2react"
import { autoHashLinkingTitleSet } from "./autoHashLinkTitleSet"
import { usePromise } from "./usePromise"

const markdownContent = fs.readFileSync(__dirname + "/../../../DOCUMENTATION.md", "utf-8")
// const markdownContent = fs.readFileSync(__dirname + "/../../../DOCUMENTATION.md", "utf-8")

let promise = md2react(markdownContent, { ...autoHashLinkingTitleSet })

Expand Down
86 changes: 20 additions & 66 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,24 @@
{
"include": [
"src"
],
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"resolveJsonModule": true,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "ESNext",
"skipLibCheck": true,

/* Strict Type-Checking Options */
// "strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts", "vite-plugin-nearley.ts"]
}
49 changes: 49 additions & 0 deletions vite-plugin-nearley.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { FilterPattern, createFilter } from "@rollup/pluginutils"
import nearleyCore from "nearley"
import nearleyCompile from "nearley/lib/compile"
import nearleyGenerate from "nearley/lib/generate"
import nearleyGrammar from "nearley/lib/nearley-language-bootstrapped"

export interface ViteNearleyOptions {
exclude?: FilterPattern
include?: FilterPattern
}

export default function nearley({ include = "**/*.ne", exclude }: ViteNearleyOptions = {}) {
const filter = createFilter(include, exclude)

return {
name: "vite-plugin-nearley",
transform(code: string, id: string) {
if (!filter(id)) {
return undefined
}
// parsing the asset
let grammarParser = new nearleyCore.Parser(nearleyGrammar)
grammarParser.feed(code)
let grammarAst = grammarParser.results[0]

let grammarInfoObject = nearleyCompile(grammarAst, {
args: [id],
})

let generatedCode: string = nearleyGenerate(grammarInfoObject, "grammar")

let truncatedCode = generatedCode
.replace(/^.*\n.*\n.*\n/, "")
.replace(/.*\n.*\n.*\n.*\n.*\n.*\n$/, "")

let importHeader: string[] = []
let filteredCode = truncatedCode.replace(
/const \{\n((\ *[a-zA-Z]+,\n)*)\} = require\('([^']+)'\)/g,
(match, g1, g2, g3) => {
importHeader.push(`import {\n${g1}} from '${g3}'\n`)
return ""
},
)
let codeResult = importHeader.join("") + filteredCode + "\nexport default grammar"

return { code: codeResult }
},
}
}
9 changes: 9 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"

import nearley from "./vite-plugin-nearley"

// https://vitejs.dev/config/
export default defineConfig({
plugins: [nearley(), react()],
})
4 changes: 4 additions & 0 deletions vite.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*?raw" {
const content: string
export default content
}
Loading

0 comments on commit 6fbd1fc

Please sign in to comment.