Skip to content

Commit

Permalink
feat: Add build script for publishing (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
trygve-lie authored Sep 23, 2024
1 parent 11cac13 commit 72e9bdd
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 209 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/node_modules
public/build
build/*
package-lock.json

# Tests
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ Web component created using [lit](https://lit.dev/)
1. Copy and paste the following code inside the `<body></body>` tag of website where the component should appear, replacing `GOOGLE-API-KEY` with your key

```
<alpaca-map key="GOOGLE-API-KEY"></alpaca-map>
<alpaca-map apiKey="GOOGLE-API-KEY"></alpaca-map>
```

1. Optional. To center the map on a favourite farm, replace the latitude and longitude with its `centerLat` and `centerLng` coordinates

```
<alpaca-map key="GOOGLE-API-KEY" centerLat="-33.8688" centerLng="151.2093"></alpaca-map>
<alpaca-map apiKey="GOOGLE-API-KEY" centerLat="-33.8688" centerLng="151.2093"></alpaca-map>
```

1. Optional. To override the data source, set the value of `dataSource`, eg

```
<alpaca-map key="GOOGLE-API-KEY" dataSource="https://www.replace-me.com/api/cool-api"></alpaca-map>
<alpaca-map apiKey="GOOGLE-API-KEY" dataSource="https://www.replace-me.com/api/cool-api"></alpaca-map>
```

## For developers 🤖
Expand Down
49 changes: 49 additions & 0 deletions dev-utils/dev-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import rollupPluginCommonjs from "@rollup/plugin-commonjs";
import rollupPluginResolve from "@rollup/plugin-node-resolve";
import rollupPluginReplace from "@rollup/plugin-replace";
import rollupPluginTerser from "@rollup/plugin-terser";
import { rollup } from "rollup";

const inputOptions = {
input: ["./src/alpaca-map.js"],
plugins: [
rollupPluginResolve({
preferBuiltins: true
}),
rollupPluginCommonjs({
include: /node_modules/
}),
rollupPluginReplace({
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
/*
rollupPluginTerser({
format: {
comments: false
}
}),
*/
],
};

const outputOptionsList = [
{
preserveModules: true,
dir: './public/build',
// file: "./public/build/alpaca-map.js",
format: "es",
// sourcemap: true,
interop: 'esModule',
},
];

let bundle = await rollup(inputOptions);

for (const outputOptions of outputOptionsList) {
await bundle.write(outputOptions);
}

if (bundle) {
await bundle.close();
}
2 changes: 1 addition & 1 deletion dev-server.js → dev-utils/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fastify = Fastify({
});

fastify.register(fastifyStatic, {
root: path.join(import.meta.dirname, "./public"),
root: path.join(import.meta.dirname, "../public"),
prefix: "/",
});

Expand Down
20 changes: 12 additions & 8 deletions build.js → dev-utils/pub-build.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import rollupPluginCommonjs from "@rollup/plugin-commonjs";
import rollupPluginResolve from "@rollup/plugin-node-resolve";
import rollupPluginReplace from "@rollup/plugin-replace";
import rollupPluginTerser from "@rollup/plugin-terser";
import { rollup } from "rollup";

const inputOptions = {
input: ["./src/alpaca-map.js"],
external: ['lit'],
plugins: [
rollupPluginResolve({ preferBuiltins: true }),
rollupPluginCommonjs({ include: /node_modules/ }),
rollupPluginResolve({
exportConditions: ['production'],
preferBuiltins: true
}),
rollupPluginCommonjs({
include: /node_modules/
}),
rollupPluginReplace({
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
rollupPluginTerser({ format: { comments: false } }),
],
};

const outputOptionsList = [
{
// preserveModules: true,
// dir: './public/build',
file: "./public/build/alpaca-map.js",
preserveModules: true,
entryFileNames: '[name].mjs',
dir: './build/node',
format: "es",
sourcemap: true,
interop: 'esModule',
},
];

Expand Down
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@
"name": "@purplebugs/alpaca-map",
"type": "module",
"version": "0.0.4",
"main": "src/alpaca-map.js",
"exports": {
".": "./build/node/src/alpaca-map.mjs"
},
"files": [
"package.json",
"README.md",
"build",
"src"
],
"scripts": {
"build:watch": "node --watch-path=./src build.js",
"build": "node build.js",
"build:publish:node": "node ./dev-utils/pub-build.js",
"build:watch": "node --watch-path=./src ./dev-utils/dev-build.js",
"build": "node ./dev-utils/dev-build.js",
"prettier": "prettier . --write",
"start": "node dev-server.js",
"start": "node ./dev-utils/dev-server.js",
"test": "node --test",
"test-ui": "playwright test"
"test-ui": "playwright test",
"prepublishOnly": "npm run build:publish:node"
},
"author": "",
"license": "MIT",
"description": "",
"devDependencies": {
"@googlemaps/js-api-loader": "1.16.8",
"@googlemaps/markerclusterer": "^2.5.3",
"@fastify/static": "7.0.4",
"@playwright/test": "^1.45.1",
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-replace": "5.0.7",
"@rollup/plugin-terser": "0.4.4",
"@types/node": "^20.14.10",
"fastify": "4.28.0",
"prettier": "3.3.2",
"rollup": "4.18.0"
"@types/node": "20.14.10",
"fastify": "4.28.1",
"prettier": "3.3.3",
"rollup": "4.21.3"
},
"dependencies": {
"@googlemaps/markerclusterer": "^2.5.3",
"lit": "^3.1.4"
"lit": "3.1.4"
}
}
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1>Alpaca Map web component - index.html page header</h1>
<alpaca-map key="AIzaSyB4xD7fB993xNwqzBwF0vFpV3Qg_N9UTTc" centerLat="-33.8688" centerLng="151.2093"></alpaca-map>
-->

<alpaca-map key="AIzaSyB4xD7fB993xNwqzBwF0vFpV3Qg_N9UTTc"></alpaca-map>
<alpaca-map apiKey="AIzaSyB4xD7fB993xNwqzBwF0vFpV3Qg_N9UTTc"></alpaca-map>
<!--
// USAGE Step 2 - END
-->
Expand All @@ -41,6 +41,6 @@ <h1>Alpaca Map web component - index.html page header</h1>
</p>
</div>

<script type="module" src="/build/alpaca-map.js"></script>
<script type="module" src="/build/src/alpaca-map.js"></script>
</body>
</html>
Loading

0 comments on commit 72e9bdd

Please sign in to comment.