diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 791ed55aa..455b9abfb 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -15,9 +15,8 @@ jobs: registry-url: https://registry.npmjs.org/ - run: yarn install --frozen-lockfile --ignore-scripts - run: yarn build - - run: cp -rf dist/index.cjs.js src - - run: cp -rf dist/index.esm.js src - - run: cp -rf package.json src - - run: cd src && npm publish --access public + - run: cp -rf package.json dist + - run: cp -rf src/types.json dist + - run: cd dist && npm publish --access public env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/package.json b/package.json index 7433dfc3f..ae5be2c86 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "@docknetwork/sdk", - "version": "0.0.4", - "main": "index.cjs.js", - "module": "index.esm.js", + "version": "0.0.5", + "main": "index.js", + "module": "index.mjs", "license": "MIT", "type": "module", "repository": { @@ -23,6 +23,7 @@ "eslint-plugin-import": "^2.20.2", "eslint-plugin-jest": "^23.8.2", "ethr-did-resolver": "^2.2.0", + "glob": "^7.1.6", "jest": "24.5.0", "jsdoc": "^3.6.3", "rollup": "1.7.0", diff --git a/rollup.config.js b/rollup.config.js index 8a7212c01..a19e2acae 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,35 +1,46 @@ -// import resolve from 'rollup-plugin-node-resolve'; -// import commonjs from 'rollup-plugin-commonjs'; -// import babel from 'rollup-plugin-babel'; import json from 'rollup-plugin-json'; import pkg from './package.json'; +import glob from 'glob'; +export default async function() { + const input = {}; -export default [ - // { - // input: 'src/umd.js', - // output: { - // name: 'index', - // file: pkg.browser, - // format: 'umd', - // }, - // plugins: [ - // resolve(), - // commonjs(), - // babel({ - // exclude: 'node_modules/**', - // }), - // ], - // }, - { + await new Promise((resolve, reject) => { + const dir = 'src'; + glob(dir + '/**/*.js', null, (er, files) => { + if (!er && files) { + for (let i = 0; i < files.length; i++) { + const fileName = files[i].substr(dir.length + 1); + if (fileName.substr(fileName.length - 3) === '.js') { + let id = fileName.substr(0, fileName.length - 3); + if (id === 'api') { + id = 'index'; + } + input[id] = files[i]; + } + } + console.log('input', input); + resolve(files); + } else { + throw new Error('Unable to list src files!'); + } + }); + }); + + return [{ plugins: [ json(), ], - input: 'src/api.js', - external: [], - output: [ - { file: 'dist/' + pkg.main, format: 'cjs' }, - { file: 'dist/' + pkg.module, format: 'es' }, - ], - }, -]; + input, + output: [{ + dir: 'dist', + format: 'esm', + entryFileNames: '[name].mjs' + }, + { + dir: 'dist', + format: 'cjs' + } + ] + }]; +};