@canopycanopycanopy/b-ber-tasks 1.2.15 → 2.0.0
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/dist/reader/index.js +26 -8
- package/dist/sass/index.js +21 -19
- package/dist/serve/index.js +42 -35
- package/package.json +13 -12
package/dist/reader/index.js
CHANGED
|
@@ -36,6 +36,8 @@ var _recursiveReaddir = _interopRequireDefault(require("recursive-readdir"));
|
|
|
36
36
|
|
|
37
37
|
var _has = _interopRequireDefault(require("lodash/has"));
|
|
38
38
|
|
|
39
|
+
/* eslint-disable camelcase */
|
|
40
|
+
|
|
39
41
|
/* eslint-disable class-methods-use-this */
|
|
40
42
|
class Reader {
|
|
41
43
|
constructor() {
|
|
@@ -45,8 +47,10 @@ class Reader {
|
|
|
45
47
|
this.epubAssets = ['META-INF', 'OPS', 'mimetype'];
|
|
46
48
|
this.readerModuleName = '@canopycanopycanopy/b-ber-reader';
|
|
47
49
|
this.readerModuleDistDir = 'dist';
|
|
48
|
-
this.readerAppPath = null;
|
|
49
|
-
|
|
50
|
+
this.readerAppPath = null; // eslint-disable-next-line no-constructor-return
|
|
51
|
+
|
|
52
|
+
return this.createOutputDirs().then(() => this.ensureReaderModuleExists()).then(() => this.copyEpubToOutputDir()).then(() => this.writeBookManifest()).then(() => this.writeWebpubManifest()).then(() => this.copyReaderAppToOutputDir()).then(() => this.injectServerDataIntoTemplate()) // .then(() => this.updateLinkedResourcesWithAbsolutePaths())
|
|
53
|
+
.then(() => this.updateAssetURLsWithAbsolutePaths()).then(() => this.injectWebpubManifestLink()).catch(_bBerLogger.default.error);
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
get remoteURL() {
|
|
@@ -123,6 +127,7 @@ class Reader {
|
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
getBookMetadata(term) {
|
|
130
|
+
if (!term) return _State.default.metadata.json();
|
|
126
131
|
const entry = (0, _find.default)(_State.default.metadata.json(), {
|
|
127
132
|
term
|
|
128
133
|
});
|
|
@@ -134,6 +139,8 @@ class Reader {
|
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
getProjectConfig(term) {
|
|
142
|
+
if (!term) return _State.default.config;
|
|
143
|
+
|
|
137
144
|
if (!(0, _has.default)(_State.default.config, term)) {
|
|
138
145
|
_bBerLogger.default.warn(`Invalid property for config: ${term}`);
|
|
139
146
|
}
|
|
@@ -142,16 +149,26 @@ class Reader {
|
|
|
142
149
|
}
|
|
143
150
|
|
|
144
151
|
writeBookManifest() {
|
|
145
|
-
|
|
152
|
+
// Get metadata for books.json
|
|
153
|
+
const id = this.getBookMetadata('identifier');
|
|
146
154
|
const title = this.getBookMetadata('title');
|
|
147
|
-
const url = `${_bBerLib.Url.trimSlashes(this.remoteURL)}/${this.outputDirName}/${this.createDirname(
|
|
148
|
-
const cover = `${url}/OPS/images/${this.getBookMetadata('cover')}`;
|
|
155
|
+
const url = `${_bBerLib.Url.trimSlashes(this.remoteURL)}/${this.outputDirName}/${this.createDirname(id)}`;
|
|
156
|
+
const cover = `${url}/OPS/images/${this.getBookMetadata('cover')}`; // Get config required by reader for books.json
|
|
157
|
+
|
|
158
|
+
const {
|
|
159
|
+
downloads,
|
|
160
|
+
ui_options,
|
|
161
|
+
layout
|
|
162
|
+
} = this.getProjectConfig();
|
|
149
163
|
const manifest = [{
|
|
150
164
|
title,
|
|
151
165
|
url,
|
|
152
166
|
cover,
|
|
153
|
-
id
|
|
154
|
-
|
|
167
|
+
id,
|
|
168
|
+
downloads,
|
|
169
|
+
ui_options,
|
|
170
|
+
layout
|
|
171
|
+
}]; // Write to an `api` dir in case the app is being deployed statically
|
|
155
172
|
|
|
156
173
|
return _fsExtra.default.writeJson(_path2.default.join(this.apiDir, 'books.json'), manifest);
|
|
157
174
|
}
|
|
@@ -210,7 +227,8 @@ class Reader {
|
|
|
210
227
|
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
211
228
|
contents = contents.replace(/__SERVER_DATA__ = {}/, `__SERVER_DATA__ = ${(0, _stringify.default)(serverData)}`);
|
|
212
229
|
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
213
|
-
}
|
|
230
|
+
} // Update URLs in CSS
|
|
231
|
+
|
|
214
232
|
|
|
215
233
|
updateLinkedResourcesWithAbsolutePaths() {
|
|
216
234
|
const indexContents = _fsExtra.default.readFileSync(_State.default.dist.root('index.html'), 'utf8');
|
package/dist/sass/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State
|
|
|
42
42
|
// running the sass task
|
|
43
43
|
const ASSET_DIRNAMES = ['fonts', 'images'];
|
|
44
44
|
const autoprefixerOptions = _State.default.config.autoprefixer_options || {
|
|
45
|
-
overrideBrowserslist: ['
|
|
45
|
+
overrideBrowserslist: ['defaults', '> 1%', 'not dead', 'not IE 11'],
|
|
46
46
|
flexbox: 'no-2009'
|
|
47
47
|
}; // Check to see if there's an `application.scss` in `_stylesheets`, and if so
|
|
48
48
|
// load that; else verify that a theme is selected in `config`, and that the
|
|
@@ -182,24 +182,26 @@ function resolveImportedModule(importPath) {
|
|
|
182
182
|
return importedModule;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
const renderCSS = scssString => new _promise.default(resolve =>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
185
|
+
const renderCSS = scssString => new _promise.default(resolve => {
|
|
186
|
+
_sass.default.render({
|
|
187
|
+
// Importer allows use of '~' to denote node_modules directory in SCSS files
|
|
188
|
+
importer: (url, _file, done) => {
|
|
189
|
+
const file = url[0] === '~' ? resolveImportedModule(url) : url;
|
|
190
|
+
return done({
|
|
191
|
+
file
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
// Add build vars at runtime with the SCSS buffer (which is transformed
|
|
195
|
+
// to string in the backticks)
|
|
196
|
+
data: `$build: "${_State.default.build}";${scssString}`,
|
|
197
|
+
includePaths: [_State.default.src.stylesheets(), _path.default.dirname(_State.default.theme.entry), _path.default.dirname(_path.default.dirname(_State.default.theme.entry))],
|
|
198
|
+
outputStyle: _State.default.env === 'production' ? 'compressed' : 'expanded',
|
|
199
|
+
errLogToConsole: true
|
|
200
|
+
}, (err, result) => {
|
|
201
|
+
if (err) throw err;
|
|
202
|
+
resolve(result);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
203
205
|
|
|
204
206
|
const applyPostProcessing = ({
|
|
205
207
|
css
|
package/dist/serve/index.js
CHANGED
|
@@ -49,47 +49,54 @@ let update = async () => {};
|
|
|
49
49
|
|
|
50
50
|
const reload = () => update().then(browserSync.reload);
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
52
|
+
const browserSyncPlugins = [{
|
|
53
|
+
module: 'bs-html-injector',
|
|
54
|
+
options: {
|
|
55
|
+
files: [{
|
|
56
|
+
match: [_path.default.resolve('_project', '**', '*.scss'), _path.default.resolve('_project', '**', '*.js'), _path.default.resolve('_project', '**', '*.md')],
|
|
57
|
+
fn: (0, _debounce.default)(() => reload(), debounceSpeed, {
|
|
58
|
+
leading: false,
|
|
59
|
+
trailing: true
|
|
60
|
+
})
|
|
61
|
+
}]
|
|
62
|
+
}
|
|
63
|
+
}];
|
|
64
|
+
|
|
65
|
+
const browserSyncMiddleware = (req, res, next) => {
|
|
66
|
+
// Set headers for XHTML files to allow document.write
|
|
67
|
+
if (/\.xhtml$/.test(req.url)) {
|
|
68
|
+
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
next();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const init = build => new _promise.default(resolve => {
|
|
75
|
+
const options = {
|
|
76
|
+
port,
|
|
77
|
+
open: false,
|
|
78
|
+
// Opens browser programatically below
|
|
79
|
+
// reloadDelay: 2000
|
|
80
|
+
// reloadDebounce: 2000
|
|
81
|
+
// reloadThrottle: 2000
|
|
82
|
+
server: {
|
|
83
|
+
baseDir: _path.default.resolve(`project-${build}`),
|
|
84
|
+
middleware: browserSyncMiddleware
|
|
85
|
+
},
|
|
86
|
+
plugins: browserSyncPlugins
|
|
87
|
+
};
|
|
88
|
+
browserSync.init(options, resolve);
|
|
89
|
+
});
|
|
83
90
|
|
|
84
91
|
const serve = async ({
|
|
85
|
-
build,
|
|
92
|
+
build: buildOption,
|
|
86
93
|
external
|
|
87
94
|
}) => {
|
|
88
95
|
const location = external ? 'external' : 'local';
|
|
89
|
-
const
|
|
90
|
-
await init(
|
|
96
|
+
const build = buildOption || 'reader';
|
|
97
|
+
await init(build);
|
|
91
98
|
const url = browserSync.getOption('urls').get(location);
|
|
92
|
-
update = config(
|
|
99
|
+
update = config(build)(url);
|
|
93
100
|
await update(); // Update the location in the config object so that a call can be made
|
|
94
101
|
// to openBrowser once the project has been built
|
|
95
102
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-tasks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/runtime-corejs3": "^7.10.5",
|
|
22
|
-
"@canopycanopycanopy/b-ber-lib": "
|
|
23
|
-
"@canopycanopycanopy/b-ber-logger": "
|
|
24
|
-
"@canopycanopycanopy/b-ber-markdown-renderer": "
|
|
25
|
-
"@canopycanopycanopy/b-ber-reader": "
|
|
26
|
-
"@canopycanopycanopy/b-ber-resources": "
|
|
27
|
-
"@canopycanopycanopy/b-ber-shapes-sequences": "
|
|
28
|
-
"@canopycanopycanopy/b-ber-templates": "
|
|
29
|
-
"@canopycanopycanopy/b-ber-validator": "
|
|
22
|
+
"@canopycanopycanopy/b-ber-lib": "2.0.0",
|
|
23
|
+
"@canopycanopycanopy/b-ber-logger": "2.0.0",
|
|
24
|
+
"@canopycanopycanopy/b-ber-markdown-renderer": "2.0.0",
|
|
25
|
+
"@canopycanopycanopy/b-ber-reader": "2.0.0",
|
|
26
|
+
"@canopycanopycanopy/b-ber-resources": "2.0.0",
|
|
27
|
+
"@canopycanopycanopy/b-ber-shapes-sequences": "2.0.0",
|
|
28
|
+
"@canopycanopycanopy/b-ber-templates": "2.0.0",
|
|
29
|
+
"@canopycanopycanopy/b-ber-validator": "2.0.0",
|
|
30
30
|
"autoprefixer": "^9.6.1",
|
|
31
31
|
"browser-sync": "^2.27.7",
|
|
32
32
|
"bs-html-injector": "^3.0.3",
|
|
@@ -54,9 +54,10 @@
|
|
|
54
54
|
"@babel/cli": "^7.10.5",
|
|
55
55
|
"@babel/core": "^7.10.5",
|
|
56
56
|
"@babel/preset-env": "^7.10.4",
|
|
57
|
-
"
|
|
57
|
+
"browserslist": "^4.17.4",
|
|
58
|
+
"jest": "^26.6.3",
|
|
58
59
|
"mock-fs": "^4.4.2",
|
|
59
|
-
"rimraf": "^2.
|
|
60
|
+
"rimraf": "^2.7.1"
|
|
60
61
|
},
|
|
61
62
|
"files": [
|
|
62
63
|
"dist"
|
|
@@ -75,5 +76,5 @@
|
|
|
75
76
|
"url": "https://maxwellsimmer.com"
|
|
76
77
|
}
|
|
77
78
|
],
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "dbeae192709705f5bc211195ff343cbd999f9caf"
|
|
79
80
|
}
|