Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start of ES6 modules: move to rollup #183

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
02bca34
update travis npm to something more recent
alicebob Apr 18, 2020
5a51d4a
restructure build process to use `rollup`
alicebob Apr 18, 2020
a91ebd2
fix lint and remove unused files
alicebob Apr 18, 2020
1a183a3
fix read-only-object errors
alicebob Apr 18, 2020
da17a11
update all tests to use `import`s
alicebob Apr 18, 2020
5ab22fd
load stand-alone candle.js file
alicebob Apr 18, 2020
38c2637
fix githash variable in the final .js file
alicebob Apr 18, 2020
2428e8c
travis: build before test
alicebob Apr 18, 2020
d3f688a
run prettier
alicebob Apr 18, 2020
1e68e0e
Merge remote-tracking branch 'origin/master' into reimport
alicebob Apr 25, 2020
b8d87b4
more clear install target
alicebob Apr 25, 2020
3a5601f
use variable for files we bundle
alicebob Apr 25, 2020
e68fe02
move format checks to the Makefile
alicebob Apr 25, 2020
96df19d
add .json files to the format checks, and prettify them
alicebob Apr 25, 2020
e15d00c
restore Grunt bundling target
robx Apr 28, 2020
3c68511
skip frozen checks
robx Apr 28, 2020
4d9ea3a
checkLineShape: test whether cell isnull, not is null
robx Apr 28, 2020
8189d2f
kinkonkan: corner excells are "isnull", they don't have coordinates
robx Apr 28, 2020
da65ab1
fix sed
robx May 6, 2020
a893dc5
dependency bump
robx May 6, 2020
b790892
use grunt concat target
robx May 6, 2020
f4a992e
change default target
robx May 6, 2020
6f61769
move more logic from Gruntfile to Makefile
robx May 6, 2020
64b5740
remove some stale package.json fields
robx May 6, 2020
f296cba
remove index.js
robx May 6, 2020
de8b52b
Merge branch 'master' into reimport
robx May 6, 2020
2d040e8
tawa: don't set error on out-of-board neighbours
robx May 6, 2020
8e2a468
remove another frozen check
robx May 6, 2020
5f9d9a9
fmt
robx May 6, 2020
a01fadf
remove npm-install makefile target
robx May 6, 2020
88b5026
Revert "remove index.js"
robx May 6, 2020
3bd5a16
or maybe try exporting the concat version (this is for pzprnode)
robx May 6, 2020
93ba59f
fancy module
alicebob May 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 1 addition & 20 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ module.exports = function(grunt){
banner: banner_full,
process: true,
},
pzpr: {
options: {
sourceMap: !PRODUCTION
},
files: [
{ src: require('./src/pzpr.js').files, dest: 'dist/js/pzpr.concat.js' }
]
},
ui: {
options:{
sourceMap: !PRODUCTION
Expand All @@ -56,16 +48,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';}
Expand Down Expand Up @@ -98,8 +80,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']);
Expand Down
68 changes: 64 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
.PHONY: build test serve format
.PHONY: default build test serve serve-all format check-format npm-install lint candle bundle rollup githash

build:
BUNDLEFILES=./src/header.js \
./src/pzpr/env.js \
./src/pzpr/event.js \
./src/pzpr/classmgr.js \
./src/pzpr/variety.js \
./src/pzpr/parser.js \
./src/pzpr/metadata.js \
./src/pzpr/util.js \
./src/puzzle/Puzzle.js \
./src/puzzle/Config.js \
./src/puzzle/Address.js \
./src/puzzle/Piece.js \
./src/puzzle/PieceList.js \
./src/puzzle/Board.js \
./src/puzzle/BoardExec.js \
./src/puzzle/GraphBase.js \
./src/puzzle/LineManager.js \
./src/puzzle/AreaManager.js \
./src/puzzle/Graphic.js \
./src/puzzle/MouseInput.js \
./src/puzzle/KeyInput.js \
./src/puzzle/Encode.js \
./src/puzzle/FileData.js \
./src/puzzle/Answer.js \
./src/puzzle/Operation.js \
./src/variety-common/Graphic.js \
./src/variety-common/KeyInput.js \
./src/variety-common/MouseInput.js \
./src/variety-common/Answer.js \
./src/variety-common/BoardExec.js \
./src/variety-common/Encode.js \
./src/variety-common/FileData.js

default: lint test

build: candle rollup githash
npm run-script build

test:
test: bundle
npm test

serve:
Expand All @@ -13,4 +48,29 @@ 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}"

npm-install:
npm install

lint:
npx eslint --quiet src src-ui test sample

candle:
mkdir -p ./dist/js/
cp ./node_modules/pzpr-canvas/dist/candle.js ./dist/js/candle.js

bundle:
mkdir -p ./dist/js/
cat ${BUNDLEFILES} > "./dist/js/pzpr.concat.js"

rollup: bundle
mkdir -p ./dist/js/
npx rollup -c ./rollup.config.js

HASH=$(shell git rev-parse --short HEAD)
githash:
sed -i s'/<%= git.hash %>/${HASH}/g' ./dist/js/pzpr.js
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@
"node": ">= 5.6.0"
},
"scripts": {
"build": "eslint --cache --quiet src src-ui && ./git-hash.sh && grunt default",
"build": "./git-hash.sh && grunt default",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the git-hash part here seems like it should be redundant with the new Makefile target

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get rid of this script entirely and call npx grunt default from the Makefile instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p.html and the examples and such are still copied with Grunt. I thought is was a bit too much to also change that in this PR. But we could.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to get rid of Grunt, I meant to get rid of the "build" script in package.json, and to call Grunt directly from the Makefile.

"release": "npm run clean && eslint --cache --quiet src && grunt release",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this (still) used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's referenced in Gruntfile:

  var PRODUCTION = (grunt.cli.tasks.indexOf('release') >= 0);

But the only difference seems to be that if PRODUCTION is true it copies over .map files, which is fine anyway?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's at least fine in the sense that I'm currently deploying those anyway... https://puzz.link/js/list.js.map

"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",
"test": "mocha -r esm -r pzpr-canvas -r source-map-support/register -R progress --recursive test",
"prepublishOnly": "npm test"
},
"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.6.0",
"rollup-plugin-terser": "^5.3.0"
},
"dependencies": {
"pzpr-canvas": "^0.8.2",
Expand Down
22 changes: 22 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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
]
};
1 change: 1 addition & 0 deletions src-ui/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta http-equiv="Content-Type" content="text/html">
<TITLE>puzz.link list of puzzle types</TITLE>
<link rel="stylesheet" href="./css/list.css?<%= git.hash %>">
<script src="./js/candle.js?<%= git.hash %>"></script>
robx marked this conversation as resolved.
Show resolved Hide resolved
<script src="./js/pzpr.js?<%= git.hash %>"></script>
<script src="./js/list.js?<%= git.hash %>"></script>
</HEAD>
Expand Down
1 change: 1 addition & 0 deletions src-ui/p.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link rel="mask-icon" href="./safari-pinned-tab.svg" color="#5bbad5">

