@penskemediacorp/larva 1.25.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.
- package/__tests__/fixtures/larva.config.js +9 -16
- package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.featured.aia.js +2 -2
- package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.featured.js +2 -2
- package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.js +1 -1
- package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.prototype.js +2 -2
- package/__tests__/fixtures/src/patterns/components/c-tagline/c-tagline.prototype.js +2 -2
- package/__tests__/fixtures/src/patterns/modules/_also-ignored/_also-ignored.prototype.js +2 -2
- package/__tests__/fixtures/src/patterns/modules/test-module/test-module.featured.js +2 -2
- package/__tests__/fixtures/src/patterns/modules/test-module/test-module.prototype.js +2 -2
- package/__tests__/fixtures/src/patterns/one-offs/newswire/newswire.prototype.js +2 -2
- package/__tests__/lib/generateStatic.test.js +120 -86
- package/__tests__/lib/utils/clonePatternData.test.js +17 -10
- package/__tests__/lib/utils/getAllPatternsObj.test.js +14 -29
- package/__tests__/lib/utils/getAppConfiguration.test.js +5 -5
- package/__tests__/lib/utils/getModuleNamesFromDirectory.test.js +29 -10
- package/__tests__/lib/utils/getPatternData.test.js +36 -23
- package/__tests__/lib/utils/getPatternPathsToLoad.test.js +5 -5
- package/__tests__/lib/utils/getPatternRoutes.test.js +4 -6
- package/__tests__/lib/utils/getPatternType.test.js +4 -4
- package/__tests__/lib/utils/getPatternVariants.test.js +7 -12
- package/__tests__/lib/utils/getPatternsIndexPath.test.js +9 -4
- package/__tests__/lib/utils/getSubDirectoryNames.test.js +16 -6
- package/__tests__/lib/utils/isCoreTheme.test.js +5 -3
- package/__tests__/lib/utils/writeJsonToFile.test.js +8 -10
- package/__tests__/lib/writeJson.test.js +39 -21
- package/bin/larva.js +6 -6
- package/build/css/larva-important.css +1 -1
- package/build/css/larva.css +1 -1
- package/build/css/larva.inline-important.css +1 -1
- package/build/css/larva.inline.css +1 -1
- package/build/js/standalone/video-showcase.js +6 -6
- package/build/svg/defs/sprite.defs.html +1 -1
- package/index.js +1 -1
- package/lib/generateStatic.js +67 -63
- package/lib/server.js +139 -117
- package/lib/start.js +1 -1
- package/lib/utils/clonePatternData.js +1 -1
- package/lib/utils/copySyncHelper.js +5 -6
- package/lib/utils/getAllPatternsObj.js +14 -9
- package/lib/utils/getAppConfiguration.js +17 -15
- package/lib/utils/getArgsFromCli.js +2 -2
- package/lib/utils/getModuleNamesFromDirectory.js +13 -6
- package/lib/utils/getPatternData.js +19 -11
- package/lib/utils/getPatternPathsToLoad.js +5 -5
- package/lib/utils/getPatternRoutes.js +29 -27
- package/lib/utils/getPatternType.js +3 -3
- package/lib/utils/getPatternVariants.js +5 -6
- package/lib/utils/getPatternsIndexPath.js +3 -3
- package/lib/utils/getSubDirectoryNames.js +5 -5
- package/lib/utils/isCoreTheme.js +1 -2
- package/lib/utils/renderSass.js +17 -14
- package/lib/utils/spawnScript.js +4 -9
- package/lib/utils/writeJsonToFile.js +2 -2
- package/lib/writeJson.js +34 -15
- package/package.json +15 -12
- package/scripts/build-html.js +21 -14
- package/scripts/build-icons.js +38 -26
- package/scripts/build-scss.js +1 -1
- package/scripts/config/.eslintrc.json +2 -1
- package/scripts/config/gulpfile.js +0 -1
- package/scripts/config/stylelint.config.js +1 -1
- package/scripts/config/webpack.config.js +22 -20
- package/scripts/dev-js.js +1 -1
- package/scripts/dev-scss.js +2 -7
- package/scripts/help.js +9 -7
- package/scripts/init.js +4 -2
- package/scripts/larva/larva.config.js +1 -1
- package/scripts/link-all.js +2 -2
- package/scripts/lint-js.js +1 -4
- package/scripts/lint-scss.js +5 -7
- package/scripts/lint.js +4 -4
- package/scripts/prod-js.js +1 -4
- package/scripts/prod-scss.js +5 -2
- package/scripts/prod.js +16 -22
- package/scripts/server.js +1 -3
- package/scripts/start.js +3 -3
- package/scripts/upgrade.js +10 -14
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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'
|
|
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(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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(
|
|
122
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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]
|
|
180
|
+
generatedSpec[ key ].tokens = true;
|
|
173
181
|
}
|
|
174
182
|
|
|
175
183
|
if ( rule.selector.match( regex ) ) {
|
|
176
|
-
generatedSpec[key]
|
|
184
|
+
generatedSpec[ key ].selectors.push( rule.selector );
|
|
177
185
|
}
|
|
178
|
-
|
|
179
|
-
});
|
|
180
|
-
|
|
186
|
+
} );
|
|
181
187
|
} );
|
|
182
188
|
|
|
183
|
-
req.params
|
|
184
|
-
req.params
|
|
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
|
-
|
|
190
|
-
|
|
192
|
+
req.params.source = 'larva';
|
|
193
|
+
req.params.pattern_nav = patterns;
|
|
191
194
|
|
|
192
|
-
|
|
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
|
|
206
|
-
req.params
|
|
207
|
-
req.params
|
|
208
|
-
|
|
209
|
-
|
|
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
|
|
223
|
+
req.params.json_pretty = JSON.stringify( req.params.data, null, '\t' );
|
|
213
224
|
}
|
|
214
225
|
|
|
215
|
-
twing
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
234
|
+
console.log( e );
|
|
221
235
|
|
|
222
|
-
|
|
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(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
@@ -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(
|
|
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 {
|
|
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
|
-
|
|
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(
|
|
32
|
+
patterns = getModuleNamesFromDirectory(
|
|
33
|
+
startPath,
|
|
34
|
+
config.ignoredModules
|
|
35
|
+
);
|
|
34
36
|
} else {
|
|
35
|
-
patterns = getSubDirectoryNames(
|
|
37
|
+
patterns = getSubDirectoryNames(
|
|
38
|
+
path.join( startPath, patternType )
|
|
39
|
+
);
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
patterns.map( ( pattern ) => {
|
|
39
|
-
obj[patternType][pattern] = getPatternVariants(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
5
|
-
|
|
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
|
|
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 {
|
|
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(
|
|
13
|
-
|
|
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
|
-
|
|
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;
|