@penskemediacorp/larva 1.7.0-alpha.0 → 1.7.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 (237) hide show
  1. package/.eslintignore +6 -0
  2. package/LICENSE +21 -0
  3. package/README.md +96 -37
  4. package/__tests__/fixtures/build/css/common.inline.css +1 -2
  5. package/__tests__/fixtures/{src/patterns/05-objects/_objects.scss → build/images/test.png} +0 -0
  6. package/__tests__/fixtures/build/js/larva-ui.js +1 -0
  7. package/__tests__/fixtures/build/svg/defs/sprite.svg +1 -0
  8. package/__tests__/fixtures/larva.config.js +18 -9
  9. package/__tests__/fixtures/public/some-library.js +1 -0
  10. package/__tests__/fixtures/src/patterns/{05-objects/o-crap/o-crap.scss → __tests__/.gitkeep} +0 -0
  11. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.featured.aia.js +3 -0
  12. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.featured.js +3 -0
  13. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.js +1 -0
  14. package/__tests__/fixtures/src/patterns/components/c-nav-link/c-nav-link.prototype.js +1 -1
  15. package/__tests__/fixtures/src/patterns/components/c-tagline/c-tagline.prototype.js +3 -0
  16. package/__tests__/fixtures/src/patterns/modules/_also-ignored/_also-ignored.prototype.js +3 -0
  17. package/__tests__/fixtures/src/patterns/modules/_also-ignored/_also-ignored.twig +3 -0
  18. package/__tests__/fixtures/src/patterns/modules/ignore-me/ignore-me.prototype.js +0 -0
  19. package/__tests__/fixtures/src/patterns/modules/ignore-me/ignore-me.twig +0 -0
  20. package/__tests__/fixtures/src/patterns/modules/test-module/test-module.featured.js +3 -0
  21. package/__tests__/fixtures/src/patterns/modules/test-module/test-module.prototype.js +3 -0
  22. package/__tests__/fixtures/src/patterns/modules/test-module/test-module.twig +0 -0
  23. package/__tests__/fixtures/src/patterns/one-offs/newswire/newswire.html +1 -0
  24. package/__tests__/fixtures/src/patterns/one-offs/newswire/newswire.prototype.js +3 -0
  25. package/__tests__/lib/generateStatic.test.js +140 -0
  26. package/__tests__/lib/utils/clonePatternData.test.js +16 -12
  27. package/__tests__/lib/utils/getAllPatternsObj.test.js +45 -0
  28. package/__tests__/lib/utils/getAppConfiguration.test.js +13 -0
  29. package/__tests__/lib/utils/getModuleNamesFromDirectory.test.js +23 -0
  30. package/__tests__/lib/utils/getPatternData.test.js +32 -5
  31. package/__tests__/lib/utils/getPatternRoutes.test.js +29 -0
  32. package/__tests__/lib/utils/getPatternVariants.test.js +20 -0
  33. package/__tests__/lib/utils/getSubDirectoryNames.test.js +17 -0
  34. package/__tests__/lib/writeJson.test.js +83 -0
  35. package/bin/larva.js +21 -6
  36. package/build/css/larva-important.css +1 -0
  37. package/build/css/larva-ui.css +1 -0
  38. package/build/css/larva.css +1 -0
  39. package/build/css/larva.inline-important.css +1 -0
  40. package/build/css/larva.inline.css +1 -0
  41. package/build/css/variety.compat-important.css +1 -0
  42. package/build/css/variety.compat.css +1 -0
  43. package/build/js/common.js +26 -0
  44. package/build/js/larva-ui.js +1 -0
  45. package/build/js/standalone/video-showcase.js +26 -0
  46. package/build/svg/brand-logo-white.svg +1 -0
  47. package/build/svg/brand-logo.svg +1 -0
  48. package/build/svg/defs/sprite.defs.html +852 -0
  49. package/build/svg/defs/sprite.defs.svg +1 -0
  50. package/build/svg/logo-404.svg +1 -0
  51. package/build/tokens/artinamerica.custom-properties.css +546 -0
  52. package/build/tokens/artinamerica.json +533 -0
  53. package/build/tokens/artinamerica.map.scss +546 -0
  54. package/build/tokens/artinamerica.raw.json +4341 -0
  55. package/build/tokens/artnews.custom-properties.css +550 -0
  56. package/build/tokens/artnews.json +536 -0
  57. package/build/tokens/artnews.map.scss +550 -0
  58. package/build/tokens/artnews.raw.json +4373 -0
  59. package/build/tokens/bbpro.custom-properties.css +96 -0
  60. package/build/tokens/bbpro.json +80 -0
  61. package/build/tokens/bbpro.map.scss +96 -0
  62. package/build/tokens/bbpro.raw.json +789 -0
  63. package/build/tokens/billboard.custom-properties.css +96 -0
  64. package/build/tokens/billboard.json +80 -0
  65. package/build/tokens/billboard.map.scss +96 -0
  66. package/build/tokens/billboard.raw.json +789 -0
  67. package/build/tokens/deadline.custom-properties.css +533 -0
  68. package/build/tokens/deadline.json +517 -0
  69. package/build/tokens/deadline.map.scss +533 -0
  70. package/build/tokens/deadline.raw.json +4204 -0
  71. package/build/tokens/default.custom-properties.css +533 -0
  72. package/build/tokens/default.json +517 -0
  73. package/build/tokens/default.map.scss +533 -0
  74. package/build/tokens/default.raw.json +4204 -0
  75. package/build/tokens/dirt.custom-properties.css +81 -0
  76. package/build/tokens/dirt.json +66 -0
  77. package/build/tokens/dirt.map.scss +81 -0
  78. package/build/tokens/dirt.raw.json +690 -0
  79. package/build/tokens/indiewire.custom-properties.css +536 -0
  80. package/build/tokens/indiewire.json +520 -0
  81. package/build/tokens/indiewire.map.scss +536 -0
  82. package/build/tokens/indiewire.raw.json +4221 -0
  83. package/build/tokens/rivet.custom-properties.css +82 -0
  84. package/build/tokens/rivet.json +68 -0
  85. package/build/tokens/rivet.map.scss +82 -0
  86. package/build/tokens/rivet.raw.json +703 -0
  87. package/build/tokens/robbreport.custom-properties.css +536 -0
  88. package/build/tokens/robbreport.json +518 -0
  89. package/build/tokens/robbreport.map.scss +536 -0
  90. package/build/tokens/robbreport.raw.json +4215 -0
  91. package/build/tokens/rollingstone-2022.custom-properties.css +534 -0
  92. package/build/tokens/rollingstone-2022.json +519 -0
  93. package/build/tokens/rollingstone-2022.map.scss +534 -0
  94. package/build/tokens/rollingstone-2022.raw.json +4035 -0
  95. package/build/tokens/rollingstone.custom-properties.css +530 -0
  96. package/build/tokens/rollingstone.json +518 -0
  97. package/build/tokens/rollingstone.map.scss +530 -0
  98. package/build/tokens/rollingstone.raw.json +4207 -0
  99. package/build/tokens/sheknows.custom-properties.css +92 -0
  100. package/build/tokens/sheknows.json +76 -0
  101. package/build/tokens/sheknows.map.scss +92 -0
  102. package/build/tokens/sheknows.raw.json +761 -0
  103. package/build/tokens/sourcingjournal.custom-properties.css +87 -0
  104. package/build/tokens/sourcingjournal.json +70 -0
  105. package/build/tokens/sourcingjournal.map.scss +87 -0
  106. package/build/tokens/sourcingjournal.raw.json +720 -0
  107. package/build/tokens/sportico.custom-properties.css +73 -0
  108. package/build/tokens/sportico.json +59 -0
  109. package/build/tokens/sportico.map.scss +73 -0
  110. package/build/tokens/sportico.raw.json +640 -0
  111. package/build/tokens/thr.custom-properties.css +83 -0
  112. package/build/tokens/thr.json +67 -0
  113. package/build/tokens/thr.map.scss +83 -0
  114. package/build/tokens/thr.raw.json +698 -0
  115. package/build/tokens/variety-compat.custom-properties.css +36 -0
  116. package/build/tokens/variety-compat.json +33 -0
  117. package/build/tokens/variety-compat.map.scss +36 -0
  118. package/build/tokens/variety-compat.raw.json +224 -0
  119. package/build/tokens/variety-vip.custom-properties.css +532 -0
  120. package/build/tokens/variety-vip.json +521 -0
  121. package/build/tokens/variety-vip.map.scss +532 -0
  122. package/build/tokens/variety-vip.raw.json +4223 -0
  123. package/build/tokens/variety.custom-properties.css +534 -0
  124. package/build/tokens/variety.json +521 -0
  125. package/build/tokens/variety.map.scss +534 -0
  126. package/build/tokens/variety.raw.json +4225 -0
  127. package/build/tokens/vibe.custom-properties.css +77 -0
  128. package/build/tokens/vibe.json +63 -0
  129. package/build/tokens/vibe.map.scss +77 -0
  130. package/build/tokens/vibe.raw.json +668 -0
  131. package/build/tokens/wwd-2021.custom-properties.css +82 -0
  132. package/build/tokens/wwd-2021.json +67 -0
  133. package/build/tokens/wwd-2021.map.scss +82 -0
  134. package/build/tokens/wwd-2021.raw.json +701 -0
  135. package/build/tokens/wwd-beauty.custom-properties.css +86 -0
  136. package/build/tokens/wwd-beauty.json +70 -0
  137. package/build/tokens/wwd-beauty.map.scss +86 -0
  138. package/build/tokens/wwd-beauty.raw.json +719 -0
  139. package/build/tokens/wwd-dd.custom-properties.css +18 -0
  140. package/build/tokens/wwd-dd.json +13 -0
  141. package/build/tokens/wwd-dd.map.scss +18 -0
  142. package/build/tokens/wwd-dd.raw.json +90 -0
  143. package/build/tokens/wwd.custom-properties.css +70 -0
  144. package/build/tokens/wwd.json +60 -0
  145. package/build/tokens/wwd.map.scss +70 -0
  146. package/build/tokens/wwd.raw.json +643 -0
  147. package/index.js +2 -1
  148. package/lib/generateStatic.js +133 -0
  149. package/lib/server.js +262 -28
  150. package/lib/start.js +7 -0
  151. package/lib/utils/clonePatternData.js +12 -3
  152. package/lib/utils/copySyncHelper.js +33 -0
  153. package/lib/utils/getAllPatternsObj.js +48 -0
  154. package/lib/utils/getAppConfiguration.js +65 -7
  155. package/lib/utils/getArgsFromCli.js +3 -0
  156. package/lib/utils/getModuleNamesFromDirectory.js +11 -0
  157. package/lib/utils/getPatternData.js +19 -13
  158. package/lib/utils/getPatternPathsToLoad.js +5 -6
  159. package/lib/utils/getPatternRoutes.js +58 -0
  160. package/lib/utils/getPatternType.js +3 -2
  161. package/lib/utils/getPatternVariants.js +24 -0
  162. package/lib/utils/getSubDirectoryNames.js +23 -0
  163. package/lib/utils/spawnScript.js +26 -0
  164. package/lib/writeJson.js +53 -0
  165. package/package.json +67 -5
  166. package/public/webfontloader.js +22 -0
  167. package/scripts/build-html.js +52 -0
  168. package/scripts/build-icons.js +80 -0
  169. package/scripts/build-scss.js +15 -0
  170. package/scripts/config/.eslintrc.json +11 -0
  171. package/scripts/config/gulpfile.js +191 -0
  172. package/scripts/config/stylelint.config.js +5 -0
  173. package/scripts/config/svgo-config.json +67 -0
  174. package/scripts/config/webpack.config.js +95 -0
  175. package/scripts/dev-js.js +13 -0
  176. package/scripts/dev-scss.js +20 -0
  177. package/scripts/help.js +65 -0
  178. package/scripts/init.js +21 -0
  179. package/scripts/larva/.nvmrc +1 -0
  180. package/scripts/larva/README.md +29 -0
  181. package/scripts/larva/larva.config.js +3 -0
  182. package/scripts/larva/src/patterns/README.md +3 -0
  183. package/scripts/larva/src/patterns/base.html +6 -0
  184. package/scripts/larva/src/patterns/components/README.md +3 -0
  185. package/scripts/larva/src/patterns/modules/README.md +3 -0
  186. package/scripts/larva/src/patterns/objects/README.md +3 -0
  187. package/scripts/larva/src/patterns/one-offs/README.md +3 -0
  188. package/scripts/link-all.js +40 -0
  189. package/scripts/lint-js.js +11 -0
  190. package/scripts/lint-scss.js +13 -0
  191. package/scripts/lint.js +73 -0
  192. package/scripts/prod-js.js +12 -0
  193. package/scripts/prod-scss.js +24 -0
  194. package/scripts/prod.js +122 -0
  195. package/scripts/server.js +11 -0
  196. package/scripts/start.js +36 -0
  197. package/scripts/upgrade.js +99 -0
  198. package/scripts/write-json.js +14 -0
  199. package/.DS_Store +0 -0
  200. package/__tests__/.DS_Store +0 -0
  201. package/__tests__/_test-boilerplate.js +0 -12
  202. package/__tests__/fixtures/src/patterns/04-components/c-nav-link/c-nav-link.json +0 -3
  203. package/__tests__/fixtures/src/patterns/04-components/c-nav-link/c-nav-link.prototype.js +0 -3
  204. package/__tests__/fixtures/src/patterns/04-components/c-nav-link/c-nav-link.twig +0 -3
  205. package/__tests__/fixtures/src/patterns/05-objects/o-crap/o-crap.json +0 -3
  206. package/__tests__/fixtures/src/patterns/05-objects/o-crap/o-crap.twig +0 -1
  207. package/__tests__/fixtures/src/patterns/05-objects/o-nav/o-nav.twig +0 -14
  208. package/__tests__/fixtures/src/patterns/06-algorithms/a-icon/a-icon.common.inline.scss +0 -3
  209. package/__tests__/fixtures/src/patterns/06-algorithms/a-wrapper/a-wrapper.common.inline.scss +0 -3
  210. package/__tests__/fixtures/src/patterns/07-utilities/u-test-three.common.async.scss +0 -3
  211. package/__tests__/fixtures/src/patterns/07-utilities/u-test-two.common.inline.scss +0 -8
  212. package/__tests__/fixtures/src/patterns/07-utilities/u-test.common.inline.scss +0 -8
  213. package/__tests__/fixtures/src/patterns/08-modules/breadcrumbs/breadcrumbs.twig +0 -1
  214. package/__tests__/lib/build.test.js +0 -20
  215. package/__tests__/lib/utils/buildPatternFilePath.test.js +0 -18
  216. package/__tests__/lib/utils/concatenateFileData.test.js +0 -26
  217. package/__tests__/lib/utils/getPatternDataPath.test.js +0 -19
  218. package/__tests__/lib/utils/getPatternDigit.test.js +0 -13
  219. package/__tests__/lib/utils/getScssPathsWithExtension.test.js +0 -29
  220. package/__tests__/lib/utils/getScssResultCss.test.js +0 -16
  221. package/__tests__/lib/utils/getScssResultFilePath.test.js +0 -14
  222. package/lib/.DS_Store +0 -0
  223. package/lib/build.js +0 -16
  224. package/lib/utils/buildPatternFilePath.js +0 -13
  225. package/lib/utils/concatenateFileData.js +0 -19
  226. package/lib/utils/getPatternDataPath.js +0 -16
  227. package/lib/utils/getPatternDigit.js +0 -15
  228. package/lib/utils/getScssPathsWithExtension.js +0 -23
  229. package/lib/utils/getScssResultCss.js +0 -18
  230. package/lib/utils/getScssResultFilePath.js +0 -11
  231. package/lib/utils/utils.js +0 -16
  232. package/lib/watch.js +0 -33
  233. package/lib/writeData.js +0 -22
  234. package/static/css/components.css +0 -4
  235. package/static/css/objects.css +0 -21
  236. package/static/css/prism.css +0 -126
  237. package/static/js/prism.js +0 -8
