diff --git a/.travis.yml b/.travis.yml index ac31b01a0..ab312037b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ language: node_js node_js: 10 script: -- npm run-script build -- npm test -- npm run-script check-format +- make lint build test check-format diff --git a/Gruntfile.js b/Gruntfile.js index daf5f8174..d56e77379 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -32,9 +32,9 @@ module.exports = function(grunt){ options: { banner: banner_full, process: true, - }, + }, pzpr: { - options: { + options:{ sourceMap: !PRODUCTION }, files: [ @@ -56,16 +56,6 @@ module.exports = function(grunt){ banner: banner_min, report: 'min' }, - pzpr:{ - options: (PRODUCTION ? {} : { - sourceMap : 'dist/js/pzpr.js.map', - sourceMapIn : 'dist/js/pzpr.concat.js.map', - sourceMapIncludeSources : true - }), - files: [ - { src: 'dist/js/pzpr.concat.js', dest: 'dist/js/pzpr.js'} - ] - }, variety:{ options: (PRODUCTION ? {} : { sourceMap : function(filename){ return filename+'.map';} @@ -96,10 +86,7 @@ module.exports = function(grunt){ } }); - grunt.registerTask('default', ['build']); - grunt.registerTask('release', ['build']); - grunt.registerTask('build', ['build:pzpr', 'build:variety', 'build:samples', 'build:ui']); - grunt.registerTask('build:pzpr', ['newer:concat:pzpr', 'newer:uglify:pzpr']); + grunt.registerTask('build', ['build:variety', 'build:samples', 'build:ui']); grunt.registerTask('build:ui', ['newer:copy:ui', 'newer:concat:ui', 'newer:uglify:ui']); grunt.registerTask('build:variety',['newer:uglify:variety']); grunt.registerTask('build:samples',['newer:uglify:samples']); diff --git a/Makefile b/Makefile index ea3c750c3..9ef07d398 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,31 @@ -.PHONY: build test serve format +.PHONY: default build test serve serve-all format check-format lint bundle rollup git-hash clean -build: - npm run-script build +default: build -test: - npm test +clean: + rm -rf ./dist/ + rm -f git.json + +build: rollup git-hash + npx grunt build + +git-hash: + ./git-hash.sh + +bundle: git-hash + npx grunt concat:pzpr + +rollup: bundle + mkdir -p ./dist/js/ + cp ./node_modules/pzpr-canvas/dist/candle.js ./dist/js/candle.js + npx rollup -c ./rollup.config.js + +test: bundle + npx grunt build:variety + npx mocha -r esm -r pzpr-canvas -r source-map-support/register -R progress --recursive test + +lint: + npx eslint --quiet src src-ui test sample serve: cd dist && python3 -m http.server -b localhost @@ -13,4 +34,7 @@ serve-all: cd dist && python3 -m http.server format: - npm run-script format + npx prettier --write "{src,src-ui,test}/**/*.{js,json,css}" + +check-format: + npx prettier --check "{src,src-ui,test}/**/*.{js,json,css}" diff --git a/index.js b/index.js index fdf94cc63..62223b47a 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,3 @@ -module.exports = require('./dist/js/pzpr.js'); +import pzpr from './dist/js/pzpr.concat.js'; +export default pzpr; diff --git a/package.json b/package.json index bbaa3a9d5..e6150ad97 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,6 @@ "version": "0.12.0", "description": "Scripts for handling puzzle objects", "main": "./index.js", - "directories": { - "test": "test" - }, "keywords": [ "puzzle", "HTML5" @@ -14,35 +11,24 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/sabo2/pzprjs" - }, - "homepage": "https://github.com/sabo2/pzprjs", - "engines": { - "node": ">= 5.6.0" - }, - "scripts": { - "build": "eslint --cache --quiet src src-ui && \"./git-hash.sh\" && grunt default", - "release": "npm run clean && eslint --cache --quiet src && grunt release", - "clean": "del dist/* pzpr-*.{zip,tar.gz,tar.bz2,tgz}", - "format": "prettier --write \"{src,src-ui,test}/**/*.{js,css}\"", - "check-format": "prettier --check \"{src,src-ui,test}/**/*.{js,css}\"", - "lint": "eslint src src-ui test sample", - "test": "eslint --quiet src src-ui test sample && mocha -r source-map-support/register -R progress --recursive test", - "prepublishOnly": "npm test" + "url": "https://github.com/robx/pzprjs" }, + "homepage": "https://puzz.link", "devDependencies": { - "del-cli": "^2.0.0", "eslint": "^5.16.0", + "esm": "^3.2.25", "grunt": "^1.1.0", "grunt-contrib-concat": "^1.0.1", "grunt-contrib-copy": "^1.0.0", "grunt-contrib-uglify": "^2.0.0", "grunt-newer": "^1.1.1", "mocha": "^6.2.3", - "prettier": "^1.19.1" + "prettier": "^1.19.1", + "rollup": "^2.8.0", + "rollup-plugin-terser": "^5.3.0" }, "dependencies": { "pzpr-canvas": "^0.8.2", - "source-map-support": "^0.5.17" + "source-map-support": "^0.5.19" } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 000000000..f371a0ae1 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,22 @@ +import { terser } from 'rollup-plugin-terser'; + +// `npm run build` -> `production` is true +// `npm run dev` -> `production` is false +const production = !process.env.ROLLUP_WATCH; + +export default { + input: 'dist/js/pzpr.concat.js', + output: { + file: 'dist/js/pzpr.js', + name: 'pzpr', + format: 'iife', + sourcemap: true, + globals: { + "pzpr-canvas": "Candle" + } + }, + context: "window", + plugins: [ + production && terser() // minify, but only in production + ] +}; diff --git a/src-ui/list.html b/src-ui/list.html index ca78aaacb..9f0cef969 100644 --- a/src-ui/list.html +++ b/src-ui/list.html @@ -5,6 +5,7 @@ puzz.link list of puzzle types + diff --git a/src-ui/p.html b/src-ui/p.html index ca2e350b8..0a7a06efa 100644 --- a/src-ui/p.html +++ b/src-ui/p.html @@ -11,6 +11,7 @@ + puzz.link player diff --git a/src-ui/rules.html b/src-ui/rules.html index f10b430a1..ea91443bc 100644 --- a/src-ui/rules.html +++ b/src-ui/rules.html @@ -39,6 +39,7 @@ } +