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

Subpackages #26

Merged
merged 3 commits into from
Dec 4, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
examples/libs/
examples/layers/
src/ThreeExtended/
packages/Main/src/ThreeExtended/
test/hooks.js
dist/
node_modules/
Expand Down
12 changes: 11 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path');

module.exports = {

// Global ESLint settings
Expand All @@ -15,7 +17,15 @@ module.exports = {
},
settings: {
'import/resolver': {
'babel-module': {},
'babel-module': {
alias: {
'@itowns/geographic': path.resolve(__dirname, 'packages/Geographic/src/Main.js'),
itowns: path.resolve(__dirname, 'packages/Main/src/Main.js'),
},
plugins: [
['module-extension-resolver'],
],
},
},
},
env: {
Expand Down
60 changes: 41 additions & 19 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- master
workflow_dispatch: {}


jobs:

# Build bundle, doc and check linter
Expand Down Expand Up @@ -55,7 +54,7 @@ jobs:
with:
name: dist-itowns
path: |
dist/**/*.js
packages/Main/dist/**/*.js
examples
buildDocs

Expand All @@ -79,8 +78,15 @@ jobs:
# Unit and coverage tests
unit-and-coverage-tests:
name: Unit and coverage tests
needs: build
needs: [build, check-commit-message]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- package: "@gchoqueux/geographic"
path: "Geographic"
- package: "itowns"
path: "Main"
steps:

# Use specific Node.js version
Expand All @@ -95,17 +101,33 @@ jobs:
- name: Install packages
run: npm ci

- name: Run unit tests
run: npm run test-with-coverage_lcov
# Transpile
- name: transpile packages
run: npm run transpile

# Code coverage
- name: Coveralls
if: ${{ success() }}
uses: coverallsapp/github-action@master
- name: Test ${{ matrix.package }}
run: npm run test-with-coverage_lcov --workspace ${{ matrix.package}}
- name: Coveralls Parallel
uses: coverallsapp/github-action@v2
with:
format: lcov
base-path: ./packages/${{ matrix.path }}
path-to-lcov: ./packages/${{ matrix.path }}/coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.package }}
parallel: true


# Final Code coverage
finish-coverage:
name: finish parallel test unit
needs: unit-and-coverage-tests
runs-on: ubuntu-latest
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
github-token: ${{ secrets.GITHUB_TOKEN }}
# Functional tests
functional-tests:
name: Functional tests
Expand Down Expand Up @@ -139,7 +161,7 @@ jobs:
publish:
name: Publish NPM package
if: ${{ github.ref == 'refs/heads/master' }}
needs: [unit-and-coverage-tests, functional-tests, check-commit-message]
needs: [finish-coverage, functional-tests]
runs-on: ubuntu-latest
permissions:
# id-token: write permission is required for npm provenance:
Expand Down Expand Up @@ -196,7 +218,7 @@ jobs:
deploy:
name: Deploy to itowns.github.io
if: ${{ github.ref == 'refs/heads/master' }}
needs: [unit-and-coverage-tests, functional-tests, check-commit-message]
needs: [finish-coverage, functional-tests]
runs-on: ubuntu-latest
steps:

