Skip to content

Commit 2bf8ead

Browse files
author
Kevin Scott
authored
Merge pull request #2 from thekevinscott/rollup
Set up a rollup pipeline
2 parents 39f1a82 + 449a38f commit 2bf8ead

File tree

7 files changed

+98
-41
lines changed

7 files changed

+98
-41
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ tslint.json
77
yarn.lock
88
rollup.config.js
99
config
10+
tests

__tests__/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import MLClassifier from '../dist/index';
2+
3+
describe('Integration test', () => {
4+
test('that it initializes', () => {
5+
const mlClassifier = new MLClassifier();
6+
expect(mlClassifier).toBeDefined();
7+
});
8+
9+
test('that it demands images', () => {
10+
const mlClassifier = new MLClassifier();
11+
return mlClassifier.addData().catch(err => {
12+
expect(err.message).toEqual('You must supply images');
13+
});
14+
});
15+
16+
test('that it demands labels', () => {
17+
const mlClassifier = new MLClassifier();
18+
return mlClassifier.addData([]).catch(err => {
19+
expect(err.message).toEqual('You must supply labels');
20+
});
21+
});
22+
});

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "ml-classifier",
3-
"version": "0.2.4",
3+
"version": "0.3.0",
44
"description": "A machine learning engine for quickly training image classification models in your browser",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
77
"repository": "https://github.com/thekevinscott/ml-classifier",
88
"scripts": {
99
"clean": "rimraf dist/*",
1010
"watch": "npm run build -- --watch",
11-
"build": "npm run clean && tsc --project tsconfig.json",
11+
"make": "npm run clean && rollup -c",
1212
"prepublish": "npm run build",
1313
"test": "jest"
1414
},
@@ -19,6 +19,7 @@
1919
"license": "MIT",
2020
"jest": {
2121
"testMatch": [
22+
"<rootDir>__tests__/**/*.(j|t)s?(x)",
2223
"<rootDir>/src/**/__tests__/**/*.(j|t)s?(x)",
2324
"<rootDir>/src/**/?(*.)(spec|test).(j|t)s?(x)"
2425
],
@@ -56,12 +57,13 @@
5657
"jest": "22.4.2",
5758
"regenerator-runtime": "^0.12.0",
5859
"rimraf": "^2.6.2",
60+
"rollup": "^0.62.0",
61+
"rollup-plugin-typescript2": "^0.15.1",
5962
"ts-jest": "22.0.1",
6063
"ts-loader": "^2.3.7",
6164
"tslint": "^5.7.0",
6265
"tslint-config-prettier": "^1.10.0",
6366
"typescript": "^2.9.2"
6467
},
65-
"dependencies": {
66-
}
68+
"dependencies": {}
6769
}