@@ -0,0 +1,191 @@
1
+ const gulp = require( 'gulp' );
2
+ const gulpClean = require( 'gulp-clean' );
3
+ const gulpIf = require( 'gulp-if' );
4
+ const gulpIgnore = require( 'gulp-ignore' );
5
+ const gulpPostCss = require( 'gulp-postcss' );
6
+ const gulpRename = require( 'gulp-rename' );
7
+ const gulpStylelint = require( 'gulp-stylelint' );
8
+
9
+ const Fibers = require( 'fibers' );
10
+ const globImporter = require( 'node-sass-glob-importer' );
11
+ const { mkdirpSync } = require( 'fs-extra' );
12
+ const path = require( 'path' );
13
+ const postCss = require( 'postcss' );
14
+ const sass = require( 'gulp-sass' );
15
+
16
+ const stylelintConfig = require( './stylelint.config' );
17
+
18
+ /**************
19
+ Config
20
+ **************/
21
+
22
+ const cssDest = './build/css/';
23
+
24
+ sass.compiler = require( 'sass' );
25
+
26
+ const sassOpts = {
27
+ fiber: Fibers,
28
+ includePaths: [
29
+ path.resolve( './node_modules' ),
30
+ path.resolve( './src/scss' ),
31
+ ],
32
+ importer: globImporter(),
33
+ };
34
+
35
+ const stylelintOpts = {
36
+ failAfterError: false,
37
+ config: stylelintConfig,
38
+ reporters: [
39
+ {
40
+ formatter: 'string',
41
+ console: true,
42
+ },
43
+ ],
44
+ };
45
+
46
+ /**************
47
+ Functions
48
+ **************/
49
+
50
+ /**
51
+ * Build CSS.
52
+ *
53
+ * Used for both prod and dev commands.
54
+ *
55
+ * Consider updating the name 'minify' to 'post' if/when
56
+ * more Post CSS functionality is added.
57
+ *
58
+ * @param {Function} done Post-build callback.
59
+ * @param {boolean} minify Run post CSS and minify output.
60
+ * @param {boolean} generateImportantVariants Whether to build variations with
61
+ * `!important` added to all rules.
62
+ */
63
+ const buildScss = (
64
+ done,
65
+ minify = false,
66
+ generateImportantVariants = false
67
+ ) => {
68
+
69
+ if ( minify ) {
70
+ sassOpts.outputStyle = 'compressed';
71
+ }
72
+
73
+ gulp.src( './entries/*.scss' )
74
+ .pipe( gulpStylelint( stylelintOpts ) )
75
+ .pipe( sass( sassOpts ).on( 'error', sass.logError ) )
76
+ .pipe( gulp.dest( cssDest ) )
77
+ .pipe( gulpIgnore.exclude( 'larva-ui.css' ) )
78
+ .pipe(
79
+ gulpIf(
80
+ generateImportantVariants,
81
+ gulpPostCss( [ declareImportanceForAll ] )
82
+ )
83
+ )
84
+ .pipe(
85
+ gulpIf(
86
+ generateImportantVariants,
87
+ gulpRename( { suffix: '-important' } )
88
+ )
89
+ )
90
+ .pipe( gulpIf( generateImportantVariants, gulp.dest( cssDest ) ) );
91
+
92
+ done();
93
+ };
94
+
95
+ /**
96
+ * Prepare destination directory.
97
+ *
98
+ * @param {Function} done Function called upon completion.
99
+ */
100
+ const clean = ( done ) => {
101
+ gulp.src( cssDest, { read: false } ).pipe( gulpClean() );
102
+
103
+ mkdirpSync( cssDest );
104
+ done();
105
+ };
106
+
107
+ /**
108
+ * Build a task from dynamic input.
109
+ *
110
+ * @param {Function} done Function called upon completion.
111
+ * @param {boolean} generateImportantVariants Whether to build variations with
112
+ * `!important` added to all rules.
113
+ */
114
+ const composeTask = ( done, generateImportantVariants = false ) => {
115
+ clean( () => {
116
+ stylelint( './src/**/*.scss' );
117
+ buildScss( done, true, generateImportantVariants );
118
+ } );
119
+ };
120
+
121
+ /**
122
+ * Add `!important` declarations to all rules, for use with older themes that
123
+ * have high specificity.
124
+ *
125
+ * Adapted from the `postcss-importantly` npm package, updated to work with
126
+ * latest version of PostCSS.
127
+ *
128
+ * @param {Object} style PostCSS Root object for current CSS.
129
+ * @param {Object} result PostCSS Result object containing transformed CSS.
130
+ * @return {Result} PostCSS Result object.
131
+ */
132
+ const declareImportanceForAll = ( style, result ) => {
133
+ const root = postCss.parse( style );
134
+
135
+ root.walkRules( ( rule ) => {
136
+ if ( 'atrule' === rule.parent.type && 'media' !== rule.parent.name ) {
137
+ return;
138
+ }
139
+
140
+ return rule.each( ( decl ) => {
141
+ if ( ! decl.value || decl.important ) {
142
+ return;
143
+ }
144
+
145
+ decl.value += '!important';
146
+
147
+ return decl;
148
+ } );
149
+ } );
150
+
151
+ result.root = root;
152
+
153
+ return result;
154
+ };
155
+
156
+ /**
157
+ * Run stylelint.
158
+ *
159
+ * @param {string} file Filename or glob to process.
160
+ */
161
+ const stylelint = ( file ) => {
162
+ gulp.src( file ).pipe( gulpStylelint( stylelintOpts ) );
163
+ };
164
+
165
+ /**************
166
+ Tasks
167
+ ***************/
168
+
169
+ // Watch the changed file, compile and lint when changed.
170
+ exports[ 'dev-scss' ] = () => {
171
+ gulp.watch( [ './src/**/*.scss', './entries/*.scss' ], buildScss ).on(
172
+ 'change',
173
+ function ( file ) {
174
+ stylelint( file );
175
+ }
176
+ );
177
+ };
178
+
179
+ // Quickly build SCSS.
180
+ exports[ 'build-scss' ] = ( done ) => {
181
+ buildScss( done );
182
+ };
183
+
184
+ // Run PostCSS on CSS.
185
+ exports[ 'prod-scss' ] = ( done ) => {
186
+ composeTask( done );
187
+ };
188
+
189
+ exports[ 'prod-scss-with-important-variants' ] = ( done ) => {
190
+ composeTask( done, true );
191
+ };
@@ -0,0 +1,5 @@
1
+ const rules = {
2
+ 'extends': '@penskemediacorp/stylelint-config'
3
+ };
4
+
5
+ module.exports = rules;
@@ -0,0 +1,67 @@
1
+ {
2
+ "plugins": [{
3
+ "removeTitle": false
4
+ },
5
+ {
6
+ "removeDoctype": true
7
+ },
8
+ {
9
+ "removeXMLNS": true
10
+ },
11
+ {
12
+ "removeXMLProcInst": true
13
+ },
14
+ {
15
+ "removeComments": true
16
+ },
17
+ {
18
+ "removeUselessDefs": true
19
+ },
20
+ {
21
+ "removeEmptyAttrs": true
22
+ },
23
+ {
24
+ "removeUselessStrokeAndFill": true
25
+ },
26
+ {
27
+ "removeUnknownsAndDefaults": true
28
+ },
29
+ {
30
+ "convertPathData": false
31
+ },
32
+ {
33
+ "cleanupIDs": true
34
+ },
35
+ {
36
+ "cleanupNumericValues": {
37
+ "floatPrecision": 3,
38
+ "leadingZero": true
39
+ }
40
+ },
41
+ {
42
+ "minifyStyles": true
43
+ },
44
+ {
45
+ "convertTransform": true
46
+ },
47
+ {
48
+ "cleanupAttrs": true
49
+ },
50
+ {
51
+ "convertPathData": true
52
+ },
53
+ {
54
+ "convertShapeToPath": true
55
+ },
56
+ {
57
+ "convertColors": {
58
+ "shorthex": false
59
+ }
60
+ },
61
+ {
62
+ "removeAttrs": {
63
+ "attrs": "fill"
64
+ }
65
+ }
66
+ ]
67
+ }
@@ -0,0 +1,95 @@
1
+ const path = require( 'path' );
2
+ const ESLintPlugin = require('eslint-webpack-plugin');
3
+
4
+ const getConfig = require( '../../index' ).getConfig;
5
+
6
+ const SRC_DIR = path.resolve( './entries' );
7
+ const BUILD_DIR = path.resolve( './build/js' );
8
+
9
+ const entries = getConfig( 'webpack' ).entries;
10
+
11
+ const aliases = {
12
+ '@larva-js': path.resolve( './node_modules/@penskemediacorp/larva-js/src' ),
13
+ '@npm': path.resolve( './node_modules/' ),
14
+ ... getConfig( 'webpack' ).aliases
15
+ };
16
+
17
+ const eslintConfig = getConfig( 'eslint', true );
18
+ const eslintConfigFile = undefined !== eslintConfig ? eslintConfig.configFile : null;
19
+
20
+ // Tools
21
+ const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
22
+
23
+
24
+ //=========================================================
25
+ // Rules
26
+ //---------------------------------------------------------
27
+ const rules = {
28
+
29
+ /**
30
+ * JS Loaders
31
+ */
32
+ pre: {
33
+ enforce: 'pre',
34
+ test: /\.js$/,
35
+ exclude: /(node_modules|nobundle|vendor)/,
36
+ },
37
+ js: {
38
+ test: /\.js$/,
39
+ include: SRC_DIR,
40
+ exclude: /(node_modules|nobundle|vendor)/,
41
+ loader: 'babel-loader',
42
+ query: {
43
+ presets: [ '@babel/preset-env' ]
44
+ }
45
+ }
46
+ };
47
+
48
+ const plugins = {
49
+ cleanup: new CleanWebpackPlugin(),
50
+ eslint: new ESLintPlugin({
51
+ overrideConfigFile: eslintConfigFile
52
+ })
53
+ };
54
+
55
+ //=========================================================
56
+ // CONFIG
57
+ //---------------------------------------------------------
58
+ const config = {
59
+ entry: entries,
60
+ output: {
61
+ path: BUILD_DIR,
62
+ filename: '[name].js'
63
+ },
64
+ module: {
65
+ rules: [ rules.js ]
66
+ },
67
+ watch: false,
68
+ watchOptions: {
69
+ ignored: /node_modules/
70
+ },
71
+ resolve: {
72
+ alias: aliases
73
+ },
74
+ optimization: {
75
+ minimize: true
76
+ }
77
+ };
78
+
79
+ module.exports = ( env, argv ) => {
80
+
81
+ if ( 'development' === argv.mode ) {
82
+ config.devtool = 'source-map';
83
+ config.module.rules = ( config.module.rules || [] ).concat( [ rules.pre ] );
84
+ config.plugins = [ plugins.eslint ];
85
+ }
86
+
87
+ if ( 'production' === argv.mode ) {
88
+ console.log( 'Building Prod JS..' );
89
+
90
+ config.module.rules = ( config.module.rules || [] ).concat( [ rules.pre ] );
91
+ config.plugins = [ plugins.eslint, plugins.cleanup ];
92
+ }
93
+
94
+ return config;
95
+ };
@@ -0,0 +1,13 @@
1
+ const path = require( 'path' );
2
+
3
+ const spawnScript = require( '../lib/utils/spawnScript' );
4
+
5
+ const configPath = path.join( __dirname, './config/webpack.config.js' );
6
+
7
+ const args = [
8
+ `--config=${ configPath }`,
9
+ '--mode=development',
10
+ '--watch=true'
11
+ ];
12
+
13
+ spawnScript( './node_modules/.bin/webpack', args );
@@ -0,0 +1,20 @@
1
+ const spawn = require( 'cross-spawn' );
2
+ const path = require( 'path' );
3
+
4
+ const getArgsFromCli = require( '../lib/utils/getArgsFromCli' );
5
+
6
+ const cliArgs = getArgsFromCli();
7
+ const gulpfilePath = path.join( __dirname, './config/gulpfile.js' );
8
+
9
+ // TODO: allow local gulpfile override by checking for --cwd and --gulpfile in cliArgs
10
+
11
+ spawn.sync(
12
+ './node_modules/.bin/gulp',
13
+ [
14
+ '--gulpfile',
15
+ gulpfilePath,
16
+ '--cwd',
17
+ process.cwd(),
18
+ ... cliArgs
19
+ ], { stdio: 'inherit' }
20
+ );
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Help command for Larva.
3
+ *
4
+ * ## OPTIONS
5
+ *
6
+ * [<command>]
7
+ * : Slug of a command to display the CLI usage information.
8
+ *
9
+ * ## EXAMPLES
10
+ *
11
+ * # Display a list of available commands.
12
+ * $ npx @penskemediacorp/larva help
13
+ *
14
+ * # Display the prod command docblock.
15
+ * $ npx @penskemediacorp/larva help prod
16
+ */
17
+
18
+ // Dependencies.
19
+ const fs = require('fs');
20
+ const path = require( 'path' );
21
+ const shell = require( 'shelljs' );
22
+
23
+ // CLI arguments.
24
+ const getArgsFromCli = require( '../lib/utils/getArgsFromCli' );
25
+ const cliArgs = getArgsFromCli();
26
+
27
+ const allowedCommands = [
28
+ 'help',
29
+ 'link-all',
30
+ 'lint',
31
+ 'prod',
32
+ 'start',
33
+ 'upgrade',
34
+ ];
35
+
36
+ // Display a generic help description.
37
+ if ( 2 !== cliArgs.length ) {
38
+ console.log( 'Usage: npx @penskemediacorp/larval <command> [--help]\n' );
39
+ console.log( `Where <command> is one of ${allowedCommands.join( ', ' )}.\n` );
40
+ return;
41
+ }
42
+
43
+ // Check for invalid commands.
44
+ const command = cliArgs[1];
45
+ if ( ! allowedCommands.includes( command ) ) {
46
+ console.log( `Invalid command '${command}'.\n` );
47
+ return;
48
+ }
49
+
50
+ // Display the docblock for a given command.
51
+ const pathToFile = path.resolve( __dirname, `${command}.js` );
52
+ try {
53
+ if ( fs.existsSync( pathToFile ) ) {
54
+ fs.readFile( pathToFile, 'utf8', ( error, data ) => {
55
+ if ( error ) {
56
+ console.error( error );
57
+ return;
58
+ }
59
+ const fileParts = data.split( '*/', 1 );
60
+ console.log( fileParts[0] + '*/' );
61
+ } );
62
+ }
63
+ } catch( error ) {
64
+ console.error( error );
65
+ }
@@ -0,0 +1,21 @@
1
+ const path = require( 'path' );
2
+ const chalk = require( 'chalk' );
3
+ const { copySync } = require( 'fs-extra' );
4
+
5
+ const copyFrom = path.join( __dirname, 'larva' );
6
+ const copyTo = process.cwd();
7
+
8
+ copySync( copyFrom, copyTo );
9
+
10
+ console.log(
11
+ chalk.green( 'Copied folder structure. Now, add the following scripts to package.json:' )
12
+ );
13
+
14
+ console.log( `
15
+ "backstop": "backstop --config=node_modules/@penskemediacorp/backstopjs-config",
16
+ "build-html": "larva build-html",
17
+ "larva": "larva server --watch src -e twig,js,html",
18
+ "parser": "./node_modules/.bin/twig-to-php-parser",
19
+ "update-larva": "npm install @penskemediacorp/larva@latest",
20
+ "write-json": "larva write-json"
21
+ ` );
@@ -0,0 +1 @@
1
+ 14
@@ -0,0 +1,29 @@
1
+ # IMPORTANT!!!!
2
+
3
+ After this directory has been copied into a consuming project, [follow these steps](https://confluence.pmcdev.io/x/JQqeAw), delete this section of the readme, and replace the {Project} text below with the name of the brand (in the bright future, this will be automated).
4
+
5
+ # {Project} Larva
6
+
7
+ This is configuration only instance of Larva. There should be no CSS or JS compiled here, only JSON configuration using existing styles from larva.css. If additional styles are needed, they should be [contributed upstream to the Larva packages](https://confluence.pmcdev.io/x/EQNCB).
8
+
9
+ ## Links
10
+
11
+ * [{Project} design tokens]().
12
+ * [{Project} style guide on Invision or XD]().
13
+ * [{Project} style guide on the static site]().
14
+
15
+ ## Development
16
+
17
+ To start developing:
18
+
19
+ 1. Run `npm install` from theme-directory/assets.
20
+ 2. Run `npm run larva` to open the Larva server.
21
+
22
+ Add pattern configurations by creating variants for modules.
23
+
24
+ ## Larva Commands
25
+
26
+ * `npm run larva` - Start the Larva pattern server. Navigate in the browser to http://localhost:3000.
27
+ * `npm run parser` - Parse recently changed pattern Twig files to PHP.
28
+ * `npm run write-json` - write pattern objects to JSON files.
29
+
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ brand: ''
3
+ };
@@ -0,0 +1,3 @@
1
+ These are project-level patterns. You can build new UI here, or configure existing UI from Larva shared modules.
2
+
3
+ Read more about using patterns on the [Larva Wiki](https://github.com/penske-media-corp/pmc-larva/wiki/).
@@ -0,0 +1,6 @@
1
+ {% extends "@larva/base.html" %}
2
+
3
+ {% block stylesheets %}
4
+ {# Add references to theme stylesheets here #}
5
+ {% endblock %}
6
+
@@ -0,0 +1,3 @@
1
+ These are project-level *components*. You should only have a few at most in here.
2
+
3
+ Read more about using patterns on the [Larva Wiki](https://github.com/penske-media-corp/pmc-larva/wiki/).
@@ -0,0 +1,3 @@
1
+ These are project-level *modules*. You will have lots and lots of modules!
2
+
3
+ Read more about using shared modules on the [Larva Wiki](https://github.com/penske-media-corp/pmc-larva/wiki/).
@@ -0,0 +1,3 @@
1
+ These are project-level *objects*. You should only have a few at most in here.
2
+
3
+ Read more about using patterns on the [Larva Wiki](https://github.com/penske-media-corp/pmc-larva/wiki/).
@@ -0,0 +1,3 @@
1
+ These are project-level *one-offs*.
2
+
3
+ One-offs are technical debt and marked as such.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * This command can be used from within any Larva project to link the Larva
3
+ * packages (from the monorepo) for local development.
4
+ *
5
+ * @see https://github.com/penske-media-corp/pmc-larva/blob/master/README.md#linking-larva-for-local-development
6
+ *
7
+ * ## OPTIONS
8
+ *
9
+ * [--help]
10
+ * : Display usage and examples for this command.
11
+ *
12
+ * ## EXAMPLES
13
+ *
14
+ * # NPM link local packages to Larva monorepo.
15
+ * $ npx @penskemediacorp/larva link-all
16
+ *
17
+ * # Help command.
18
+ * $ npx @penskemediacorp/larva link-all help
19
+ */
20
+
21
+ const shell = require( 'shelljs' );
22
+
23
+ // CLI arguments.
24
+ const getArgsFromCli = require( '../lib/utils/getArgsFromCli' );
25
+ const cliArgs = getArgsFromCli();
26
+
27
+ // Handle help command.
28
+ if ( cliArgs.includes( '--help' ) ) {
29
+ shell.exec( `npx @penskemediacorp/larva help link-all` );
30
+ return;
31
+ }
32
+
33
+ shell.exec( 'npm link @penskemediacorp/larva' );
34
+ shell.exec( 'npm link @penskemediacorp/larva-css' );
35
+ shell.exec( 'npm link @penskemediacorp/larva-js' );
36
+ shell.exec( 'npm link @penskemediacorp/larva-patterns' );
37
+ shell.exec( 'npm link @penskemediacorp/larva-scss' );
38
+ shell.exec( 'npm link @penskemediacorp/larva-svg' );
39
+ shell.exec( 'npm link @penskemediacorp/larva-tokens' );
40
+ shell.exec( 'npm link @penskemediacorp/twig-to-php-parser' );
@@ -0,0 +1,11 @@
1
+ const getAppConfiguration = require( '../lib/utils/getAppConfiguration' );
2
+ const spawnScript = require( '../lib/utils/spawnScript' );
3
+
4
+ const { configFile } = getAppConfiguration( 'eslint' );
5
+
6
+ const args = [
7
+ '--c',
8
+ configFile
9
+ ];
10
+
11
+ spawnScript( './node_modules/.bin/eslint', args );
@@ -0,0 +1,13 @@
1
+ const path = require( 'path' );
2
+
3
+ const stylelintConfigPath = path.join( __dirname, './config/stylelint.config.js' );
4
+ const spawnScript = require( '../lib/utils/spawnScript' );
5
+
6
+ const args = [
7
+ 'files',
8
+ './src/scss',
9
+ '--config',
10
+ stylelintConfigPath
11
+ ];
12
+
13
+ spawnScript( './node_modules/.bin/stylelint', args );
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Lint JavaScript and CSS files in a Larva project.
3
+ *
4
+ * ## OPTIONS
5
+ *
6
+ * [--help]
7
+ * : Display usage and examples for this command.
8
+ *
9
+ * [--css]
10
+ * : Lint CSS assets.
11
+ *
12
+ * [--js]
13
+ * : Lint JavaScript assets.
14
+ *
15
+ * [--fix]
16
+ * : Try to automatically fix any issues that arise while linting.
17
+ *
18
+ * ## EXAMPLES
19
+ *
20
+ * # Lint CSS and JavaScript assets.
21
+ * $ npx @penskemediacorp/larva lint
22
+ *
23
+ * # Only lint CSS assets.
24
+ * $ npx @penskemediacorp/larva lint --css
25
+ *
26
+ * # Only lint JavaScripot assets.
27
+ * $ npx @penskemediacorp/larva lint --js
28
+ *
29
+ * # Fix CSS and JavaScript assets.
30
+ * $ npx @penskemediacorp/larva lint --fix
31
+ *
32
+ * # Mix and match, fix JavaScript assets.
33
+ * $ npx @penskemediacorp/larva lint --js --fix
34
+ *
35
+ * # Help command.
36
+ * $ npx @penskemediacorp/larva lint --help
37
+ */
38
+
39
+ // Dependencies.
40
+ const path = require( 'path' );
41
+ const shell = require( 'shelljs' );
42
+
43
+ // Construct some paths to point our scripts at.
44
+ const binPath = path.resolve( __dirname, '../bin/larva.js' ); // For sibling scripts.
45
+ const workingDirectory = process.cwd(); // For paths relative to the directory this script was called from.
46
+
47
+ // CLI arguments.
48
+ const getArgsFromCli = require( '../lib/utils/getArgsFromCli' );
49
+ const cliArgs = getArgsFromCli();
50
+
51
+ // Handle help command.
52
+ if ( cliArgs.includes( '--help' ) ) {
53
+ shell.exec( `npx @penskemediacorp/larva help lint` );
54
+ return;
55
+ }
56
+
57
+ // Trigger linting when a specific flag is present, or when neither flag is
58
+ // present.
59
+ const lintCSS = cliArgs.includes( '--css' ) || ! cliArgs.includes( '--js' );
60
+ const lintJS = cliArgs.includes( '--js' ) || ! cliArgs.includes( '--css' );
61
+
62
+ // Appends ` fix` to our linting scripts if the flag is present.
63
+ const fix = cliArgs.includes( '--fix' ) ? ' fix' : '';
64
+
65
+ if ( lintCSS ) {
66
+ console.log( 'Linting CSS assets\n\n\n' );
67
+ shell.exec( `${binPath} lint-scss${fix}` );
68
+ }
69
+
70
+ if ( lintJS ) {
71
+ console.log( 'Linting JavaScript assets\n\n\n' );
72
+ shell.exec( `${binPath} lint-js ${workingDirectory}${fix}` );
73
+ }