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

feat(esm): migrate this package to a pure ESM #252

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
509 changes: 257 additions & 252 deletions decktape.js

Large diffs are not rendered by default.

370 changes: 177 additions & 193 deletions libs/nomnom.js

Large diffs are not rendered by default.

44 changes: 3 additions & 41 deletions libs/util.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
'use strict';

module.exports.delay = delay => value => new Promise(resolve => setTimeout(resolve, delay, value));
export const delay = delay => value => new Promise(resolve => setTimeout(resolve, delay, value));

module.exports.pause = ms => module.exports.delay(ms)();
export const pause = ms => delay(ms)();

module.exports.wait = ms => () => module.exports.delay(ms);

// Can be removed when Node 8 becomes a requirement

// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
if (!String.prototype.padStart) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

String.prototype.padStart = function padStart(targetLength, padString) {
targetLength = targetLength >> 0; //floor if number or convert non-number to 0;
padString = String(padString || ' ');
if (this.length > targetLength) {
return String(this);
} else {
targetLength = targetLength - this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength / padString.length);
}
return padString.slice(0, targetLength) + String(this);
}
};
}

// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
if (!String.prototype.padEnd) {
String.prototype.padEnd = function padEnd(targetLength, padString) {
targetLength = targetLength >> 0; //floor if number or convert non-number to 0;
padString = String(padString || ' ');
if (this.length > targetLength) {
return String(this);
} else {
targetLength = targetLength - this.length;
if (targetLength > padString.length) {
padString += padString.repeat(targetLength / padString.length);
}
return String(this) + padString.slice(0, targetLength);
}
};
}
export const wait = ms => () => delay(ms);
53 changes: 47 additions & 6 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"homepage": "https://github.com/astefanutti/decktape",
"license": "MIT",
"main": "decktape.js",
"type": "module",
"bin": {
"decktape": "decktape.js"
},
Expand All @@ -20,14 +21,15 @@
"url": "https://github.com/astefanutti/decktape/issues"
},
"dependencies": {
"chalk": "^4.1.2",
"chalk": "~5.1.2",
"chalk-template": "^0.4.0",
"fonteditor-core": "2.1.10",
"pdf-lib": "1.17.1",
"puppeteer": "18.2.1",
"puppeteer-core": "18.2.1",
"urijs": "1.19.11"
},
"engines": {
"node": ">=12.0.0"
"node": ">=12.20"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the minimal version for ESM

}
}
4 changes: 2 additions & 2 deletions plugins/bespoke.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
exports.help =
export const help =
`Requires the bespoke-extern module to expose the Bespoke.js API to a global variable named
'bespoke' and provides access to the collection of deck instances via 'bespoke.decks
and the most recent deck via 'bespoke.deck'.`;

exports.create = page => new Bespoke(page);
export const create = page => new Bespoke(page);

class Bespoke {

Expand Down
2 changes: 1 addition & 1 deletion plugins/deck.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Deck(page);
export const create = page => new Deck(page);

class Deck {

Expand Down
2 changes: 1 addition & 1 deletion plugins/dzslides.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new DZSlides(page);
export const create = page => new DZSlides(page);

class DZSlides {

Expand Down
2 changes: 1 addition & 1 deletion plugins/flowtime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Flowtime(page);
export const create = page => new Flowtime(page);

class Flowtime {

Expand Down
14 changes: 7 additions & 7 deletions plugins/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// and detects changes to the DOM. The deck is considered over when no change
// is detected afterward.

const { pause } = require('../libs/util');
import { pause } from '../libs/util.js';

exports.options = {
export const options = {
key : {
default : 'ArrowRight',
metavar : '<key>',
Expand All @@ -23,24 +23,24 @@ exports.options = {
},
};

exports.help =
export const help =
`Emulates the end-user interaction by pressing the key with the specified --key option
and iterates over the presentation as long as:
- Any change to the DOM is detected by observing mutation events targeting the body element
and its subtree,
- Nor the number of slides exported has reached the specified --max-slides option.
The --key option must be one of the 'KeyboardEvent' keys and defaults to [${exports.options.key.default}].`;
The --key option must be one of the 'KeyboardEvent' keys and defaults to [${options.key.default}].`;

exports.create = (page, options) => new Generic(page, options);
export const create = (page, options) => new Generic(page, options);

class Generic {
constructor(page, options) {
this.page = page;
this.options = options;
this.currentSlide = 1;
this.isNextSlideDetected = false;
this.key = this.options.key || exports.options.key.default;
this.media = this.options.media || exports.options.media.default;
this.key = this.options.key || options.key.default;
this.media = this.options.media || options.media.default;
}

getName() {
Expand Down
2 changes: 1 addition & 1 deletion plugins/impress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Impress(page);
export const create = page => new Impress(page);

class Impress {

Expand Down
2 changes: 1 addition & 1 deletion plugins/inspire.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Inspire(page);
export const create = page => new Inspire(page);

class Inspire {

Expand Down
2 changes: 1 addition & 1 deletion plugins/nuedeck.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new NueDeck(page);
export const create = page => new NueDeck(page);

class NueDeck {

Expand Down
2 changes: 1 addition & 1 deletion plugins/remark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Remark(page);
export const create = page => new Remark(page);

class Remark {

Expand Down
4 changes: 2 additions & 2 deletions plugins/reveal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const URI = require('urijs');
import URI from 'urijs';

exports.create = page => new Reveal(page);
export const create = page => new Reveal(page);

class Reveal {

Expand Down
2 changes: 1 addition & 1 deletion plugins/rise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new RISE(page);
export const create = page => new RISE(page);

class RISE {

Expand Down
2 changes: 1 addition & 1 deletion plugins/shower-1.x.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Shower(page);
export const create = page => new Shower(page);

class Shower {

Expand Down
2 changes: 1 addition & 1 deletion plugins/shower-2.x.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Shower(page);
export const create = page => new Shower(page);

class Shower {

Expand Down
2 changes: 1 addition & 1 deletion plugins/slidy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new Slidy(page);
export const create = page => new Slidy(page);

class Slidy {

Expand Down
2 changes: 1 addition & 1 deletion plugins/webslides.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.create = page => new WebSlides(page);
export const create = page => new WebSlides(page);

class WebSlides {

Expand Down