From aa596576c9d82d2efa535ccd3f6f4b92c8d0b21f Mon Sep 17 00:00:00 2001 From: Jeremy Shipman Date: Fri, 24 Jul 2020 21:49:01 +1200 Subject: [PATCH 01/24] Converted code to typescript, test runner to testem --- .gitignore | 6 +- .nycrc.json | 8 + TODO.md | 13 + karma.conf.js | 94 --- package.json | 64 +- {demo => public}/daisy.png | Bin {demo => public}/easeljs.js | 0 {demo => public}/flower.svg | 0 index.html => public/index.html | 6 +- {demo => public}/spectre.min.css | 0 rollup.config.js | 7 + demo/demo.js => src/demo/index.ts | 18 +- src/freetransform/helpers.ts | 58 ++ .../freetransform/index.ts | 635 ++++++++---------- src/types/createjs.d.ts | 12 + testem-client-hook.js | 12 + testem-coverage-server.js | 84 +++ testem.js | 43 ++ testem.mustache | 29 + .../createjs.text-fix.ts | 1 + ...ormTool-test.js => freetransform-tests.ts} | 8 +- tests/index.ts | 2 + tests/jasmine-pixelmatch.d.ts | 15 + tests/pixelmatch-helpers-test.js | 16 - tests/pixelmatch-helpers.js | 154 ----- tests/setup-helpers.js | 24 - tests/{easel-text-test.js => text-tests.ts} | 4 + tsconfig.json | 24 + 28 files changed, 676 insertions(+), 661 deletions(-) create mode 100644 .nycrc.json delete mode 100644 karma.conf.js rename {demo => public}/daisy.png (100%) rename {demo => public}/easeljs.js (100%) rename {demo => public}/flower.svg (100%) rename index.html => public/index.html (87%) rename {demo => public}/spectre.min.css (100%) create mode 100644 rollup.config.js rename demo/demo.js => src/demo/index.ts (93%) create mode 100644 src/freetransform/helpers.ts rename createjs.util.FreeTransformTool.js => src/freetransform/index.ts (60%) create mode 100644 src/types/createjs.d.ts create mode 100644 testem-client-hook.js create mode 100644 testem-coverage-server.js create mode 100644 testem.js create mode 100644 testem.mustache rename createjs.text-fix.js => tests/createjs.text-fix.ts (95%) rename tests/{create.js.util.FreeTransformTool-test.js => freetransform-tests.ts} (90%) create mode 100644 tests/index.ts create mode 100644 tests/jasmine-pixelmatch.d.ts delete mode 100644 tests/pixelmatch-helpers-test.js delete mode 100644 tests/pixelmatch-helpers.js delete mode 100644 tests/setup-helpers.js rename tests/{easel-text-test.js => text-tests.ts} (92%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 688baed..50c968b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ node_modules package-lock.json -research \ No newline at end of file +research +/dist +/tmp +/coverage +/docs \ No newline at end of file diff --git a/.nycrc.json b/.nycrc.json new file mode 100644 index 0000000..31dd491 --- /dev/null +++ b/.nycrc.json @@ -0,0 +1,8 @@ +{ + "cache": false, + "compact": false, + "reporter": ["text", "lcov"], + "excludeAfterRemap": false, + "all": true, + "temp-dir": "tmp" +} diff --git a/TODO.md b/TODO.md index 60d503f..7ecb2a0 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,20 @@ # TODO +Convert to Typescript? + Update border, and constrain elements +## Transforming withing a container + +It is useful to support transforming elements within a container. +Use case: design area has been resized/zoomed. + +Currently the coordinate systems are out, and the boundary mechanism fails too. + +Come up with a design / plan... + +We might need to introduce functions for transforming through parent layers. + ## Build test infrastructure - Build out test suite diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 2bbd2bd..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,94 +0,0 @@ -// eslint env node - -// Karma configuration -// Generated on Wed Dec 11 2019 07:30:25 GMT+1300 (NZDT) - -module.exports = function(config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: "", - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ["jasmine"], - - // list of files / patterns to load in the browser - files: [ - { - pattern: "tests/images/*.*", - watched: false, - included: false, - served: true, - nocache: false - }, - "module-shim.js", - "node_modules/pixelmatch/index.js", - "demo/easeljs.js", - "createjs.text-fix.js", - "node_modules/txtjs/dist/txt.js", - "createjs.util.FreeTransformTool.js", - "tests/*.js" - ], - - proxies: { - "/img/": "/base/tests/images/" - }, - - // list of files / patterns to exclude - exclude: [], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: {}, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ["progress"], - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, - - browsers: ["ChromeWithoutGPU", "FirefoxWithoutGPU"], - - // disable gpu to stay consistent with headless renders - customLaunchers: { - ChromeWithoutGPU: { - base: "Chrome", - flags: ["--disable-gpu"] - }, - ChromeHeadlessWithoutGPU: { - base: "ChromeHeadless", - flags: ["--disable-gpu"] - }, - FirefoxWithoutGPU: { - base: "Firefox", - prefs: { - "webgl.disabled": true - } - } - }, - - client: { - clearContext: false - }, - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity - }); -}; diff --git a/package.json b/package.json index 297e60c..baaccab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "createjs-free-transform-tool", - "version": "1.0.0", + "version": "1.1.0", "description": "Provides ability to free transform CreateJS Display Objects", "keywords": [ "canvas", @@ -20,31 +20,53 @@ "license": "MIT", "author": "Jeremy Shipman", "files": [ - "createjs.util.FreeTransformTool.js" + "dist/createjs.util.FreeTransformTool.js" ], - "browser": "createjs.util.FreeTransformTool.js", + "browser": "dist/createjs.util.FreeTransformTool.js", "scripts": { - "start": "http-server .", - "lint": "eslint ./*FreeTransformTool.js", - "test": "npm run lint && npm run test:ci", - "test:ci": "karma start --browsers=ChromeHeadlessWithoutGPU,FirefoxHeadless --single-run", - "test:server": "karma start --reporters=kjhtml" + "start": "run-s dev", + "dev": "run-p dev:server dev:watch", + "dev:server": "live-server --ignore=node_modules dist", + "dev:watch": "onchange src/* -- npm run build", + "build": "mkdir -p tmp && run-s build:compile bundle:umd copy", + "copy": "copyfiles -f public/* dist/", + "build:compile": "tsc --project .", + "bundle:umd": "run-s bundle:lib:umd bundle:demo:umd bundle:tests:umd", + "bundle:lib:umd": "rollup -c -f umd dist/esnext/src/freetransform/index.js --name=createjs.util.FreeTransformTool --file=dist/createjs.util.FreeTransformTool.js --sourcemap", + "bundle:lib:cov:umd": "rollup -c -f umd dist/instrumented/index.js --name=createjs.util.FreeTransformTool --file=dist/createjs.util.FreeTransformTool.instrumented.js --sourcemap", + "bundle:demo:umd": "rollup -c -f umd dist/esnext/src/demo/index.js --globals freetransform:createjs.util.FreeTransformTool --file=dist/demo.umd.js --sourcemap", + "bundle:tests:umd": "rollup -c -f umd dist/esnext/tests/index.js --globals freetransform:createjs.util.FreeTransformTool --file=dist/tests.umd.js --sourcemap", + "test": "run-s cov:instrument bundle:lib:cov:umd test:ci", + "test:ci": "testem ci .", + "test:server": "testem server .", + "cov:instrument": "mkdir -p tmp && nyc instrument dist/esnext/src/freetransform dist/instrumented", + "cov:view": "nyc report && live-server coverage/lcov-report", + "docs:build": "typedoc --tsconfig src", + "docs:view": "live-server docs", + "clean": "rm -Rf dist docs coverage tmp" }, "devDependencies": { - "@types/createjs": "0.0.29", - "@types/pixelmatch": "^5.0.0", - "eslint": "^6.7.2", - "eslint-config-prettier": "^6.7.0", - "eslint-plugin-jasmine": "^4.1.0", - "eslint-plugin-prettier": "^3.1.1", - "http-server": "^0.11.1", + "@recreatejs/jasmine-pixelmatch": "^0.1.0", + "@rollup/plugin-commonjs": "^14.0.0", + "@rollup/plugin-node-resolve": "^8.4.0", + "@types/easeljs": "^1.0.0", + "@types/jasmine": "^3.5.11", + "@typescript-eslint/eslint-plugin": "^3.5.0", + "@typescript-eslint/parser": "^3.5.0", + "copyfiles": "^2.3.0", + "eslint": "^7.3.1", "jasmine-core": "^3.5.0", - "karma": "^4.4.1", - "karma-chrome-launcher": "^3.1.0", - "karma-firefox-launcher": "^1.2.0", - "karma-jasmine": "^2.0.1", - "karma-jasmine-html-reporter": "^1.4.2", + "live-server": "^1.2.1", + "npm-run-all": "^4.1.5", + "nyc": "^15.1.0", + "onchange": "^7.0.2", "pixelmatch": "^5.1.0", - "prettier": "^1.19.1" + "prettier": "^2.0.5", + "rollup": "^2.18.1", + "rollup-plugin-sourcemaps": "^0.6.2", + "testem": "^3.2.0", + "tslib": "^2.0.0", + "typedoc": "^0.17.8", + "typescript": "^3.9.5" } } diff --git a/demo/daisy.png b/public/daisy.png similarity index 100% rename from demo/daisy.png rename to public/daisy.png diff --git a/demo/easeljs.js b/public/easeljs.js similarity index 100% rename from demo/easeljs.js rename to public/easeljs.js diff --git a/demo/flower.svg b/public/flower.svg similarity index 100% rename from demo/flower.svg rename to public/flower.svg diff --git a/index.html b/public/index.html similarity index 87% rename from index.html rename to public/index.html index 070c3eb..67b4afd 100644 --- a/index.html +++ b/public/index.html @@ -3,7 +3,7 @@ Create.js Free Transform Tool - +