rollup.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rollup.config.js
2+
import typescript from 'rollup-plugin-typescript2';
3+
4+
export default {
5+
entry: './src/index.ts',
6+
output: {
7+
name: 'MLClassifier',
8+
file: './dist/index.js',
9+
format: 'umd',
10+
},
11+
plugins: [
12+
typescript({
13+
}),
14+
],
15+
};
16+

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ class MLClassifier {
7272
public getModel = () => this.model;
7373

7474
public addData = async (images: tf.Tensor3D[], labels: string[], dataType: DataType = DataType.TRAIN) => {
75+
if (!images) {
76+
throw new Error('You must supply images');
77+
}
78+
if (!labels) {
79+
throw new Error('You must supply labels');
80+
}
7581
if (dataType === DataType.TRAIN || dataType === DataType.EVAL) {
76-
if (!labels) {
77-
throw new Error(`You must provide labels when supplying ${dataType} data`);
78-
}
79-
8082
const activatedImages = await Promise.all(images.map(async (image: tf.Tensor3D, idx: number) => {
8183
return await this.cropAndActivateImage(image);
8284
}));

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
"module": "esnext",
66
"target": "es5",
77
"lib": ["esnext", "dom"],
8-
98
"sourceMap": true,
109
"allowJs": false,
11-
"declaration": true,
12-
"jsx": "react",
10+
"declaration": false,
1311
"moduleResolution": "node",
1412
"rootDir": "src",
1513
"forceConsistentCasingInFileNames": true,

yarn.lock

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,6 @@
836836
version "0.6.7"
837837
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-0.6.7.tgz#aa4f994c4104a8cf3f93b5e13ab051685c092c80"
838838

839-
"@tensorflow/tfjs-node@^0.1.7":
840-
version "0.1.7"
841-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-node/-/tfjs-node-0.1.7.tgz#76b827c32504efed9cbd9b1b1394e4ec53e45fe5"
842-
dependencies:
843-
bindings "~1.3.0"
844-
845839
"@tensorflow/tfjs@^0.11.7":
846840
version "0.11.7"
847841
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-0.11.7.tgz#5b5fe7b17bca2d2088fdd01aea0660517364b752"
@@ -850,6 +844,10 @@
850844
"@tensorflow/tfjs-core" "0.11.9"
851845
"@tensorflow/tfjs-layers" "0.6.7"
852846

847+
848+
version "0.0.39"
849+
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
850+
853851
"@types/jest@^23.1.1":
854852
version "23.1.3"
855853
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.3.tgz#4db19b2e7627dc254bbed5781b5609c621b5ad8e"
@@ -858,6 +856,10 @@
858856
version "3.0.32"
859857
resolved "https://registry.yarnpkg.com/@types/long/-/long-3.0.32.tgz#f4e5af31e9e9b196d8e5fca8a5e2e20aa3d60b69"
860858

859+
"@types/node@*":
860+
version "10.5.2"
861+
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.2.tgz#f19f05314d5421fe37e74153254201a7bf00a707"
862+
861863
"@types/node@^10.3.4":
862864
version "10.5.1"
863865
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.1.tgz#d578446f4abff5c0b49ade9b4e5274f6badaadfc"
@@ -1317,10 +1319,6 @@ binary-extensions@^1.0.0:
13171319
version "1.11.0"
13181320
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205"
13191321

1320-
bindings@~1.3.0:
1321-
version "1.3.0"
1322-
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"
1323-
13241322
brace-expansion@^1.1.7:
13251323
version "1.1.11"
13261324
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -1786,6 +1784,10 @@ estraverse@^4.2.0:
17861784
version "4.2.0"
17871785
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"
17881786

1787+
estree-walker@^0.5.2:
1788+
version "0.5.2"
1789+
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39"
1790+
17891791
esutils@^2.0.2:
17901792
version "2.0.2"
17911793
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
@@ -1996,6 +1998,14 @@ [email protected]:
19961998
jsonfile "^4.0.0"
19971999
universalify "^0.1.0"
19982000

2001+
fs-extra@^5.0.0:
2002+
version "5.0.0"
2003+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
2004+
dependencies:
2005+
graceful-fs "^4.1.2"
2006+
jsonfile "^4.0.0"
2007+
universalify "^0.1.0"
2008+
19992009
fs-minipass@^1.2.5:
20002010
version "1.2.5"
20012011
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d"
@@ -2094,13 +2104,6 @@ growly@^1.3.0:
20942104
version "1.3.0"
20952105
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
20962106

2097-
haikunator@^2.0.0:
2098-
version "2.0.0"
2099-
resolved "https://registry.yarnpkg.com/haikunator/-/haikunator-2.0.0.tgz#db740d7eff50e2e9c2f030ad15b195b4a6cbec3c"
2100-
dependencies:
2101-
lodash.defaults "^4.2.0"
2102-
random-seed "^0.3.0"
2103-
21042107
handlebars@^4.0.3:
21052108
version "4.0.11"
21062109
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc"
@@ -2861,7 +2864,7 @@ json-stable-stringify@^1.0.1:
28612864
dependencies:
28622865
jsonify "~0.0.0"
28632866

2864-
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
2867+
json-stringify-safe@~5.0.1:
28652868
version "5.0.1"
28662869
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
28672870

@@ -2958,10 +2961,6 @@ locate-path@^2.0.0:
29582961
p-locate "^2.0.0"
29592962
path-exists "^3.0.0"
29602963

2961-
lodash.defaults@^4.2.0:
2962-
version "4.2.0"
2963-
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
2964-
29652964
lodash.sortby@^4.7.0:
29662965
version "4.7.0"
29672966
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
@@ -3519,12 +3518,6 @@ [email protected]:
35193518
version "0.2.0"
35203519
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
35213520

3522-
random-seed@^0.3.0:
3523-
version "0.3.0"
3524-
resolved "https://registry.yarnpkg.com/random-seed/-/random-seed-0.3.0.tgz#d945f2e1f38f49e8d58913431b8bf6bb937556cd"
3525-
dependencies:
3526-
json-stringify-safe "^5.0.1"
3527-
35283521
randomatic@^3.0.0:
35293522
version "3.0.0"
35303523
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.0.0.tgz#d35490030eb4f7578de292ce6dfb04a91a128923"
@@ -3729,7 +3722,7 @@ [email protected]:
37293722
version "1.1.7"
37303723
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
37313724

3732-
resolve@^1.1.7, resolve@^1.3.2:
3725+
resolve@^1.1.7, resolve@^1.3.2, resolve@^1.8.1:
37333726
version "1.8.1"
37343727
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
37353728
dependencies:
@@ -3751,6 +3744,29 @@ rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2:
37513744
dependencies:
37523745
glob "^7.0.5"
37533746

3747+
"rollup-plugin-typescript2@https://github.com/ezolenko/rollup-plugin-typescript2":
3748+
version "0.16.0"
3749+
resolved "https://github.com/ezolenko/rollup-plugin-typescript2#f0e466c89f288f5b7434a513370201ef9da56aff"
3750+
dependencies:
3751+
fs-extra "^5.0.0"
3752+
resolve "^1.8.1"
3753+
rollup-pluginutils "^2.3.0"
3754+
tslib "1.9.3"
3755+
3756+
rollup-pluginutils@^2.3.0:
3757+
version "2.3.0"
3758+
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.3.0.tgz#478ace04bd7f6da2e724356ca798214884738fc4"
3759+
dependencies:
3760+
estree-walker "^0.5.2"
3761+
micromatch "^2.3.11"
3762+
3763+
rollup@^0.62.0:
3764+
version "0.62.0"
3765+
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.62.0.tgz#4ca8b3c9582195dc9341ff8a1375f58319b95bfc"
3766+
dependencies:
3767+
"@types/estree" "0.0.39"
3768+
"@types/node" "*"
3769+
37543770
rsvp@^3.3.3:
37553771
version "3.6.2"
37563772
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.6.2.tgz#2e96491599a96cde1b515d5674a8f7a91452926a"
@@ -4178,7 +4194,7 @@ ts-loader@^2.3.7:
41784194
loader-utils "^1.0.2"
41794195
semver "^5.0.1"
41804196

4181-
tslib@^1.8.0, tslib@^1.8.1:
4197+
tslib@1.9.3, tslib@^1.8.0, tslib@^1.8.1:
41824198
version "1.9.3"
41834199
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
41844200

0 commit comments

Comments
 (0)