@penskemediacorp/larva 1.23.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/__tests__/fixtures/larva.config.js +9 -16
  2. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.featured.aia.js +2 -2
  3. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.featured.js +2 -2
  4. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.js +1 -1
  5. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.prototype.js +2 -2
  6. package/__tests__/fixtures/src/patterns/components/c-tagline/c-tagline.prototype.js +2 -2
  7. package/__tests__/fixtures/src/patterns/modules/_also-ignored/_also-ignored.prototype.js +2 -2
  8. package/__tests__/fixtures/src/patterns/modules/test-module/test-module.featured.js +2 -2
  9. package/__tests__/fixtures/src/patterns/modules/test-module/test-module.prototype.js +2 -2
  10. package/__tests__/fixtures/src/patterns/one-offs/newswire/newswire.prototype.js +2 -2
  11. package/__tests__/lib/generateStatic.test.js +120 -86
  12. package/__tests__/lib/utils/clonePatternData.test.js +17 -10
  13. package/__tests__/lib/utils/getAllPatternsObj.test.js +14 -29
  14. package/__tests__/lib/utils/getAppConfiguration.test.js +5 -5
  15. package/__tests__/lib/utils/getModuleNamesFromDirectory.test.js +29 -10
  16. package/__tests__/lib/utils/getPatternData.test.js +36 -23
  17. package/__tests__/lib/utils/getPatternPathsToLoad.test.js +5 -5
  18. package/__tests__/lib/utils/getPatternRoutes.test.js +4 -6
  19. package/__tests__/lib/utils/getPatternType.test.js +4 -4
  20. package/__tests__/lib/utils/getPatternVariants.test.js +7 -12
  21. package/__tests__/lib/utils/getPatternsIndexPath.test.js +9 -4
  22. package/__tests__/lib/utils/getSubDirectoryNames.test.js +16 -6
  23. package/__tests__/lib/utils/isCoreTheme.test.js +5 -3
  24. package/__tests__/lib/utils/writeJsonToFile.test.js +8 -10
  25. package/__tests__/lib/writeJson.test.js +39 -21
  26. package/bin/larva.js +6 -6
  27. package/build/css/larva-important.css +1 -1
  28. package/build/css/larva.css +1 -1
  29. package/build/css/larva.inline-important.css +1 -1
  30. package/build/css/larva.inline.css +1 -1
  31. package/build/css/variety.compat-important.css +1 -1
  32. package/build/css/variety.compat.css +1 -1
  33. package/build/js/standalone/video-showcase.js +6 -6
  34. package/build/svg/defs/sprite.defs.html +5 -5
  35. package/index.js +1 -1
  36. package/lib/generateStatic.js +67 -63
  37. package/lib/server.js +139 -117
  38. package/lib/start.js +1 -1
  39. package/lib/utils/clonePatternData.js +1 -1
  40. package/lib/utils/copySyncHelper.js +5 -6
  41. package/lib/utils/getAllPatternsObj.js +14 -9
  42. package/lib/utils/getAppConfiguration.js +17 -15
  43. package/lib/utils/getArgsFromCli.js +2 -2
  44. package/lib/utils/getModuleNamesFromDirectory.js +13 -6
  45. package/lib/utils/getPatternData.js +19 -11
  46. package/lib/utils/getPatternPathsToLoad.js +5 -5
  47. package/lib/utils/getPatternRoutes.js +29 -27
  48. package/lib/utils/getPatternType.js +3 -3
  49. package/lib/utils/getPatternVariants.js +5 -6
  50. package/lib/utils/getPatternsIndexPath.js +3 -3
  51. package/lib/utils/getSubDirectoryNames.js +5 -5
  52. package/lib/utils/isCoreTheme.js +1 -2
  53. package/lib/utils/renderSass.js +17 -14
  54. package/lib/utils/spawnScript.js +4 -9
  55. package/lib/utils/writeJsonToFile.js +2 -2
  56. package/lib/writeJson.js +34 -15
  57. package/package.json +15 -12
  58. package/scripts/build-html.js +21 -14
  59. package/scripts/build-icons.js +38 -26
  60. package/scripts/build-scss.js +1 -1
  61. package/scripts/config/.eslintrc.json +2 -1
  62. package/scripts/config/gulpfile.js +0 -1
  63. package/scripts/config/stylelint.config.js +1 -1
  64. package/scripts/config/webpack.config.js +22 -20
  65. package/scripts/dev-js.js +1 -1
  66. package/scripts/dev-scss.js +2 -7
  67. package/scripts/help.js +9 -7
  68. package/scripts/init.js +4 -2
  69. package/scripts/larva/larva.config.js +1 -1
  70. package/scripts/link-all.js +2 -2
  71. package/scripts/lint-js.js +1 -4
  72. package/scripts/lint-scss.js +5 -7
  73. package/scripts/lint.js +4 -4
  74. package/scripts/prod-js.js +1 -4
  75. package/scripts/prod-scss.js +5 -2
  76. package/scripts/prod.js +16 -22
  77. package/scripts/server.js +1 -3
  78. package/scripts/start.js +3 -3
  79. package/scripts/upgrade.js +10 -14
  80. package/scripts/write-json.js +4 -2
