diff --git a/.gitignore b/.gitignore index 16d8d68..6ed9f88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -node_modules/ \ No newline at end of file +node_modules/ +.env \ No newline at end of file diff --git a/.sample.env b/.sample.env new file mode 100644 index 0000000..c4c6a53 --- /dev/null +++ b/.sample.env @@ -0,0 +1 @@ +PORT=5555 \ No newline at end of file diff --git a/README.md b/README.md index c487858..efb74a7 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,11 @@ This package also renders its own documentation and development environment. **TODO** explain how glitch remix / pull request flow works, use docs from community site +### Running Locally +If you'd like to work on this project locally, clone the repository, then run `npm install` to setup the dependencies. Run `npm start` to start the server. + +You may wish to add a .env file so that the project consistently starts on the same port. See .sample.env for an example. + ### Remote components While you are building or updating a component in this library, you may wish to see it in the context of your application. This package exports the helper `createRemoteComponent` that loads a development version of the library from a URL. For example: diff --git a/package-lock.json b/package-lock.json index 99d4423..ae11c70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -644,6 +644,11 @@ "esutils": "^2.0.2" } }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package.json b/package.json index 7b3d5dd..c801328 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "postversion": "npm run changelog" }, "dependencies": { + "dotenv": "^8.2.0", "prop-types": "15.x", "react-textarea-autosize": "^7.1.0" }, diff --git a/server/index.js b/server/index.js index ff7729d..7fbbadf 100644 --- a/server/index.js +++ b/server/index.js @@ -1,8 +1,12 @@ const express = require('express'); const app = express(); +const path = require('path'); const { getBundle } = require('./rollup'); const { serveTest } = require('../test/remote-component/server'); +const dotenv = require('dotenv'); + +dotenv.config(); const globals = { react: 'React', @@ -18,16 +22,16 @@ app.use(function(req, res, next) { res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); next(); }); - + app.get('/stories.js', async (req, res) => { - const output = await getBundle('/app/lib/stories.js', { format: 'iife', output: { name: 'glitchComponentLibrary' }, globals }); + const output = await getBundle(path.resolve(__dirname, '../lib/stories.js'), { format: 'iife', output: { name: 'glitchComponentLibrary' }, globals }); res.type('js'); res.send(output); }); app.get('/module.js', async (req, res) => { const fullUrl = `https://${req.get('host')}${req.originalUrl}`; - const output = await getBundle('/app/lib/index.js', { + const output = await getBundle(path.resolve(__dirname, '../lib/index.js'), { format: 'umd', name: 'glitchComponentLibrary', amd: { id: fullUrl, define: 'defineSharedComponent' }, diff --git a/server/rollup.js b/server/rollup.js index 054ac97..81bae52 100644 --- a/server/rollup.js +++ b/server/rollup.js @@ -16,7 +16,7 @@ async function build({ filePath, bundleOptions, additionalConfig = {} }) { return { code, filesToWatch: Object.keys(modules) - .filter((fileName) => fileName.startsWith('/app/')) + .filter((fileName) => fileName.startsWith(__dirname)) .sort(), }; }