From 0da5aa5a691e263d2587fe0a843282aa27167ffb Mon Sep 17 00:00:00 2001 From: ViktorKukurba Date: Thu, 17 Sep 2020 16:54:45 +0300 Subject: [PATCH] Fix npm submodules creation --- .npmignore | 16 ++++++++++++++++ copy-types.js | 4 +++- package.json | 21 ++++++++------------- rollup.config.js | 16 +++++++++++----- src/examples/test.js | 27 +++++++++++++++++++++++++++ src/utils/helpers.ts | 2 +- 6 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 src/examples/test.js diff --git a/.npmignore b/.npmignore index 9eee4bf..026854b 100644 --- a/.npmignore +++ b/.npmignore @@ -5,3 +5,19 @@ rollup.config.js jest.config.js *.tgz tsconfig.json +./copy-types.js + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* + +/docs +/md-docs diff --git a/copy-types.js b/copy-types.js index f0d9fe0..15dabc3 100644 --- a/copy-types.js +++ b/copy-types.js @@ -1,5 +1,7 @@ const fs = require('fs'); ['array', 'string', 'utils'].forEach(subFolder => { - fs.writeFileSync(`./${subFolder}/index.d.ts`, `export * from './${subFolder}'`) + fs.writeFileSync(`./${subFolder}/index.d.ts`, `export * from './${subFolder}'; + export * from './types';`); + fs.copyFileSync('./src/types.ts', `./${subFolder}/types.ts`) }); diff --git a/package.json b/package.json index 5166769..442a7a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datapipe-js", - "version": "0.3.2", + "version": "0.3.4", "description": "dataPipe is a JavaScript library for data manipulations, data transformations and data wrangling library inspired by LINQ (C#) and Pandas (Python)", "main": "dist/cjs/data-pipe.js", "module": "dist/esm/data-pipe.mjs", @@ -11,29 +11,23 @@ "require": "./dist/cjs/data-pipe.js" }, "./array": { - "import": "./dist/esm/array/index.mjs", - "require": "./dist/cjs/array/index.js" + "import": "./array/index.mjs", + "require": "./array/index.js" }, "./string": { - "import": "./dist/esm/string/index.mjs", + "import": "./string/index.mjs", "require": "./dist/cjs/string/index.js" }, "./utils": { - "import": "./dist/esm/utils/index.mjs", - "require": "./dist/cjs/utils/index.js" + "import": "./utils/index.mjs", + "require": "./utils/index.js" } }, - "files": [ - "utils", - "array", - "string", - "dist" - ], "scripts": { "test": "jest", "test:dev": "jest --watch", "test:dev:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch", - "build": "npx rollup -c && npm run docs", + "build": "npx rollup -c && npm run docs && node copy-types.js", "build:publish": "npm run build && npm publish", "docs": "npx typedoc src --plugin none", "docs:md": "npx typedoc src --out md-docs --plugin typedoc-plugin-markdown", @@ -76,6 +70,7 @@ "jest-fetch-mock": "^2.1.2", "rollup": "^1.31.1", "rollup-plugin-copy": "^3.3.0", + "rollup-plugin-delete": "^2.0.0", "rollup-plugin-livereload": "^1.0.4", "rollup-plugin-serve": "^1.0.1", "rollup-plugin-typescript2": "^0.25.3", diff --git a/rollup.config.js b/rollup.config.js index bee7320..2881c2a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,8 +1,10 @@ import typescript from 'rollup-plugin-typescript2'; import { uglify } from 'rollup-plugin-uglify'; +import del from 'rollup-plugin-delete' const pkg = require('./package.json'); const input = 'src/index.ts'; +const subModules = ['array', 'string', 'utils']; export default [{ input: 'src/commonjs.ts', @@ -11,6 +13,11 @@ export default [{ ], treeshake: true, plugins: [ + del({ + targets: ['./dist', ...subModules.map(m => `./${m}`)], + hook: 'buildStart', + runOnce: true + }), typescript({ clean: true }), @@ -34,19 +41,18 @@ export default [{ clean: true }) ] -}, ...['array', 'string', 'utils'].map(subFolder => ({ +}, ...subModules.map(subFolder => ({ input: `src/${subFolder}/index.ts`, - output: { file: `dist/esm/${subFolder}/index.mjs`, format: 'esm', sourcemap: true, compact: true }, + output: { file: `${subFolder}/index.mjs`, format: 'esm', sourcemap: true, compact: true }, treeshake: true, plugins: [ typescript({ clean: true }) ], -})), -...['array', 'string', 'utils'].map(subFolder => ({ +})), ...subModules.map(subFolder => ({ input: `src/${subFolder}/index.ts`, - output: { file: `dist/cjs/${subFolder}/index.js`, format: 'cjs', sourcemap: true, compact: true }, + output: { file: `${subFolder}/index.js`, format: 'cjs', sourcemap: true, compact: true }, treeshake: true, plugins: [ typescript({ diff --git a/src/examples/test.js b/src/examples/test.js new file mode 100644 index 0000000..59f84a6 --- /dev/null +++ b/src/examples/test.js @@ -0,0 +1,27 @@ +const { dataPipe } = require('datapipe-js'); +const { avg } = require('datapipe-js/array'); +const fetch = require('node-fetch'); + +async function main() { + + const dataUrl = "https://raw.githubusercontent.com/FalconSoft/sample-data/master/CSV/sample-testing-data-100.csv"; + const csv = await (await fetch(dataUrl)).text(); + + return dataPipe() + .fromCsv(csv) + .groupBy(r => r.Country) + .select(g => ({ + country: dataPipe(g).first().Country, + sales: dataPipe(g).sum(i => i.Sales), + avg: avg(g, i => i.Sales), + count: g.length + }) + ) + .where(r => r.sales > 5000) + .sort("sales DESC") + .toArray(); +} + +main() + .then(console.log) + .catch(console.error) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index f23428e..bd672e1 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -298,4 +298,4 @@ export function getFieldDescriptions(items: Record[]): Field } return Object.values(resultMap); -} \ No newline at end of file +}