package/lib/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const path = require( 'path' );
2
- const express = require('express');
2
+ const express = require( 'express' );
3
3
  const { marked } = require( 'marked' );
4
4
  const fs = require( 'fs' );
5
5
  const globby = require( 'globby' );
@@ -8,12 +8,12 @@ const {
8
8
  TwingEnvironment,
9
9
  TwingLoaderFilesystem,
10
10
  TwingFilter,
11
- TwingFunction
12
- } = require('twing');
11
+ TwingFunction,
12
+ } = require( 'twing' );
13
13
 
14
14
  const fontData = require( '../../larva-tokens/lib/font-data' );
15
15
 
16
- const getAppConfiguration = require('./utils/getAppConfiguration' );
16
+ const getAppConfiguration = require( './utils/getAppConfiguration' );
17
17
  const getPatternPathsToLoad = require( './utils/getPatternPathsToLoad' );
18
18
  const getPatternData = require( './utils/getPatternData' );
19
19
  const getAllPatternsObj = require( './utils/getAllPatternsObj' );
@@ -26,34 +26,34 @@ const assetsConfig = getAppConfiguration( 'assets' );
26
26
  const themeAssetsConfig = getAppConfiguration( 'themeAssets' );
27
27
  const twigPaths = getPatternPathsToLoad( patternConfig );
28
28
 
29
- let loader = new TwingLoaderFilesystem( twigPaths );
29
+ const loader = new TwingLoaderFilesystem( twigPaths );
30
30
 
31
31
  // Add markdown filter
32
32
  const markdownFilter = new TwingFilter( 'markdown', ( string ) => {
33
33
  if ( string ) {
34
34
  return Promise.resolve( marked( string ) );
35
- } else {
36
- const noDocsMessage = '**This needs docs!** <br>Create a README.md in the pattern\'s directory and add details about using this pattern in markdown.';
37
-
38
- return Promise.resolve( marked( noDocsMessage ) );
39
35
  }
40
- });
36
+ const noDocsMessage =
37
+ "**This needs docs!** <br>Create a README.md in the pattern's directory and add details about using this pattern in markdown.";
38
+
39
+ return Promise.resolve( marked( noDocsMessage ) );
40
+ } );
41
41
 
42
42
  // Support `{{ item|markup }}` syntax for outputting escaped content within loops.
43
43
  const markupFilter = new TwingFilter(
44
44
  'markup',
45
45
  ( string ) => Promise.resolve( string ),
46
46
  {},
47
- { is_safe: ['html'] }
47
+ { is_safe: [ 'html' ] }
48
48
  );
49
49
 
