@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.
- 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 +7 -7
- package/build/svg/defs/sprite.defs.html +1 -1
- package/build/tokens/spy-2022.custom-properties.css +1 -0
- package/build/tokens/spy-2022.json +521 -0
- package/build/tokens/spy-2022.map.scss +536 -0
- package/build/tokens/spy-2022.raw.json +4039 -0
- 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/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
|
};
|
package/lib/generateStatic.js
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
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
|
+
};
|