Skip to content

Commit

Permalink
merge (release)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Aug 8, 2023
1 parent f5ec1b5 commit b8e1411
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ jobs:
with:
token: ${{ secrets.GIT_TOKEN }}

- name: Determine Alpha, Beta or Release
- name: Build OpenCV
id: build_open_cv
run: |
mkdir build
cd build
# https://docs.opencv.org/3.4/d4/da1/tutorial_js_setup.html
git clone https://github.com/opencv/opencv.git
cd opencv
cd opencv
sed -i "s/white_list = makeWhiteList(\[core, imgproc, objdetect, video, dnn, features2d, photo, calib3d\])/white_list = makeWhiteList([core, imgproc, video, features2d])/g" ./platforms/js/opencv_js.config.py
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:2.0.10 emcmake python3 ./platforms/js/build_js.py build_js
- name: Copy OpenCV
id: copy_open_cv
run: |
cp -f ./build/opencv/build_js/bin/opencv.js ./public/
- name: Determine Alpha, Beta or Release
id: which_tag
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ Online Storybook Demo: https://wonderful-forest-0a9f5b103.3.azurestaticapps.net/

```bash
npm install @axa-fr/slight-capture --save

# To install in your public folder a light version of opencv.js
node ./node_modules/@axa-fr/react-oidc/bin/copy-opencv.mjs public
```


WARNING : To keep opencv.js up to date. You may setup a postinstall script in your package.json file to update it at each npm install. For example :
```sh
"scripts": {
...
"postinstall": "node ./node_modules/@axa-fr/react-oidc/bin/copy-opencv.mjs public"
},
```


The sample bellow use react, but the library work with vanilla JS with any framework of your choice.

```javascript
Expand Down
57 changes: 57 additions & 0 deletions bin/copy-opencv.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';

try {

/**
* Script to run after npm install
*
* Copy selected files to user's directory
*/
const script_prefix= 'oidc-client';

const copyFile = async (src, dest, overwrite) => {
if(!fileExists(src)) {
console.log(`[${script_prefix}:skip] file does not exist ${src}`);
return false;
}
if (!overwrite) {
if (fileExists(dest)) {
console.log(`[${script_prefix}:skip] file exists not overwriting ${dest}`);
return true;
}
}
await fs.promises.copyFile(src, dest);
console.log(`[${script_prefix}:copy] ${dest}`);
return false
};

const fileExists = (path) => {
return !!fs.existsSync(path);
};

const initPath = process.cwd();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const srcDir = path.join(__dirname, "public");
const destinationFolder = process.argv.length >= 3 ? process.argv[2] : 'public';
const destinationDir = path.join(initPath, destinationFolder);

const files = [
{
fileName: 'opencv.js',
overwrite: true,
},
];

for await (const file of files) {
await copyFile(
path.join(srcDir, file.fileName),
path.join(destinationDir, file.fileName),
file.overwrite
);
}

} catch (err) {
console.warn(err);
}

0 comments on commit b8e1411

Please sign in to comment.