@canopycanopycanopy/b-ber-tasks 1.2.16 → 2.0.2

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.
@@ -1,42 +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
-
22
+ /* eslint-disable camelcase */
39
23
  /* eslint-disable class-methods-use-this */
24
+
40
25
  class Reader {
41
26
  constructor() {
42
27
  this.outputDirName = 'epub';
@@ -46,25 +31,24 @@ class Reader {
46
31
  this.readerModuleName = '@canopycanopycanopy/b-ber-reader';
47
32
  this.readerModuleDistDir = 'dist';
48
33
  this.readerAppPath = null;
49
- return this.createOutputDirs().then(() => this.ensureReaderModuleExists()).then(() => this.copyEpubToOutputDir()).then(() => this.writeBookManifest()).then(() => this.writeWebpubManifest()).then(() => this.copyReaderAppToOutputDir()).then(() => this.injectServerDataIntoTemplate()).then(() => this.updateLinkedResourcesWithAbsolutePaths()).then(() => this.updateAssetURLsWithAbsolutePaths()).then(() => this.injectWebpubManifestLink()).catch(_bBerLogger.default.error);
50
- }
51
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
+ }
52
40
  get remoteURL() {
53
41
  if (process.env.NODE_ENV === 'production' && (!_State.default.config || !_State.default.config.remote_url || /^http/.test(_State.default.config.remote_url) === false)) {
54
42
  throw new Error('Task [build/reader] requires a remote_url to be set in config.yml');
55
43
  }
56
-
57
44
  return _State.default.config.remote_url || 'http://localhost:4000/';
58
45
  }
59
-
60
46
  createDirname(s) {
61
47
  if (!s || typeof s !== 'string') {
62
48
  return _crypto.default.randomBytes(20).toString('hex');
63
49
  }
64
-
65
50
  return s.replace(/[^0-9a-zA-Z-]/g, '-');
66
51
  }
67
-
68
52
  ensureReaderModuleExists() {
69
53
  try {
70
54
  this.readerAppPath = _path2.default.join(_path2.default.dirname(_path2.default.join(require.resolve(this.readerModuleName))), this.readerModuleDistDir);
@@ -73,122 +57,107 @@ class Reader {
73
57
  // module not found using require.resolve, so we check if there's a symlinked version available
74
58
  _bBerLogger.default.warn(`Could not find globally installed module ${this.readerModuleName}`);
75
59
  }
76
-
77
60
  const {
78
61
  paths
79
62
  } = module;
80
63
  let modulePath;
81
-
82
64
  for (let i = 0; i < paths.length; i++) {
83
65
  const _path = _path2.default.resolve(paths[i], this.readerModuleName);
84
-
85
66
  if (_fsExtra.default.existsSync(_path)) {
86
67
  modulePath = _path;
87
68
  break;
88
69
  }
89
70
  }
90
-
91
71
  if (!modulePath) {
92
72
  _bBerLogger.default.error(`Cannot find module ${this.readerModuleName}. Try running npm i -S ${this.readerModuleName}`);
93
73
  }
94
-
95
74
  try {
96
75
  this.readerAppPath = _fsExtra.default.realpathSync(_path2.default.join(modulePath, this.readerModuleDistDir));
97
-
98
76
  const pkg = _fsExtra.default.readJsonSync(_path2.default.join(modulePath, this.readerModuleDistDir, 'package.json'));
99
-
100
77
  _bBerLogger.default.warn(`Loaded ${this.readerModuleName} v${pkg.version}`);
101
-
102
78
  return;
103
79
  } catch (err) {
104
80
  _bBerLogger.default.error(`
105
81
  A symlinked version of ${this.readerModuleName} was found but is inaccessible.
106
82
  Try running npm i -S ${this.readerModuleName}, or rebuilding the reader package if running this command in a development environment
107
83
  `);
108
-
109
84
  process.exit(1);
110
85
  }
111
86
  }
112
-
113
87
  createOutputDirs() {
114
88
  return _fsExtra.default.ensureDir(this.outputDir).then(() => _fsExtra.default.ensureDir(this.apiDir));
115
89
  }
116
-
117
90
  copyEpubToOutputDir() {
118
91
  var _context;
119
-
120
92
  const epubDir = this.createDirname(this.getBookMetadata('identifier'));
121
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)));
122
94
  return _promise.default.all(promises);
123
95
  }