50
50
  const kebabify = ( name ) => {
51
- let kebabCase = [];
51
+ const kebabCase = [];
52
52
 
53
53
  // TODO: find a more concise way of turning a string into an iterable
54
- for (let i = 0; i < name.length; i++) {
55
- let letter = name[i];
56
- kebabCase[i] = letter;
54
+ for ( let i = 0; i < name.length; i++ ) {
55
+ const letter = name[ i ];
56
+ kebabCase[ i ] = letter;
57
57
  }
58
58
 
59
59
  return kebabCase.reduce( ( a, b ) => {
@@ -61,47 +61,51 @@ const kebabify = ( name ) => {
61
61
  return a.toLowerCase() + '-';
62
62
  }
63
63
  return a.toLowerCase() + b.toLowerCase();
64
- });
64
+ } );
65
65
  };
66
66
 
67
67
  // TODO: Could be an array/iterator if the namespace can be extracted from the key, the larva.config API could
68
68
  // change to `patterns: { larva: /larva/path/here/, project: /project/path/here }`
69
69
  loader.addPath( patternConfig.larvaPatternsDir, 'larva' );
70
70
 
71
- if( fs.existsSync( patternConfig.projectPatternsDir ) ) {
71
+ if ( fs.existsSync( patternConfig.projectPatternsDir ) ) {
72
72
  loader.addPath( patternConfig.projectPatternsDir, 'project' );
73
73
  }
74
74
 
75
- let twing = new TwingEnvironment( loader, { debug: true } );
75
+ const twing = new TwingEnvironment( loader, { debug: true } );
76
76
 
77
77
  twing.addFilter( markdownFilter );
78
78
  twing.addFilter( markupFilter );
79
79
 
80
80
  // Add custom function support for doing wp action: {{ wp_action( ... ) }}
81
- twing.addFunction(new TwingFunction('wp_action',() => {
82
- // We're relying on twig-to-php-parser for translation, so just return empty string for now
83
- return Promise.resolve('');
84
- }));
81
+ twing.addFunction(
82
+ new TwingFunction( 'wp_action', () => {
83
+ // We're relying on twig-to-php-parser for translation, so just return empty string for now
84
+ return Promise.resolve( '' );
85
+ } )
86
+ );
85
87
 
86
- let patterns = {
88
+ const patterns = {
87
89
  larva: getAllPatternsObj( patternConfig.larvaPatternsDir ),
88
- project: getAllPatternsObj( patternConfig.projectPatternsDir )
90
+ project: getAllPatternsObj( patternConfig.projectPatternsDir ),
89
91
  };
90
92
 
91
93
  // Use the project version if it exists, else use the larva version
92
94
  if ( fs.existsSync( assetsConfig.path ) ) {
93
- app.use( '/assets' , express.static( assetsConfig.path ) );
95
+ app.use( '/assets', express.static( assetsConfig.path ) );
94
96
  }
95
97
 
96
98
  // Expose any theme directories with assets in the express server
97
99
  const themeAssetKeys = Object.keys( themeAssetsConfig );
98
100
 
99
- themeAssetKeys.forEach( key => {
100
- app.use( '/assets/theme/' + key , express.static( themeAssetsConfig[key] ) );
101
- });
102
-
103
- app.use( '/:source?/css', function (req, res) {
101
+ themeAssetKeys.forEach( ( key ) => {
102
+ app.use(
103
+ '/assets/theme/' + key,
104
+ express.static( themeAssetsConfig[ key ] )
105
+ );
106
+ } );
104
107
 
108
+ app.use( '/:source?/css', function ( req, res ) {
105
109
  /**
106
110
  * Generate Larva CSS Docs
107
111
  *
@@ -118,8 +122,14 @@ app.use( '/:source?/css', function (req, res) {
118
122
  */
119
123
 
120
124
  const postcss = require( 'postcss' );
121
- const cssPath = path.join( process.cwd(), './node_modules/@penskemediacorp/larva/build/css/larva.css' );
122
- const sassPath = path.join( process.cwd(), './node_modules/@penskemediacorp/larva-css/src/' );
125
+ const cssPath = path.join(
126
+ process.cwd(),
127
+ './node_modules/@penskemediacorp/larva/build/css/larva.css'
128
+ );
129
+ const sassPath = path.join(
130
+ process.cwd(),
131
+ './node_modules/@penskemediacorp/larva-css/src/'
132
+ );
123
133
 
124
134
  const hasTokens = [
125
135
  'u-background-color',
@@ -132,65 +142,62 @@ app.use( '/:source?/css', function (req, res) {
132
142
  ];
133
143
 
134
144
  const baseNames = ( () => {
135
-
136
- let files = globby.sync( sassPath, {
145
+ const files = globby.sync( sassPath, {
137
146
  expandDirectories: {
138
- files: ['*.scss']
139
- }
147
+ files: [ '*.scss' ],
148
+ },
140
149
  } );
141
150
 
142
151
  return files.map( ( item ) => {
143
- let parts = item.split( '/' );
144
- let baseName = parts[ parts.length - 1 ].split( '.' );
145
- return baseName[0];
152
+ const parts = item.split( '/' );
153
+ const baseName = parts[ parts.length - 1 ].split( '.' );
154
+ return baseName[ 0 ];
146
155
  } );
147
156
  } )();
148
157
 
149
158
  const cssString = fs.readFileSync( cssPath );
150
159
 
151
- const cssRoot = postcss.parse( cssString )
160
+ const cssRoot = postcss.parse( cssString );
152
161
 
153
162
  const generatedSpec = ( () => {
154
- let obj = {};
163
+ const obj = {};
155
164
 
156
165
  baseNames.forEach( ( item ) => {
157
- obj[item] = {
166
+ obj[ item ] = {
158
167
  selectors: [],
159
- tokens: false
168
+ tokens: false,
160
169
  };
161
- })
170
+ } );
162
171
 
163
172
  return obj;
164
173
  } )();
165
174
 
166
- cssRoot.walkRules( rule => {
167
-
168
- Object.keys( generatedSpec ).forEach( key => {
169
- let regex = new RegExp( '.*lrv-' + key + '.*', 'g' );
175
+ cssRoot.walkRules( ( rule ) => {
176
+ Object.keys( generatedSpec ).forEach( ( key ) => {
177
+ const regex = new RegExp( '.*lrv-' + key + '.*', 'g' );
170
178
 
171
179
  if ( -1 !== hasTokens.indexOf( key ) ) {
172
- generatedSpec[key]['tokens'] = true;
180
+ generatedSpec[ key ].tokens = true;
173
181
  }
174
182
 
175
183
  if ( rule.selector.match( regex ) ) {
176
- generatedSpec[key]['selectors'].push( rule.selector );
184
+ generatedSpec[ key ].selectors.push( rule.selector );
177
185
  }
178
-
179
- });
180
-
186
+ } );
181
187
  } );
182
188
 
183
- req.params[ 'name' ] = 'Larva CSS';
184
- req.params[ 'spec' ] = generatedSpec;
185
-
186
- req.params[ 'source' ] = 'larva';
187
- req.params[ 'pattern_nav' ] = patterns;
189
+ req.params.name = 'Larva CSS';
190
+ req.params.spec = generatedSpec;
188
191
 
189
- twing.render( 'css.html', req.params ).then( output => res.end( output ) );
190
- });
192
+ req.params.source = 'larva';
193
+ req.params.pattern_nav = patterns;
191
194
 
192
- app.get( '/:source/:type/:name/:variant?', function (req, res) {
195
+ twing
196
+ .render( 'css.html', req.params )
197
+ .then( ( output ) => res.end( output ) );
198
+ } );
193
199
 
200
+ app.get( '/:source/:type/:name/:variant?', function ( req, res ) {
194
201
  let patternsPath;
195
202
 
196
203
  if ( 'larva' === req.params.source ) {
@@ -202,83 +209,98 @@ app.get( '/:source/:type/:name/:variant?', function (req, res) {
202
209
  }
203
210
 
204
211
  // Support query parameters for conditionally loading stylesheets and scripts
205
- req.params[ 'query' ] = req.query;
206
- req.params[ 'pattern_nav' ] = patterns;
207
- req.params[ 'data' ] = undefined !== patternsPath ? getPatternData( patternsPath, req.params ) : null;
208
- req.params[ 'brand' ] = req.query.tokens ? req.query.tokens : brandConfig;
209
- req.params[ 'variants' ] = patterns[req.params.source][req.params.type][req.params.name];
212
+ req.params.query = req.query;
213
+ req.params.pattern_nav = patterns;
214
+ req.params.data =
215
+ undefined !== patternsPath
216
+ ? getPatternData( patternsPath, req.params )
217
+ : null;
218
+ req.params.brand = req.query.tokens ? req.query.tokens : brandConfig;
219
+ req.params.variants =
220
+ patterns[ req.params.source ][ req.params.type ][ req.params.name ];
210
221
 
211
222
  if ( 'algorithms' !== req.params.type ) {
212
- req.params[ 'json_pretty' ] = JSON.stringify( req.params[ 'data' ], null, '\t' );
223
+ req.params.json_pretty = JSON.stringify( req.params.data, null, '\t' );
213
224
  }
214
225
 
215
- twing.render( 'pattern.html', req.params ).then( ( output ) => {
216
- res.end( output );
217
- }).catch( e => {
218
- const errorMessage = `Cannot render template! \n\n${e}`;
226
+ twing
227
+ .render( 'pattern.html', req.params )
228
+ .then( ( output ) => {
229
+ res.end( output );
230
+ } )
231
+ .catch( ( e ) => {
232
+ const errorMessage = `Cannot render template! \n\n${ e }`;
219
233
 
220
- console.log( e );
234
+ console.log( e );
221
235
 
222
- res.end( errorMessage );
223
- } );
224
- });
225
-
226
- app.get( '/:source?/style-guide', function (req, res ) {
236
+ res.end( errorMessage );
237
+ } );
238
+ } );
227
239
 
240
+ app.get( '/:source?/style-guide', function ( req, res ) {
228
241
  const brand = req.query.tokens ? req.query.tokens : brandConfig;
229
242
  const tokensPath = path.join( assetsConfig.path, 'build/tokens' );
230
243
 
231
- const tokensData = (() => {
244
+ const tokensData = ( () => {
232
245
  try {
233
- return require( path.join( tokensPath, `${brand}.json` ) );
246
+ return require( path.join( tokensPath, `${ brand }.json` ) );
234
247
  } catch ( e ) {
235
248
  return null;
236
249
  }
237
- })();
250
+ } )();
238
251
 
239
252
  const colorsByProperty = ( () => {
240
253
  if ( ! tokensData ) return;
241
254
 
242
- const colorTokens = Object.keys( tokensData ).filter( item => item.includes( 'COLOR' ) );
243
- const colorNames = colorTokens.map( token => kebabify( token ) );
244
-
245
- return colorNames.reduce( (acc, curr) => {
246
- Object.keys( acc ).forEach( key => {
247
- if ( curr.startsWith( key ) ) {
248
- acc[key].push( 'lrv-u-' + curr );
249
- }
250
- });
251
-
252
- return acc;
253
- }, {
254
- color: [],
255
- 'background-color': [],
256
- 'border-color': []
257
- });
258
- })();
259
-
260
- req.params[ 'name' ] = `Style Guide`;
261
- req.params[ 'font_styles' ] = fontData.groupedSelectors;
262
- req.params[ 'colors' ] = colorsByProperty;
263
- req.params[ 'brand' ] = req.query.tokens ? req.query.tokens : brandConfig;
264
- req.params[ 'pattern_nav' ] = patterns;
265
-
266
- twing.render( 'style-guide/index.html', req.params ).then( output => res.end( output ) ).catch( e => {
267
- const errorMessage = `Cannot render template! \n\n${e}`;
255
+ const colorTokens = Object.keys( tokensData ).filter( ( item ) =>
256
+ item.includes( 'COLOR' )
257
+ );
258
+ const colorNames = colorTokens.map( ( token ) => kebabify( token ) );
259
+
260
+ return colorNames.reduce(
261
+ ( acc, curr ) => {
262
+ Object.keys( acc ).forEach( ( key ) => {
263
+ if ( curr.startsWith( key ) ) {
264
+ acc[ key ].push( 'lrv-u-' + curr );
265
+ }
266
+ } );
267
+
268
+ return acc;
269
+ },
270
+ {
271
+ color: [],
272
+ 'background-color': [],
273
+ 'border-color': [],
274
+ }
275
+ );
276
+ } )();
268
277
 
269
- console.log( e );
278
+ req.params.name = `Style Guide`;
279
+ req.params.font_styles = fontData.groupedSelectors;
280
+ req.params.colors = colorsByProperty;
281
+ req.params.brand = req.query.tokens ? req.query.tokens : brandConfig;
282
+ req.params.pattern_nav = patterns;
270
283
 
271
- res.end( errorMessage );
272
- } );
284
+ twing
285
+ .render( 'style-guide/index.html', req.params )
286
+ .then( ( output ) => res.end( output ) )
287
+ .catch( ( e ) => {
288
+ const errorMessage = `Cannot render template! \n\n${ e }`;
273
289
 
274
- });
290
+ console.log( e );
275
291
 
276
- app.get( '/:source?/:type?', function (req, res) {
277
- req.params[ 'source' ] = 'larva';
278
- req.params[ 'type' ] = req.params.type;
279
- req.params[ 'pattern_nav' ] = patterns;
280
- req.params[ 'brand' ] = req.query.tokens ? req.query.tokens : brandConfig;
281
- twing.render( 'index.html', req.params ).then( output => res.end( output ) );
282
- });
292
+ res.end( errorMessage );
293
+ } );
294
+ } );
295
+
296
+ app.get( '/:source?/:type?', function ( req, res ) {
297
+ req.params.source = 'larva';
298
+ req.params.type = req.params.type;
299
+ req.params.pattern_nav = patterns;
300
+ req.params.brand = req.query.tokens ? req.query.tokens : brandConfig;
301
+ twing
302
+ .render( 'index.html', req.params )
303
+ .then( ( output ) => res.end( output ) );
304
+ } );
283
305
 
284
306
  module.exports = app;
package/lib/start.js CHANGED
@@ -4,4 +4,4 @@ const port = process.env.NODE_PORT || 3000;
4
4
 
5
5
  app.listen( port, () => {
6
6
  console.log( 'Larva server is listening on port ' + port );
7
- });
7
+ } );
@@ -10,4 +10,4 @@ module.exports = function clonePatternData( slug ) {
10
10
  } catch {
11
11
  return clonedeep( require( path.join( larvaPatternsDir, slug ) ) );
12
12
  }
13
- }
13
+ };
@@ -14,20 +14,19 @@ const chalk = require( 'chalk' );
14
14
  */
15
15
 
16
16
  module.exports = function copySyncHelper( src, dest ) {
17
-
18
17
  const name = path.basename( src );
19
18
 
20
19
  try {
21
20
  fs.copySync( src, dest );
22
21
 
23
- console.log( `Copied '${name}'.` );
22
+ console.log( `Copied '${ name }'.` );
24
23
  } catch ( e ) {
25
-
26
24
  if ( 'ENOENT' === e.code ) {
27
- console.log( chalk.grey( `Can't find '${name}' to copy, skipping.` ) );
25
+ console.log(
26
+ chalk.grey( `Can't find '${ name }' to copy, skipping.` )
27
+ );
28
28
  } else {
29
29
  console.error( e );
30
30
  }
31
-
32
31
  }
33
- }
32
+ };
@@ -13,36 +13,41 @@ const config = getAppConfiguration( 'patterns' );
13
13
  * return an object representing all the pattern types, patterns, and their variants.
14
14
  *
15
15
  * @param {string} startPath - Path to look in for all patterns. Should be assets/src/patterns.
16
- * @return {object} - Object representing all patterns and variants
16
+ * @return {Object} - Object representing all patterns and variants
17
17
  */
18
18
 
19
19
  module.exports = function getAllPatternsObj( startPath ) {
20
-
21
20
  const patternDirs = getSubDirectoryNames( startPath );
22
21
 
23
- let obj = {};
22
+ const obj = {};
24
23
 
25
24
  try {
26
25
  patternDirs.map( ( patternType ) => {
27
26
  let patterns = [];
28
- obj[patternType] = {};
27
+ obj[ patternType ] = {};
29
28
 
30
29
  // Modules can be ignored, which maybe is unecessary
31
30
  // but for now continue on that path.
32
31
  if ( 'modules' === patternType ) {
33
- patterns = getModuleNamesFromDirectory( startPath, config.ignoredModules );
32
+ patterns = getModuleNamesFromDirectory(
33
+ startPath,
34
+ config.ignoredModules
35
+ );
34
36
  } else {
35
- patterns = getSubDirectoryNames( path.join( startPath, patternType ) );
37
+ patterns = getSubDirectoryNames(
38
+ path.join( startPath, patternType )
39
+ );
36
40
  }
37
41
 
38
42
  patterns.map( ( pattern ) => {
39
- obj[patternType][pattern] = getPatternVariants( path.join( startPath, `${patternType}/${pattern}` ) );
43
+ obj[ patternType ][ pattern ] = getPatternVariants(
44
+ path.join( startPath, `${ patternType }/${ pattern }` )
45
+ );
40
46
  } );
41
-
42
47
  } );
43
48
  } catch ( e ) {
44
49
  console.error( e );
45
50
  }
46
51
 
47
52
  return obj;
48
- }
53
+ };
@@ -18,64 +18,66 @@ const path = require( 'path' );
18
18
  */
19
19
 
20
20
  const defaultConfig = {
21
-
22
21
  eslint: {
23
- configFile: path.join( __dirname, '../../scripts/config/.eslintrc.json' ),
22
+ configFile: path.join(
23
+ __dirname,
24
+ '../../scripts/config/.eslintrc.json'
25
+ ),
24
26
  },
25
27
 
26
28
  webpack: {
27
29
  aliases: {
28
30
  '@js': path.resolve( './src/js' ),
29
31
  '@npm': path.resolve( './node_modules' ),
30
- '@larva-js': path.resolve( './node_modules/@penskemediacorp/larva-js/src' ),
32
+ '@larva-js': path.resolve(
33
+ './node_modules/@penskemediacorp/larva-js/src'
34
+ ),
31
35
  },
32
36
  entries: {
33
37
  'larva-ui': path.resolve( './entries/larva-ui.entry.js' ),
34
- common: path.resolve( './entries/common.entry.js' )
35
- }
38
+ common: path.resolve( './entries/common.entry.js' ),
39
+ },
36
40
  },
37
41
 
38
42
  patterns: {
39
- larvaPatternsDir: path.resolve( './node_modules/@penskemediacorp/larva-patterns' ),
43
+ larvaPatternsDir: path.resolve(
44
+ './node_modules/@penskemediacorp/larva-patterns'
45
+ ),
40
46
  projectPatternsDir: path.resolve( './src/patterns' ),
41
47
  },