Expand All @@ -212,12 +234,12 @@ jobs:
mkdir -p itowns/dist
mkdir -p itowns/potree/build
mkdir -p itowns/potree/libs
cp -R dist/*.js itowns/dist/
cp -R packages/Main/dist/*.js itowns/dist
cp -R examples itowns/
cp -R buildDocs itowns/docs

# When deploying a release, we copy itowns bundles in dev folder to be published on
# iTowns/itowns.github.io. This is because we can't publish both a release version
# gchoqueux/itowns.github.io. This is because we can't publish both a release version
# (in itowns/ folder) and a @next version (in itowns/dev folder) at the same time.
- name: add dev bundle if release
if: ${{ startsWith(github.event.head_commit.message, 'release v' ) }}
Expand All @@ -231,7 +253,7 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: iTowns/itowns.github.io
external_repository: gchoqueux/itowns.github.io
publish_dir: ./itowns
destination_dir: ./itowns
publish_branch: master
Expand All @@ -241,12 +263,12 @@ jobs:
- name: Deploy Dev to itowns.github.io
# Prevent deploying @next version when a release is done. Doing so would cause an issue,
# since it is not possible to use the same deploy key to simultaneously deploy two different
# folders on iTowns/itowns.github.io (the release bundle on previous step and this one.
# folders on gchoqueux/itowns.github.io (the release bundle on previous step and this one.
if: ${{ !startsWith(github.event.head_commit.message, 'release v' ) }}
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: iTowns/itowns.github.io
external_repository: gchoqueux/itowns.github.io
publish_dir: ./itowns
destination_dir: ./itowns/dev
publish_branch: master
Expand All @@ -257,7 +279,7 @@ jobs:
release:
name: Release GitHub
if: ${{ github.ref == 'refs/heads/master' && startsWith( github.event.head_commit.message, 'release v' ) }}
needs: [unit-and-coverage-tests, functional-tests, check-commit-message]
needs: [finish-coverage, functional-tests]
runs-on: ubuntu-latest
steps:

Expand Down Expand Up @@ -308,7 +330,7 @@ jobs:
# Zip assets into bundle
- name: Zip assets
run: |
zip --junk-paths bundles ./dist/*.js ./dist/*.map
zip --junk-paths bundles ./packages/Main/dist/*.js ./packages/Main/dist/*.map

# Upload release asset
- name: upload release asset
Expand Down
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# See https://help.github.com/articles/ignoring-files/ for how to configure your environment.
# See https://github.com/github/gitignore/tree/master/Global for a list of global ignore rules.

/node_modules/
/dist/
node_modules/
**/dist/
/potree/
potree
/lib/
**/lib/
/docs/out/
coverage
**/coverage
.nyc_output/
/src/ThreeExtended/
**/src/ThreeExtended/
11 changes: 11 additions & 0 deletions CODING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ See the [node website](https://nodejs.org) to install node and npm.
* You can then require `src/Main.js` in your code
* Test and lint changes: see test, lint and test-examples npm script

## Monorepo structure

The project is organized into the following sub-packages. This structuring is in progress.
The roadmap is to divide the `Main` sub-module into independent functionalities.
The final structure is exposed in this (page)[https://github.com/iTowns/itowns/issues/2414].

* `Geographic` (public): The geographic package provides utilities for handling coordinates, ellipsoids, extents and rotations across different coordinate systems;
* `Main` (public): all featues that haven't yet been moved to sub-module;
* `Debug` (private, for the moment): iTowns debugging utilities;
* `Widgets` (private, for the moment): Graphic user interface for iTowns;

## Debugging
* `babel-inline-import-loader` prevents the source map debug in browser. If you
want launch server and debug with the original source map, run : `npm run
Expand Down
14 changes: 12 additions & 2 deletions Gruntfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ module.exports = (grunt) => {
pkg: grunt.file.readJSON('package.json'),
bump: {
options: {
files: ['package.json', 'package-lock.json', 'src/Main.js'],
files: ['package.json', 'package-lock.json', 'packages/Main/src/Main.js',
'packages/Main/package.json',
'packages/Geographic/package.json',
'packages/Widgets/package.json',
'packages/Debug/package.json',
],
updateConfigs: [],
commit: true,
commitMessage: 'release v%VERSION%',
commitFiles: ['package.json', 'package-lock.json', 'src/Main.js'],
commitFiles: ['package.json', 'package-lock.json',
'packages/Main/package.json',
'packages/Geographic/package.json',
'packages/Widgets/package.json',
'packages/Debug/package.json',
],
createTag: false,
tagName: 'v%VERSION%',
tagMessage: 'Release %VERSION%.',
Expand Down
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,48 @@ github release page.

In your project:

To use all iTowns features, install `itowns` package :

```bash
npm install --save itowns
```

```js
import { Coordinates } from 'itowns';

const coordinates = new Coordinates('EPSG:4326', 88., 50.3, 120.3);

// change projection system to pseudo mercator
coordinates.as('EPSG:3857');
```

To import Widget features

```js
import { Navigation } from 'itowns/widgets';

const viewerDiv = document.getElementById('viewerDiv');

// Create a GlobeView
const view = new itowns.GlobeView(viewerDiv);

// Add navigation widget
const navigation = new Navigation(view, {
position: 'bottom-right',
translate: { y: -40 },
});
```

To use only geographic features, install `@itowns/geographic` package :

```bash
npm install --save @itowns/geographic
```

```js
import { Coordinates, Extent, CRS } from '@itowns/geographic';
```

This package contains the ES5-compatible sources of iTowns, up to date with the latest release.

If you're using a module bundler (like wepback), you can directly write
Expand Down
6 changes: 5 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"babelrcRoots": [
"."
".",
"./packages/Geographic",
"./packages/Main",
"./packages/Debug",
"./packages/Widgets"
]
}
3 changes: 3 additions & 0 deletions config/babel-register/babel-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ async function transpile(source, context) {
* the Node.js default resolve hook after the last user-supplied resolve hook
*/
export async function resolve(specifier, context, nextResolve) {
if (specifier == '@itowns/geographic') {
specifier = '@gchoqueux/geographic';
}
// Try to resolve the path of an imported module.
// If the resolver failed, retry substituting the extension with '.ts'.
try {
Expand Down
12 changes: 12 additions & 0 deletions config/concurrently.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import concurrently from 'concurrently';

import fs from 'fs';

const pck = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const script = process.argv[2];

concurrently(pck.workspaces.map(workspace => ({
command: `npm run ${script} -w ${workspace} --if-present`,
name: `${workspace}`,
})));

12 changes: 0 additions & 12 deletions config/prepare.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import chalk from 'chalk';
import copyfiles from 'copyfiles';
// const chalk = require('chalk');
import { execSync } from 'child_process';
import threeExamples from './threeExamples.mjs';



Expand Down Expand Up @@ -33,12 +30,3 @@ const npmVersion = execSync('npm --version', {
if (npmVersion) {
console.log(chalk.green('Npm version :', npmVersion), '\n');
}



// Copy and patch THREE Examples Files
const paths = threeExamples.filesExamples.map(f => f.replace('./', './node_modules/three/examples/jsm/'));

paths.push(threeExamples.patchedPath);

copyfiles(paths, { up: 4 }, () => {});
5 changes: 3 additions & 2 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@
}
},
"source": {
"include": [ "src", "examples/js/plugins" ],
"exclude": [ "src/ThreeExtended" ]
"include": [ "examples/js/plugins", "packages" ],
"exclude": [ "packages/Main/src/ThreeExtended" ],
"excludePattern": "(^|\\/|\\\\)lib"
},
"plugins": ["plugins/markdown"]
}
Loading
Loading