<link rel="stylesheet" href="./css/ui.css?<%= git.hash %>" type="text/css">
<script type="text/javascript" src="./js/candle.js?<%= git.hash %>"></script>
<script type="text/javascript" src="./js/pzpr.js?<%= git.hash %>"></script>
<script type="text/javascript" src="./js/pzpr-ui.js?<%= git.hash %>"></script>
<title>puzz.link player</title>
Expand Down
1 change: 1 addition & 0 deletions src-ui/rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
}
</style>

<script type="text/javascript" src="./js/candle.js?<%= git.hash %>"></script>
<script type="text/javascript" src="./js/pzpr.js?<%= git.hash %>"></script>
<script>

Expand Down
43 changes: 22 additions & 21 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{
"env": {
"browser": true, // Allow to use browser defined variable (not console, alert etc.)
"node": true // Allow to use node defined variable (require, process etc.)
"browser": true, // Allow to use browser defined variable (not console, alert etc.)
"node": true // Allow to use node defined variable (require, process etc.)
},
"parserOptions": {
"ecmaVersion": 5
"ecmaVersion": 5,
"sourceType": "module"
},
"globals": {
"pzpr": "readonly"
},
"extends": "eslint:recommended", // Implement recommended rules
"extends": "eslint:recommended", // Implement recommended rules
"rules": {
"curly": ["error", "all"], // Error for no curly brancket in loop or conditions
"no-unused-vars": // Error for unused variables, not detect arguments
["error", {"args": "none"}],
"no-undef": "error", // Error for unused variable (that will become global variable)
"new-cap": "error", // Error for lowercase first letter or constructor call as function
"eqeqeq": ["error", "always"], // Error for ==, != to compare
"no-use-before-define": // Error for using variable before definition
["error", {"functions":false, "classes":false}],
"curly": ["error", "all"], // Error for no curly brancket in loop or conditions
// Error for unused variables, not detect arguments
"no-unused-vars": ["error", { "args": "none" }],
"no-undef": "error", // Error for unused variable (that will become global variable)
"new-cap": "error", // Error for lowercase first letter or constructor call as function
"eqeqeq": ["error", "always"], // Error for ==, != to compare
// Error for using variable before definition
"no-use-before-define": ["error", { "functions": false, "classes": false }],
"comma-dangle": ["error", "never"], // Error for trailing comma
"no-redeclare": "warn", // Warn redefine variable (TODO: make this rule error)
"no-redeclare": "warn", // Warn redefine variable (TODO: make this rule error)
//"block-scoped-var": "warn", // Warn var declaration inside block scope
"no-empty": "off", // Allow empty block statements
"no-constant-condition": // Allow constant condition in conditions
["error", {"checkLoops": false}],
"no-useless-escape": "off", // Allow unnessesary escape charactors
"no-extra-boolean-cast": "off", // Allow to use boolean cast for boolean value
"no-mixed-spaces-and-tabs": "off", // Allow to use spaces and tabs for indent
"dot-notation": "off", // Allow object access via obj["name"]
"no-loop-func": "off" // Allow function definition in loop
"no-empty": "off", // Allow empty block statements
// Allow constant condition in conditions
"no-constant-condition": ["error", { "checkLoops": false }],
"no-useless-escape": "off", // Allow unnessesary escape charactors
"no-extra-boolean-cast": "off", // Allow to use boolean cast for boolean value
"no-mixed-spaces-and-tabs": "off", // Allow to use spaces and tabs for indent
"dot-notation": "off", // Allow object access via obj["name"]
"no-loop-func": "off" // Allow function definition in loop
}
}
3 changes: 0 additions & 3 deletions src/common/intro.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/common/outro.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var pzpr = {
version: "<%= git.hash %>"
};
export default pzpr;