124
-
125
96
  getBookMetadata(term) {
97
+ if (!term) return _State.default.metadata.json();
126
98
  const entry = (0, _find.default)(_State.default.metadata.json(), {
127
99
  term
128
100
  });
129
101
  if (entry && entry.value) return entry.value;
130
-
131
102
  _bBerLogger.default.warn(`Could not find metadata value for ${term}`);
132
-
133
103
  return '';
134
104
  }
135
-
136
105
  getProjectConfig(term) {
106
+ if (!term) return _State.default.config;
137
107
  if (!(0, _has.default)(_State.default.config, term)) {
138
108
  _bBerLogger.default.warn(`Invalid property for config: ${term}`);
139
109
  }
140
-
141
110
  return _State.default.config[term];
142
111
  }
143
-
144
112
  writeBookManifest() {
145
- const identifier = this.getBookMetadata('identifier');
113
+ // Get metadata for books.json
114
+ const id = this.getBookMetadata('identifier');
146
115
  const title = this.getBookMetadata('title');
147
- const url = `${_bBerLib.Url.trimSlashes(this.remoteURL)}/${this.outputDirName}/${this.createDirname(identifier)}`;
116
+ const url = `${_bBerLib.Url.trimSlashes(this.remoteURL)}/${this.outputDirName}/${this.createDirname(id)}`;
148
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();
149
125
  const manifest = [{
150
126
  title,
151
127
  url,
152
128
  cover,
153
- id: identifier
154
- }]; // write to an `api` dir in case the app is being deployed statically
129
+ id,
130
+ downloads,
131
+ ui_options,
132
+ layout
133
+ }];
155
134
 
135
+ // Write to an `api` dir in case the app is being deployed statically
156
136
  return _fsExtra.default.writeJson(_path2.default.join(this.apiDir, 'books.json'), manifest);
157
137
  }
158
-
159
138
  writeWebpubManifest() {
160
139
  const assetsDir = _path2.default.join(process.cwd(), this.outputDir, this.getBookMetadata('identifier'), 'OPS');
161
-
162
140
  return (0, _recursiveReaddir.default)(assetsDir).then(files => {
163
141
  const manifest = (0, _utils.generateWebpubManifest)(files);
164
-
165
142
  _fsExtra.default.writeJson(_State.default.dist.root('manifest.json'), manifest);
166
143
  });
167
144
  }
168
-
169
145
  injectWebpubManifestLink() {
170
146
  const indexHTML = _State.default.dist.root('index.html');
171
-
172
147
  const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
173
-
174
148
  let contents;
175
149
  contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
176
150
  contents = contents.replace(/<\/head>/, `<link rel="manifest" type="application/webpub+json" href="${readerURL}manifest.json"></head>`);
177
151
  return _fsExtra.default.writeFile(indexHTML, contents);
178
152
  }
179
-
180
153
  copyReaderAppToOutputDir() {
181
154
  var _context2;
182
-
183
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))));
184
156
  return _promise.default.all(promises);
185
157
  }
