@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
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
const fs = require( 'fs' );
|
|
2
2
|
|
|
3
3
|
module.exports = function getPatternPathsToLoad( config ) {
|
|
4
|
-
|
|
4
|
+
const paths = [];
|
|
5
5
|
|
|
6
6
|
if ( undefined === config ) {
|
|
7
7
|
throw new Error( `Pattern configuration is undefined.` );
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
|
|
10
10
|
// Look in projectPatternsDir first.
|
|
11
|
-
if( fs.existsSync( config.projectPatternsDir ) ) {
|
|
11
|
+
if ( fs.existsSync( config.projectPatternsDir ) ) {
|
|
12
12
|
paths.push( config.projectPatternsDir );
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
if( fs.existsSync( config.larvaPatternsDir ) ) {
|
|
15
|
+
if ( fs.existsSync( config.larvaPatternsDir ) ) {
|
|
16
16
|
paths.push( config.larvaPatternsDir );
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
return paths;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
@@ -16,43 +16,45 @@
|
|
|
16
16
|
*
|
|
17
17
|
* Return an array with routes for every pattern in the object.
|
|
18
18
|
*
|
|
19
|
-
* @param {
|
|
20
|
-
* @return {
|
|
19
|
+
* @param {Object} patternsObj - An object with two levels of keys where patternObj['components']['c-link'] is an array of c-link variants.
|
|
20
|
+
* @return {Array} - An array of string routes e.g. [ '/components/c-link/', '/components/c-link/sponsored' ]
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
const chalk = require( 'chalk' );
|
|
24
24
|
|
|
25
25
|
module.exports = function getPatternRoutes( patterns ) {
|
|
26
|
-
|
|
27
26
|
let patternRoutes = [];
|
|
28
27
|
|
|
29
28
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
patternRoutes = Object.keys( patterns )
|
|
30
|
+
.map( ( type ) => {
|
|
31
|
+
return Object.keys( patterns[ type ] )
|
|
32
|
+
.map( ( name ) => {
|
|
33
|
+
const path = `${ type }/${ name }`;
|
|
34
|
+
|
|
35
|
+
if ( patterns[ type ][ name ].length > 1 ) {
|
|
36
|
+
return patterns[ type ][ name ].map(
|
|
37
|
+
( variant ) => {
|
|
38
|
+
if ( 'prototype' !== variant ) {
|
|
39
|
+
return path + '/' + variant;
|
|
40
|
+
}
|
|
41
|
+
return path;
|
|
42
|
+
}
|
|
43
|
+
);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} ).flat();
|
|
51
|
-
|
|
52
|
-
} ).flat();
|
|
45
|
+
return path;
|
|
46
|
+
} )
|
|
47
|
+
.flat();
|
|
48
|
+
} )
|
|
49
|
+
.flat();
|
|
53
50
|
} catch ( error ) {
|
|
54
|
-
console.error(
|
|
51
|
+
console.error(
|
|
52
|
+
chalk.red(
|
|
53
|
+
'Could not build the pattern routes. Is the pattern object structure correct?'
|
|
54
|
+
),
|
|
55
|
+
error
|
|
56
|
+
);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
return patternRoutes;
|
|
58
|
-
}
|
|
60
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Note 4/6/20 - This might not be necessary since we can use the directory name.
|
|
2
|
-
module.exports = function getPatternType
|
|
2
|
+
module.exports = function getPatternType( patternName ) {
|
|
3
3
|
const patternNamespace = patternName.substring( 0, 2 );
|
|
4
4
|
let patternType = 'modules';
|
|
5
5
|
|
|
6
|
-
if ( 'o-' ===
|
|
6
|
+
if ( 'o-' === patternNamespace ) {
|
|
7
7
|
patternType = 'objects';
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -12,4 +12,4 @@ module.exports = function getPatternType ( patternName ) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
return patternType;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Return an array of "variants", or the pattern.XX.js from a
|
|
2
|
+
* Return an array of "variants", or the pattern.XX.js from a
|
|
3
3
|
* given directory.
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* @param {string} startPath - the pattern directory to search.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const fs = require( 'fs' );
|
|
9
9
|
|
|
10
10
|
// https://regex101.com/r/DgnTR4/2
|
|
11
|
-
const regex = new RegExp( '(.[^.]+)
|
|
11
|
+
const regex = new RegExp( '(.[^.]+).(.+).js$' );
|
|
12
12
|
|
|
13
13
|
module.exports = function getPatternVariants( startPath ) {
|
|
14
|
-
|
|
15
14
|
// Only return Node prototype files that follow pattern name.XX.js
|
|
16
15
|
const files = fs.readdirSync( startPath ).filter( ( file ) => {
|
|
17
16
|
if ( /.+\..*\.js$/.test( file ) ) {
|
|
@@ -20,5 +19,5 @@ module.exports = function getPatternVariants( startPath ) {
|
|
|
20
19
|
} );
|
|
21
20
|
|
|
22
21
|
// Return array of the name of the variant e.g. XX in name.XX.js
|
|
23
|
-
return files.map( ( file ) => file.match( regex )[2] );
|
|
24
|
-
};
|
|
22
|
+
return files.map( ( file ) => file.match( regex )[ 2 ] );
|
|
23
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const isCoreTheme = require( './isCoreTheme' );
|
|
2
2
|
|
|
3
3
|
module.exports = function getPatternsIndexPath( config ) {
|
|
4
|
-
// TODO: add parent/child-esque logic for Larva patterns will occur i.e. the app
|
|
4
|
+
// TODO: add parent/child-esque logic for Larva patterns will occur i.e. the app
|
|
5
5
|
// should look first in the theme, then in larvaPatternsDir.
|
|
6
6
|
// if ( isCoreTheme( config ) ) {
|
|
7
|
-
|
|
7
|
+
return config.larvaPatternsDir;
|
|
8
8
|
// } else {
|
|
9
9
|
// return config.projectPatternsDir;
|
|
10
10
|
// }
|
|
11
|
-
}
|
|
11
|
+
};
|
|
@@ -5,19 +5,19 @@ const chalk = require( 'chalk' );
|
|
|
5
5
|
* Get Subdirectory names
|
|
6
6
|
*
|
|
7
7
|
* @param {string} path path to a directory containing subdirectories.
|
|
8
|
-
* @return {
|
|
8
|
+
* @return {Array} array of strings representing names of subdirectories.
|
|
9
9
|
*
|
|
10
10
|
* @link: https://stackoverflow.com/questions/18112204/get-all-directories-within-directory-nodejs
|
|
11
11
|
**/
|
|
12
12
|
|
|
13
13
|
module.exports = function getSubDirectoryNames( path ) {
|
|
14
14
|
try {
|
|
15
|
-
return fs.readdirSync( path ).filter( function( file ) {
|
|
15
|
+
return fs.readdirSync( path ).filter( function ( file ) {
|
|
16
16
|
if ( 'node_modules' !== file && 'fixtures' !== file ) {
|
|
17
17
|
return fs.statSync( path + '/' + file ).isDirectory();
|
|
18
18
|
}
|
|
19
|
-
});
|
|
19
|
+
} );
|
|
20
20
|
} catch {
|
|
21
|
-
console.error( path +
|
|
21
|
+
console.error( path + " doesn't exist." );
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
};
|
package/lib/utils/isCoreTheme.js
CHANGED
package/lib/utils/renderSass.js
CHANGED
|
@@ -3,18 +3,21 @@ const path = require( 'path' );
|
|
|
3
3
|
|
|
4
4
|
module.exports = function renderSass( sassData ) {
|
|
5
5
|
return new Promise( ( resolve, reject ) => {
|
|
6
|
-
sass.render(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
sass.render(
|
|
7
|
+
{
|
|
8
|
+
data: sassData,
|
|
9
|
+
includePaths: [
|
|
10
|
+
path.resolve( process.cwd(), './node_modules' ), // Command should be run from same directory as node_modules
|
|
11
|
+
path.resolve( process.cwd(), './src' ),
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
( err, result ) => {
|
|
15
|
+
if ( err ) {
|
|
16
|
+
reject( err );
|
|
17
|
+
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
19
|
+
resolve( result );
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
} );
|
|
23
|
+
};
|
package/lib/utils/spawnScript.js
CHANGED
|
@@ -5,7 +5,7 @@ const getArgsFromCli = require( './getArgsFromCli' );
|
|
|
5
5
|
// Filter out the first CLI argument which is the Larva command,
|
|
6
6
|
// and not needed for the binary.
|
|
7
7
|
const cliArgsWithoutScriptName = ( () => {
|
|
8
|
-
|
|
8
|
+
const cliArgs = getArgsFromCli();
|
|
9
9
|
|
|
10
10
|
if ( cliArgs.length ) {
|
|
11
11
|
cliArgs.shift();
|
|
@@ -15,12 +15,7 @@ const cliArgsWithoutScriptName = ( () => {
|
|
|
15
15
|
} )();
|
|
16
16
|
|
|
17
17
|
module.exports = function spawnScript( binaryFile, scriptArgs ) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[
|
|
22
|
-
... scriptArgs,
|
|
23
|
-
... cliArgsWithoutScriptName
|
|
24
|
-
], { stdio: 'inherit' }
|
|
25
|
-
);
|
|
18
|
+
spawn.sync( binaryFile, [ ...scriptArgs, ...cliArgsWithoutScriptName ], {
|
|
19
|
+
stdio: 'inherit',
|
|
20
|
+
} );
|
|
26
21
|
};
|
package/lib/writeJson.js
CHANGED
|
@@ -9,30 +9,46 @@ const writeJsonToFile = require( './utils/writeJsonToFile' );
|
|
|
9
9
|
|
|
10
10
|
// The fromLarva flag can come from CLI argument
|
|
11
11
|
module.exports = function writeJson( patternConfig, fromLarva = false ) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const sourceDirectory =
|
|
13
|
+
true === fromLarva
|
|
14
|
+
? patternConfig.larvaPatternsDir
|
|
15
|
+
: patternConfig.projectPatternsDir;
|
|
16
|
+
const ignoredModules = patternConfig.ignoredModules
|
|
17
|
+
? patternConfig.ignoredModules
|
|
18
|
+
: [];
|
|
19
|
+
const modulesArr = getModuleNamesFromDirectory(
|
|
20
|
+
sourceDirectory,
|
|
21
|
+
ignoredModules
|
|
22
|
+
);
|
|
16
23
|
|
|
17
24
|
modulesArr.forEach( ( moduleName ) => {
|
|
18
|
-
|
|
19
25
|
const startPath = sourceDirectory + '/modules/' + moduleName;
|
|
20
26
|
const variants = getPatternVariants( startPath );
|
|
21
27
|
|
|
22
28
|
variants.forEach( ( variant ) => {
|
|
23
|
-
|
|
24
29
|
const moduleData = getPatternData( sourceDirectory, {
|
|
25
30
|
type: 'modules',
|
|
26
31
|
name: moduleName,
|
|
27
|
-
variant
|
|
32
|
+
variant,
|
|
28
33
|
} );
|
|
29
34
|
|
|
30
|
-
const jsonDestPath = path.resolve(
|
|
35
|
+
const jsonDestPath = path.resolve(
|
|
36
|
+
patternConfig.projectPatternsDir,
|
|
37
|
+
'../../build/json/modules/' +
|
|
38
|
+
moduleName +
|
|
39
|
+
'.' +
|
|
40
|
+
variant +
|
|
41
|
+
'.json'
|
|
42
|
+
);
|
|
31
43
|
|
|
32
44
|
// If JSON data and module prototype are the same, pass, otherwise write the data to file
|
|
33
45
|
let hasChanged = true;
|
|
34
46
|
try {
|
|
35
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
fs.existsSync( jsonDestPath ) &&
|
|
49
|
+
JSON.stringify( require( jsonDestPath ) ) ===
|
|
50
|
+
JSON.stringify( moduleData )
|
|
51
|
+
) {
|
|
36
52
|
hasChanged = false;
|
|
37
53
|
}
|
|
38
54
|
} catch ( error ) {
|
|
@@ -41,13 +57,16 @@ module.exports = function writeJson( patternConfig, fromLarva = false ) {
|
|
|
41
57
|
|
|
42
58
|
if ( hasChanged ) {
|
|
43
59
|
writeJsonToFile( jsonDestPath, moduleData );
|
|
44
|
-
console.log(
|
|
60
|
+
console.log(
|
|
61
|
+
chalk.green.bold(
|
|
62
|
+
`Wrote JSON for ${ moduleName }.${ variant }`
|
|
63
|
+
)
|
|
64
|
+
);
|
|
45
65
|
} else {
|
|
46
|
-
console.log(
|
|
66
|
+
console.log(
|
|
67
|
+
chalk.grey( `No updates in ${ moduleName }.${ variant }` )
|
|
68
|
+
);
|
|
47
69
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
);
|
|
51
|
-
|
|
70
|
+
} );
|
|
52
71
|
} );
|
|
53
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@penskemediacorp/larva",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "laras126 <laras126@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Penske-Media-Corp/pmc-larva/tree/master/packages/larva#readme",
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/core": "^7.10.5",
|
|
45
45
|
"@babel/preset-env": "^7.10.4",
|
|
46
|
-
"@penskemediacorp/backstopjs-config": "^1.
|
|
47
|
-
"@penskemediacorp/eslint-config": "^1.
|
|
48
|
-
"@penskemediacorp/larva-css": "^1.
|
|
49
|
-
"@penskemediacorp/larva-js": "^1.
|
|
50
|
-
"@penskemediacorp/larva-patterns": "^1.
|
|
51
|
-
"@penskemediacorp/larva-scss": "^1.
|
|
52
|
-
"@penskemediacorp/larva-svg": "^1.
|
|
53
|
-
"@penskemediacorp/larva-tokens": "^1.
|
|
54
|
-
"@penskemediacorp/stylelint-config": "^1.
|
|
55
|
-
"@penskemediacorp/twig-to-php-parser": "^1.
|
|
46
|
+
"@penskemediacorp/backstopjs-config": "^1.26.0",
|
|
47
|
+
"@penskemediacorp/eslint-config": "^1.26.0",
|
|
48
|
+
"@penskemediacorp/larva-css": "^1.26.0",
|
|
49
|
+
"@penskemediacorp/larva-js": "^1.26.0",
|
|
50
|
+
"@penskemediacorp/larva-patterns": "^1.26.0",
|
|
51
|
+
"@penskemediacorp/larva-scss": "^1.26.0",
|
|
52
|
+
"@penskemediacorp/larva-svg": "^1.26.0",
|
|
53
|
+
"@penskemediacorp/larva-tokens": "^1.26.0",
|
|
54
|
+
"@penskemediacorp/stylelint-config": "^1.26.0",
|
|
55
|
+
"@penskemediacorp/twig-to-php-parser": "^1.26.0",
|
|
56
56
|
"axios": "^0.21.1",
|
|
57
57
|
"babel-loader": "^8.1.0",
|
|
58
58
|
"chalk": "^4.1.0",
|
|
@@ -89,5 +89,8 @@
|
|
|
89
89
|
"webpack": "^4.43.0",
|
|
90
90
|
"webpack-cli": "^3.3.12"
|
|
91
91
|
},
|
|
92
|
-
"
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"prettier": "npm:wp-prettier@^2.6.2"
|
|
94
|
+
},
|
|
95
|
+
"gitHead": "b9202e08f96e47041512b3b1a743c58f89b39152"
|
|
93
96
|
}
|
package/scripts/build-html.js
CHANGED
|
@@ -9,14 +9,17 @@ const getAllPatternsObj = require( '../lib/utils/getAllPatternsObj' );
|
|
|
9
9
|
|
|
10
10
|
const config = getAppConfiguration( 'patterns' );
|
|
11
11
|
const cliArgs = getArgsFromCli();
|
|
12
|
-
const source = 'larva' === cliArgs[1] ? 'larva' : 'project';
|
|
13
|
-
const port = process.env.NODE_PORT || '3000'
|
|
12
|
+
const source = 'larva' === cliArgs[ 1 ] ? 'larva' : 'project';
|
|
13
|
+
const port = process.env.NODE_PORT || '3000';
|
|
14
14
|
|
|
15
15
|
const urlBase = 'http://localhost:' + port + '/' + source;
|
|
16
16
|
const buildPath = path.join( process.cwd(), './build/html/' + source );
|
|
17
17
|
|
|
18
18
|
const patternsObj = ( () => {
|
|
19
|
-
const patternDir =
|
|
19
|
+
const patternDir =
|
|
20
|
+
'larva' === source
|
|
21
|
+
? config.larvaPatternsDir
|
|
22
|
+
: config.projectPatternsDir;
|
|
20
23
|
return getAllPatternsObj( patternDir );
|
|
21
24
|
} )();
|
|
22
25
|
|
|
@@ -32,7 +35,7 @@ const staticPaths = [
|
|
|
32
35
|
'',
|
|
33
36
|
];
|
|
34
37
|
|
|
35
|
-
staticPaths.forEach( p => {
|
|
38
|
+
staticPaths.forEach( ( p ) => {
|
|
36
39
|
// Only build these paths for the larva source.
|
|
37
40
|
if ( p === 'style-guide' || p === 'css' ) {
|
|
38
41
|
if ( 'larva' !== source ) {
|
|
@@ -40,13 +43,17 @@ staticPaths.forEach( p => {
|
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
routesArr.push( p )
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
generateStatic(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
routesArr.push( p );
|
|
47
|
+
} );
|
|
48
|
+
|
|
49
|
+
generateStatic(
|
|
50
|
+
routesArr,
|
|
51
|
+
buildPath,
|
|
52
|
+
( message ) => {
|
|
53
|
+
// TODO: copy assets into build path
|
|
54
|
+
// copy assets from larva package to static
|
|
55
|
+
// copy assets from project to assets
|
|
56
|
+
console.log( message );
|
|
57
|
+
},
|
|
58
|
+
urlBase
|
|
59
|
+
);
|
package/scripts/build-icons.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const SVGSpriter = require('svg-sprite');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const mkdirp = require('mkdirp');
|
|
6
|
-
const globby = require('globby');
|
|
7
|
-
const fs = require('fs');
|
|
3
|
+
const SVGSpriter = require( 'svg-sprite' );
|
|
4
|
+
const path = require( 'path' );
|
|
5
|
+
const mkdirp = require( 'mkdirp' );
|
|
6
|
+
const globby = require( 'globby' );
|
|
7
|
+
const fs = require( 'fs' );
|
|
8
8
|
const svgoConfig = require( './config/svgo-config.json' );
|
|
9
9
|
|
|
10
10
|
const projectIconsPath = path.join( process.cwd(), './src/svg/icons' );
|
|
11
|
-
const larvaIconsPath = path.join(
|
|
11
|
+
const larvaIconsPath = path.join(
|
|
12
|
+
process.cwd(),
|
|
13
|
+
'./node_modules/@penskemediacorp/larva-svg/src'
|
|
14
|
+
);
|
|
12
15
|
|
|
13
16
|
// TODO: unfinished feature
|
|
14
17
|
// const getSassVarsString = require( './lib/getSassVarsString' );
|
|
@@ -19,20 +22,20 @@ const config = {
|
|
|
19
22
|
mode: {
|
|
20
23
|
defs: {
|
|
21
24
|
example: true,
|
|
22
|
-
sprite: 'sprite.defs.svg'
|
|
23
|
-
}
|
|
25
|
+
sprite: 'sprite.defs.svg',
|
|
26
|
+
},
|
|
24
27
|
},
|
|
25
28
|
shape: {
|
|
26
29
|
id: {
|
|
27
30
|
separator: '',
|
|
28
31
|
},
|
|
29
32
|
transform: {
|
|
30
|
-
svgo: svgoConfig
|
|
31
|
-
}
|
|
33
|
+
svgo: svgoConfig,
|
|
34
|
+
},
|
|
32
35
|
},
|
|
33
36
|
svg: {
|
|
34
37
|
dimensionAttributes: false,
|
|
35
|
-
}
|
|
38
|
+
},
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
const spriter = new SVGSpriter( config );
|
|
@@ -40,21 +43,30 @@ const spriter = new SVGSpriter( config );
|
|
|
40
43
|
const svgFiles = globby.sync( [ larvaIconsPath, projectIconsPath ], {
|
|
41
44
|
expandDirectories: {
|
|
42
45
|
extensions: [ 'svg' ],
|
|
43
|
-
}
|
|
44
|
-
});
|
|
46
|
+
},
|
|
47
|
+
} );
|
|
45
48
|
|
|
46
49
|
// TODO: unfinished feature
|
|
47
50
|
// let scssIcons = {};
|
|
48
51
|
|
|
49
|
-
console.log(
|
|
52
|
+
console.log(
|
|
53
|
+
`Looking for icon SVGs in ${ path.relative(
|
|
54
|
+
process.cwd(),
|
|
55
|
+
larvaIconsPath
|
|
56
|
+
) } and ${ path.relative( process.cwd(), projectIconsPath ) }...`
|
|
57
|
+
);
|
|
50
58
|
|
|
51
|
-
svgFiles.forEach( file => {
|
|
59
|
+
svgFiles.forEach( ( file ) => {
|
|
52
60
|
// TODO: unfinished feature.
|
|
53
61
|
// Build Sass vars object
|
|
54
62
|
// scssIcons[ path.basename( file, '.svg' ) ] = fs.readFileSync( file, { encoding: 'utf-8' } );
|
|
55
63
|
|
|
56
|
-
spriter.add(
|
|
57
|
-
|
|
64
|
+
spriter.add(
|
|
65
|
+
file,
|
|
66
|
+
path.basename( file ),
|
|
67
|
+
fs.readFileSync( file, { encoding: 'utf-8' } )
|
|
68
|
+
);
|
|
69
|
+
} );
|
|
58
70
|
|
|
59
71
|
console.log( 'Building SVG icon sprite...' );
|
|
60
72
|
|
|
@@ -63,18 +75,18 @@ console.log( 'Building SVG icon sprite...' );
|
|
|
63
75
|
// fs.writeFileSync( path.join( process.cwd(), './build/a-icon-svg.scss' ), getSassVarsString( scssIcons ) );
|
|
64
76
|
|
|
65
77
|
// Compile the sprite
|
|
66
|
-
spriter.compile( function( error, result, cssData ) {
|
|
67
|
-
|
|
78
|
+
spriter.compile( function ( error, result, cssData ) {
|
|
68
79
|
// Run through all configured output modes
|
|
69
|
-
for (
|
|
70
|
-
|
|
80
|
+
for ( const mode in result ) {
|
|
71
81
|
// Run through all created resources and write them to disk
|
|
72
|
-
for (
|
|
73
|
-
mkdirp.sync( path.dirname( result[mode][type].path ) );
|
|
74
|
-
fs.writeFileSync(
|
|
82
|
+
for ( const type in result[ mode ] ) {
|
|
83
|
+
mkdirp.sync( path.dirname( result[ mode ][ type ].path ) );
|
|
84
|
+
fs.writeFileSync(
|
|
85
|
+
result[ mode ][ type ].path,
|
|
86
|
+
result[ mode ][ type ].contents
|
|
87
|
+
);
|
|
75
88
|
}
|
|
76
|
-
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
console.log( 'Completed building SVG icon sprite.' );
|
|
80
|
-
});
|
|
92
|
+
} );
|
package/scripts/build-scss.js
CHANGED