42
48
 
43
49
  assets: {
44
50
  path: ( () => {
45
-
46
51
  // Fragile way to detect existing Larva sites
47
52
  if ( fs.existsSync( path.resolve( './build/css' ) ) ) {
48
53
  return path.resolve( './' );
49
54
  }
50
55
 
51
56
  return path.resolve( './node_modules/@penskemediacorp/larva' );
52
- })(),
57
+ } )(),
53
58
  },
54
59
 
55
60
  themeAssets: {},
56
61
  };
57
62
 
58
63
  module.exports = function getAppConfiguration( key, usePackageDefault = true ) {
59
-
60
64
  try {
61
-
62
65
  let appRoot = process.cwd();
63
66
 
64
67
  if ( 'test' === process.env.NODE_ENV ) {
65
68
  appRoot = path.join( __dirname, '../../__tests__/fixtures/' );
66
69
  }
67
70
 
68
- let config = require( `${appRoot}/larva.config.js` );
71
+ const config = require( `${ appRoot }/larva.config.js` );
69
72
 
70
73
  // If config not found in approot, fallback to package default in root
71
- if ( undefined === config[key] && usePackageDefault ) {
74
+ if ( undefined === config[ key ] && usePackageDefault ) {
72
75
  return defaultConfig[ key ];
73
76
  }
74
77
 
75
- return config[key];
76
-
78
+ return config[ key ];
77
79
  } catch ( error ) {
78
- console.warn( 'Using default configuration. ');
80
+ console.warn( 'Using default configuration. ' );
79
81
 
80
82
  return defaultConfig[ key ];
81
83
  }
@@ -1,3 +1,3 @@
1
1
  module.exports = function getArgsFromCli() {
2
- return process.argv.slice(2);
3
- }
2
+ return process.argv.slice( 2 );
3
+ };
@@ -1,11 +1,18 @@
1
1
  const getSubDirectoryNames = require( './getSubDirectoryNames' );
2
2
  const path = require( 'path' );
3
3
 
4
- module.exports = function getModuleNamesFromDirectory( directory, ignoredModules = [] ) {
5
- let moduleNames = getSubDirectoryNames( path.join( directory , 'modules' ) );
4
+ module.exports = function getModuleNamesFromDirectory(
5
+ directory,
6
+ ignoredModules = []
7
+ ) {
8
+ const moduleNames = getSubDirectoryNames(
9
+ path.join( directory, 'modules' )
10
+ );
6
11
 
7
12
  return moduleNames.filter( ( moduleName ) => {
8
- return ! moduleName.startsWith( '_' ) && -1 === ignoredModules.indexOf( moduleName );
9
- });
10
-
11
- }
13
+ return (
14
+ ! moduleName.startsWith( '_' ) &&
15
+ -1 === ignoredModules.indexOf( moduleName )
16
+ );
17
+ } );
18
+ };
@@ -4,31 +4,39 @@ const path = require( 'path' );
4
4
  * Get Pattern Data
