Last active
February 19, 2019 21:16
-
-
Save dbabbs/787541ef350dd2f7d0a9b607492907e3 to your computer and use it in GitHub Desktop.
playing around with npx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
// const args = require('minimist')(process.argv.slice(2)); | |
const opn = require('opn') | |
// console.log(args); | |
// const name = args['n']; | |
// const id = args['id']; | |
// const code = args['code'] | |
const name = 'here-template'; | |
console.log(name) | |
const html = | |
`<html> | |
<head> | |
<title>Test page</title> | |
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" /> | |
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script> | |
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script> | |
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script> | |
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script> | |
<link rel="stylesheet" type="text/css" href="index.css"> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="index.js"></script> | |
</body> | |
</html> | |
`; | |
const css = | |
`body, html { | |
padding: 0; | |
margin: 0; | |
border: 0; | |
} | |
#map { | |
height: 100vh; | |
width: 100vw; | |
} | |
`; | |
const js = | |
`const platform = new H.service.Platform({ | |
app_id: 'DemoAppId01082013GAL', | |
app_code: 'AJKnXv84fjrb0KIHawS0Tg', | |
useHTTPS: true, | |
useCIT: true | |
}); | |
const pixelRatio = 2; // alternatively window.devicePixelRatio | |
const tileSize = pixelRatio === 1 ? 256 : 512; | |
const ppi = pixelRatio === 1 ? undefined : 320; | |
const maptypes = platform.createDefaultLayers({ | |
tileSize: tileSize, | |
ppi: ppi | |
}); | |
const map = new H.Map(document.getElementById('map'), maptypes.normal.mapnight, { | |
zoom: 3, | |
center: {lat: 41, lng: -121}, | |
pixelRatio: pixelRatio | |
}); | |
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map)); | |
const ui = H.ui.UI.createDefault(map, maptypes); | |
map.setBaseLayer(platform.getMapTileService().createTileLayer('basetile', 'reduced.night', tileSize, 'jpg',null, 1, true, {crossOrigin: "anonymous"})) | |
`; | |
console.log('gonna execute'); | |
if (!fs.existsSync(`./${name}`)){ | |
fs.mkdirSync(`./${name}`); | |
} | |
fs.writeFile(`./${name}/index.html`, html, function (err) { | |
if (err) throw err; | |
console.log('html created'); | |
}); | |
fs.writeFile(`./${name}/index.js`, js, function (err) { | |
if (err) throw err; | |
console.log('javascript created'); | |
}); | |
fs.writeFile(`./${name}/index.css`, css, function (err) { | |
if (err) throw err; | |
console.log('css created'); | |
}); | |
opn(`./${name}/index.html`).then(() => { | |
process.exit() | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "make-here", | |
"version": "1.0.0", | |
"description": "install here \tquickly", | |
"main": "index.js", | |
"dependencies": { | |
"minimist": "^1.2.0", | |
"opn": "^5.4.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"bin": "./index.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment