@canopycanopycanopy/b-ber-tasks 3.0.8-nav-memo.2 → 3.0.8-next.100
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/reader/index.js
DELETED
|
@@ -1,205 +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 _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
11
|
-
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
12
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
|
-
var _path2 = _interopRequireDefault(require("path"));
|
|
14
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
15
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
16
|
-
var _find = _interopRequireDefault(require("lodash/find"));
|
|
17
|
-
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
18
|
-
var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
|
|
19
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
20
|
-
var _recursiveReaddir = _interopRequireDefault(require("recursive-readdir"));
|
|
21
|
-
var _has = _interopRequireDefault(require("lodash/has"));
|
|
22
|
-
/* eslint-disable camelcase */
|
|
23
|
-
/* eslint-disable class-methods-use-this */
|
|
24
|
-
|
|
25
|
-
class Reader {
|
|
26
|
-
constructor() {
|
|
27
|
-
this.outputDirName = 'epub';
|
|
28
|
-
this.outputDir = _State.default.dist.root(this.outputDirName);
|
|
29
|
-
this.apiDir = _State.default.dist.root('api');
|
|
30
|
-
this.epubAssets = ['META-INF', 'OPS', 'mimetype'];
|
|
31
|
-
this.readerModuleName = '@canopycanopycanopy/b-ber-reader';
|
|
32
|
-
this.readerModuleDistDir = 'dist';
|
|
33
|
-
this.readerAppPath = null;
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line no-constructor-return
|
|
36
|
-
return this.createOutputDirs().then(() => this.ensureReaderModuleExists()).then(() => this.copyEpubToOutputDir()).then(() => this.writeBookManifest()).then(() => this.writeWebpubManifest()).then(() => this.copyReaderAppToOutputDir()).then(() => this.injectServerDataIntoTemplate())
|
|
37
|
-
// .then(() => this.updateLinkedResourcesWithAbsolutePaths())
|
|
38
|
-
.then(() => this.updateAssetURLsWithAbsolutePaths()).then(() => this.injectWebpubManifestLink()).catch(_bBerLogger.default.error);
|
|
39
|
-
}
|
|
40
|
-
get remoteURL() {
|
|
41
|
-
if (process.env.NODE_ENV === 'production' && (!_State.default.config || !_State.default.config.remote_url || /^http/.test(_State.default.config.remote_url) === false)) {
|
|
42
|
-
throw new Error('Task [build/reader] requires a remote_url to be set in config.yml');
|
|
43
|
-
}
|
|
44
|
-
return _State.default.config.remote_url || 'http://localhost:4000/';
|
|
45
|
-
}
|
|
46
|
-
createDirname(s) {
|
|
47
|
-
if (!s || typeof s !== 'string') {
|
|
48
|
-
return _crypto.default.randomBytes(20).toString('hex');
|
|
49
|
-
}
|
|
50
|
-
return s.replace(/[^0-9a-zA-Z-]/g, '-');
|
|
51
|
-
}
|
|
52
|
-
ensureReaderModuleExists() {
|
|
53
|
-
try {
|
|
54
|
-
this.readerAppPath = _path2.default.join(_path2.default.dirname(_path2.default.join(require.resolve(this.readerModuleName))), this.readerModuleDistDir);
|
|
55
|
-
return;
|
|
56
|
-
} catch (err) {
|
|
57
|
-
// module not found using require.resolve, so we check if there's a symlinked version available
|
|
58
|
-
_bBerLogger.default.warn(`Could not find globally installed module ${this.readerModuleName}`);
|
|
59
|
-
}
|
|
60
|
-
const {
|
|
61
|
-
paths
|
|
62
|
-
} = module;
|
|
63
|
-
let modulePath;
|
|
64
|
-
for (let i = 0; i < paths.length; i++) {
|
|
65
|
-
const _path = _path2.default.resolve(paths[i], this.readerModuleName);
|
|
66
|
-
if (_fsExtra.default.existsSync(_path)) {
|
|
67
|
-
modulePath = _path;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!modulePath) {
|
|
72
|
-
_bBerLogger.default.error(`Cannot find module ${this.readerModuleName}. Try running npm i -S ${this.readerModuleName}`);
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
this.readerAppPath = _fsExtra.default.realpathSync(_path2.default.join(modulePath, this.readerModuleDistDir));
|
|
76
|
-
const pkg = _fsExtra.default.readJsonSync(_path2.default.join(modulePath, this.readerModuleDistDir, 'package.json'));
|
|
77
|
-
_bBerLogger.default.warn(`Loaded ${this.readerModuleName} v${pkg.version}`);
|
|
78
|
-
return;
|
|
79
|
-
} catch (err) {
|
|
80
|
-
_bBerLogger.default.error(`
|
|
81
|
-
A symlinked version of ${this.readerModuleName} was found but is inaccessible.
|
|
82
|
-
Try running npm i -S ${this.readerModuleName}, or rebuilding the reader package if running this command in a development environment
|
|
83
|
-
`);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
createOutputDirs() {
|
|
88
|
-
return _fsExtra.default.ensureDir(this.outputDir).then(() => _fsExtra.default.ensureDir(this.apiDir));
|
|
89
|
-
}
|
|
90
|
-
copyEpubToOutputDir() {
|
|
91
|
-
var _context;
|
|
92
|
-
const epubDir = this.createDirname(this.getBookMetadata('identifier'));
|
|
93
|
-
const promises = (0, _map.default)(_context = this.epubAssets).call(_context, item => _fsExtra.default.move(_State.default.dist.root(item), _path2.default.join(this.outputDir, epubDir, item)));
|
|
94
|
-
return _promise.default.all(promises);
|
|
95
|
-
}
|
|
96
|
-
getBookMetadata(term) {
|
|
97
|
-
if (!term) return _State.default.metadata.json();
|
|
98
|
-
const entry = (0, _find.default)(_State.default.metadata.json(), {
|
|
99
|
-
term
|
|
100
|
-
});
|
|
101
|
-
if (entry && entry.value) return entry.value;
|
|
102
|
-
_bBerLogger.default.warn(`Could not find metadata value for ${term}`);
|
|
103
|
-
return '';
|
|
104
|
-
}
|
|
105
|
-
getProjectConfig(term) {
|
|
106
|
-
if (!term) return _State.default.config;
|
|
107
|
-
if (!(0, _has.default)(_State.default.config, term)) {
|
|
108
|
-
_bBerLogger.default.warn(`Invalid property for config: ${term}`);
|
|
109
|
-
}
|
|
110
|
-
return _State.default.config[term];
|
|
111
|
-
}
|
|
112
|
-
writeBookManifest() {
|
|
113
|
-
// Get metadata for books.json
|
|
114
|
-
const id = this.getBookMetadata('identifier');
|
|
115
|
-
const title = this.getBookMetadata('title');
|
|
116
|
-
const url = `${_bBerLib.Url.trimSlashes(this.remoteURL)}/${this.outputDirName}/${this.createDirname(id)}`;
|
|
117
|
-
const cover = `${url}/OPS/images/${this.getBookMetadata('cover')}`;
|
|
118
|
-
|
|
119
|
-
// Get config required by reader for books.json
|
|
120
|
-
const {
|
|
121
|
-
downloads,
|
|
122
|
-
ui_options,
|
|
123
|
-
layout
|
|
124
|
-
} = this.getProjectConfig();
|
|
125
|
-
const manifest = [{
|
|
126
|
-
title,
|
|
127
|
-
url,
|
|
128
|
-
cover,
|
|
129
|
-
id,
|
|
130
|
-
downloads,
|
|
131
|
-
ui_options,
|
|
132
|
-
layout
|
|
133
|
-
}];
|
|
134
|
-
|
|
135
|
-
// Write to an `api` dir in case the app is being deployed statically
|
|
136
|
-
return _fsExtra.default.writeJson(_path2.default.join(this.apiDir, 'books.json'), manifest);
|
|
137
|
-
}
|
|
138
|
-
writeWebpubManifest() {
|
|
139
|
-
const assetsDir = _path2.default.join(process.cwd(), this.outputDir, this.getBookMetadata('identifier'), 'OPS');
|
|
140
|
-
return (0, _recursiveReaddir.default)(assetsDir).then(files => {
|
|
141
|
-
const manifest = (0, _utils.generateWebpubManifest)(files);
|
|
142
|
-
_fsExtra.default.writeJson(_State.default.dist.root('manifest.json'), manifest);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
injectWebpubManifestLink() {
|
|
146
|
-
const indexHTML = _State.default.dist.root('index.html');
|
|
147
|
-
const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
|
|
148
|
-
let contents;
|
|
149
|
-
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
150
|
-
contents = contents.replace(/<\/head>/, `<link rel="manifest" type="application/webpub+json" href="${readerURL}manifest.json"></head>`);
|
|
151
|
-
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
152
|
-
}
|
|
153
|
-
copyReaderAppToOutputDir() {
|
|
154
|
-
var _context2;
|
|
155
|
-
const promises = (0, _map.default)(_context2 = _fsExtra.default.readdirSync(this.readerAppPath)).call(_context2, file => _fsExtra.default.copy(_path2.default.join(this.readerAppPath, file), _path2.default.resolve(_State.default.dist.root(file))));
|
|
156
|
-
return _promise.default.all(promises);
|
|
157
|
-
}
|
|
158
|
-
injectServerDataIntoTemplate() {
|
|
159
|
-
const indexHTML = _State.default.dist.root('index.html');
|
|
160
|
-
const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
|
|
161
|
-
const identifier = this.getBookMetadata('identifier');
|
|
162
|
-
const bookURL = `${readerURL}epub/${identifier}`;
|
|
163
|
-
const serverData = {
|
|
164
|
-
books: [{
|
|
165
|
-
title: this.getBookMetadata('title'),
|
|
166
|
-
url: bookURL,
|
|
167
|
-
cover: this.getBookMetadata('cover')
|
|
168
|
-
}],
|
|
169
|
-
bookURL,
|
|
170
|
-
projectURL: _bBerLib.Url.addTrailingSlash(this.getProjectConfig('remote_url')),
|
|
171
|
-
downloads: this.getProjectConfig('downloads'),
|
|
172
|
-
basePath: _bBerLib.Url.addTrailingSlash(this.getProjectConfig('base_path')),
|
|
173
|
-
loadRemoteLibrary: false,
|
|
174
|
-
uiOptions: this.getProjectConfig('ui_options'),
|
|
175
|
-
cache: this.getProjectConfig('cache'),
|
|
176
|
-
layout: this.getProjectConfig('layout')
|
|
177
|
-
};
|
|
178
|
-
let contents;
|
|
179
|
-
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
180
|
-
contents = contents.replace(/__SERVER_DATA__ = {}/, `__SERVER_DATA__ = ${(0, _stringify.default)(serverData)}`);
|
|
181
|
-
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Update URLs in CSS
|
|
185
|
-
updateLinkedResourcesWithAbsolutePaths() {
|
|
186
|
-
const indexContents = _fsExtra.default.readFileSync(_State.default.dist.root('index.html'), 'utf8');
|
|
187
|
-
const versionHash = indexContents.match(/link href="\/(\w+\.css)"/)[1];
|
|
188
|
-
const stylesheet = _State.default.dist.root(versionHash);
|
|
189
|
-
const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
|
|
190
|
-
let contents;
|
|
191
|
-
contents = _fsExtra.default.readFileSync(stylesheet, 'utf8');
|
|
192
|
-
contents = contents.replace(/url\(\//g, `url(${readerURL}`);
|
|
193
|
-
return _fsExtra.default.writeFile(stylesheet, contents);
|
|
194
|
-
}
|
|
195
|
-
updateAssetURLsWithAbsolutePaths() {
|
|
196
|
-
const indexHTML = _State.default.dist.root('index.html');
|
|
197
|
-
const readerURL = _bBerLib.Url.removeTrailingSlash(this.getProjectConfig('reader_url'));
|
|
198
|
-
let contents;
|
|
199
|
-
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
200
|
-
contents = contents.replace(/(src|href)="(\/[^"]+?)"/g, `$1="${readerURL}$2"`);
|
|
201
|
-
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const main = () => new Reader();
|
|
205
|
-
var _default = exports.default = main;
|
package/dist/render/index.js
DELETED
|
@@ -1,53 +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 _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
|
|
11
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
12
|
-
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
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 _bBerMarkdownRenderer = _interopRequireDefault(require("@canopycanopycanopy/b-ber-markdown-renderer"));
|
|
17
|
-
var _Xhtml = _interopRequireDefault(require("@canopycanopycanopy/b-ber-templates/Xhtml"));
|
|
18
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
19
|
-
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
20
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
21
|
-
const writeMarkupToFile = (fname, markup) => {
|
|
22
|
-
_fsExtra.default.writeFile(_State.default.dist.text(`${fname}.xhtml`), markup).then(() => _bBerLogger.default.info(`render xhtml [${_path.default.basename(fname)}.xhtml]`));
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// Convert Markdown to HTML and wrap with page template
|
|
26
|
-
const createPageLayout = (fileName, data) => {
|
|
27
|
-
const textDir = _State.default.dist.text();
|
|
28
|
-
const body = _bBerMarkdownRenderer.default.render(fileName, data);
|
|
29
|
-
const markup = _bBerLib.Template.render(body, _Xhtml.default.body());
|
|
30
|
-
return _fsExtra.default.mkdirp(textDir).then(() => writeMarkupToFile(fileName, markup)).catch(_bBerLogger.default.error);
|
|
31
|
-
};
|
|
32
|
-
const createXTHMLFile = fpath => _fsExtra.default.readFile(fpath, 'utf8').then(data => createPageLayout(_path.default.basename(fpath, '.md'), data)).catch(_bBerLogger.default.error);
|
|
33
|
-
function render() {
|
|
34
|
-
const markdownDir = _State.default.src.markdown();
|
|
35
|
-
return _fsExtra.default.readdir(markdownDir).then(files => {
|
|
36
|
-
var _context, _context2;
|
|
37
|
-
// Sort the files in the order that they appear in `type.yml`, so that they
|
|
38
|
-
// and the images they contain are processed in the correct order
|
|
39
|
-
const promises = (0, _reduce.default)(_context = (0, _sort.default)(_context2 = (0, _filter.default)(files).call(files, a => a.charAt(0) !== '.')).call(_context2, (a, b) => {
|
|
40
|
-
const fileNameA = _path.default.basename(a, '.md');
|
|
41
|
-
const fileNameB = _path.default.basename(b, '.md');
|
|
42
|
-
const indexA = (0, _indexOf.default)(_State.default).call(_State.default, 'spine.flattened', {
|
|
43
|
-
fileName: fileNameA
|
|
44
|
-
});
|
|
45
|
-
const indexB = (0, _indexOf.default)(_State.default).call(_State.default, 'spine.flattened', {
|
|
46
|
-
fileName: fileNameB
|
|
47
|
-
});
|
|
48
|
-
return indexA < indexB ? -1 : indexA > indexB ? 1 : 0;
|
|
49
|
-
})).call(_context, (acc, curr) => acc.then(() => createXTHMLFile(_path.default.join(markdownDir, curr)).then(() => _bBerLogger.default.info(`render markdown [${_path.default.basename(curr)}]`))), _promise.default.resolve());
|
|
50
|
-
return promises.catch(_bBerLogger.default.error);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
var _default = exports.default = render;
|
package/dist/sample/index.js
DELETED
|
@@ -1,11 +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 _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
10
|
-
const sample = () => _promise.default.resolve();
|
|
11
|
-
var _default = exports.default = sample;
|
package/dist/sass/index.js
DELETED
|
@@ -1,185 +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 _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
10
|
-
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
11
|
-
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
12
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
13
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
14
|
-
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
15
|
-
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
16
|
-
var _path = _interopRequireDefault(require("path"));
|
|
17
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
18
|
-
var _sass = _interopRequireDefault(require("sass"));
|
|
19
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
20
|
-
var _autoprefixer = _interopRequireDefault(require("autoprefixer"));
|
|
21
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
22
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
23
|
-
// dirnames that may be referenced in the theme. we copy over assets when
|
|
24
|
-
// running the sass task
|
|
25
|
-
const ASSET_DIRNAMES = ['fonts', 'images'];
|
|
26
|
-
const autoprefixerOptions = _State.default.config.autoprefixer_options || {
|
|
27
|
-
overrideBrowserslist: ['defaults', '> 1%', 'not dead', 'not IE 11'],
|
|
28
|
-
flexbox: 'no-2009'
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Check to see if there's an `application.scss` in `_stylesheets`, and if so
|
|
32
|
-
// load that; else verify that a theme is selected in `config`, and that the
|
|
33
|
-
// theme's `application.scss` exists, then load that; else write a blank file.
|
|
34
|
-
const createSCSSString = () => {
|
|
35
|
-
const chunks = [];
|
|
36
|
-
const {
|
|
37
|
-
theme
|
|
38
|
-
} = _State.default;
|
|
39
|
-
const themeName = theme.name;
|
|
40
|
-
const themeSettingsPath = _State.default.src.stylesheets(themeName, '_settings.scss');
|
|
41
|
-
const themeOverridesPath = _State.default.src.stylesheets(themeName, '_overrides.scss');
|
|
42
|
-
const themeStylesPath = theme.entry;
|
|
43
|
-
|
|
44
|
-
// load user-defined variables
|
|
45
|
-
if (_fsExtra.default.existsSync(themeSettingsPath)) {
|
|
46
|
-
const variableOverrides = _fsExtra.default.readFileSync(themeSettingsPath);
|
|
47
|
-
_bBerLogger.default.info(`sass use overrides [${_path.default.basename(themeSettingsPath)}]`);
|
|
48
|
-
_bBerLogger.default.info('sass prepend overrides');
|
|
49
|
-
chunks.push(variableOverrides);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// load theme styles
|
|
53
|
-
if (_fsExtra.default.existsSync(themeStylesPath)) {
|
|
54
|
-
const themeStyles = _fsExtra.default.readFileSync(themeStylesPath);
|
|
55
|
-
_bBerLogger.default.info(`sass attempt build with [${themeName}] theme`);
|
|
56
|
-
chunks.push(themeStyles);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// load user-defined styles
|
|
60
|
-
if (_fsExtra.default.existsSync(themeOverridesPath)) {
|
|
61
|
-
const styleOverrides = _fsExtra.default.readFileSync(themeOverridesPath);
|
|
62
|
-
_bBerLogger.default.info(`sass use user-defined styles [${_path.default.basename(themeOverridesPath)}]`);
|
|
63
|
-
_bBerLogger.default.info('sass append user-defined styles');
|
|
64
|
-
chunks.push(styleOverrides);
|
|
65
|
-
}
|
|
66
|
-
if (chunks.length < 1) _bBerLogger.default.error('No readable stylesheets were found');
|
|
67
|
-
return (0, _concat.default)(Buffer).call(Buffer, chunks);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// make sure the compiled output dir exists
|
|
71
|
-
const ensureCSSDir = () => _fsExtra.default.mkdirp(_State.default.dist.stylesheets());
|
|
72
|
-
|
|
73
|
-
// copy assets that exist in theme directory to the corresponding directory in
|
|
74
|
-
// _project:
|
|
75
|
-
//
|
|
76
|
-
// my-theme/fonts/my-font.ttf -> _project/_fonts/my-font.ttf
|
|
77
|
-
// my-theme/images/my-image.jpg -> _project/_images/my-image.jpg
|
|
78
|
-
//
|
|
79
|
-
// if the asset already exists in the _project dir, it is *not* overwritten.
|
|
80
|
-
//
|
|
81
|
-
// these assets are then copied to the correct build dir by the `copy` task.
|
|
82
|
-
//
|
|
83
|
-
const copyThemeAssets = () => {
|
|
84
|
-
const {
|
|
85
|
-
theme
|
|
86
|
-
} = _State.default;
|
|
87
|
-
const fileData = (0, _reduce.default)(ASSET_DIRNAMES).call(ASSET_DIRNAMES, (acc, curr) => {
|
|
88
|
-
var _context, _context2;
|
|
89
|
-
const themePath = _path.default.resolve(_path.default.dirname(theme.entry), curr);
|
|
90
|
-
const srcPath = _State.default.src.root(`_${curr}`);
|
|
91
|
-
_fsExtra.default.mkdirpSync(srcPath);
|
|
92
|
-
try {
|
|
93
|
-
_fsExtra.default.lstatSync(themePath).isDirectory();
|
|
94
|
-
} catch (err) {
|
|
95
|
-
if (err.code === 'ENOENT') return acc;
|
|
96
|
-
throw new Error(`There was a problem copying [${themePath}] to [${srcPath}]`);
|
|
97
|
-
}
|
|
98
|
-
const data = (0, _map.default)(_context = (0, _filter.default)(_context2 = _fsExtra.default.readdirSync(themePath)).call(_context2, a => a.charAt(0) !== '.')).call(_context, fileName => ({
|
|
99
|
-
input: _path.default.join(themePath, fileName),
|
|
100
|
-
output: _path.default.join(srcPath, fileName)
|
|
101
|
-
}));
|
|
102
|
-
return (0, _concat.default)(acc).call(acc, data);
|
|
103
|
-
}, []);
|
|
104
|
-
const promises = (0, _map.default)(fileData).call(fileData, ({
|
|
105
|
-
input,
|
|
106
|
-
output
|
|
107
|
-
}) => _fsExtra.default.copy(input, output, {
|
|
108
|
-
overwrite: false,
|
|
109
|
-
errorOnExist: false
|
|
110
|
-
}));
|
|
111
|
-
return _promise.default.all(promises);
|
|
112
|
-
};
|
|
113
|
-
function resolveImportedModule(importPath) {
|
|
114
|
-
// Remove preceeding tilde
|
|
115
|
-
const trimmedImportPath = (0, _slice.default)(importPath).call(importPath, 1);
|
|
116
|
-
|
|
117
|
-
// Get the import path as an array
|
|
118
|
-
let importTree = trimmedImportPath.split(_path.default.sep);
|
|
119
|
-
|
|
120
|
-
// Remove empty entries caused by leading/trailing slashes
|
|
121
|
-
importTree = (0, _filter.default)(importTree).call(importTree, Boolean);
|
|
122
|
-
|
|
123
|
-
// Define both the scope and the name - the scope will be
|
|
124
|
-
// used to resolve the import and get the necessary path, the
|
|
125
|
-
// name will be used to construct the final file path
|
|
126
|
-
let moduleScope = '';
|
|
127
|
-
let moduleName = importTree.shift();
|
|
128
|
-
|
|
129
|
-
// Allow scoped packages
|
|
130
|
-
if (moduleName[0] === '@') {
|
|
131
|
-
moduleScope = moduleName;
|
|
132
|
-
moduleName = importTree.shift();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// @foo/bar | foo
|
|
136
|
-
const moduleNameWithScope = _path.default.join(moduleScope, moduleName);
|
|
137
|
-
|
|
138
|
-
// Get the module
|
|
139
|
-
const modulePath = require.resolve(moduleNameWithScope, {
|
|
140
|
-
paths: [_path.default.join(_path.default.dirname(_State.default.theme.entry))]
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// No path was provided, return the imported node module
|
|
144
|
-
if (!importTree.length) return modulePath;
|
|
145
|
-
|
|
146
|
-
// User is importing a specific file, find it and return its location. Remove
|
|
147
|
-
// the modules scope from the name when finding the path
|
|
148
|
-
const moduleIndex = (0, _indexOf.default)(modulePath).call(modulePath, moduleName) + moduleName.length;
|
|
149
|
-
const packagePath = (0, _slice.default)(modulePath).call(modulePath, 0, moduleIndex);
|
|
150
|
-
const importedModule = _path.default.join(packagePath, ...importTree);
|
|
151
|
-
return importedModule;
|
|
152
|
-
}
|
|
153
|
-
const renderCSS = scssString => new _promise.default(resolve => {
|
|
154
|
-
_sass.default.render({
|
|
155
|
-
// Importer allows use of '~' to denote node_modules directory in SCSS files
|
|
156
|
-
importer: (url, _file, done) => {
|
|
157
|
-
const file = url[0] === '~' ? resolveImportedModule(url) : url;
|
|
158
|
-
return done({
|
|
159
|
-
file
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
// Add build vars at runtime with the SCSS buffer (which is transformed
|
|
163
|
-
// to string in the backticks)
|
|
164
|
-
data: `$build: "${_State.default.build}";${scssString}`,
|
|
165
|
-
includePaths: [_State.default.src.stylesheets(), _path.default.dirname(_State.default.theme.entry), _path.default.dirname(_path.default.dirname(_State.default.theme.entry))],
|
|
166
|
-
outputStyle: _State.default.env === 'production' ? 'compressed' : 'expanded',
|
|
167
|
-
errLogToConsole: true
|
|
168
|
-
}, (err, result) => {
|
|
169
|
-
if (err) throw err;
|
|
170
|
-
resolve(result);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
const applyPostProcessing = ({
|
|
174
|
-
css
|
|
175
|
-
}) => (0, _postcss.default)((0, _autoprefixer.default)(autoprefixerOptions)).process(css, {
|
|
176
|
-
from: undefined
|
|
177
|
-
});
|
|
178
|
-
const writeCSSFile = ({
|
|
179
|
-
css
|
|
180
|
-
}) => {
|
|
181
|
-
const fileName = _State.default.env === 'production' ? `${_State.default.hash}.css` : 'application.css';
|
|
182
|
-
return _fsExtra.default.writeFile(_State.default.dist.stylesheets(fileName), css);
|
|
183
|
-
};
|
|
184
|
-
const sass = () => ensureCSSDir().then(copyThemeAssets).then(createSCSSString).then(renderCSS).then(applyPostProcessing).then(writeCSSFile).catch(_bBerLogger.default.error);
|
|
185
|
-
var _default = exports.default = sass;
|
package/dist/scripts/index.js
DELETED
|
@@ -1,54 +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 _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
11
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
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
|
-
var _uglifyJs = _interopRequireDefault(require("uglify-js"));
|
|
17
|
-
const uglifyOptions = _State.default.config.uglify_options || {
|
|
18
|
-
compress: {
|
|
19
|
-
// eslint-disable-next-line camelcase
|
|
20
|
-
dead_code: true,
|
|
21
|
-
conditionals: true,
|
|
22
|
-
booleans: true
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const uglify = contents => {
|
|
26
|
-
const result = _uglifyJs.default.minify(contents, uglifyOptions);
|
|
27
|
-
if (result.error) throw result.error;
|
|
28
|
-
if (result.warnings) _bBerLogger.default.warn(result.warnings);
|
|
29
|
-
return result.code;
|
|
30
|
-
};
|
|
31
|
-
const optimized = files => {
|
|
32
|
-
const contents = (0, _map.default)(files).call(files, file => _fsExtra.default.readFileSync(_path.default.resolve(_State.default.src.javascripts(file)), 'utf8')).join('');
|
|
33
|
-
const js = uglify(contents);
|
|
34
|
-
const {
|
|
35
|
-
hash
|
|
36
|
-
} = _State.default;
|
|
37
|
-
const out = _State.default.dist.javascripts(`${hash}.js`);
|
|
38
|
-
return _fsExtra.default.writeFile(out, js).then(() => _bBerLogger.default.info('scripts emit [%s]', `javascripts${_path.default.sep}${_path.default.basename(out)}`));
|
|
39
|
-
};
|
|
40
|
-
const unoptimized = files => {
|
|
41
|
-
const promises = (0, _map.default)(files).call(files, file => {
|
|
42
|
-
const input = _State.default.src.javascripts(file);
|
|
43
|
-
const output = _State.default.dist.javascripts(file);
|
|
44
|
-
return _fsExtra.default.copy(input, output).then(() => _bBerLogger.default.info('scripts emit [%s]', `javascripts${_path.default.sep}${_path.default.basename(output)}`));
|
|
45
|
-
});
|
|
46
|
-
return _promise.default.all(promises);
|
|
47
|
-
};
|
|
48
|
-
const write = () => _fsExtra.default.readdir(_State.default.src.javascripts()).then(_files => {
|
|
49
|
-
const files = (0, _filter.default)(_files).call(_files, a => _path.default.extname(a) === '.js');
|
|
50
|
-
return (_State.default.env === 'production' ? optimized : unoptimized)(files);
|
|
51
|
-
});
|
|
52
|
-
const ensureDir = () => _fsExtra.default.mkdirp(_State.default.dist.javascripts());
|
|
53
|
-
const scripts = () => ensureDir().then(write).catch(_bBerLogger.default.error);
|
|
54
|
-
var _default = exports.default = scripts;
|
package/dist/serialize.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
|
4
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
5
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
6
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
7
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.default = void 0;
|
|
11
|
-
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
12
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
13
|
-
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
14
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
15
|
-
var tasks = _interopRequireWildcard(require(".."));
|
|
16
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof _WeakMap) return null; var r = new _WeakMap(), t = new _WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? _Object$getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? _Object$defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
-
// This is basically the engine of our application. `serialize` is responsible
|
|
19
|
-
// for taking in the list of tasks that need to be run, calling their
|
|
20
|
-
// associated handlers, handling errors if any are encountered, and then
|
|
21
|
-
// calling the next task in the list.
|
|
22
|
-
//
|
|
23
|
-
// b-ber is designed so that there are two components to each task:
|
|
24
|
-
//
|
|
25
|
-
// 1) a command script that's invoked by the user from the CLI, used to
|
|
26
|
-
// parse the CLI arguments
|
|
27
|
-
//
|
|
28
|
-
// 2) a handler script that actually does the work
|
|
29
|
-
//
|
|
30
|
-
// `serialize` works by calling the handlers that are exported by `bber-
|
|
31
|
-
// output/index.js` directly.
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
const validate = fn => {
|
|
35
|
-
if (typeof fn !== 'function') {
|
|
36
|
-
throw new Error(`async#serialize: Invalid parameter [${fn}] is [${typeof fn}], expected [function]`);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const done = resp => {
|
|
40
|
-
_bBerLogger.default.notify('done', {
|
|
41
|
-
state: _State.default
|
|
42
|
-
});
|
|
43
|
-
return resp;
|
|
44
|
-
};
|
|
45
|
-
const taskReducer = (acc, curr) => {
|
|
46
|
-
const fn = tasks[curr] || curr;
|
|
47
|
-
validate(fn);
|
|
48
|
-
return acc.then(resp => {
|
|
49
|
-
_bBerLogger.default.notify('start', curr);
|
|
50
|
-
return fn(resp).then(resp2 => {
|
|
51
|
-
_bBerLogger.default.notify('stop', curr);
|
|
52
|
-
return resp2;
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const serialize = sequence => (0, _reduce.default)(sequence).call(sequence, taskReducer, _promise.default.resolve()).then(done).catch(_bBerLogger.default.error);
|
|
57
|
-
var _default = exports.default = serialize;
|
package/dist/serve/index.js
DELETED
|
@@ -1,83 +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 _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
12
|
-
var _sequences = _interopRequireDefault(require("@canopycanopycanopy/b-ber-shapes-sequences/sequences"));
|
|
13
|
-
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
14
|
-
var _browserSync = require("browser-sync");
|
|
15
|
-
var _ = require("..");
|
|
16
|
-
const browserSync = (0, _browserSync.create)();
|
|
17
|
-
const port = 4000;
|
|
18
|
-
const debounceSpeed = 500;
|
|
19
|
-
const config = build => url => () => {
|
|
20
|
-
_State.default.update('build', build);
|
|
21
|
-
_State.default.update('footnotes', []);
|
|
22
|
-
_State.default.update('config.base_url', '/');
|
|
23
|
-
_State.default.update('config.base_path', '/');
|
|
24
|
-
_State.default.update('config.remote_url', url);
|
|
25
|
-
_State.default.update('config.reader_url', url);
|
|
26
|
-
return (0, _.serialize)(_sequences.default[build]);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Declared below once browserSync has been initialized
|
|
30
|
-
let update = async () => {};
|
|
31
|
-
const reload = () => update().then(browserSync.reload);
|
|
32
|
-
const browserSyncPlugins = [{
|
|
33
|
-
module: 'bs-html-injector',
|
|
34
|
-
options: {
|
|
35
|
-
files: [{
|
|
36
|
-
match: [_path.default.resolve('_project', '**', '*.scss'), _path.default.resolve('_project', '**', '*.js'), _path.default.resolve('_project', '**', '*.md')],
|
|
37
|
-
fn: (0, _debounce.default)(() => reload(), debounceSpeed, {
|
|
38
|
-
leading: false,
|
|
39
|
-
trailing: true
|
|
40
|
-
})
|
|
41
|
-
}]
|
|
42
|
-
}
|
|
43
|
-
}];
|
|
44
|
-
const browserSyncMiddleware = (req, res, next) => {
|
|
45
|
-
// Set headers for XHTML files to allow document.write
|
|
46
|
-
if (/\.xhtml$/.test(req.url)) {
|
|
47
|
-
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
|
48
|
-
}
|
|
49
|
-
next();
|
|
50
|
-
};
|
|
51
|
-
const init = build => new _promise.default(resolve => {
|
|
52
|
-
const options = {
|
|
53
|
-
port,
|
|
54
|
-
open: false,
|
|
55
|
-
// Opens browser programatically below
|
|
56
|
-
// reloadDelay: 2000
|
|
57
|
-
// reloadDebounce: 2000
|
|
58
|
-
// reloadThrottle: 2000
|
|
59
|
-
server: {
|
|
60
|
-
baseDir: _path.default.resolve(`project-${build}`),
|
|
61
|
-
middleware: browserSyncMiddleware
|
|
62
|
-
},
|
|
63
|
-
plugins: browserSyncPlugins
|
|
64
|
-
};
|
|
65
|
-
browserSync.init(options, resolve);
|
|
66
|
-
});
|
|
67
|
-
const serve = async ({
|
|
68
|
-
build: buildOption,
|
|
69
|
-
external
|
|
70
|
-
}) => {
|
|
71
|
-
const location = external ? 'external' : 'local';
|
|
72
|
-
const build = buildOption || 'reader';
|
|
73
|
-
await init(build);
|
|
74
|
-
const url = browserSync.getOption('urls').get(location);
|
|
75
|
-
update = config(build)(url);
|
|
76
|
-
await update();
|
|
77
|
-
|
|
78
|
-
// Update the location in the config object so that a call can be made
|
|
79
|
-
// to openBrowser once the project has been built
|
|
80
|
-
browserSync.instance.setOption('open', location);
|
|
81
|
-
browserSync.instance.utils.openBrowser(url, browserSync.instance.options, browserSync.instance);
|
|
82
|
-
};
|
|
83
|
-
var _default = exports.default = serve;
|