@penskemediacorp/larva 1.25.0 → 1.28.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 (82) 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/js/standalone/video-showcase.js +7 -7
  32. package/build/svg/defs/sprite.defs.html +1 -1
  33. package/build/tokens/spy-2022.custom-properties.css +1 -0
  34. package/build/tokens/spy-2022.json +521 -0
  35. package/build/tokens/spy-2022.map.scss +536 -0
  36. package/build/tokens/spy-2022.raw.json +4039 -0
  37. package/index.js +1 -1
  38. package/lib/generateStatic.js +67 -63
  39. package/lib/server.js +139 -117
  40. package/lib/start.js +1 -1
  41. package/lib/utils/clonePatternData.js +1 -1
  42. package/lib/utils/copySyncHelper.js +5 -6
  43. package/lib/utils/getAllPatternsObj.js +14 -9
  44. package/lib/utils/getAppConfiguration.js +17 -15
  45. package/lib/utils/getArgsFromCli.js +2 -2
  46. package/lib/utils/getModuleNamesFromDirectory.js +13 -6
  47. package/lib/utils/getPatternData.js +19 -11
  48. package/lib/utils/getPatternPathsToLoad.js +5 -5
  49. package/lib/utils/getPatternRoutes.js +29 -27
  50. package/lib/utils/getPatternType.js +3 -3
  51. package/lib/utils/getPatternVariants.js +5 -6
  52. package/lib/utils/getPatternsIndexPath.js +3 -3
  53. package/lib/utils/getSubDirectoryNames.js +5 -5
  54. package/lib/utils/isCoreTheme.js +1 -2
  55. package/lib/utils/renderSass.js +17 -14
  56. package/lib/utils/spawnScript.js +4 -9
  57. package/lib/utils/writeJsonToFile.js +2 -2
  58. package/lib/writeJson.js +34 -15
  59. package/package.json +15 -12
  60. package/scripts/build-html.js +21 -14
  61. package/scripts/build-icons.js +38 -26
  62. package/scripts/build-scss.js +1 -1
  63. package/scripts/config/.eslintrc.json +2 -1
  64. package/scripts/config/gulpfile.js +0 -1
  65. package/scripts/config/stylelint.config.js +1 -1
  66. package/scripts/config/webpack.config.js +22 -20
  67. package/scripts/dev-js.js +1 -1
  68. package/scripts/dev-scss.js +2 -7
  69. package/scripts/help.js +9 -7
  70. package/scripts/init.js +4 -2
  71. package/scripts/larva/larva.config.js +1 -1
  72. package/scripts/link-all.js +2 -2
  73. package/scripts/lint-js.js +1 -4
  74. package/scripts/lint-scss.js +5 -7
  75. package/scripts/lint.js +4 -4
  76. package/scripts/prod-js.js +1 -4
  77. package/scripts/prod-scss.js +5 -2
  78. package/scripts/prod.js +16 -22
  79. package/scripts/server.js +1 -3
  80. package/scripts/start.js +3 -3
  81. package/scripts/upgrade.js +10 -14
  82. package/scripts/write-json.js +4 -2
package/index.js CHANGED
@@ -3,5 +3,5 @@
3
3
  module.exports = {
4
4
  clone: require( './lib/utils/clonePatternData' ),
5
5
  getConfig: require( './lib/utils/getAppConfiguration' ),
6
- __experimentalCloneWithFallback: require( './lib/utils/clonePatternData' )
6
+ __experimentalCloneWithFallback: require( './lib/utils/clonePatternData' ),
7
7
  };
@@ -18,25 +18,29 @@ const themeAssetsConfig = getAppConfiguration( 'themeAssets' );
18
18
  * of each route, and write the content to directory structure that
19
19
  * mirrors the pattern routes.
20
20
  *
21
- * @param {array} routesArr An array of routes in a pattern server, excluding the pattern source (i.e. larva or project).
21
+ * @param {Array} routesArr An array of routes in a pattern server, excluding the pattern source (i.e. larva or project).
22
22
  * This is the result of getPatternRoutes.
23
23
  * @param {string} buildPath A directory where the HTML files should be written.
24
- * @param {function} done A callback function to run when the site generation completes.
24
+ * @param {Function} done A callback function to run when the site generation completes.
25
25
  * @param {string} urlBase The base URL for the pattern library e.g. 'http://localhost:3001/larva'.
26
26
  * Pattern routes will be appended to this. Should not end in slash.
27
27
  *
28
28
  * @see {@link getPatternRoutes}.
29
29
  */
30
30
 
