@canopycanopycanopy/b-ber-tasks 3.0.8-nav-memo.4 → 3.0.8-next.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -4
- package/dist/index.d.ts +144 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2109 -176
- package/dist/web/search.js +1 -1
- package/dist/web/worker.js +1 -1
- package/package.json +22 -23
- package/dist/clean/index.js +0 -25
- package/dist/container/index.js +0 -48
- package/dist/copy/index.js +0 -60
- package/dist/cover/index.js +0 -217
- package/dist/deploy/index.js +0 -188
- package/dist/epub/index.js +0 -24
- package/dist/footnotes/index.js +0 -56
- package/dist/generate/index.js +0 -79
- package/dist/init/index.js +0 -73
- package/dist/inject/index.js +0 -80
- package/dist/loi/index.js +0 -130
- package/dist/mobi/index.js +0 -39
- package/dist/mobi/mobi-css.js +0 -85
- package/dist/opf/ManifestAndMetadata.js +0 -96
- package/dist/opf/Navigation.js +0 -199
- package/dist/opf/Opf.js +0 -56
- package/dist/opf/helpers.js +0 -57
- package/dist/opf/index.js +0 -31
- package/dist/pdf/index.js +0 -59
- package/dist/reader/index.js +0 -205
- package/dist/render/index.js +0 -53
- package/dist/sample/index.js +0 -11
- package/dist/sass/index.js +0 -185
- package/dist/scripts/index.js +0 -54
- package/dist/serialize.js +0 -57
- package/dist/serve/index.js +0 -83
- package/dist/validate/index.js +0 -51
- package/dist/web/Template.js +0 -171
- package/dist/web/index.js +0 -371
- package/dist/xml/index.js +0 -57
package/dist/web/search.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var searchInput=null;var searchButton=null;var searchButtonOpen=null;var searchButtonClose=null;var publicationContents=null;var clonedContents=null;function closeSearchBar(){if(!searchInput||!searchButtonClose)return;searchInput.classList.remove("publication__search__input--expanded");searchButtonClose.classList.remove("publication__search__button--close--visible");searchInput.value=""}function openSearchBar(){if(!searchInput||!searchButtonClose)return;searchInput.classList.add("publication__search__input--expanded");searchButtonClose.classList.add("publication__search__button--close--visible");searchInput.focus()}function toggleSearchBar(){if(!searchInput||!searchButtonClose)return;if(searchInput.classList.contains("publication__search__input--expanded")){closeSearchBar()}else{openSearchBar()}}function bindEventHandlers(){searchInput=document.querySelector(".publication__search__input");searchButtonOpen=document.querySelector(".publication__search__button--open");searchButtonClose=document.querySelector(".publication__search__button--close");publicationContents=document.querySelector(".publication__contents");clonedContents=publicationContents.cloneNode(true);if(window.Worker){initializeWebWorker()}searchButtonOpen.addEventListener("click",openSearchBar,false);searchButtonClose.addEventListener("click",closeSearchBar,false);publicationContents.addEventListener("click",closeSearchBar,false);document.addEventListener("keyup",function(e){if(e&&e.which&&e.which===27){closeSearchBar()}},false)}function initializeWebWorker(){var worker=new Worker("%BASE_URL%
|
|
1
|
+
(function(){var searchInput=null;var searchButton=null;var searchButtonOpen=null;var searchButtonClose=null;var publicationContents=null;var clonedContents=null;function closeSearchBar(){if(!searchInput||!searchButtonClose)return;searchInput.classList.remove("publication__search__input--expanded");searchButtonClose.classList.remove("publication__search__button--close--visible");searchInput.value=""}function openSearchBar(){if(!searchInput||!searchButtonClose)return;searchInput.classList.add("publication__search__input--expanded");searchButtonClose.classList.add("publication__search__button--close--visible");searchInput.focus()}function toggleSearchBar(){if(!searchInput||!searchButtonClose)return;if(searchInput.classList.contains("publication__search__input--expanded")){closeSearchBar()}else{openSearchBar()}}function bindEventHandlers(){searchInput=document.querySelector(".publication__search__input");searchButtonOpen=document.querySelector(".publication__search__button--open");searchButtonClose=document.querySelector(".publication__search__button--close");publicationContents=document.querySelector(".publication__contents");clonedContents=publicationContents.cloneNode(true);if(window.Worker){initializeWebWorker()}searchButtonOpen.addEventListener("click",openSearchBar,false);searchButtonClose.addEventListener("click",closeSearchBar,false);publicationContents.addEventListener("click",closeSearchBar,false);document.addEventListener("keyup",function(e){if(e&&e.which&&e.which===27){closeSearchBar()}},false)}function initializeWebWorker(){var worker=new Worker("%BASE_URL%worker.js");var timer;var debounceSpeed=200;if(!searchInput||!publicationContents)return;function parseSearchResults(results){return results.reduce(function(acc,curr){return acc.concat(' <div class="search__result"> <a class="search__result__link" href="'+curr.url+'"> '+(curr.title?'<h1 class="search__result__title">'+curr.title+"</h1>":"")+" "+(curr.body?'<div class="search__result__body">'+curr.body+"</div>":"")+" </a> </div>")},'<section class="search__results">')+"</section>"}function resetContents(){publicationContents.innerHTML=clonedContents.innerHTML}function debounceSearch(){clearTimeout(timer);timer=setTimeout(function(){var term=searchInput.value.trim();if(!term){resetContents();return}worker.postMessage({term:term})},debounceSpeed)}worker.addEventListener("message",function(e){if(!e.data)return;if(e.data.readyState&&e.data.readyState>3){searchInput.removeAttribute("disabled")}if(e.data.results){publicationContents.innerHTML=parseSearchResults(e.data.results)}});searchInput.addEventListener("keyup",debounceSearch)}window.addEventListener("load",bindEventHandlers,false)})();
|
package/dist/web/worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
importScripts("%BASE_URL%
|
|
1
|
+
importScripts("%BASE_URL%lunr.js");var searchIndex;var records=[];var readyState=0;function onRequestReadyStateChange(state){if(!state)state=null;readyState=state||this.readyState;postMessage({readyState:readyState})}function onRequestLoad(){records=JSON.parse(this.responseText);searchIndex=lunr(function(){this.metadataWhitelist=["position"];this.field("title");this.field("body");this.ref("id");records.forEach(function(record,i){this.add(record)},this)});onRequestReadyStateChange(this.readyState)}function getSearchIndex(){var req=new XMLHttpRequest;req.addEventListener("load",onRequestLoad);req.addEventListener("open",onRequestReadyStateChange);req.addEventListener("send",onRequestReadyStateChange);req.open("GET","%BASE_URL%search-index.json");req.send()}function trimResultBody(data){return data}function parseSearchResults(results){var output=[];var markerStart="<mark>";var markerEnd="</mark>";var markerLength=markerStart.length+markerEnd.length;var markerOffset=0;var resultsObject={};var text="";var textOffset=100;if(!results||!results.length)return output;results.forEach(function(result){Object.keys(result.matchData.metadata).forEach(function(term){var match=result.matchData.metadata[term];resultsObject={};resultsObject.url=records[result.ref].url;Object.keys(match).forEach(function(fieldName){var position=match[fieldName].position;for(var i=0;i<position.length;i++){var content=records[result.ref][fieldName].trim();if(!content)continue;var begin=position[i][0];var length=position[i][1];var firstIndex=begin-textOffset;var prefix=firstIndex<0?"...":"";var before=content.slice(firstIndex,begin);var marked=markerStart+content.slice(begin,begin+length)+markerEnd;var after=content.slice(begin+length,begin+length+textOffset);var suffix=begin+length+textOffset>content.length?"":"...";text='<span class="search__result__text">'+prefix+before+marked+after+suffix+"</span>"}resultsObject[fieldName]=text});output.push(resultsObject)})});return output}function doSearch(term){var results=searchIndex.query(function(q){q.term(term,{fields:["title","body"],editDistance:1})});return parseSearchResults(results)}getSearchIndex();onmessage=function(e){if(readyState<4)return;var results=doSearch(e.data.term);postMessage({results:results})};
|
package/package.json
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-tasks",
|
|
3
|
-
"version": "3.0.8-
|
|
3
|
+
"version": "3.0.8-next.101+b6a7f323",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
+
"build": "tsdown && npm run copy",
|
|
8
9
|
"copy": "./copy.sh",
|
|
9
|
-
"
|
|
10
|
-
"prepare": "npm run clean && npm run prepare:dist",
|
|
11
|
-
"build": "npm run prepare",
|
|
12
|
-
"watch": "npm run copy && BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --watch src --ignore **/__tests__/**,src/web/search.js,src/web/worker.js,src/web/navigation.js,src/web/event-handlers.js,src/serve/server.js",
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
13
11
|
"test": "jest"
|
|
14
12
|
},
|
|
15
13
|
"author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
|
|
@@ -18,15 +16,14 @@
|
|
|
18
16
|
"access": "public"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@canopycanopycanopy/b-ber-
|
|
23
|
-
"@canopycanopycanopy/b-ber-
|
|
24
|
-
"@canopycanopycanopy/b-ber-
|
|
25
|
-
"@canopycanopycanopy/b-ber-
|
|
26
|
-
"@canopycanopycanopy/b-ber-
|
|
27
|
-
"@canopycanopycanopy/b-ber-
|
|
28
|
-
"@canopycanopycanopy/b-ber-
|
|
29
|
-
"@canopycanopycanopy/b-ber-validator": "3.0.8-nav-memo.4+d47a9aae",
|
|
19
|
+
"@canopycanopycanopy/b-ber-lib": "3.0.8-next.101+b6a7f323",
|
|
20
|
+
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.101+b6a7f323",
|
|
21
|
+
"@canopycanopycanopy/b-ber-markdown-renderer": "3.0.8-next.101+b6a7f323",
|
|
22
|
+
"@canopycanopycanopy/b-ber-reader": "3.0.8-next.101+b6a7f323",
|
|
23
|
+
"@canopycanopycanopy/b-ber-resources": "3.0.8-next.101+b6a7f323",
|
|
24
|
+
"@canopycanopycanopy/b-ber-shapes-sequences": "3.0.8-next.101+b6a7f323",
|
|
25
|
+
"@canopycanopycanopy/b-ber-templates": "3.0.8-next.101+b6a7f323",
|
|
26
|
+
"@canopycanopycanopy/b-ber-validator": "3.0.8-next.101+b6a7f323",
|
|
30
27
|
"autoprefixer": "^9.6.1",
|
|
31
28
|
"browser-sync": "^2.27.7",
|
|
32
29
|
"bs-html-injector": "^3.0.3",
|
|
@@ -51,13 +48,15 @@
|
|
|
51
48
|
"xmlhttprequest-ssl": "^2.0.0"
|
|
52
49
|
},
|
|
53
50
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"rimraf": "^2.7.1"
|
|
51
|
+
"@swc/core": "^1.15.40",
|
|
52
|
+
"@swc/jest": "^0.2.39",
|
|
53
|
+
"@types/browser-sync": "^2.29.1",
|
|
54
|
+
"@types/recursive-readdir": "^2.2.4",
|
|
55
|
+
"@types/uglify-js": "^3.17.5",
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"rimraf": "^2.7.1",
|
|
58
|
+
"tsdown": "^0.22.1",
|
|
59
|
+
"typescript": "^6.0.3"
|
|
61
60
|
},
|
|
62
61
|
"files": [
|
|
63
62
|
"dist"
|
|
@@ -76,5 +75,5 @@
|
|
|
76
75
|
"url": "https://maxwellsimmer.com"
|
|
77
76
|
}
|
|
78
77
|
],
|
|
79
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "b6a7f323cd34b837eb49ad96b1062bd6e0af207f"
|
|
80
79
|
}
|
package/dist/clean/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
5
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
10
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
11
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
12
|
-
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
14
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
15
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
16
|
-
// Remove an ebook's output directory and outdated builds
|
|
17
|
-
const clean = () => {
|
|
18
|
-
var _context, _context2;
|
|
19
|
-
const projectRoot = _path.default.dirname(_State.default.distDir);
|
|
20
|
-
const fileType = `.${_State.default.build}`;
|
|
21
|
-
const promises = (0, _map.default)(_context = (0, _filter.default)(_context2 = _fsExtra.default.readdirSync(projectRoot)).call(_context2, a => _path.default.extname(a) === fileType)).call(_context, b => _fsExtra.default.remove(_path.default.join(projectRoot, b)).then(() => _bBerLogger.default.info('clean remove [%s]', b)));
|
|
22
|
-
return _promise.default.all(promises).then(() => _fsExtra.default.remove(_State.default.distDir).then(() => _bBerLogger.default.info('clean remove [%s]', _State.default.distDir)));
|
|
23
|
-
};
|
|
24
|
-
var _default = () => clean().catch(_bBerLogger.default.error);
|
|
25
|
-
exports.default = _default;
|
package/dist/container/index.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
5
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
|
|
10
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
11
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
12
|
-
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
14
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
15
|
-
var _Xml = _interopRequireDefault(require("@canopycanopycanopy/b-ber-templates/Xml"));
|
|
16
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
17
|
-
/* eslint-disable class-methods-use-this */
|
|
18
|
-
|
|
19
|
-
class Container {
|
|
20
|
-
get dirs() {
|
|
21
|
-
return [_State.default.dist.ops(), _State.default.dist.root('META-INF')];
|
|
22
|
-
}
|
|
23
|
-
constructor() {
|
|
24
|
-
var _context;
|
|
25
|
-
this.init = (0, _bind.default)(_context = this.init).call(_context, this);
|
|
26
|
-
}
|
|
27
|
-
write() {
|
|
28
|
-
const files = [{
|
|
29
|
-
path: _path.default.join('META-INF', 'container.xml'),
|
|
30
|
-
content: _Xml.default.container()
|
|
31
|
-
}, {
|
|
32
|
-
path: 'mimetype',
|
|
33
|
-
content: _Xml.default.mimetype()
|
|
34
|
-
}];
|
|
35
|
-
const promises = (0, _map.default)(files).call(files, file => _fsExtra.default.writeFile(_State.default.dist.root(file.path), file.content).then(() => _bBerLogger.default.info('container emit [%s]', file.path)));
|
|
36
|
-
return _promise.default.all(promises);
|
|
37
|
-
}
|
|
38
|
-
makedirs() {
|
|
39
|
-
var _context2;
|
|
40
|
-
const promises = (0, _map.default)(_context2 = this.dirs).call(_context2, dir => _fsExtra.default.mkdirs(dir).then(() => _bBerLogger.default.info('container emit [%s]', dir)));
|
|
41
|
-
return _promise.default.all(promises);
|
|
42
|
-
}
|
|
43
|
-
init() {
|
|
44
|
-
return this.makedirs().then(() => this.write()).catch(_bBerLogger.default.error);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const container = new Container();
|
|
48
|
-
var _default = exports.default = container.init;
|
package/dist/copy/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
5
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
10
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
11
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
12
|
-
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
13
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
14
|
-
var _path = _interopRequireDefault(require("path"));
|
|
15
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
16
|
-
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
17
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
18
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
19
|
-
const FILE_SIZE_WARNING_LIMIT = 1500000; // 1.5Mb
|
|
20
|
-
const cwd = process.cwd();
|
|
21
|
-
|
|
22
|
-
// Copy directories of assets into the output directory
|
|
23
|
-
const copy = () => {
|
|
24
|
-
var _context;
|
|
25
|
-
let {
|
|
26
|
-
ignore
|
|
27
|
-
} = _State.default.config;
|
|
28
|
-
if (!(0, _isArray.default)(ignore)) ignore = [];
|
|
29
|
-
ignore = (0, _reduce.default)(ignore).call(ignore, (acc, curr) => {
|
|
30
|
-
acc[_path.default.resolve(cwd, curr)] = true;
|
|
31
|
-
return acc;
|
|
32
|
-
}, {});
|
|
33
|
-
const dirs = (0, _filter.default)(_context = [{
|
|
34
|
-
from: _path.default.resolve(_State.default.src.images()),
|
|
35
|
-
to: _path.default.resolve(_State.default.dist.images())
|
|
36
|
-
}, {
|
|
37
|
-
from: _path.default.resolve(_State.default.src.fonts()),
|
|
38
|
-
to: _path.default.resolve(_State.default.dist.fonts())
|
|
39
|
-
}, {
|
|
40
|
-
from: _path.default.resolve(_State.default.src.media()),
|
|
41
|
-
to: _path.default.resolve(_State.default.dist.media())
|
|
42
|
-
}]).call(_context, dir => !ignore[dir.from]);
|
|
43
|
-
const promises = (0, _map.default)(dirs).call(dirs, dir => _fsExtra.default.mkdirp(dir.to).then(() => _fsExtra.default.mkdirp(dir.from)).then(() => _fsExtra.default.copy(dir.from, dir.to, {
|
|
44
|
-
overwrite: false,
|
|
45
|
-
filter: file => _path.default.basename(file).charAt(0) !== '.' && !ignore[file]
|
|
46
|
-
})).then(() => _fsExtra.default.readdir(dir.to)).then(files => {
|
|
47
|
-
const baseTo = `${_path.default.basename(dir.to)}`;
|
|
48
|
-
(0, _forEach.default)(files).call(files, file => {
|
|
49
|
-
const {
|
|
50
|
-
size
|
|
51
|
-
} = _fsExtra.default.statSync(_path.default.join(dir.to, file));
|
|
52
|
-
_bBerLogger.default.info('copy [%s - {%d}]', `${baseTo}/${file}`, size);
|
|
53
|
-
if (size > FILE_SIZE_WARNING_LIMIT) {
|
|
54
|
-
_bBerLogger.default.warn('copy [%s - {%d}] Large file sizes may cause performance issues in some output formats', file, size);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}));
|
|
58
|
-
return _promise.default.all(promises).catch(_bBerLogger.default.error);
|
|
59
|
-
};
|
|
60
|
-
var _default = exports.default = copy;
|
package/dist/cover/index.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
5
|
-
var _filterInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
6
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
7
|
-
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
8
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
9
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
10
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
11
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
12
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
exports.default = void 0;
|
|
16
|
-
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
17
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
18
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
19
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
21
|
-
var _path = _interopRequireDefault(require("path"));
|
|
22
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
23
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
24
|
-
var _imageSize = _interopRequireDefault(require("image-size"));
|
|
25
|
-
var _pureimage = _interopRequireDefault(require("pureimage"));
|
|
26
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
27
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
28
|
-
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
29
|
-
var _Xhtml = _interopRequireDefault(require("@canopycanopycanopy/b-ber-templates/Xhtml"));
|
|
30
|
-
var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
|
|
31
|
-
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty2(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
32
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
33
|
-
class Cover {
|
|
34
|
-
constructor() {
|
|
35
|
-
(0, _defineProperty2.default)(this, "getPosY", () => {
|
|
36
|
-
this.posY = this.posY ? this.posY + this.lineHeight : this.marginTop + this.fontSize;
|
|
37
|
-
return this.posY;
|
|
38
|
-
});
|
|
39
|
-
// Necessary to flush the state if running in sequence with other builds
|
|
40
|
-
(0, _defineProperty2.default)(this, "loadInitialState", async () => {
|
|
41
|
-
this.posY = 0;
|
|
42
|
-
this.coverXHTMLContent = '';
|
|
43
|
-
this.coverEntry = '';
|
|
44
|
-
this.coverImagePath = '';
|
|
45
|
-
});
|
|
46
|
-
(0, _defineProperty2.default)(this, "writeCoverXHTML", async () => {
|
|
47
|
-
// Omit cover.xhtml from the PDF build to allow users to define special
|
|
48
|
-
// treatment for the cover in config.yml
|
|
49
|
-
if (_State.default.build === 'pdf') return;
|
|
50
|
-
const textDir = _State.default.dist.text();
|
|
51
|
-
const coverFilePath = _State.default.dist.text('cover.xhtml');
|
|
52
|
-
await _fsExtra.default.mkdirp(textDir);
|
|
53
|
-
await _fsExtra.default.writeFile(coverFilePath, this.coverXHTMLContent);
|
|
54
|
-
_bBerLogger.default.info('cover wrote XML [cover.xhtml]');
|
|
55
|
-
});
|
|
56
|
-
(0, _defineProperty2.default)(this, "init", () => this.loadInitialState().then(() => this.createCoverImage()).then(() => this.writeCoverXHTML()).catch(_bBerLogger.default.error));
|
|
57
|
-
const defaultMetadata = {
|
|
58
|
-
title: '',
|
|
59
|
-
creator: '',
|
|
60
|
-
'date-modified': String(new Date()),
|
|
61
|
-
identifier: ''
|
|
62
|
-
};
|
|
63
|
-
const fileMetadata = this.YAMLToObject(_State.default.metadata.json());
|
|
64
|
-
this.metadata = _objectSpread(_objectSpread({}, defaultMetadata), fileMetadata);
|
|
65
|
-
this.metadataYAML = _State.default.src.root('metadata.yml');
|
|
66
|
-
this.coverPrefix = '__bber_cover__';
|
|
67
|
-
this.coverXHTMLContent = '';
|
|
68
|
-
this.coverEntry = '';
|
|
69
|
-
this.coverImagePath = '';
|
|
70
|
-
|
|
71
|
-
// cover data
|
|
72
|
-
this.width = 1600;
|
|
73
|
-
this.height = 2400;
|
|
74
|
-
this.fontSize = 45;
|
|
75
|
-
this.lineHeight = this.fontSize * 1.35;
|
|
76
|
-
this.marginLeft = this.fontSize * 2;
|
|
77
|
-
this.marginTop = this.fontSize * 2;
|
|
78
|
-
this.colorBackground = '#5050c5';
|
|
79
|
-
this.colorText = '#ffffff';
|
|
80
|
-
this.fontName = 'Free Universal';
|
|
81
|
-
|
|
82
|
-
// File name needs to be added to copy.sh
|
|
83
|
-
this.fontFile = 'freeuniversal-bold-webfont.ttf';
|
|
84
|
-
|
|
85
|
-
// increments paragraph Y position
|
|
86
|
-
this.posY = 0;
|
|
87
|
-
}
|
|
88
|
-
// eslint-disable-next-line class-methods-use-this
|
|
89
|
-
YAMLToObject() {
|
|
90
|
-
var _context;
|
|
91
|
-
return (0, _reduce.default)(_context = _State.default.metadata.json()).call(_context, (acc, curr) => {
|
|
92
|
-
if (curr.term && curr.value) {
|
|
93
|
-
acc[curr.term] = curr.value;
|
|
94
|
-
}
|
|
95
|
-
return acc;
|
|
96
|
-
}, {});
|
|
97
|
-
}
|
|
98
|
-
removeDefaultCovers() {
|
|
99
|
-
const imageDir = _State.default.src.images();
|
|
100
|
-
const files = _fsExtra.default.readdirSync(imageDir);
|
|
101
|
-
const covers = (0, _filter.default)(files).call(files, file => _path.default.basename(file).match(new RegExp(this.coverPrefix)));
|
|
102
|
-
if (!covers.length) return _promise.default.resolve();
|
|
103
|
-
const promises = (0, _map.default)(covers).call(covers, file => _fsExtra.default.remove(_path.default.join(imageDir, file)).then(() => _bBerLogger.default.info('cover remove outdated cover image [%s]', file)));
|
|
104
|
-
return _promise.default.all(promises);
|
|
105
|
-
}
|
|
106
|
-
wrapText(ctx, text) {
|
|
107
|
-
const maxWidth = this.width - this.marginLeft * 2;
|
|
108
|
-
const words = text.split(' ');
|
|
109
|
-
let line = '';
|
|
110
|
-
for (let n = 0; n < words.length; n++) {
|
|
111
|
-
const testLine = `${line}${words[n]} `;
|
|
112
|
-
const metrics = ctx.measureText(testLine);
|
|
113
|
-
const testWidth = metrics.width;
|
|
114
|
-
if (testWidth > maxWidth && n > 0) {
|
|
115
|
-
ctx.fillText(line, this.marginLeft, this.getPosY());
|
|
116
|
-
line = `${words[n]} `;
|
|
117
|
-
} else {
|
|
118
|
-
line = testLine;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
ctx.fillText(line, this.marginLeft, this.getPosY());
|
|
122
|
-
}
|
|
123
|
-
generateDefaultCoverImage() {
|
|
124
|
-
return new _promise.default(resolve => {
|
|
125
|
-
const img = _pureimage.default.make(this.width, this.height);
|
|
126
|
-
const ctx = img.getContext('2d');
|
|
127
|
-
const font = _pureimage.default.registerFont(_path.default.join(__dirname, this.fontFile), this.fontName);
|
|
128
|
-
return font.load(() => {
|
|
129
|
-
ctx.fillStyle = this.colorBackground;
|
|
130
|
-
ctx.fillRect(0, 0, this.width, this.height);
|
|
131
|
-
ctx.font = `${this.fontSize}px '${this.fontName}'`;
|
|
132
|
-
ctx.fillStyle = this.colorText;
|
|
133
|
-
|
|
134
|
-
// add text
|
|
135
|
-
ctx.fillText('Title', this.marginLeft, this.getPosY());
|
|
136
|
-
ctx.fillText(this.metadata.title, this.marginLeft, this.getPosY());
|
|
137
|
-
ctx.fillText('', this.marginLeft, this.getPosY());
|
|
138
|
-
ctx.fillText('Creator', this.marginLeft, this.getPosY());
|
|
139
|
-
ctx.fillText(this.metadata.creator, this.marginLeft, this.getPosY());
|
|
140
|
-
ctx.fillText('', this.marginLeft, this.getPosY());
|
|
141
|
-
ctx.fillText('Publisher', this.marginLeft, this.getPosY());
|
|
142
|
-
ctx.fillText(this.metadata.publisher, this.marginLeft, this.getPosY());
|
|
143
|
-
ctx.fillText('', this.marginLeft, this.getPosY());
|
|
144
|
-
ctx.fillText('Description', this.marginLeft, this.getPosY());
|
|
145
|
-
this.wrapText(ctx, this.metadata.description);
|
|
146
|
-
ctx.fillText('', this.marginLeft, this.getPosY());
|
|
147
|
-
ctx.fillText('b-ber version', this.marginLeft, this.getPosY());
|
|
148
|
-
ctx.fillText(_State.default.version, this.marginLeft, this.getPosY());
|
|
149
|
-
return _pureimage.default.encodeJPEGToStream(img, _fsExtra.default.createWriteStream(this.coverImagePath)).then(() => {
|
|
150
|
-
_bBerLogger.default.info('cover generated image [%s]', this.coverImagePath);
|
|
151
|
-
resolve();
|
|
152
|
-
}).catch(_bBerLogger.default.error);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
generateCoverXHTML() {
|
|
157
|
-
// Get the image dimensions and pass them to the coverSVG template
|
|
158
|
-
const {
|
|
159
|
-
width,
|
|
160
|
-
height
|
|
161
|
-
} = (0, _imageSize.default)(this.coverImagePath);
|
|
162
|
-
const href = `images/${encodeURIComponent(this.coverEntry)}`;
|
|
163
|
-
const svg = _Xhtml.default.cover({
|
|
164
|
-
width,
|
|
165
|
-
height,
|
|
166
|
-
href
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// Set the content string to be written once resolved
|
|
170
|
-
this.coverXHTMLContent = _bBerLib.Template.render(svg, _Xhtml.default.body());
|
|
171
|
-
_bBerLogger.default.info('cover build [cover.xhtml]');
|
|
172
|
-
}
|
|
173
|
-
addCoverToMetadata() {
|
|
174
|
-
return _fsExtra.default.writeFile(this.metadataYAML, _State.default.metadata.yaml());
|
|
175
|
-
}
|
|
176
|
-
createCoverImage() {
|
|
177
|
-
this.coverEntry = `${this.coverPrefix}${_crypto.default.randomBytes(20).toString('hex')}.jpg`;
|
|
178
|
-
this.coverImagePath = _State.default.src.images(this.coverEntry);
|
|
179
|
-
|
|
180
|
-
// Load metadata.yml
|
|
181
|
-
const metadata = _bBerLib.YamlAdaptor.load(this.metadataYAML);
|
|
182
|
-
|
|
183
|
-
// Check if cover if referenced
|
|
184
|
-
const coverListedInMetadata = (0, _utils.getBookMetadata)('cover', _State.default);
|
|
185
|
-
if (coverListedInMetadata) {
|
|
186
|
-
// TODO: fixme, for generated covers
|
|
187
|
-
// @issue: https://github.com/triplecanopy/b-ber/issues/208
|
|
188
|
-
this.coverEntry = coverListedInMetadata.replace(/_jpg$/, '.jpg');
|
|
189
|
-
_bBerLogger.default.info('cover verify image [%s]', this.coverEntry);
|
|
190
|
-
|
|
191
|
-
// There's a reference to a cover image, so create a cover.xhtml file
|
|
192
|
-
// containing an SVG-wrapped `image` element with the appropriate cover
|
|
193
|
-
// dimensions and write it to the `text` dir.
|
|
194
|
-
|
|
195
|
-
// check that the cover image file exists, throw if not
|
|
196
|
-
this.coverImagePath = _State.default.src.images(this.coverEntry);
|
|
197
|
-
if (!_fsExtra.default.existsSync(this.coverImagePath)) {
|
|
198
|
-
_bBerLogger.default.error('Cover image listed in metadata.yml cannot be found');
|
|
199
|
-
}
|
|
200
|
-
return this.generateCoverXHTML();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// If there's no cover referenced in the metadata.yml, create one
|
|
204
|
-
// that displays the book's metadata (title, generator version, etc)
|
|
205
|
-
// and add it to metadata.yml
|
|
206
|
-
_bBerLogger.default.info('cover generated image [%s]', this.coverEntry);
|
|
207
|
-
const coverMetadata = {
|
|
208
|
-
term: 'cover',
|
|
209
|
-
value: this.coverEntry
|
|
210
|
-
};
|
|
211
|
-
_State.default.metadata.add(coverMetadata);
|
|
212
|
-
this.metadata = _objectSpread(_objectSpread(_objectSpread({}, coverMetadata), this.metadata), metadata);
|
|
213
|
-
return this.removeDefaultCovers().then(() => this.generateDefaultCoverImage()).then(() => this.generateCoverXHTML()).then(() => this.addCoverToMetadata()).catch(_bBerLogger.default.error);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const cover = new Cover();
|
|
217
|
-
var _default = exports.default = cover.init;
|
package/dist/deploy/index.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
5
|
-
var _filterInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
6
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
7
|
-
var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
8
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
9
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
10
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
11
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
12
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
exports.default = void 0;
|
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
17
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
|
|
18
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
19
|
-
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
20
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
21
|
-
var _map2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
22
|
-
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
23
|
-
var _path = _interopRequireDefault(require("path"));
|
|
24
|
-
var _readline = _interopRequireDefault(require("readline"));
|
|
25
|
-
var _child_process = require("child_process");
|
|
26
|
-
var _YamlAdaptor = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/YamlAdaptor"));
|
|
27
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
28
|
-
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty2(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
29
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty2(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty2(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
30
|
-
const cwd = process.cwd();
|
|
31
|
-
const defaultBuilds = ['epub', 'mobi', 'reader'];
|
|
32
|
-
const args = new _map.default([['epub', '--include "*.epub"'], ['mobi', '--include "*.mobi"'], ['pdf', '--include "*.pdf"'], ['xml', '--include "*.xml"'], ['reader', '--include "project-reader/*"'], ['web', '--include "project-web/*"']]);
|
|
33
|
-
|
|
34
|
-
// Set far off cache for all files. Must not use `--metadata-directive REPLACE` or files
|
|
35
|
-
// will just download in the browser without being served
|
|
36
|
-
// https://stackoverflow.com/questions/10435334/set-cache-control-for-entire-s3-bucket-automatically-using-bucket-policies
|
|
37
|
-
const cacheArgsBucket = ['--recursive', '--acl public-read',
|
|
38
|
-
// '--metadata-directive REPLACE',
|
|
39
|
-
'--expires 2034-01-01T00:00:00Z', '--cache-control max-age=31536000,public'];
|
|
40
|
-
|
|
41
|
-
// Set immediate re-fetch for XML, JSON and downloads
|
|
42
|
-
const cacheArgsFiles = ['--recursive', '--exclude "*"', '--include "*.ncx"', '--include "*.opf"', '--include "*.json"', '--include "*.epub"', '--include "*.mobi"', '--include "*.pdf"', '--include "*.xml"', '--metadata-directive REPLACE', '--acl public-read', '--expires 1970-01-01T00:00:00Z', '--cache-control max-age=0,public'];
|
|
43
|
-
|
|
44
|
-
// Also invalidate cache for X/HTML, but requires settings
|
|
45
|
-
// `content-type` to prevent the browser from downloading them
|
|
46
|
-
// directly
|
|
47
|
-
const cacheArgsHTML = ['--recursive', '--exclude "*"', '--include "*.html"', '--include "*.xhtml"', '--acl public-read', '--metadata-directive REPLACE', '--content-type text/html', '--expires 1970-01-01T00:00:00Z', '--cache-control max-age=0,public'];
|
|
48
|
-
async function ensureAwsCli() {
|
|
49
|
-
try {
|
|
50
|
-
(0, _child_process.execSync)('aws --version > /dev/null 2>&1', {
|
|
51
|
-
cwd
|
|
52
|
-
});
|
|
53
|
-
} catch (err) {
|
|
54
|
-
console.log('AWS CLI must be installed to run deploy');
|
|
55
|
-
console.log('See installation instructions here: https://docs.aws.amazon.com/cli/latest/userguide/installing.html');
|
|
56
|
-
process.exit(0);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function run(command, callback) {
|
|
60
|
-
const proc = (0, _child_process.exec)(command, {
|
|
61
|
-
cwd
|
|
62
|
-
});
|
|
63
|
-
proc.stdout.on('data', data => console.log(String(data)));
|
|
64
|
-
proc.stderr.on('data', data => console.log(String(data)));
|
|
65
|
-
proc.on('error', err => {
|
|
66
|
-
console.log('');
|
|
67
|
-
console.log('ERROR: aws encountered an error');
|
|
68
|
-
console.log(err.message);
|
|
69
|
-
console.log(err.stack);
|
|
70
|
-
});
|
|
71
|
-
proc.on('close', code => {
|
|
72
|
-
if (code !== 0) {
|
|
73
|
-
console.log('');
|
|
74
|
-
console.log(`ERROR: aws exited with code ${code}`);
|
|
75
|
-
}
|
|
76
|
-
if (callback) callback();
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function deploy({
|
|
80
|
-
bucketURL,
|
|
81
|
-
awsRegion,
|
|
82
|
-
builds
|
|
83
|
-
}) {
|
|
84
|
-
console.log('');
|
|
85
|
-
console.log('Uploading project files...');
|
|
86
|
-
return new _promise.default(resolve => {
|
|
87
|
-
const sourceDir = _path.default.resolve(cwd, './');
|
|
88
|
-
let command = [`aws s3 cp ${sourceDir} ${bucketURL}`, '--recursive', '--exclude "*"', `--region ${awsRegion}`];
|
|
89
|
-
(0, _forEach.default)(builds).call(builds, arg => command.push(args.get(arg)));
|
|
90
|
-
command = command.join(' ');
|
|
91
|
-
return run(command, resolve);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function ensureEnvVars() {
|
|
95
|
-
const {
|
|
96
|
-
AWS_ACCESS_KEY_ID,
|
|
97
|
-
AWS_SECRET_ACCESS_KEY,
|
|
98
|
-
BBER_BUCKET_REGION
|
|
99
|
-
} = process.env;
|
|
100
|
-
if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !BBER_BUCKET_REGION) {
|
|
101
|
-
_bBerLogger.default.error('[AWS_ACCESS_KEY_ID], [AWS_SECRET_ACCESS_KEY] and [BBER_BUCKET_REGION] must be set to deploy the project');
|
|
102
|
-
}
|
|
103
|
-
const configFile = _path.default.resolve(cwd, 'config.yml');
|
|
104
|
-
const config = _YamlAdaptor.default.load(configFile);
|
|
105
|
-
const {
|
|
106
|
-
bucket_url: bucketURL
|
|
107
|
-
} = config;
|
|
108
|
-
if (!bucketURL) {
|
|
109
|
-
_bBerLogger.default.error('[bucketURL] must be set in config.yml to deploy the project');
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
bucketURL,
|
|
113
|
-
awsRegion: BBER_BUCKET_REGION
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function extractVars(config) {
|
|
117
|
-
var _context;
|
|
118
|
-
const {
|
|
119
|
-
bucketURL,
|
|
120
|
-
awsRegion
|
|
121
|
-
} = config;
|
|
122
|
-
let {
|
|
123
|
-
builds
|
|
124
|
-
} = config;
|
|
125
|
-
if (!builds || !builds.length) builds = defaultBuilds;
|
|
126
|
-
builds = (0, _filter.default)(_context = (0, _map2.default)(builds).call(builds, str => str.toLowerCase())).call(_context, arg => args.has(arg));
|
|
127
|
-
return {
|
|
128
|
-
bucketURL,
|
|
129
|
-
awsRegion,
|
|
130
|
-
builds
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function deployWithPrompt(config) {
|
|
134
|
-
return new _promise.default(resolve => {
|
|
135
|
-
const rl = _readline.default.createInterface(process.stdin, process.stdout);
|
|
136
|
-
const {
|
|
137
|
-
bucketURL,
|
|
138
|
-
awsRegion,
|
|
139
|
-
builds
|
|
140
|
-
} = config;
|
|
141
|
-
console.log('');
|
|
142
|
-
console.log('Does the following look OK?');
|
|
143
|
-
console.log('');
|
|
144
|
-
console.log(` Bucket URL: ${bucketURL}`);
|
|
145
|
-
console.log(` AWS Region: ${awsRegion}`);
|
|
146
|
-
console.log(` Builds: ${builds.join(', ')}`);
|
|
147
|
-
console.log('');
|
|
148
|
-
rl.setPrompt(' [yN] ');
|
|
149
|
-
rl.prompt();
|
|
150
|
-
rl.on('line', data => {
|
|
151
|
-
if (data === 'y' || data === 'yes') {
|
|
152
|
-
return deploy({
|
|
153
|
-
bucketURL,
|
|
154
|
-
awsRegion,
|
|
155
|
-
builds
|
|
156
|
-
}).then(() => rl.close());
|
|
157
|
-
}
|
|
158
|
-
process.exit(0);
|
|
159
|
-
}).on('close', resolve);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
function deployWithoutPrompt(config) {
|
|
163
|
-
_bBerLogger.default.notice('Deploy command run with "--yes", skipping confirmation');
|
|
164
|
-
return deploy(config);
|
|
165
|
-
}
|
|
166
|
-
function setCachePolicy({
|
|
167
|
-
bucketURL,
|
|
168
|
-
awsRegion
|
|
169
|
-
}, cacheArgs) {
|
|
170
|
-
var _context2;
|
|
171
|
-
console.log('Setting cache policy...');
|
|
172
|
-
const command = (0, _concat.default)(_context2 = [`aws s3 cp ${bucketURL} ${bucketURL}`, `--region ${awsRegion}`]).call(_context2, cacheArgs).join(' ');
|
|
173
|
-
return new _promise.default(resolve => run(command, resolve));
|
|
174
|
-
}
|
|
175
|
-
function main({
|
|
176
|
-
builds,
|
|
177
|
-
yes
|
|
178
|
-
}) {
|
|
179
|
-
let config = {};
|
|
180
|
-
return ensureAwsCli().then(ensureEnvVars).then(response => {
|
|
181
|
-
config = extractVars(_objectSpread(_objectSpread({}, response), {}, {
|
|
182
|
-
builds
|
|
183
|
-
}));
|
|
184
|
-
if (yes) return deployWithoutPrompt(config);
|
|
185
|
-
return deployWithPrompt(config);
|
|
186
|
-
}).then(() => setCachePolicy(config, cacheArgsBucket)).then(() => setCachePolicy(config, cacheArgsFiles)).then(() => setCachePolicy(config, cacheArgsHTML)).catch(_bBerLogger.default.error);
|
|
187
|
-
}
|
|
188
|
-
var _default = exports.default = main;
|