├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── .gitignore ├── eslint.config.mjs ├── package-lock.json ├── package.json ├── readme.md ├── src └── main.js └── test └── test.js /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: weekly 7 | open-pull-requests-limit: 10 8 | versioning-strategy: increase-if-necessary 9 | - package-ecosystem: github-actions 10 | directory: "/" 11 | schedule: 12 | interval: weekly 13 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | env: 12 | CI: true 13 | 14 | jobs: 15 | run: 16 | name: Node ${{ matrix.node }} / ${{ matrix.platform }} 17 | runs-on: ${{ matrix.platform }} 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | platform: 23 | - ubuntu-latest 24 | - macos-latest 25 | - windows-latest 26 | node: 27 | - 20 28 | - 22 29 | 30 | steps: 31 | - name: Set git to use LF 32 | run: | 33 | git config --global core.autocrlf false 34 | git config --global core.eol lf 35 | 36 | - name: Clone repository 37 | uses: actions/checkout@v4 38 | 39 | - name: Set Node.js version 40 | uses: actions/setup-node@v4 41 | with: 42 | node-version: ${{ matrix.node }} 43 | 44 | - run: node --version 45 | - run: npm --version 46 | 47 | - name: Install npm dependencies 48 | run: npm ci 49 | 50 | - name: Run tests 51 | run: npm test 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import openlayers from 'eslint-config-openlayers'; 2 | 3 | /** 4 | * @type {Array} 5 | */ 6 | export default [...openlayers]; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-ol-app", 3 | "version": "1.2.0", 4 | "description": "Initialize a new OpenLayers application", 5 | "main": "src/main.js", 6 | "scripts": { 7 | "lint": "eslint src test", 8 | "pretest": "npm run lint", 9 | "test": "mocha --recursive test" 10 | }, 11 | "bin": { 12 | "create-ol-app": "src/main.js" 13 | }, 14 | "files": [ 15 | "src/" 16 | ], 17 | "keywords": [ 18 | "openlayers", 19 | "ol", 20 | "map", 21 | "mapping" 22 | ], 23 | "license": "BSD-2-Clause", 24 | "devDependencies": { 25 | "eslint": "^9.16.0", 26 | "eslint-config-openlayers": "^20.0.0", 27 | "mocha": "^11.0.1" 28 | }, 29 | "dependencies": { 30 | "commander": "^14.0.0", 31 | "degit": "^2.8.4", 32 | "fs-extra": "^11.2.0", 33 | "validate-npm-package-name": "^6.0.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # create-ol-app 2 | 3 | The `create-ol-app` program sets up a project directory with the dependencies required for developing an OpenLayers application. The program requires `npx`, distributed with [Node](https://nodejs.org/) (at least version 12), and [`git`](https://github.com/git-guides/install-git). 4 | 5 | Using `create-ol-app` saves you from having to set up or configure tools like Vite, webpack, or Parcel. After setting up a new OpenLayers application, you can proceed with configuring the development environment to your liking – the `create-ol-app` program sets up the required tools, but doesn't lock you in to any specific configuration. 6 | 7 | ## Creating a new application 8 | 9 | To create a new OpenLayers application, choose a name for your application (`my-app` below) and run the following: 10 | 11 | npx create-ol-app my-app 12 | 13 | *🐛 If you get an error like "could not find commit hash" when running `create-ol-app`, make sure that you have [`git` installed](https://github.com/git-guides/install-git)*. 14 | 15 | This will create a new directory called `my-app` (choose a different name if you like) and install the dependencies for OpenLayers application development. By default, [Vite](https://vitejs.dev/) is used for development and bundling. See below for other options. 16 | 17 | *💡 Tip – if you run `npx create-ol-app` with no additional arguments, the new application will be set up in the current directory.* 18 | 19 | After the step above completes, you can change into your new application directory and start a development server: 20 | 21 | cd my-app 22 | npm start 23 | 24 | See the `my-app/readme.md` for more detail on working with the new application. 25 | 26 | ### Choosing a bundler 27 | 28 | The `create-ol-app` program supports a few different module bundlers. By default, an application is set up using [Vite](https://vitejs.dev/). To use a different bundler, pass the `--template` option to `create-ol-app`. 29 | 30 | The default template uses Vite. This is equivalent to running the following: 31 | 32 | npx create-ol-app my-app --template vite 33 | 34 | To see what other templates are available, see the help output for the `create-ol-app` program: 35 | 36 | npx create-ol-app --help 37 | 38 | To use webpack instead of Vite, run the following: 39 | 40 | npx create-ol-app my-app --template webpack 41 | 42 | After creating a new application, see the included `readme.md` for more details on getting started. 43 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const {spawn} = require('child_process'); 3 | const path = require('path'); 4 | const {Command, Option} = require('commander'); 5 | const degit = require('degit'); 6 | const fse = require('fs-extra'); 7 | const validatePackageName = require('validate-npm-package-name'); 8 | const packageJson = require('../package.json'); 9 | 10 | // must be a corresponding openlayers/ol-