31
-
32
- module.exports = function generateStatic( routesArr, buildPath, done, urlBase = 'http://localhost:3000/larva' ) {
31
+ module.exports = function generateStatic(
32
+ routesArr,
33
+ buildPath,
34
+ done,
35
+ urlBase = 'http://localhost:3000/larva'
36
+ ) {
33
37
  const errors = [];
34
38
 
35
39
  fs.mkdirpSync( buildPath );
36
40
 
37
41
  // Copy assets from assets/build and assets/public
38
42
  // to the static site build directory.
39
- console.log( '\nCopying assets...\n')
43
+ console.log( '\nCopying assets...\n' );
40
44
 
41
45
  // assets/public dir contains fonts and non-built things.
42
46
  const publicAssetsSrc = ( () => {
@@ -44,90 +48,90 @@ module.exports = function generateStatic( routesArr, buildPath, done, urlBase =
44
48
 
45
49
  // Fallback to assets in Larva
46
50
  if ( ! fs.existsSync( pubPath ) ) {
47
- pubPath = path.join( assetsConfig.path, 'public' )
51
+ pubPath = path.join( assetsConfig.path, 'public' );
48
52
  }
49
53
 
50
54
  return pubPath;
51
- })();
55
+ } )();
52
56
  const publicAssetsDest = path.join( buildPath, '../assets/public' );
53
57
 
54
- const builtAssets = [
55
- 'js',
56
- 'css',
57
- 'tokens',
58
- 'images',
59
- 'svg'
60
- ];
58
+ const builtAssets = [ 'js', 'css', 'tokens', 'images', 'svg' ];
61
59
 
62
- builtAssets.forEach( item => {
63
- const dest = path.join( buildPath, `../assets/build/${item}` );
64
- const src = path.join( assetsConfig.path, `build/${item}` );
60
+ builtAssets.forEach( ( item ) => {
61
+ const dest = path.join( buildPath, `../assets/build/${ item }` );
62
+ const src = path.join( assetsConfig.path, `build/${ item }` );
65
63
 
66
64
  copySyncHelper( src, dest );
67
- });
65
+ } );
68
66
 
69
67
  copySyncHelper( publicAssetsSrc, publicAssetsDest );
70
68
 
71
69
  const themeAssetKeys = Object.keys( themeAssetsConfig );
72
70
 
73
- themeAssetKeys.forEach( key => {
74
- const src = themeAssetsConfig[key];
75
- const dest = path.join( buildPath, `../assets/theme/${key}` );
71
+ themeAssetKeys.forEach( ( key ) => {
72
+ const src = themeAssetsConfig[ key ];
73
+ const dest = path.join( buildPath, `../assets/theme/${ key }` );
76
74
 
77
75
  copySyncHelper( src, dest );
78
- });
76
+ } );
79
77
 
80
78
  // Build the site.
81
79
  // Cycle through the list of routes and write the response
82
80
  // to files.
83
- console.log( '\nBuilding site...\n');
81
+ console.log( '\nBuilding site...\n' );
84
82
 
85
83
  try {
86
-
87
84
  const promises = routesArr.map( ( route ) => {
88
-
89
85
  const dir = path.join( buildPath, route );
90
- const url = `${urlBase}/${route}`;
91
-
92
- return axios.get( url ).then( ( response ) => {
93
-
94
- if ( 200 === response.status ) {
95
- mkdirp.sync( dir );
96
- fs.writeFileSync( `${dir}/index.html`, response.data );
97
- console.log( `Built ${route}.` );
98
- }
99
-
100
- } ).catch( ( e ) => {
101
-
102
- if ( 'ECONNREFUSED' === e.code ) {
103
- process.exitCode = 1;
104
- } else {
105
- mkdirp.sync( dir );
106
- fs.writeFileSync( `${dir}/index.html`, e.message );
107
-
108
- console.log( chalk.yellow( `Error writing ${route}: ${e.message}.` ) );
109
- }
110
-
111
- });
112
-
86
+ const url = `${ urlBase }/${ route }`;
87
+
88
+ return axios
89
+ .get( url )
90
+ .then( ( response ) => {
91
+ if ( 200 === response.status ) {
92
+ mkdirp.sync( dir );
93
+ fs.writeFileSync(
94
+ `${ dir }/index.html`,
95
+ response.data
96
+ );
97
+ console.log( `Built ${ route }.` );
98
+ }
99
+ } )
100
+ .catch( ( e ) => {
101
+ if ( 'ECONNREFUSED' === e.code ) {
102
+ process.exitCode = 1;
103
+ } else {
104
+ mkdirp.sync( dir );
105
+ fs.writeFileSync( `${ dir }/index.html`, e.message );
106
+
107
+ console.log(
108
+ chalk.yellow(
109
+ `Error writing ${ route }: ${ e.message }.`
110
+ )
111
+ );
112
+ }
113
+ } );
113
114
  } );
114
115
 
115
- axios.all( promises ).then( () => {
116
-
117
- if ( errors.length > 0 ) {
118
- console.log( errors );
119
- }
120
-
121
- done( chalk.green( `\nSite built to build/html/${path.basename( buildPath )}. Check output for issues.\n` ) );
122
-
123
- } ).catch( ( e ) => {
124
-
125
- done( chalk.bold.red( e ) );
126
-
127
- });
116
+ axios
117
+ .all( promises )
118
+ .then( () => {
119
+ if ( errors.length > 0 ) {
120
+ console.log( errors );
121
+ }
128
122
 
123
+ done(
124
+ chalk.green(
125
+ `\nSite built to build/html/${ path.basename(
126
+ buildPath
127
+ ) }. Check output for issues.\n`
128
+ )
129
+ );
130
+ } )
131
+ .catch( ( e ) => {
132
+ done( chalk.bold.red( e ) );
133
+ } );
129
134
  } catch ( e ) {
130
135
  console.error( e );
131
136
  }
132
-
133
- }
137
+ };
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
+ };