diff --git a/.gitignore b/.gitignore index b7b711f3..96b72065 100644 --- a/.gitignore +++ b/.gitignore @@ -172,9 +172,14 @@ CACHE/ # VSCode .vscode -# Docker data # Docker data postgres-data/ src/media/ +src/static/ *.log + +node_modules/ + +# Ignore all generated static files from the npm module +src/npm/static/ diff --git a/README.md b/README.md index 6979dcff..3faad167 100644 --- a/README.md +++ b/README.md @@ -24,22 +24,25 @@ To get started with Project Moore, follow these instructions to set up a **development** environment: 1. Install Python 3, at least version 3.6 or up. -2. [Install postgresql](INSTALLING_POSTGRES.md) -3. Install the following python packages: +2. [Install the LTS version of NodeJS](https://nodejs.org). If you are using Ubuntu or Ubuntu for windows, use [NVM](https://github.com/nvm-sh/nvm) to install the LTS version node instead. +3. [Install postgresql](INSTALLING_POSTGRES.md) +4. Install the following python packages: - python3-venv - python3-dev - build-essential - libpq-dev -4. Clone the repository. -5. Copy the file `.env-template` and name the copy `.env` -6. Fill in the necessary variables in `.env`. `MELOS_URL` and `MELOS_ADMIN` are required. You might have to fill in some database credidentils. Check `src/moore/settings/base.py` for which default values are used if you don't specify and credidentials. -7. Run `source ./source_me.sh` to create a virtual environment. -8. Run `pip install --upgrade pip` to make sure that pip is running the latest version -9. Run `pip install -r dev-requirements.txt` -10. Use `cd src` to enter the website directory. -11. Run `./manage.py migrate` to initialize the database. -12. Run `./manage.py compilemessages` to create all the translations. -13. Run `./manage.py createsuperuser` to create an admin user. (if the ssn is not passed, the most likely fault lies with the db-credentials) +5. Clone the repository. +6. Copy the file `.env-template` and name the copy `.env` +7. Fill in the necessary variables in `.env`. `MELOS_URL` and `MELOS_ADMIN` are required. You might have to fill in some database credidentils. Check `src/moore/settings/base.py` for which default values are used if you don't specify and credidentials. +8. Run `source ./source_me.sh` to create a virtual environment. +9. Run `pip install --upgrade pip` to make sure that pip is running the latest version +10. Run `pip install -r dev-requirements.txt` +11. Use `cd src` to enter the website directory. +12. Run `./manage.py migrate` to initialize the database. +13. Run `./manage.py compilemessages` to create all the translations. +14. Run `./manage.py createsuperuser` to create an admin user. (if the ssn is not passed, the most likely fault lies with the db-credentials) +15. Use `cd npm` and run the command `npx vite build` to compile all javascript libraries. +16. Go back to `src` by running `cd ..` During development, you can run a test web server using `./manage.py runserver`. @@ -61,6 +64,7 @@ environment all set up: 1. Run `docker exec -it moore python src/manage.py compilemessages` to create all the translations 1. Run `docker exec -it moore python src/manage.py createsuperuser` to create an admin user. +1. Run `docker exec -w src/npm -it npx vite build` to compile all javascript libraries. The Moore application is now available on `http://localhost:8000` and can be started using `docker-compose up -d` (the `-d` flag starts the instance in the background) and stopped `docker-compose stop`. diff --git a/requirements.txt b/requirements.txt index 503259f2..e1835396 100644 --- a/requirements.txt +++ b/requirements.txt @@ -38,3 +38,6 @@ django-jsonschema-form==1.0.3 # Improved environment variable handling python-decouple==3.7 + +# Add customabilitiy for including JS scripts in Forms media +django-js-asset==2.0.0 diff --git a/src/blocks/templates/blocks/html_editor.html b/src/blocks/templates/blocks/html_editor.html new file mode 100644 index 00000000..c8f42812 --- /dev/null +++ b/src/blocks/templates/blocks/html_editor.html @@ -0,0 +1,42 @@ + + +
+ diff --git a/src/blocks/widgets.py b/src/blocks/widgets.py index 2bb574e0..ebe736fa 100644 --- a/src/blocks/widgets.py +++ b/src/blocks/widgets.py @@ -1,35 +1,19 @@ from django import forms +from js_asset import JS from wagtail.utils.widgets import WidgetWithScript class CodeMirrorWidget(WidgetWithScript, forms.Textarea): - def render_js_init(self, id, name, value): - js = """ - document.addEventListener('DOMContentLoaded', function(){{ - CodeMirror.fromTextArea( - document.getElementById("{id}"), - {{ - lineWrapping: true, - indentUnit: 4, - mode: "htmlmixed", - autoRefresh: true - }} - ) - }}); - """ - return js.format(id=id) + template_name = 'blocks/html_editor.html' @property def media(self): - return forms.Media( - css={'all': ('libraries/codemirror/codemirror.css',)}, - js=( - 'libraries/codemirror/codemirror.js', - 'libraries/codemirror/autorefresh.js', - 'libraries/codemirror/xml.js', - 'libraries/codemirror/css.js', - 'libraries/codemirror/javascript.js', - 'libraries/codemirror/htmlmixed.js', - ) - ) + # The JS module allows us to add custom attributes to script tags. + # In this case we need to add type=module since codemirror.js is + # made as an ES module. + media = forms.Media(js=[ + JS("codemirror.js", {"type": "module"}) + ]) + + return media diff --git a/src/moore/settings/base.py b/src/moore/settings/base.py index eba7302d..67a8ebf1 100644 --- a/src/moore/settings/base.py +++ b/src/moore/settings/base.py @@ -36,6 +36,7 @@ 'materialize', 'members', 'news', + 'npm', 'search', 'moore', # include for templatetags diff --git a/src/npm/README.md b/src/npm/README.md new file mode 100644 index 00000000..9cf6d88c --- /dev/null +++ b/src/npm/README.md @@ -0,0 +1,42 @@ +# NPM modules + +This app allows the possiblity to install and use NPM modules within project moore. +Previously, JavaScript files had to be downloaded and added directly to the source code. +This makes it difficult to remember and actually update the library and is not a practice used anymore (2023). + +This module allows packages to be installed via npm which is the recommended way to install javascript packages. + +## How to use + +The packages from npm and any other custom code that we add on top of them, do not work directly in browsers. In order to get the code to be usable by browsers, Vite is used to compile them. + +1. All javascript files that should be compiled to work in browsers must be added in `vite.config.js` under `build --> rollupOptions --> input`, +2. Run `npx vite build` to compile the files. This creates a folder called `static` with the files compiled for the browser. +3. In the part of django where you want to use the javascript code, import the javascript file. How exactly you will do this depends on how you intend to use it. See examples below +4. Start the django server with `./manage.py runserver` which automatically collects the compiled javascript files from the generated static folder. + +## Example + +In this example we will install a javascript library called codemirror which replaces an textarea with an code editor (in this case it will be used to write HTML code) on a webpage. + +1. First we install codemirror, its languages support for html and its state handler (all three of them were required for the purposes the code editor was going to be used for) `npm i codemirror @codemirror/lang-html @codemirror/state` + +2. Next we create a new file called `codemirror.js` in the same directory as `vite.config.js`. In this file we import the parts of the library we want to use and create some extra code that will fit our purpose. Finally they are exported, which allows them to be used by django. **NOTE:** Only those parts that have been exported can be accessed by django!. + +![Example code for codemirror.js](images/codemirror-example.png "Example code for codemirror.js") + +3. In `vite.config.js` under `build --> rollupOptions --> input`, we add codemirror so that vite will compile it. + +![Example of how a javascript file should be added to vite](images/vite-example.png "Example of how a javascript file should be added to vite") + +4. We run `npx vite build` in the terminal to compile the files which creates a folder called `static` containing a file called `codemirror.js` which contains the compiled version of our original `codemirror.js` file. + +5. In the CodemirrorWidget in django we first have to import the javascript file so that it can be used by django. In this case since the javascript will be used by a form widget, the javascript file can be imported in the forms media object. **Important:** The javascript has to imported with `type=module` + +![Example of how the code is imported](images/codemirror-widget.png "Example of how the code is imported") + +6. In the widgets template code, the javascript code can now be imported and used as normal javascript. + +![Example of how to use the imported javascript file](images/widget-html.png "Example of how to use the imported javascript file") + +7. We run `./manage.py runserver` which automatically gets the compile javascript file since it is in a folder called static and makes it available to our code written in django. diff --git a/src/npm/codemirror.js b/src/npm/codemirror.js new file mode 100644 index 00000000..df596ed2 --- /dev/null +++ b/src/npm/codemirror.js @@ -0,0 +1,11 @@ +import { basicSetup, EditorView } from "codemirror"; +import { EditorState } from "@codemirror/state"; +import { html } from "@codemirror/lang-html"; + +const theme = EditorView.baseTheme({ + "&.cm-editor": { + fontSize: "1rem", + }, +}); + +export { EditorView, EditorState, html, basicSetup, theme }; diff --git a/src/npm/images/codemirror-example.png b/src/npm/images/codemirror-example.png new file mode 100644 index 00000000..b7855a80 Binary files /dev/null and b/src/npm/images/codemirror-example.png differ diff --git a/src/npm/images/codemirror-widget.png b/src/npm/images/codemirror-widget.png new file mode 100644 index 00000000..aa0e0e0c Binary files /dev/null and b/src/npm/images/codemirror-widget.png differ diff --git a/src/npm/images/vite-example.png b/src/npm/images/vite-example.png new file mode 100644 index 00000000..fcf0b5e0 Binary files /dev/null and b/src/npm/images/vite-example.png differ diff --git a/src/npm/images/widget-html.png b/src/npm/images/widget-html.png new file mode 100644 index 00000000..0313f69c Binary files /dev/null and b/src/npm/images/widget-html.png differ diff --git a/src/npm/index.js b/src/npm/index.js new file mode 100644 index 00000000..1de53c03 --- /dev/null +++ b/src/npm/index.js @@ -0,0 +1,2 @@ +// This file does not serve any purpose but is required by vite +// to generate each javascript file as separate files diff --git a/src/npm/materialize.js b/src/npm/materialize.js new file mode 100644 index 00000000..cea25c5f --- /dev/null +++ b/src/npm/materialize.js @@ -0,0 +1 @@ +export default () => console.log("materilze"); diff --git a/src/npm/package-lock.json b/src/npm/package-lock.json new file mode 100644 index 00000000..cd87e4a4 --- /dev/null +++ b/src/npm/package-lock.json @@ -0,0 +1,434 @@ +{ + "name": "moore-npm-deps", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "moore-npm-deps", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@codemirror/lang-html": "^6.4.3", + "@codemirror/state": "^6.2.0", + "codemirror": "^6.0.1", + "vite": "^4.1.4" + } + }, + "node_modules/@codemirror/autocomplete": { + "version": "6.4.2", + "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.4.2.tgz", + "integrity": "sha512-8WE2xp+D0MpWEv5lZ6zPW1/tf4AGb358T5GWYiKEuCP8MvFfT3tH2mIF9Y2yr2e3KbHuSvsVhosiEyqCpiJhZQ==", + "dependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.6.0", + "@lezer/common": "^1.0.0" + }, + "peerDependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "@lezer/common": "^1.0.0" + } + }, + "node_modules/@codemirror/commands": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.2.1.tgz", + "integrity": "sha512-FFiNKGuHA5O8uC6IJE5apI5rT9gyjlw4whqy4vlcX0wE/myxL6P1s0upwDhY4HtMWLOwzwsp0ap3bjdQhvfDOA==", + "dependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.2.0", + "@codemirror/view": "^6.0.0", + "@lezer/common": "^1.0.0" + } + }, + "node_modules/@codemirror/lang-css": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/@codemirror/lang-css/-/lang-css-6.1.1.tgz", + "integrity": "sha512-P6jdNEHyRcqqDgbvHYyC9Wxkek0rnG3a9aVSRi4a7WrjPbQtBTaOmvYpXmm13zZMAatO4Oqpac+0QZs7sy+LnQ==", + "dependencies": { + "@codemirror/autocomplete": "^6.0.0", + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@lezer/css": "^1.0.0" + } + }, + "node_modules/@codemirror/lang-html": { + "version": "6.4.3", + "resolved": "https://registry.npmjs.org/@codemirror/lang-html/-/lang-html-6.4.3.tgz", + "integrity": "sha512-VKzQXEC8nL69Jg2hvAFPBwOdZNvL8tMFOrdFwWpU+wc6a6KEkndJ/19R5xSaglNX6v2bttm8uIEFYxdQDcIZVQ==", + "dependencies": { + "@codemirror/autocomplete": "^6.0.0", + "@codemirror/lang-css": "^6.0.0", + "@codemirror/lang-javascript": "^6.0.0", + "@codemirror/language": "^6.4.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.2.2", + "@lezer/common": "^1.0.0", + "@lezer/css": "^1.1.0", + "@lezer/html": "^1.3.0" + } + }, + "node_modules/@codemirror/lang-javascript": { + "version": "6.1.5", + "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.1.5.tgz", + "integrity": "sha512-BS2SmI1IXxWqMPhbJ0DC3eAHAK9V9XvdHMSqwvTBnmh5xFALt+cVDg7XE/A1dxdxzXYXyeqGddgqx1rQv7AYaw==", + "dependencies": { + "@codemirror/autocomplete": "^6.0.0", + "@codemirror/language": "^6.6.0", + "@codemirror/lint": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "@lezer/common": "^1.0.0", + "@lezer/javascript": "^1.0.0" + } + }, + "node_modules/@codemirror/language": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.6.0.tgz", + "integrity": "sha512-cwUd6lzt3MfNYOobdjf14ZkLbJcnv4WtndYaoBkbor/vF+rCNguMPK0IRtvZJG4dsWiaWPcK8x1VijhvSxnstg==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "@lezer/common": "^1.0.0", + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0", + "style-mod": "^4.0.0" + } + }, + "node_modules/@codemirror/lint": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.2.0.tgz", + "integrity": "sha512-KVCECmR2fFeYBr1ZXDVue7x3q5PMI0PzcIbA+zKufnkniMBo1325t0h1jM85AKp8l3tj67LRxVpZfgDxEXlQkg==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "crelt": "^1.0.5" + } + }, + "node_modules/@codemirror/search": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.3.0.tgz", + "integrity": "sha512-rBhZxzT34CarfhgCZGhaLBScABDN3iqJxixzNuINp9lrb3lzm0nTpR77G1VrxGO3HOGK7j62jcJftQM7eCOIuw==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "crelt": "^1.0.5" + } + }, + "node_modules/@codemirror/state": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.2.0.tgz", + "integrity": "sha512-69QXtcrsc3RYtOtd+GsvczJ319udtBf1PTrr2KbLWM/e2CXUPnh0Nz9AUo8WfhSQ7GeL8dPVNUmhQVgpmuaNGA==" + }, + "node_modules/@codemirror/view": { + "version": "6.9.2", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.9.2.tgz", + "integrity": "sha512-ci0r/v6aKOSlzOs7/STMTYP3jX/+YMq2dAfAJcLIB6uom4ThtrUlzeuS7GTRGNqJJ+qAJR1vGWfXgu4CO/0myQ==", + "dependencies": { + "@codemirror/state": "^6.1.4", + "style-mod": "^4.0.0", + "w3c-keyname": "^2.2.4" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.17.tgz", + "integrity": "sha512-mdPjPxfnmoqhgpiEArqi4egmBAMYvaObgn4poorpUaqmvzzbvqbowRllQ+ZgzGVMGKaPkqUmPDOOFQRUFDmeUw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@lezer/common": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.0.2.tgz", + "integrity": "sha512-SVgiGtMnMnW3ActR8SXgsDhw7a0w0ChHSYAyAUxxrOiJ1OqYWEKk/xJd84tTSPo1mo6DXLObAJALNnd0Hrv7Ng==" + }, + "node_modules/@lezer/css": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@lezer/css/-/css-1.1.1.tgz", + "integrity": "sha512-mSjx+unLLapEqdOYDejnGBokB5+AiJKZVclmud0MKQOKx3DLJ5b5VTCstgDDknR6iIV4gVrN6euzsCnj0A2gQA==", + "dependencies": { + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0" + } + }, + "node_modules/@lezer/highlight": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.1.3.tgz", + "integrity": "sha512-3vLKLPThO4td43lYRBygmMY18JN3CPh9w+XS2j8WC30vR4yZeFG4z1iFe4jXE43NtGqe//zHW5q8ENLlHvz9gw==", + "dependencies": { + "@lezer/common": "^1.0.0" + } + }, + "node_modules/@lezer/html": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@lezer/html/-/html-1.3.4.tgz", + "integrity": "sha512-HdJYMVZcT4YsMo7lW3ipL4NoyS2T67kMPuSVS5TgLGqmaCjEU/D6xv7zsa1ktvTK5lwk7zzF1e3eU6gBZIPm5g==", + "dependencies": { + "@lezer/common": "^1.0.0", + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0" + } + }, + "node_modules/@lezer/javascript": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.4.2.tgz", + "integrity": "sha512-77qdAD4zanmImPiAu4ibrMUzRc79UHoccdPa+Ey5iwS891TAkhnMAodUe17T7zV7tnF7e9HXM0pfmjoGEhrppg==", + "dependencies": { + "@lezer/highlight": "^1.1.3", + "@lezer/lr": "^1.3.0" + } + }, + "node_modules/@lezer/lr": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.3.3.tgz", + "integrity": "sha512-JPQe3mwJlzEVqy67iQiiGozhcngbO8QBgpqZM6oL1Wj/dXckrEexpBLeFkq0edtW5IqnPRFxA24BHJni8Js69w==", + "dependencies": { + "@lezer/common": "^1.0.0" + } + }, + "node_modules/codemirror": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.1.tgz", + "integrity": "sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==", + "dependencies": { + "@codemirror/autocomplete": "^6.0.0", + "@codemirror/commands": "^6.0.0", + "@codemirror/language": "^6.0.0", + "@codemirror/lint": "^6.0.0", + "@codemirror/search": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0" + } + }, + "node_modules/crelt": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.5.tgz", + "integrity": "sha512-+BO9wPPi+DWTDcNYhr/W90myha8ptzftZT+LwcmUbbok0rcP/fequmFYCw8NMoH7pkAZQzU78b3kYrlua5a9eA==" + }, + "node_modules/esbuild": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.17.tgz", + "integrity": "sha512-G8LEkV0XzDMNwXKgM0Jwu3nY3lSTwSGY6XbxM9cr9+s0T/qSV1q1JVPBGzm3dcjhCic9+emZDmMffkwgPeOeLg==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.16.17", + "@esbuild/android-arm64": "0.16.17", + "@esbuild/android-x64": "0.16.17", + "@esbuild/darwin-arm64": "0.16.17", + "@esbuild/darwin-x64": "0.16.17", + "@esbuild/freebsd-arm64": "0.16.17", + "@esbuild/freebsd-x64": "0.16.17", + "@esbuild/linux-arm": "0.16.17", + "@esbuild/linux-arm64": "0.16.17", + "@esbuild/linux-ia32": "0.16.17", + "@esbuild/linux-loong64": "0.16.17", + "@esbuild/linux-mips64el": "0.16.17", + "@esbuild/linux-ppc64": "0.16.17", + "@esbuild/linux-riscv64": "0.16.17", + "@esbuild/linux-s390x": "0.16.17", + "@esbuild/linux-x64": "0.16.17", + "@esbuild/netbsd-x64": "0.16.17", + "@esbuild/openbsd-x64": "0.16.17", + "@esbuild/sunos-x64": "0.16.17", + "@esbuild/win32-arm64": "0.16.17", + "@esbuild/win32-ia32": "0.16.17", + "@esbuild/win32-x64": "0.16.17" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/is-core-module": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.11.0.tgz", + "integrity": "sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==", + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/nanoid": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, + "node_modules/picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" + }, + "node_modules/postcss": { + "version": "8.4.21", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", + "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + } + ], + "dependencies": { + "nanoid": "^3.3.4", + "picocolors": "^1.0.0", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dependencies": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/rollup": { + "version": "3.18.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.18.0.tgz", + "integrity": "sha512-J8C6VfEBjkvYPESMQYxKHxNOh4A5a3FlP+0BETGo34HEcE4eTlgCrO2+eWzlu2a/sHs2QUkZco+wscH7jhhgWg==", + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=14.18.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/source-map-js": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/style-mod": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.0.0.tgz", + "integrity": "sha512-OPhtyEjyyN9x3nhPsu76f52yUGXiZcgvsrFVtvTkyGRQJ0XK+GPc6ov1z+lRpbeabka+MYEQxOYRnt5nF30aMw==" + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/vite": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.1.4.tgz", + "integrity": "sha512-3knk/HsbSTKEin43zHu7jTwYWv81f8kgAL99G5NWBcA1LKvtvcVAC4JjBH1arBunO9kQka+1oGbrMKOjk4ZrBg==", + "dependencies": { + "esbuild": "^0.16.14", + "postcss": "^8.4.21", + "resolve": "^1.22.1", + "rollup": "^3.10.0" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + }, + "peerDependencies": { + "@types/node": ">= 14", + "less": "*", + "sass": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.4.0" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + } + } + }, + "node_modules/w3c-keyname": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.6.tgz", + "integrity": "sha512-f+fciywl1SJEniZHD6H+kUO8gOnwIr7f4ijKA6+ZvJFjeGi1r4PDLl53Ayud9O/rk64RqgoQine0feoeOU0kXg==" + } + } +} diff --git a/src/npm/package.json b/src/npm/package.json new file mode 100644 index 00000000..9085f8b9 --- /dev/null +++ b/src/npm/package.json @@ -0,0 +1,20 @@ +{ + "name": "moore-npm-deps", + "version": "1.0.0", + "description": "A collection of all packages that moore needs from npm", + "type": "module", + "files": [ + "static" + ], + "scripts": { + "build": "vite build" + }, + "author": "UTN", + "license": "ISC", + "dependencies": { + "@codemirror/lang-html": "^6.4.3", + "@codemirror/state": "^6.2.0", + "codemirror": "^6.0.1", + "vite": "^4.1.4" + } +} diff --git a/src/npm/vite.config.js b/src/npm/vite.config.js new file mode 100644 index 00000000..4e3ef779 --- /dev/null +++ b/src/npm/vite.config.js @@ -0,0 +1,27 @@ +import { resolve } from "path"; +import { defineConfig } from "vite"; + +export default defineConfig({ + build: { + lib: { + // The index does not serve any purpose but the entry and name + // is required for vite to create the javascript files as separate files + entry: resolve(__dirname, "index.js"), + name: "Moore NPM dependencies", + }, + rollupOptions: { + input: { + // If new javascript files are created + // Add them here + codemirror: resolve(__dirname, "codemirror.js"), + materialize: resolve(__dirname, "materialize.js"), + }, + output: [ + { + entryFileNames: ({ name }) => `${name}.js`, + dir: resolve(__dirname, "static"), + }, + ], + }, + }, +});