5
5
  *
6
6
  * @param {string} patternsPath
7
- * @param {object} params Object containing name of pattern
7
+ * @param {Object} params Object containing name of pattern
8
8
  */
9
9
  function getPatternData( patternsPath, params ) {
10
-
11
10
  const variant = params.variant || 'prototype';
12
- const patternPath = path.join( patternsPath, params.type, params.name, params.name + '.' + variant + '.js' );
13
- const jsonPath = path.join( patternsPath, params.type, params.name, params.name + '.json' )
11
+ const patternPath = path.join(
12
+ patternsPath,
13
+ params.type,
14
+ params.name,
15
+ params.name + '.' + variant + '.js'
16
+ );
17
+ const jsonPath = path.join(
18
+ patternsPath,
19
+ params.type,
20
+ params.name,
21
+ params.name + '.json'
22
+ );
14
23
 
15
24
  try {
16
25
  return require( patternPath );
17
- } catch( e ) {
26
+ } catch ( e ) {
18
27
  const originalError = e;
19
28
 
20
29
  try {
21
30
  // Backwards compat for Deadline when patterns were stored as JSON
22
- let patternData = require( jsonPath );
31
+ const patternData = require( jsonPath );
23
32
  return patternData;
24
33
  } catch ( e ) {
25
34
  return {
26
- message: `Error getting data for "${params.name}".<br>There is likely a problem with ${params.name}.${variant}.js.`,
27
- error: originalError
28
- }
35
+ message: `Error getting data for "${ params.name }".<br>There is likely a problem with ${ params.name }.${ variant }.js.`,
36
+ error: originalError,
37
+ };
29
38
  }
30
39
  }
31
-
32
40
  }
33
41
 
34
- module.exports = getPatternData;
42
+ module.exports = getPatternData;