@canopycanopycanopy/b-ber-tasks 2.0.0 → 2.0.3
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/clean/index.js +0 -15
- package/dist/container/index.js +1 -20
- package/dist/copy/index.js +2 -20
- package/dist/cover/index.js +20 -75
- package/dist/deploy/index.js +11 -54
- package/dist/epub/index.js +0 -12
- package/dist/footnotes/index.js +0 -27
- package/dist/generate/index.js +5 -32
- package/dist/index.js +0 -52
- package/dist/init/index.js +4 -29
- package/dist/inject/index.js +3 -31
- package/dist/loi/index.js +16 -61
- package/dist/mobi/index.js +8 -17
- package/dist/mobi/mobi-css.js +2 -39
- package/dist/opf/ManifestAndMetadata.js +18 -35
- package/dist/opf/Navigation.js +28 -82
- package/dist/opf/Opf.js +3 -20
- package/dist/opf/helpers.js +5 -20
- package/dist/opf/index.js +0 -10
- package/dist/pdf/index.js +3 -29
- package/dist/reader/index.js +11 -69
- package/dist/render/index.js +2 -28
- package/dist/sample/index.js +0 -6
- package/dist/sass/index.js +30 -66
- package/dist/scripts/index.js +0 -24
- package/dist/serialize.js +1 -20
- package/dist/serve/index.js +5 -29
- package/dist/validate/index.js +0 -24
- package/dist/web/Template.js +0 -21
- package/dist/web/index.js +31 -128
- package/dist/xml/index.js +0 -30
- package/package.json +10 -10
package/dist/reader/index.js
CHANGED
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
14
|
-
|
|
15
10
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
16
|
-
|
|
17
11
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
18
|
-
|
|
19
12
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
20
|
-
|
|
21
13
|
var _path2 = _interopRequireDefault(require("path"));
|
|
22
|
-
|
|
23
14
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
24
|
-
|
|
25
15
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
26
|
-
|
|
27
16
|
var _find = _interopRequireDefault(require("lodash/find"));
|
|
28
|
-
|
|
29
17
|
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
30
|
-
|
|
31
18
|
var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
|
|
32
|
-
|
|
33
19
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
34
|
-
|
|
35
20
|
var _recursiveReaddir = _interopRequireDefault(require("recursive-readdir"));
|
|
36
|
-
|
|
37
21
|
var _has = _interopRequireDefault(require("lodash/has"));
|
|
38
|
-
|
|
39
22
|
/* eslint-disable camelcase */
|
|
40
|
-
|
|
41
23
|
/* eslint-disable class-methods-use-this */
|
|
24
|
+
|
|
42
25
|
class Reader {
|
|
43
26
|
constructor() {
|
|
44
27
|
this.outputDirName = 'epub';
|
|
@@ -47,28 +30,25 @@ class Reader {
|
|
|
47
30
|
this.epubAssets = ['META-INF', 'OPS', 'mimetype'];
|
|
48
31
|
this.readerModuleName = '@canopycanopycanopy/b-ber-reader';
|
|
49
32
|
this.readerModuleDistDir = 'dist';
|
|
50
|
-
this.readerAppPath = null;
|
|
33
|
+
this.readerAppPath = null;
|
|
51
34
|
|
|
52
|
-
|
|
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())
|
|
53
38
|
.then(() => this.updateAssetURLsWithAbsolutePaths()).then(() => this.injectWebpubManifestLink()).catch(_bBerLogger.default.error);
|
|
54
39
|
}
|
|
55
|
-
|
|
56
40
|
get remoteURL() {
|
|
57
41
|
if (process.env.NODE_ENV === 'production' && (!_State.default.config || !_State.default.config.remote_url || /^http/.test(_State.default.config.remote_url) === false)) {
|
|
58
42
|
throw new Error('Task [build/reader] requires a remote_url to be set in config.yml');
|
|
59
43
|
}
|
|
60
|
-
|
|
61
44
|
return _State.default.config.remote_url || 'http://localhost:4000/';
|
|
62
45
|
}
|
|
63
|
-
|
|
64
46
|
createDirname(s) {
|
|
65
47
|
if (!s || typeof s !== 'string') {
|
|
66
48
|
return _crypto.default.randomBytes(20).toString('hex');
|
|
67
49
|
}
|
|
68
|
-
|
|
69
50
|
return s.replace(/[^0-9a-zA-Z-]/g, '-');
|
|
70
51
|
}
|
|
71
|
-
|
|
72
52
|
ensureReaderModuleExists() {
|
|
73
53
|
try {
|
|
74
54
|
this.readerAppPath = _path2.default.join(_path2.default.dirname(_path2.default.join(require.resolve(this.readerModuleName))), this.readerModuleDistDir);
|
|
@@ -77,84 +57,66 @@ class Reader {
|
|
|
77
57
|
// module not found using require.resolve, so we check if there's a symlinked version available
|
|
78
58
|
_bBerLogger.default.warn(`Could not find globally installed module ${this.readerModuleName}`);
|
|
79
59
|
}
|
|
80
|
-
|
|
81
60
|
const {
|
|
82
61
|
paths
|
|
83
62
|
} = module;
|
|
84
63
|
let modulePath;
|
|
85
|
-
|
|
86
64
|
for (let i = 0; i < paths.length; i++) {
|
|
87
65
|
const _path = _path2.default.resolve(paths[i], this.readerModuleName);
|
|
88
|
-
|
|
89
66
|
if (_fsExtra.default.existsSync(_path)) {
|
|
90
67
|
modulePath = _path;
|
|
91
68
|
break;
|
|
92
69
|
}
|
|
93
70
|
}
|
|
94
|
-
|
|
95
71
|
if (!modulePath) {
|
|
96
72
|
_bBerLogger.default.error(`Cannot find module ${this.readerModuleName}. Try running npm i -S ${this.readerModuleName}`);
|
|
97
73
|
}
|
|
98
|
-
|
|
99
74
|
try {
|
|
100
75
|
this.readerAppPath = _fsExtra.default.realpathSync(_path2.default.join(modulePath, this.readerModuleDistDir));
|
|
101
|
-
|
|
102
76
|
const pkg = _fsExtra.default.readJsonSync(_path2.default.join(modulePath, this.readerModuleDistDir, 'package.json'));
|
|
103
|
-
|
|
104
77
|
_bBerLogger.default.warn(`Loaded ${this.readerModuleName} v${pkg.version}`);
|
|
105
|
-
|
|
106
78
|
return;
|
|
107
79
|
} catch (err) {
|
|
108
80
|
_bBerLogger.default.error(`
|
|
109
81
|
A symlinked version of ${this.readerModuleName} was found but is inaccessible.
|
|
110
82
|
Try running npm i -S ${this.readerModuleName}, or rebuilding the reader package if running this command in a development environment
|
|
111
83
|
`);
|
|
112
|
-
|
|
113
84
|
process.exit(1);
|
|
114
85
|
}
|
|
115
86
|
}
|
|
116
|
-
|
|
117
87
|
createOutputDirs() {
|
|
118
88
|
return _fsExtra.default.ensureDir(this.outputDir).then(() => _fsExtra.default.ensureDir(this.apiDir));
|
|
119
89
|
}
|
|
120
|
-
|
|
121
90
|
copyEpubToOutputDir() {
|
|
122
91
|
var _context;
|
|
123
|
-
|
|
124
92
|
const epubDir = this.createDirname(this.getBookMetadata('identifier'));
|
|
125
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)));
|
|
126
94
|
return _promise.default.all(promises);
|
|
127
95
|
}
|
|
128
|
-
|
|
129
96
|
getBookMetadata(term) {
|
|
130
97
|
if (!term) return _State.default.metadata.json();
|
|
131
98
|
const entry = (0, _find.default)(_State.default.metadata.json(), {
|
|
132
99
|
term
|
|
133
100
|
});
|
|
134
101
|
if (entry && entry.value) return entry.value;
|
|
135
|
-
|
|
136
102
|
_bBerLogger.default.warn(`Could not find metadata value for ${term}`);
|
|
137
|
-
|
|
138
103
|
return '';
|
|
139
104
|
}
|
|
140
|
-
|
|
141
105
|
getProjectConfig(term) {
|
|
142
106
|
if (!term) return _State.default.config;
|
|
143
|
-
|
|
144
107
|
if (!(0, _has.default)(_State.default.config, term)) {
|
|
145
108
|
_bBerLogger.default.warn(`Invalid property for config: ${term}`);
|
|
146
109
|
}
|
|
147
|
-
|
|
148
110
|
return _State.default.config[term];
|
|
149
111
|
}
|
|
150
|
-
|
|
151
112
|
writeBookManifest() {
|
|
152
113
|
// Get metadata for books.json
|
|
153
114
|
const id = this.getBookMetadata('identifier');
|
|
154
115
|
const title = this.getBookMetadata('title');
|
|
155
116
|
const url = `${_bBerLib.Url.trimSlashes(this.remoteURL)}/${this.outputDirName}/${this.createDirname(id)}`;
|
|
156
|
-
const cover = `${url}/OPS/images/${this.getBookMetadata('cover')}`;
|
|
117
|
+
const cover = `${url}/OPS/images/${this.getBookMetadata('cover')}`;
|
|
157
118
|
|
|
119
|
+
// Get config required by reader for books.json
|
|
158
120
|
const {
|
|
159
121
|
downloads,
|
|
160
122
|
ui_options,
|
|
@@ -168,44 +130,34 @@ class Reader {
|
|
|
168
130
|
downloads,
|
|
169
131
|
ui_options,
|
|
170
132
|
layout
|
|
171
|
-
}];
|
|
133
|
+
}];
|
|
172
134
|
|
|
135
|
+
// Write to an `api` dir in case the app is being deployed statically
|
|
173
136
|
return _fsExtra.default.writeJson(_path2.default.join(this.apiDir, 'books.json'), manifest);
|
|
174
137
|
}
|
|
175
|
-
|
|
176
138
|
writeWebpubManifest() {
|
|
177
139
|
const assetsDir = _path2.default.join(process.cwd(), this.outputDir, this.getBookMetadata('identifier'), 'OPS');
|
|
178
|
-
|
|
179
140
|
return (0, _recursiveReaddir.default)(assetsDir).then(files => {
|
|
180
141
|
const manifest = (0, _utils.generateWebpubManifest)(files);
|
|
181
|
-
|
|
182
142
|
_fsExtra.default.writeJson(_State.default.dist.root('manifest.json'), manifest);
|
|
183
143
|
});
|
|
184
144
|
}
|
|
185
|
-
|
|
186
145
|
injectWebpubManifestLink() {
|
|
187
146
|
const indexHTML = _State.default.dist.root('index.html');
|
|
188
|
-
|
|
189
147
|
const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
|
|
190
|
-
|
|
191
148
|
let contents;
|
|
192
149
|
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
193
150
|
contents = contents.replace(/<\/head>/, `<link rel="manifest" type="application/webpub+json" href="${readerURL}manifest.json"></head>`);
|
|
194
151
|
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
195
152
|
}
|
|
196
|
-
|
|
197
153
|
copyReaderAppToOutputDir() {
|
|
198
154
|
var _context2;
|
|
199
|
-
|
|
200
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))));
|
|
201
156
|
return _promise.default.all(promises);
|
|
202
157
|
}
|
|
203
|
-
|
|
204
158
|
injectServerDataIntoTemplate() {
|
|
205
159
|
const indexHTML = _State.default.dist.root('index.html');
|
|
206
|
-
|
|
207
160
|
const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
|
|
208
|
-
|
|
209
161
|
const identifier = this.getBookMetadata('identifier');
|
|
210
162
|
const bookURL = `${readerURL}epub/${identifier}`;
|
|
211
163
|
const serverData = {
|
|
@@ -227,38 +179,28 @@ class Reader {
|
|
|
227
179
|
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
228
180
|
contents = contents.replace(/__SERVER_DATA__ = {}/, `__SERVER_DATA__ = ${(0, _stringify.default)(serverData)}`);
|
|
229
181
|
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
230
|
-
}
|
|
231
|
-
|
|
182
|
+
}
|
|
232
183
|
|
|
184
|
+
// Update URLs in CSS
|
|
233
185
|
updateLinkedResourcesWithAbsolutePaths() {
|
|
234
186
|
const indexContents = _fsExtra.default.readFileSync(_State.default.dist.root('index.html'), 'utf8');
|
|
235
|
-
|
|
236
187
|
const versionHash = indexContents.match(/link href="\/(\w+\.css)"/)[1];
|
|
237
|
-
|
|
238
188
|
const stylesheet = _State.default.dist.root(versionHash);
|
|
239
|
-
|
|
240
189
|
const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
|
|
241
|
-
|
|
242
190
|
let contents;
|
|
243
191
|
contents = _fsExtra.default.readFileSync(stylesheet, 'utf8');
|
|
244
192
|
contents = contents.replace(/url\(\//g, `url(${readerURL}`);
|
|
245
193
|
return _fsExtra.default.writeFile(stylesheet, contents);
|
|
246
194
|
}
|
|
247
|
-
|
|
248
195
|
updateAssetURLsWithAbsolutePaths() {
|
|
249
196
|
const indexHTML = _State.default.dist.root('index.html');
|
|
250
|
-
|
|
251
197
|
const readerURL = _bBerLib.Url.removeTrailingSlash(this.getProjectConfig('reader_url'));
|
|
252
|
-
|
|
253
198
|
let contents;
|
|
254
199
|
contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
|
|
255
200
|
contents = contents.replace(/(src|href)="(\/[^"]+?)"/g, `$1="${readerURL}$2"`);
|
|
256
201
|
return _fsExtra.default.writeFile(indexHTML, contents);
|
|
257
202
|
}
|
|
258
|
-
|
|
259
203
|
}
|
|
260
|
-
|
|
261
204
|
const main = () => new Reader();
|
|
262
|
-
|
|
263
205
|
var _default = main;
|
|
264
206
|
exports.default = _default;
|
package/dist/render/index.js
CHANGED
|
@@ -1,69 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
14
|
-
|
|
15
10
|
var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
|
|
16
|
-
|
|
17
11
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
18
|
-
|
|
19
12
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
20
|
-
|
|
21
13
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
|
-
|
|
23
14
|
var _path = _interopRequireDefault(require("path"));
|
|
24
|
-
|
|
25
15
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
26
|
-
|
|
27
16
|
var _bBerMarkdownRenderer = _interopRequireDefault(require("@canopycanopycanopy/b-ber-markdown-renderer"));
|
|
28
|
-
|
|
29
17
|
var _Xhtml = _interopRequireDefault(require("@canopycanopycanopy/b-ber-templates/Xhtml"));
|
|
30
|
-
|
|
31
18
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
32
|
-
|
|
33
19
|
var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
|
|
34
|
-
|
|
35
20
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
36
|
-
|
|
37
21
|
const writeMarkupToFile = (fname, markup) => {
|
|
38
22
|
_fsExtra.default.writeFile(_State.default.dist.text(`${fname}.xhtml`), markup).then(() => _bBerLogger.default.info(`render xhtml [${_path.default.basename(fname)}.xhtml]`));
|
|
39
|
-
};
|
|
40
|
-
|
|
23
|
+
};
|
|
41
24
|
|
|
25
|
+
// Convert Markdown to HTML and wrap with page template
|
|
42
26
|
const createPageLayout = (fileName, data) => {
|
|
43
27
|
const textDir = _State.default.dist.text();
|
|
44
|
-
|
|
45
28
|
const body = _bBerMarkdownRenderer.default.render(fileName, data);
|
|
46
|
-
|
|
47
29
|
const markup = _bBerLib.Template.render(body, _Xhtml.default.body());
|
|
48
|
-
|
|
49
30
|
return _fsExtra.default.mkdirp(textDir).then(() => writeMarkupToFile(fileName, markup)).catch(_bBerLogger.default.error);
|
|
50
31
|
};
|
|
51
|
-
|
|
52
32
|
const createXTHMLFile = fpath => _fsExtra.default.readFile(fpath, 'utf8').then(data => createPageLayout(_path.default.basename(fpath, '.md'), data)).catch(_bBerLogger.default.error);
|
|
53
|
-
|
|
54
33
|
function render() {
|
|
55
34
|
const markdownDir = _State.default.src.markdown();
|
|
56
|
-
|
|
57
35
|
return _fsExtra.default.readdir(markdownDir).then(files => {
|
|
58
36
|
var _context, _context2;
|
|
59
|
-
|
|
60
37
|
// Sort the files in the order that they appear in `type.yml`, so that they
|
|
61
38
|
// and the images they contain are processed in the correct order
|
|
62
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) => {
|
|
63
40
|
const fileNameA = _path.default.basename(a, '.md');
|
|
64
|
-
|
|
65
41
|
const fileNameB = _path.default.basename(b, '.md');
|
|
66
|
-
|
|
67
42
|
const indexA = (0, _indexOf.default)(_State.default).call(_State.default, 'spine.flattened', {
|
|
68
43
|
fileName: fileNameA
|
|
69
44
|
});
|
|
@@ -75,6 +50,5 @@ function render() {
|
|
|
75
50
|
return promises.catch(_bBerLogger.default.error);
|
|
76
51
|
});
|
|
77
52
|
}
|
|
78
|
-
|
|
79
53
|
var _default = render;
|
|
80
54
|
exports.default = _default;
|
package/dist/sample/index.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
14
|
-
|
|
15
10
|
const sample = () => _promise.default.resolve();
|
|
16
|
-
|
|
17
11
|
var _default = sample;
|
|
18
12
|
exports.default = _default;
|
package/dist/sass/index.js
CHANGED
|
@@ -1,102 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
14
|
-
|
|
15
10
|
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
16
|
-
|
|
17
11
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
18
|
-
|
|
19
12
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
20
|
-
|
|
21
13
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
|
-
|
|
23
14
|
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
24
|
-
|
|
25
15
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
26
|
-
|
|
27
16
|
var _path = _interopRequireDefault(require("path"));
|
|
28
|
-
|
|
29
17
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
30
|
-
|
|
31
18
|
var _sass = _interopRequireDefault(require("sass"));
|
|
32
|
-
|
|
33
19
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
34
|
-
|
|
35
20
|
var _autoprefixer = _interopRequireDefault(require("autoprefixer"));
|
|
36
|
-
|
|
37
21
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
38
|
-
|
|
39
22
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
40
|
-
|
|
41
23
|
// dirnames that may be referenced in the theme. we copy over assets when
|
|
42
24
|
// running the sass task
|
|
43
25
|
const ASSET_DIRNAMES = ['fonts', 'images'];
|
|
44
26
|
const autoprefixerOptions = _State.default.config.autoprefixer_options || {
|
|
45
27
|
overrideBrowserslist: ['defaults', '> 1%', 'not dead', 'not IE 11'],
|
|
46
28
|
flexbox: 'no-2009'
|
|
47
|
-
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Check to see if there's an `application.scss` in `_stylesheets`, and if so
|
|
48
32
|
// load that; else verify that a theme is selected in `config`, and that the
|
|
49
33
|
// theme's `application.scss` exists, then load that; else write a blank file.
|
|
50
|
-
|
|
51
34
|
const createSCSSString = () => {
|
|
52
35
|
const chunks = [];
|
|
53
36
|
const {
|
|
54
37
|
theme
|
|
55
38
|
} = _State.default;
|
|
56
39
|
const themeName = theme.name;
|
|
57
|
-
|
|
58
40
|
const themeSettingsPath = _State.default.src.stylesheets(themeName, '_settings.scss');
|
|
59
|
-
|
|
60
41
|
const themeOverridesPath = _State.default.src.stylesheets(themeName, '_overrides.scss');
|
|
42
|
+
const themeStylesPath = theme.entry;
|
|
61
43
|
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
// load user-defined variables
|
|
64
45
|
if (_fsExtra.default.existsSync(themeSettingsPath)) {
|
|
65
46
|
const variableOverrides = _fsExtra.default.readFileSync(themeSettingsPath);
|
|
66
|
-
|
|
67
47
|
_bBerLogger.default.info(`sass use overrides [${_path.default.basename(themeSettingsPath)}]`);
|
|
68
|
-
|
|
69
48
|
_bBerLogger.default.info('sass prepend overrides');
|
|
70
|
-
|
|
71
49
|
chunks.push(variableOverrides);
|
|
72
|
-
}
|
|
73
|
-
|
|
50
|
+
}
|
|
74
51
|
|
|
52
|
+
// load theme styles
|
|
75
53
|
if (_fsExtra.default.existsSync(themeStylesPath)) {
|
|
76
54
|
const themeStyles = _fsExtra.default.readFileSync(themeStylesPath);
|
|
77
|
-
|
|
78
55
|
_bBerLogger.default.info(`sass attempt build with [${themeName}] theme`);
|
|
79
|
-
|
|
80
56
|
chunks.push(themeStyles);
|
|
81
|
-
}
|
|
82
|
-
|
|
57
|
+
}
|
|
83
58
|
|
|
59
|
+
// load user-defined styles
|
|
84
60
|
if (_fsExtra.default.existsSync(themeOverridesPath)) {
|
|
85
61
|
const styleOverrides = _fsExtra.default.readFileSync(themeOverridesPath);
|
|
86
|
-
|
|
87
62
|
_bBerLogger.default.info(`sass use user-defined styles [${_path.default.basename(themeOverridesPath)}]`);
|
|
88
|
-
|
|
89
63
|
_bBerLogger.default.info('sass append user-defined styles');
|
|
90
|
-
|
|
91
64
|
chunks.push(styleOverrides);
|
|
92
65
|
}
|
|
93
|
-
|
|
94
66
|
if (chunks.length < 1) _bBerLogger.default.error('No readable stylesheets were found');
|
|
95
67
|
return (0, _concat.default)(Buffer).call(Buffer, chunks);
|
|
96
|
-
};
|
|
68
|
+
};
|
|
97
69
|
|
|
70
|
+
// make sure the compiled output dir exists
|
|
71
|
+
const ensureCSSDir = () => _fsExtra.default.mkdirp(_State.default.dist.stylesheets());
|
|
98
72
|
|
|
99
|
-
|
|
73
|
+
// copy assets that exist in theme directory to the corresponding directory in
|
|
100
74
|
// _project:
|
|
101
75
|
//
|
|
102
76
|
// my-theme/fonts/my-font.ttf -> _project/_fonts/my-font.ttf
|
|
@@ -106,28 +80,21 @@ const ensureCSSDir = () => _fsExtra.default.mkdirp(_State.default.dist.styleshee
|
|
|
106
80
|
//
|
|
107
81
|
// these assets are then copied to the correct build dir by the `copy` task.
|
|
108
82
|
//
|
|
109
|
-
|
|
110
|
-
|
|
111
83
|
const copyThemeAssets = () => {
|
|
112
84
|
const {
|
|
113
85
|
theme
|
|
114
86
|
} = _State.default;
|
|
115
87
|
const fileData = (0, _reduce.default)(ASSET_DIRNAMES).call(ASSET_DIRNAMES, (acc, curr) => {
|
|
116
88
|
var _context, _context2;
|
|
117
|
-
|
|
118
89
|
const themePath = _path.default.resolve(_path.default.dirname(theme.entry), curr);
|
|
119
|
-
|
|
120
90
|
const srcPath = _State.default.src.root(`_${curr}`);
|
|
121
|
-
|
|
122
91
|
_fsExtra.default.mkdirpSync(srcPath);
|
|
123
|
-
|
|
124
92
|
try {
|
|
125
93
|
_fsExtra.default.lstatSync(themePath).isDirectory();
|
|
126
94
|
} catch (err) {
|
|
127
95
|
if (err.code === 'ENOENT') return acc;
|
|
128
96
|
throw new Error(`There was a problem copying [${themePath}] to [${srcPath}]`);
|
|
129
97
|
}
|
|
130
|
-
|
|
131
98
|
const data = (0, _map.default)(_context = (0, _filter.default)(_context2 = _fsExtra.default.readdirSync(themePath)).call(_context2, a => a.charAt(0) !== '.')).call(_context, fileName => ({
|
|
132
99
|
input: _path.default.join(themePath, fileName),
|
|
133
100
|
output: _path.default.join(srcPath, fileName)
|
|
@@ -143,45 +110,46 @@ const copyThemeAssets = () => {
|
|
|
143
110
|
}));
|
|
144
111
|
return _promise.default.all(promises);
|
|
145
112
|
};
|
|
146
|
-
|
|
147
113
|
function resolveImportedModule(importPath) {
|
|
148
114
|
// Remove preceeding tilde
|
|
149
|
-
const trimmedImportPath = (0, _slice.default)(importPath).call(importPath, 1);
|
|
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);
|
|
150
119
|
|
|
151
|
-
|
|
120
|
+
// Remove empty entries caused by leading/trailing slashes
|
|
121
|
+
importTree = (0, _filter.default)(importTree).call(importTree, Boolean);
|
|
152
122
|
|
|
153
|
-
|
|
123
|
+
// Define both the scope and the name - the scope will be
|
|
154
124
|
// used to resolve the import and get the necessary path, the
|
|
155
125
|
// name will be used to construct the final file path
|
|
156
|
-
|
|
157
126
|
let moduleScope = '';
|
|
158
|
-
let moduleName = importTree.shift();
|
|
127
|
+
let moduleName = importTree.shift();
|
|
159
128
|
|
|
129
|
+
// Allow scoped packages
|
|
160
130
|
if (moduleName[0] === '@') {
|
|
161
131
|
moduleScope = moduleName;
|
|
162
132
|
moduleName = importTree.shift();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const moduleNameWithScope = _path.default.join(moduleScope, moduleName); // Get the module
|
|
133
|
+
}
|
|
167
134
|
|
|
135
|
+
// @foo/bar | foo
|
|
136
|
+
const moduleNameWithScope = _path.default.join(moduleScope, moduleName);
|
|
168
137
|
|
|
138
|
+
// Get the module
|
|
169
139
|
const modulePath = require.resolve(moduleNameWithScope, {
|
|
170
140
|
paths: [_path.default.join(_path.default.dirname(_State.default.theme.entry))]
|
|
171
|
-
});
|
|
141
|
+
});
|
|
172
142
|
|
|
143
|
+
// No path was provided, return the imported node module
|
|
144
|
+
if (!importTree.length) return modulePath;
|
|
173
145
|
|
|
174
|
-
|
|
146
|
+
// User is importing a specific file, find it and return its location. Remove
|
|
175
147
|
// the modules scope from the name when finding the path
|
|
176
|
-
|
|
177
148
|
const moduleIndex = (0, _indexOf.default)(modulePath).call(modulePath, moduleName) + moduleName.length;
|
|
178
149
|
const packagePath = (0, _slice.default)(modulePath).call(modulePath, 0, moduleIndex);
|
|
179
|
-
|
|
180
150
|
const importedModule = _path.default.join(packagePath, ...importTree);
|
|
181
|
-
|
|
182
151
|
return importedModule;
|
|
183
152
|
}
|
|
184
|
-
|
|
185
153
|
const renderCSS = scssString => new _promise.default(resolve => {
|
|
186
154
|
_sass.default.render({
|
|
187
155
|
// Importer allows use of '~' to denote node_modules directory in SCSS files
|
|
@@ -202,21 +170,17 @@ const renderCSS = scssString => new _promise.default(resolve => {
|
|
|
202
170
|
resolve(result);
|
|
203
171
|
});
|
|
204
172
|
});
|
|
205
|
-
|
|
206
173
|
const applyPostProcessing = ({
|
|
207
174
|
css
|
|
208
175
|
}) => (0, _postcss.default)((0, _autoprefixer.default)(autoprefixerOptions)).process(css, {
|
|
209
176
|
from: undefined
|
|
210
177
|
});
|
|
211
|
-
|
|
212
178
|
const writeCSSFile = ({
|
|
213
179
|
css
|
|
214
180
|
}) => {
|
|
215
181
|
const fileName = _State.default.env === 'production' ? `${_State.default.hash}.css` : 'application.css';
|
|
216
182
|
return _fsExtra.default.writeFile(_State.default.dist.stylesheets(fileName), css);
|
|
217
183
|
};
|
|
218
|
-
|
|
219
184
|
const sass = () => ensureCSSDir().then(copyThemeAssets).then(createSCSSString).then(renderCSS).then(applyPostProcessing).then(writeCSSFile).catch(_bBerLogger.default.error);
|
|
220
|
-
|
|
221
185
|
var _default = sass;
|
|
222
186
|
exports.default = _default;
|
package/dist/scripts/index.js
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
14
|
-
|
|
15
10
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
16
|
-
|
|
17
11
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
18
|
-
|
|
19
12
|
var _path = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
13
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
22
|
-
|
|
23
14
|
var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
|
|
24
|
-
|
|
25
15
|
var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
|
|
26
|
-
|
|
27
16
|
var _uglifyJs = _interopRequireDefault(require("uglify-js"));
|
|
28
|
-
|
|
29
17
|
const uglifyOptions = _State.default.config.uglify_options || {
|
|
30
18
|
compress: {
|
|
31
19
|
// eslint-disable-next-line camelcase
|
|
@@ -34,46 +22,34 @@ const uglifyOptions = _State.default.config.uglify_options || {
|
|
|
34
22
|
booleans: true
|
|
35
23
|
}
|
|
36
24
|
};
|
|
37
|
-
|
|
38
25
|
const uglify = contents => {
|
|
39
26
|
const result = _uglifyJs.default.minify(contents, uglifyOptions);
|
|
40
|
-
|
|
41
27
|
if (result.error) throw result.error;
|
|
42
28
|
if (result.warnings) _bBerLogger.default.warn(result.warnings);
|
|
43
29
|
return result.code;
|
|
44
30
|
};
|
|
45
|
-
|
|
46
31
|
const optimized = files => {
|
|
47
32
|
const contents = (0, _map.default)(files).call(files, file => _fsExtra.default.readFileSync(_path.default.resolve(_State.default.src.javascripts(file)), 'utf8')).join('');
|
|
48
33
|
const js = uglify(contents);
|
|
49
34
|
const {
|
|
50
35
|
hash
|
|
51
36
|
} = _State.default;
|
|
52
|
-
|
|
53
37
|
const out = _State.default.dist.javascripts(`${hash}.js`);
|
|
54
|
-
|
|
55
38
|
return _fsExtra.default.writeFile(out, js).then(() => _bBerLogger.default.info('scripts emit [%s]', `javascripts${_path.default.sep}${_path.default.basename(out)}`));
|
|
56
39
|
};
|
|
57
|
-
|
|
58
40
|
const unoptimized = files => {
|
|
59
41
|
const promises = (0, _map.default)(files).call(files, file => {
|
|
60
42
|
const input = _State.default.src.javascripts(file);
|
|
61
|
-
|
|
62
43
|
const output = _State.default.dist.javascripts(file);
|
|
63
|
-
|
|
64
44
|
return _fsExtra.default.copy(input, output).then(() => _bBerLogger.default.info('scripts emit [%s]', `javascripts${_path.default.sep}${_path.default.basename(output)}`));
|
|
65
45
|
});
|
|
66
46
|
return _promise.default.all(promises);
|
|
67
47
|
};
|
|
68
|
-
|
|
69
48
|
const write = () => _fsExtra.default.readdir(_State.default.src.javascripts()).then(_files => {
|
|
70
49
|
const files = (0, _filter.default)(_files).call(_files, a => _path.default.extname(a) === '.js');
|
|
71
50
|
return (_State.default.env === 'production' ? optimized : unoptimized)(files);
|
|
72
51
|
});
|
|
73
|
-
|
|
74
52
|
const ensureDir = () => _fsExtra.default.mkdirp(_State.default.dist.javascripts());
|
|
75
|
-
|
|
76
53
|
const scripts = () => ensureDir().then(write).catch(_bBerLogger.default.error);
|
|
77
|
-
|
|
78
54
|
var _default = scripts;
|
|
79
55
|
exports.default = _default;
|