186
-
187
158
  injectServerDataIntoTemplate() {
188
159
  const indexHTML = _State.default.dist.root('index.html');
189
-
190
160
  const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
191
-
192
161
  const identifier = this.getBookMetadata('identifier');
193
162
  const bookURL = `${readerURL}epub/${identifier}`;
194
163
  const serverData = {
@@ -212,35 +181,26 @@ class Reader {
212
181
  return _fsExtra.default.writeFile(indexHTML, contents);
213
182
  }
214
183
 
184
+ // Update URLs in CSS
215
185
  updateLinkedResourcesWithAbsolutePaths() {
216
186
  const indexContents = _fsExtra.default.readFileSync(_State.default.dist.root('index.html'), 'utf8');
217
-
218
187
  const versionHash = indexContents.match(/link href="\/(\w+\.css)"/)[1];
219
-
220
188
  const stylesheet = _State.default.dist.root(versionHash);
221
-
222
189
  const readerURL = _bBerLib.Url.addTrailingSlash(this.getProjectConfig('reader_url'));
223
-
224
190
  let contents;
225
191
  contents = _fsExtra.default.readFileSync(stylesheet, 'utf8');
226
192
  contents = contents.replace(/url\(\//g, `url(${readerURL}`);
227
193
  return _fsExtra.default.writeFile(stylesheet, contents);
228
194
  }
229
-
230
195
  updateAssetURLsWithAbsolutePaths() {
231
196
  const indexHTML = _State.default.dist.root('index.html');
232
-
233
197
  const readerURL = _bBerLib.Url.removeTrailingSlash(this.getProjectConfig('reader_url'));
234
-
235
198
  let contents;
236
199
  contents = _fsExtra.default.readFileSync(indexHTML, 'utf8');
237
200
  contents = contents.replace(/(src|href)="(\/[^"]+?)"/g, `$1="${readerURL}$2"`);
238
201
  return _fsExtra.default.writeFile(indexHTML, contents);
239
202
  }
240
-
241
203
  }
242
-
243
204
  const main = () => new Reader();
244
-
245
205
  var _default = main;
246
206
  exports.default = _default;
@@ -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
- }; // Convert Markdown to HTML and wrap with page template
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;
@@ -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;
@@ -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
- overrideBrowserslist: ['last 2 versions', '> 2%'],
27
+ overrideBrowserslist: ['defaults', '> 1%', 'not dead', 'not IE 11'],
46
28
  flexbox: 'no-2009'
47
- }; // Check to see if there's an `application.scss` in `_stylesheets`, and if so
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
- const themeStylesPath = theme.entry; // load user-defined variables
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
- } // load theme styles
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
- } // load user-defined styles
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
- }; // make sure the compiled output dir exists
68
+ };
97
69
 
70
+ // make sure the compiled output dir exists
71
+ const ensureCSSDir = () => _fsExtra.default.mkdirp(_State.default.dist.stylesheets());
98
72
 
99
- const ensureCSSDir = () => _fsExtra.default.mkdirp(_State.default.dist.stylesheets()); // copy assets that exist in theme directory to the corresponding directory in
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,78 +110,77 @@ 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); // Get the import path as an array
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
- let importTree = trimmedImportPath.split(_path.default.sep); // Remove empty entries caused by leading/trailing slashes
120
+ // Remove empty entries caused by leading/trailing slashes
121
+ importTree = (0, _filter.default)(importTree).call(importTree, Boolean);
152
122
 
153
- importTree = (0, _filter.default)(importTree).call(importTree, Boolean); // Define both the scope and the name - the scope will be
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(); // Allow scoped packages
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
- } // @foo/bar | foo
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
- }); // No path was provided, return the imported node module
141
+ });
172
142
 
143
+ // No path was provided, return the imported node module
144
+ if (!importTree.length) return modulePath;
173
145
 
174
- if (!importTree.length) return modulePath; // User is importing a specific file, find it and return its location. Remove
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
- const renderCSS = scssString => new _promise.default(resolve => _sass.default.render({
186
- // Importer allows use of '~' to denote node_modules directory in SCSS files
187
- importer: (url, _file, done) => {
188
- const file = url[0] === '~' ? resolveImportedModule(url) : url;
189
- return done({
190
- file
191
- });
192
- },
193
- // Add build vars at runtime with the SCSS buffer (which is transformed
194
- // to string in the backticks)
195
- data: `$build: "${_State.default.build}";${scssString}`,
196
- includePaths: [_State.default.src.stylesheets(), _path.default.dirname(_State.default.theme.entry), _path.default.dirname(_path.default.dirname(_State.default.theme.entry))],
197
- outputStyle: _State.default.env === 'production' ? 'compressed' : 'expanded',
198
- errLogToConsole: true
199
- }, (err, result) => {
200
- if (err) throw err;
201
- resolve(result);
202
- }));
203
-
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
+ });
204
173
  const applyPostProcessing = ({
205
174
  css
206
175
  }) => (0, _postcss.default)((0, _autoprefixer.default)(autoprefixerOptions)).process(css, {
207
176
  from: undefined
208
177
  });
209
-
210
178
  const writeCSSFile = ({
211
179
  css
212
180
  }) => {
213
181
  const fileName = _State.default.env === 'production' ? `${_State.default.hash}.css` : 'application.css';
214
182
  return _fsExtra.default.writeFile(_State.default.dist.stylesheets(fileName), css);
215
183
  };
216
-
217
184
  const sass = () => ensureCSSDir().then(copyThemeAssets).then(createSCSSString).then(renderCSS).then(applyPostProcessing).then(writeCSSFile).catch(_bBerLogger.default.error);
218
-
219
185
  var _default = sass;
220
186
  exports.default = _default;