import Candle from "pzpr-canvas";
pzpr.Candle = Candle;

//eslint-disable-next-line no-unused-vars
var document = this.document || pzpr.Candle.document;
//eslint-disable-next-line no-unused-vars
var DOMParser = this.DOMParser || pzpr.Candle.DOMParser;
//eslint-disable-next-line no-unused-vars
var XMLSerializer = this.XMLSerializer || pzpr.Candle.XMLSerializer;
13 changes: 0 additions & 13 deletions src/lib/candle-intro.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/lib/candle-outro.js

This file was deleted.

8 changes: 6 additions & 2 deletions src/puzzle/Piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ pzpr.classmgr.makeCommon({
}

this.addOpe(prop, this[prop], num);
this[prop] = num;
if (!Object.isFrozen(this)) {
this[prop] = num;
}
robx marked this conversation as resolved.
Show resolved Hide resolved

var trialstage = this.board.trialstage;
if (trialstage > 0) {
Expand Down Expand Up @@ -292,7 +294,9 @@ pzpr.classmgr.makeCommon({
//---------------------------------------------------------------------------
seterr: function(num) {
if (this.board.isenableSetError()) {
this.error = num;
if (!Object.isFrozen(this)) {
this.error = num;
}
}
},
setinfo: function(num) {
Expand Down
4 changes: 3 additions & 1 deletion src/puzzle/PieceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ pzpr.classmgr.makeCommon({
return;
}
for (var i = 0; i < this.length; i++) {
this[i].error = num;
if (!Object.isFrozen(this[i])) {
this[i].error = num;
}
}
},
setnoerr: function() {
Expand Down
41 changes: 0 additions & 41 deletions src/pzpr.js

This file was deleted.

Loading