Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable library for frameworks via NPM modules #129

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/apps/react-basic/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["transform-class-properties"]
}
6 changes: 6 additions & 0 deletions examples/apps/react-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A previous link is required to test current status

- `npm link` in the parent project
- `npm link @carto/web-sdk` in this app

Then, to run the project `npm install` and `npm run start`
8,562 changes: 8,562 additions & 0 deletions examples/apps/react-basic/package-lock.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions examples/apps/react-basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "react-basic",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open --mode development",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@carto/web-sdk": "^1.0.0-alpha.2",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@babel/core": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"babel-loader": "^8.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"html-loader": "^1.3.0",
"html-webpack-plugin": "^4.4.1",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
21 changes: 21 additions & 0 deletions examples/apps/react-basic/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body,
#app,
#map {
width: 100vw;
height: 100vh;
box-sizing: border-box;
margin: 0;
}
</style>
</head>
<body>
<div id="app"></div>
</body>
</html>
25 changes: 25 additions & 0 deletions examples/apps/react-basic/src/Map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { auth, viz } from '@carto/web-sdk';

class Map extends React.Component {
map = null;

componentDidMount() {
auth.setDefaultCredentials({ username: 'public' });
// this.map = viz.createMap();
this.map = viz.createMap({
basemap: 'darkmatter',
view: { zoom: 4, longitude: 3, latitude: 40, pitch: 0, bearing: 0 },
container: 'map'
});

const ports = new viz.Layer('world_ports');
ports.addTo(this.map);
}

render() {
return <div id="map">Map</div>;
}
}

export default Map;
5 changes: 5 additions & 0 deletions examples/apps/react-basic/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Map from './Map';

ReactDOM.render(<Map />, document.getElementById('app'));
38 changes: 38 additions & 0 deletions examples/apps/react-basic/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader'
}
]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: './public/index.html',
filename: './index.html'
})
]
};
3 changes: 1 addition & 2 deletions examples/basemap/carto.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ <h4 class="as-subheader as-mb--12">
</main>
</div>

<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.js"></script>
<script src="https://unpkg.com/[email protected]/dist.min.js"></script>
<script src="/dist/umd/index.min.js"></script>

Expand All @@ -61,7 +60,7 @@ <h4 class="as-subheader as-mb--12">
// by default you get a full world positron basemap, centered at (0, 0) coordinates
const deckMap = carto.viz.createMap();
// ... but all these variations are also allowed
// const deckMap = carto.viz.createMap({ basemap: 'voyager'});
// const deckMap = carto.viz.createMap({ basemap: 'voyager'});
// const deckMap = carto.viz.createMap({ basemap: 'darkmatter', view: { zoom: 4 } });
// const deckMap = carto.viz.createMap({ basemap: 'positron', view: { zoom: 4, longitude: 3, latitude: 40, pitch: 45, bearing: 30 }, container: 'map' });

Expand Down
7 changes: 5 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
preset: 'ts-jest',
modulePathIgnorePatterns: ['__tests__/.*/cases/', 'dist'],
modulePathIgnorePatterns: ['__tests__/.*/cases/','__tests__/stubs/*', 'dist'],
rootDir: './',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
}
},
setupFiles: [
'<rootDir>/src/viz/__tests__/stubs/jest.stub.js'
]
};
Loading