Skip to content

Commit

Permalink
Fix npm submodules creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorKukurba committed Sep 17, 2020
1 parent a3398a0 commit 0da5aa5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 20 deletions.
16 changes: 16 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion copy-types.js
Original file line number Diff line number Diff line change
@@ -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`)
});
21 changes: 8 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 11 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -11,6 +13,11 @@ export default [{
],
treeshake: true,
plugins: [
del({
targets: ['./dist', ...subModules.map(m => `./${m}`)],
hook: 'buildStart',
runOnce: true
}),
typescript({
clean: true
}),
Expand All @@ -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({
Expand Down
27 changes: 27 additions & 0 deletions src/examples/test.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,4 @@ export function getFieldDescriptions(items: Record<string, ScalarType>[]): Field
}

return Object.values(resultMap);
}
}

0 comments on commit 0da5aa5

Please sign in to comment.