@penskemediacorp/larva 1.5.6-alpha.0 → 1.6.1

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 (238) 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/utils/writeJsonToFile.test.js +29 -0
  35. package/__tests__/lib/writeJson.test.js +83 -0
  36. package/bin/larva.js +25 -0
  37. package/build/css/larva-important.css +1 -0
  38. package/build/css/larva-ui.css +1 -0
  39. package/build/css/larva.css +1 -0
  40. package/build/css/larva.inline-important.css +1 -0
  41. package/build/css/larva.inline.css +1 -0
  42. package/build/css/variety.compat-important.css +1 -0
  43. package/build/css/variety.compat.css +1 -0
  44. package/build/js/common.js +26 -0
  45. package/build/js/larva-ui.js +1 -0
  46. package/build/js/standalone/video-showcase.js +26 -0
  47. package/build/svg/brand-logo-white.svg +1 -0
  48. package/build/svg/brand-logo.svg +1 -0
  49. package/build/svg/defs/sprite.defs.html +852 -0
  50. package/build/svg/defs/sprite.defs.svg +1 -0
  51. package/build/svg/logo-404.svg +1 -0
  52. package/build/tokens/artinamerica.custom-properties.css +546 -0
  53. package/build/tokens/artinamerica.json +533 -0
  54. package/build/tokens/artinamerica.map.scss +546 -0
  55. package/build/tokens/artinamerica.raw.json +4341 -0
  56. package/build/tokens/artnews.custom-properties.css +550 -0
  57. package/build/tokens/artnews.json +536 -0
  58. package/build/tokens/artnews.map.scss +550 -0
  59. package/build/tokens/artnews.raw.json +4373 -0
  60. package/build/tokens/bbpro.custom-properties.css +96 -0
  61. package/build/tokens/bbpro.json +80 -0
  62. package/build/tokens/bbpro.map.scss +96 -0
  63. package/build/tokens/bbpro.raw.json +789 -0
  64. package/build/tokens/billboard.custom-properties.css +96 -0
  65. package/build/tokens/billboard.json +80 -0
  66. package/build/tokens/billboard.map.scss +96 -0
  67. package/build/tokens/billboard.raw.json +789 -0
  68. package/build/tokens/deadline.custom-properties.css +533 -0
  69. package/build/tokens/deadline.json +517 -0
  70. package/build/tokens/deadline.map.scss +533 -0
  71. package/build/tokens/deadline.raw.json +4204 -0
  72. package/build/tokens/default.custom-properties.css +533 -0
  73. package/build/tokens/default.json +517 -0
  74. package/build/tokens/default.map.scss +533 -0
  75. package/build/tokens/default.raw.json +4204 -0
  76. package/build/tokens/dirt.custom-properties.css +81 -0
  77. package/build/tokens/dirt.json +66 -0
  78. package/build/tokens/dirt.map.scss +81 -0
  79. package/build/tokens/dirt.raw.json +690 -0
  80. package/build/tokens/indiewire.custom-properties.css +536 -0
  81. package/build/tokens/indiewire.json +520 -0
  82. package/build/tokens/indiewire.map.scss +536 -0
  83. package/build/tokens/indiewire.raw.json +4221 -0
  84. package/build/tokens/rivet.custom-properties.css +82 -0
  85. package/build/tokens/rivet.json +68 -0
  86. package/build/tokens/rivet.map.scss +82 -0
  87. package/build/tokens/rivet.raw.json +703 -0
  88. package/build/tokens/robbreport.custom-properties.css +536 -0
  89. package/build/tokens/robbreport.json +518 -0
  90. package/build/tokens/robbreport.map.scss +536 -0
  91. package/build/tokens/robbreport.raw.json +4215 -0
  92. package/build/tokens/rollingstone-2022.custom-properties.css +534 -0
  93. package/build/tokens/rollingstone-2022.json +519 -0
  94. package/build/tokens/rollingstone-2022.map.scss +534 -0
  95. package/build/tokens/rollingstone-2022.raw.json +4035 -0
  96. package/build/tokens/rollingstone.custom-properties.css +530 -0
  97. package/build/tokens/rollingstone.json +518 -0
  98. package/build/tokens/rollingstone.map.scss +530 -0
  99. package/build/tokens/rollingstone.raw.json +4207 -0
  100. package/build/tokens/sheknows.custom-properties.css +92 -0
  101. package/build/tokens/sheknows.json +76 -0
  102. package/build/tokens/sheknows.map.scss +92 -0
  103. package/build/tokens/sheknows.raw.json +761 -0
  104. package/build/tokens/sourcingjournal.custom-properties.css +87 -0
  105. package/build/tokens/sourcingjournal.json +70 -0
  106. package/build/tokens/sourcingjournal.map.scss +87 -0
  107. package/build/tokens/sourcingjournal.raw.json +720 -0
  108. package/build/tokens/sportico.custom-properties.css +73 -0
  109. package/build/tokens/sportico.json +59 -0
  110. package/build/tokens/sportico.map.scss +73 -0
  111. package/build/tokens/sportico.raw.json +640 -0
  112. package/build/tokens/thr.custom-properties.css +83 -0
  113. package/build/tokens/thr.json +67 -0
  114. package/build/tokens/thr.map.scss +83 -0
  115. package/build/tokens/thr.raw.json +698 -0
  116. package/build/tokens/variety-compat.custom-properties.css +36 -0
  117. package/build/tokens/variety-compat.json +33 -0
  118. package/build/tokens/variety-compat.map.scss +36 -0
  119. package/build/tokens/variety-compat.raw.json +224 -0
  120. package/build/tokens/variety-vip.custom-properties.css +532 -0
  121. package/build/tokens/variety-vip.json +521 -0
  122. package/build/tokens/variety-vip.map.scss +532 -0
  123. package/build/tokens/variety-vip.raw.json +4223 -0
  124. package/build/tokens/variety.custom-properties.css +534 -0
  125. package/build/tokens/variety.json +521 -0
  126. package/build/tokens/variety.map.scss +534 -0
  127. package/build/tokens/variety.raw.json +4225 -0
  128. package/build/tokens/vibe.custom-properties.css +77 -0
  129. package/build/tokens/vibe.json +63 -0
  130. package/build/tokens/vibe.map.scss +77 -0
  131. package/build/tokens/vibe.raw.json +668 -0
  132. package/build/tokens/wwd-2021.custom-properties.css +82 -0
  133. package/build/tokens/wwd-2021.json +67 -0
  134. package/build/tokens/wwd-2021.map.scss +82 -0
  135. package/build/tokens/wwd-2021.raw.json +701 -0
  136. package/build/tokens/wwd-beauty.custom-properties.css +86 -0
  137. package/build/tokens/wwd-beauty.json +70 -0
  138. package/build/tokens/wwd-beauty.map.scss +86 -0
  139. package/build/tokens/wwd-beauty.raw.json +719 -0
  140. package/build/tokens/wwd-dd.custom-properties.css +18 -0
  141. package/build/tokens/wwd-dd.json +13 -0
  142. package/build/tokens/wwd-dd.map.scss +18 -0
  143. package/build/tokens/wwd-dd.raw.json +90 -0
  144. package/build/tokens/wwd.custom-properties.css +70 -0
  145. package/build/tokens/wwd.json +60 -0
  146. package/build/tokens/wwd.map.scss +70 -0
  147. package/build/tokens/wwd.raw.json +643 -0
  148. package/index.js +3 -2
  149. package/lib/generateStatic.js +133 -0
  150. package/lib/server.js +262 -28
  151. package/lib/start.js +7 -0
  152. package/lib/utils/clonePatternData.js +12 -3
  153. package/lib/utils/copySyncHelper.js +33 -0
  154. package/lib/utils/getAllPatternsObj.js +48 -0
  155. package/lib/utils/getAppConfiguration.js +65 -7
  156. package/lib/utils/getArgsFromCli.js +3 -0
  157. package/lib/utils/getModuleNamesFromDirectory.js +11 -0
  158. package/lib/utils/getPatternData.js +25 -11
  159. package/lib/utils/getPatternPathsToLoad.js +5 -6
  160. package/lib/utils/getPatternRoutes.js +58 -0
  161. package/lib/utils/getPatternType.js +3 -2
  162. package/lib/utils/getPatternVariants.js +24 -0
  163. package/lib/utils/getSubDirectoryNames.js +23 -0
  164. package/lib/utils/spawnScript.js +26 -0
  165. package/lib/utils/writeJsonToFile.js +6 -0
  166. package/lib/writeJson.js +53 -0
  167. package/package.json +70 -5
  168. package/public/webfontloader.js +22 -0
  169. package/scripts/build-html.js +52 -0
  170. package/scripts/build-icons.js +80 -0
  171. package/scripts/build-scss.js +15 -0
  172. package/scripts/config/.eslintrc.json +11 -0
  173. package/scripts/config/gulpfile.js +191 -0
  174. package/scripts/config/stylelint.config.js +5 -0
  175. package/scripts/config/svgo-config.json +67 -0
  176. package/scripts/config/webpack.config.js +95 -0
  177. package/scripts/dev-js.js +13 -0
  178. package/scripts/dev-scss.js +20 -0
  179. package/scripts/help.js +65 -0
  180. package/scripts/init.js +21 -0
  181. package/scripts/larva/.nvmrc +1 -0
  182. package/scripts/larva/README.md +29 -0
  183. package/scripts/larva/larva.config.js +3 -0
  184. package/scripts/larva/src/patterns/README.md +3 -0
  185. package/scripts/larva/src/patterns/base.html +6 -0
  186. package/scripts/larva/src/patterns/components/README.md +3 -0
  187. package/scripts/larva/src/patterns/modules/README.md +3 -0
  188. package/scripts/larva/src/patterns/objects/README.md +3 -0
  189. package/scripts/larva/src/patterns/one-offs/README.md +3 -0
  190. package/scripts/link-all.js +40 -0
  191. package/scripts/lint-js.js +11 -0
  192. package/scripts/lint-scss.js +13 -0
  193. package/scripts/lint.js +73 -0
  194. package/scripts/prod-js.js +12 -0
  195. package/scripts/prod-scss.js +24 -0
  196. package/scripts/prod.js +122 -0
  197. package/scripts/server.js +11 -0
  198. package/scripts/start.js +36 -0
  199. package/scripts/upgrade.js +99 -0
  200. package/scripts/write-json.js +14 -0
  201. package/.DS_Store +0 -0
  202. package/__tests__/.DS_Store +0 -0
  203. package/__tests__/_test-boilerplate.js +0 -12
  204. package/__tests__/fixtures/src/patterns/04-components/c-nav-link/c-nav-link.json +0 -3
  205. package/__tests__/fixtures/src/patterns/04-components/c-nav-link/c-nav-link.prototype.js +0 -3
  206. package/__tests__/fixtures/src/patterns/04-components/c-nav-link/c-nav-link.twig +0 -3
  207. package/__tests__/fixtures/src/patterns/05-objects/o-crap/o-crap.json +0 -3
  208. package/__tests__/fixtures/src/patterns/05-objects/o-crap/o-crap.twig +0 -1
  209. package/__tests__/fixtures/src/patterns/05-objects/o-nav/o-nav.twig +0 -14
  210. package/__tests__/fixtures/src/patterns/06-algorithms/a-icon/a-icon.common.inline.scss +0 -3
  211. package/__tests__/fixtures/src/patterns/06-algorithms/a-wrapper/a-wrapper.common.inline.scss +0 -3
  212. package/__tests__/fixtures/src/patterns/07-utilities/u-test-three.common.async.scss +0 -3
  213. package/__tests__/fixtures/src/patterns/07-utilities/u-test-two.common.inline.scss +0 -8
  214. package/__tests__/fixtures/src/patterns/07-utilities/u-test.common.inline.scss +0 -8
  215. package/__tests__/fixtures/src/patterns/08-modules/breadcrumbs/breadcrumbs.twig +0 -1
  216. package/__tests__/lib/build.test.js +0 -20
  217. package/__tests__/lib/utils/buildPatternFilePath.test.js +0 -18
  218. package/__tests__/lib/utils/concatenateFileData.test.js +0 -26
  219. package/__tests__/lib/utils/getPatternDataPath.test.js +0 -19
  220. package/__tests__/lib/utils/getPatternDigit.test.js +0 -13
  221. package/__tests__/lib/utils/getScssPathsWithExtension.test.js +0 -29
  222. package/__tests__/lib/utils/getScssResultCss.test.js +0 -16
  223. package/__tests__/lib/utils/getScssResultFilePath.test.js +0 -14
  224. package/lib/.DS_Store +0 -0
  225. package/lib/build.js +0 -16
  226. package/lib/utils/buildPatternFilePath.js +0 -13
  227. package/lib/utils/concatenateFileData.js +0 -19
  228. package/lib/utils/getPatternDataPath.js +0 -16
  229. package/lib/utils/getPatternDigit.js +0 -15
  230. package/lib/utils/getScssPathsWithExtension.js +0 -23
  231. package/lib/utils/getScssResultCss.js +0 -18
  232. package/lib/utils/getScssResultFilePath.js +0 -11
  233. package/lib/utils/utils.js +0 -16
  234. package/lib/watch.js +0 -33
  235. package/static/css/components.css +0 -4
  236. package/static/css/objects.css +0 -21
  237. package/static/css/prism.css +0 -126
  238. package/static/js/prism.js +0 -8
package/.eslintignore ADDED
@@ -0,0 +1,6 @@
1
+ lib/**/*.js
2
+ node_modules/**/*.js
3
+ lib/**/*.js
4
+ __tests__/**/*.js
5
+ build/**/*.js
6
+ src/js/vendor/*.js
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Penske Media Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,67 +1,126 @@
1
- # Larva!
1
+ # Larva
2
2
 
3
- If you want _all of Larva_, this is your repo. This is where you should start for new projects and for refactoring old projects onto the system.
3
+ _Note:_ This package may eventually be split into separate packages.
4
4
 
5
- This package is essentially a wrapper that brings all of the other packages together, and provides the tools for using them to develop modules. It contains an Express server and UI for configuring patterns, and _will_ contain scripts to scaffold patterns, test them, and probably do all kinds of other cools stuff. For the time being, it's pretty much just the server and a very basic UI.
5
+ By nature it is a wrapper package that brings all of the smaller Larva packages together, and provides a sandbox for testing Larva tools. Now, it also contains the `larva` binary build scripts and the Larva UI Express server for patterns development.
6
+
7
+ * An Express server and UI for building project-level patterns and configuring existing patterns
8
+ * Gulp configuration for building SCSS
9
+ * A basic webpack configuration for JS
10
+ * An init command for scaffolding the Larva directory structure
11
+ * The `write-json` script for building the JSON for each pattern
12
+ * A `larva` binary that provides access to all of the above
6
13
 
7
14
  ## Usage
8
15
 
9
- ### Absolutely required directory structure
16
+ ### If a brand new project:
17
+
18
+ In order to avoid conflicting node versions, Larva should be contained to its own directory.
19
+
20
+ **If you are working in a brand new project**, create a directory called `assets` and follow the below steps from the root of `assets`.
21
+
22
+ **If you are working in an existing project**, create a directory called `larva` and follow the below steps from its root.
23
+
24
+ First we will initialize an npm package, install Larva, and run the init command to scaffold our directory structure:
25
+
26
+ _// TODO: the `npx` workflow needs to be tested once this is released on npm._
27
+
28
+ ```
29
+ # Create an npm package
30
+ $ npm init
31
+
32
+ # Add Larva and scaffold directory structure
33
+ $ npx @penskemediacorp/larva init
34
+ ```
10
35
 
11
- Any project consuming Larva, must have the following directory structure:
36
+ This will install the main Larva package and create a directory called larva/ that contains a scaffold of the directory structure. Move the contents of this directory into your current working directory so that the directory structure aligns with the following:
12
37
 
13
38
  ```
14
39
  |- pmc-consuming-project/
15
- |- assets/
40
+ |- assets/ (or larva if in an older code-base)
16
41
  |- build/
17
- |- css/
18
- |- js/
19
- |- images/
20
42
  |- node_modules/
21
43
  |- src/
22
- |- patterns/
23
- |- 04-components/
24
- |- 05-objects/
25
- |- 06-algorithms/
26
- |- 07-utilities/
27
- |- 08-modules/
28
- |- 09-one-offs/
29
- |- public
30
- |- {fonts}
44
+ |- entries/
45
+ |- public/
31
46
  |- package.json
32
47
  |- larva.config.js
33
- |- template-parts/ (only if there are parsed patterns)
34
- |- patterns/
48
+ |- .nvmrc
35
49
  ```
36
- ### In a brand new project
37
50
 
38
- To install Larva, run the following command from the asset directory of a consuming project:
51
+ Next, check in root README.md from the scaffold and copy the scripts into package.json as directed.
52
+
53
+ Finally, create a directory `template-parts/patterns` to hold the PHP version of patterns. If working from the CLI, you can copy/paste this bash command:
54
+
39
55
  ```
40
- npm install @penskemediacorp/larva
56
+ |- pmc-consuming-project/
57
+ |- template-parts/
58
+ |- patterns/
41
59
  ```
42
60
 
43
- Then, create a file, larva.config.js in the assets directory. Add the following:
61
+ ## `larva` Binary & Build Scripts
44
62
 
45
- ```
46
- const path = require( 'path' );
63
+ Inspired by [@wordpress/scripts](https://github.com/WordPress/gutenberg/tree/master/packages/scripts), this package provides a bindary and several scripts for performing common tasks when building UI with Larva. This code lives in the `scripts` directory of this package.
64
+
65
+ For asset building commands, JS and SCSS can be run at the same time, or separately, in order to minimize the build time for cases where either JS or SCSS, not both, need to be built.
66
+
67
+ ### Usage
47
68
 
48
- module.exports = {
49
- patterns: {
50
- larvaPatternsDir: path.resolve( __dirname, 'node_modules/@penksemediacorp/larva-patterns' ),
51
- projectPatternsDir: path.resolve( __dirname, './src/patterns' )
69
+ Assuming Larva is installed, make sure the @penskemediacorp/larva package is at least at version 8.0.0-alpha.
70
+
71
+ To use the build scripts, add the following to package.json in a project that uses the [Larva assets directory structure](https://github.com/penske-media-corp/pmc-larva/tree/master/packages/larva#usage):
72
+
73
+ ```
74
+ {
75
+ "scripts": {
76
+ "prod": "larva prod-scss & larva prod-js",
77
+ "prod:scss": "larva prod-scss",
78
+ "prod:js": "larva prod-js",
79
+ "dev": "larva dev-js & larva dev-scss",
80
+ "dev:scss": "larva dev-scss",
81
+ "dev:js": "larva dev-js",
82
+ "lint": "larva lint-scss & larva lint-js",
83
+ "lint:scss": "larva lint-scss",
84
+ "lint:js": "larva lint-js ./",
85
+ "lint-fix": "larva lint-scss --fix & npm run lint:js --fix",
86
+ "lint-fix:scss": "larva lint-scss --fix",
87
+ "lint-fix:js": "larva lint-js --fix",
88
+ "larva": "larva server",
89
+ "write-json": "larva write-json larva && larva write-json",
90
+ "build-icons": "larva build-icons",
91
+ "build-html": "larva build-html"
52
92
  }
53
93
  }
54
94
  ```
55
95
 
56
- Create the following directories in your-theme/assets/src/patterns:
96
+ #### Script Usage Notes
57
97
 
98
+ **`build-html`**
58
99
 
59
- (yes, there will be a scaffold task, someday)
100
+ This is the script for building static HTML files for deployment. It accepts two CLI arguments, the first for build source ('project' or 'larva') and the second as an optional port number. The default is 3000.
60
101
 
61
- To start the server, you must be in the same directory as `larva.config.js` or, in other words, working within a "host" project. The Larva mono-repo is set up to be a "host" project, and the server can be started from within the root of the repository with the following command:
102
+ Example of building HTML for project Larva patterns:
103
+ `npm run build-html -- project`.
62
104
 
63
- ```
64
- ➜ pmc-larva$ npm run larva
65
- ```
105
+ Example of building HTML for Larva patterns with a server on port 2003:
106
+ `npm run build-html -- larva 2003`.
107
+
108
+ **`prod:scss`**
109
+
110
+ This command accepts an optional flag, `--generate-important-variants`, which
111
+ produces a second version of each entrypoint. In these variants, every rule
112
+ includes the `!important` declaration. These stylesheets are used with themes
113
+ that have not fully adopted Larva, allowing Larva to overcome the theme's
114
+ styles' specificity.
115
+
116
+ ### Overview of Functionality
117
+
118
+ This operates by way of a single binary, `larva`, and provides a layer of abstraction around CLI commands from various tools. The `larva` binary will point to a default configuration for each command and run its package's associated binary (e.g. `eslint` or `gulp`). The configurations are stored in separate package so as to be available to projects not using Larva.
119
+
120
+ For example, when the below scripts are present in a consuming projects package.json, the following would happen for `npm run dev:scss` (with the `scripts` value: `larva dev-scss`) in this package:
121
+ 1. In `bin/larva.js`, get arguments from CLI, and execute a file with name corresponding to the argument.
122
+ 2. `dev-scss.js` executes `gulp` CLI with additional arguments defined in the JS file via `spawnScript`, which uses the `cross-spawn` npm package to handle cross-platform inconsistencies.
66
123
 
67
- This will bring up the server for developing patterns at localhost:3000.
124
+ Similarly, `npm run lint:js` (with the `scripts` value: `larva lint-js`) would do the following:
125
+ 1. In `bin/larva.js`, get arguments from CLI and execute lint-js.js.
126
+ 2. `lint-js.js` executes the `eslint` CLI with both CLI arguments and specific arguments defined in the script.
@@ -1,2 +1 @@
1
- .pmc-a-wrapper {
2
- margin: auto; }
1
+ .testing { color: green; }
@@ -0,0 +1 @@
1
+ console.log( 'test js build file' );
@@ -0,0 +1 @@
1
+ <svg></svg>
@@ -12,23 +12,32 @@ module.exports = {
12
12
  },
13
13
 
14
14
  backstop: {
15
- pmcMainQaUrl: 'https://pmc:for-the-win@deadline-2019.pmcqa.com',
16
- pmcTestPaths: [
15
+ testBaseUrl: 'https://pmc:for-the-win@deadline-2019.pmcqa.com',
16
+ testPaths: [
17
17
  '/',
18
18
  '/blog/'
19
19
  ],
20
- pmcScenario: {
20
+ testScenario: {
21
21
  'delay': 5000,
22
22
  'misMatchThreshold': 0.5
23
- }
23
+ },
24
+ larvaModules: [ 'footer', 'mega-menu-content', 'social-share' ]
25
+ },
26
+
27
+ patterns: {
28
+ projectPatternsDir: path.join( __dirname, './src/patterns' ),
29
+ larvaPatternsDir: path.resolve( __dirname, '../../../larva-patterns' ),
30
+ ignoredModules: [
31
+ 'ignore-me'
32
+ ]
33
+ },
34
+
35
+ assets: {
36
+ path: __dirname
24
37
  },
25
38
 
26
39
  parser: {
27
40
  isCore: false,
28
41
  },
29
-
30
- patterns: {
31
- themePatternsDir: path.resolve( './src/patterns' ),
32
- larvaPatternsDir: path.resolve( __dirname, '../../node_modules/@penskemediacorp/larva-patterns' )
33
- }
42
+
34
43
  };
@@ -0,0 +1 @@
1
+ console.log( 'test' );
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ modifier_class: 'featured aia'
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ modifier_class: 'featured'
3
+ };
@@ -0,0 +1 @@
1
+ // this could be JSX or a React component.
@@ -1,3 +1,3 @@
1
1
  module.exports = {
2
- "modifier_class": ""
2
+ modifier_class: ''
3
3
  };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ c_tagline_text: 'overrode the larva pattern'
3
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ also_ignored_classes: 'lrv-u-color-black'
3
+ };
@@ -0,0 +1,3 @@
1
+ <div class="_also-ignored {{ _also_ignored_classes }}">
2
+
3
+ </div>
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ test_module_classes: 'lrv-a-glue'
3
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ test_module_classes: 'lrv-u-flex'
3
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ name: "newswire"
3
+ };
@@ -0,0 +1,140 @@
1
+ const path = require( 'path' );
2
+ const exec = require( 'child_process' ).exec;
3
+ const app = require( '../../lib/server' );
4
+ const fs = require( 'fs-extra' );
5
+
6
+ const port = 5555;
7
+ const urlBase = 'http://localhost:' + port + '/larva';
8
+ const generateStatic = require( '../../lib/generateStatic' );
9
+
10
+ const fixture = path.join( __dirname, '../fixtures' );
11
+ const buildPath = path.join( fixture, './build/html/project' );
12
+
13
+ beforeAll( ( done ) => {
14
+ app.listen( port, () => {
15
+ done();
16
+ });
17
+ });
18
+
19
+ describe( 'generateStatic', () => {
20
+
21
+ beforeEach( ( done ) => {
22
+
23
+ exec( 'mkdir -p ' + buildPath, ( err ) => {
24
+ if ( err ) {
25
+ console.error( err );
26
+ }
27
+ done();
28
+ } );
29
+
30
+ } );
31
+
32
+ it( 'creates an index.html file for a prototype pattern', ( done ) => {
33
+
34
+ const routesArr = [
35
+ 'components/c-link'
36
+ ];
37
+
38
+ generateStatic( routesArr, buildPath, () => {
39
+ expect(
40
+ fs.existsSync( path.join( buildPath, 'components/c-link/index.html' ) )
41
+ ).toBe( true );
42
+ done();
43
+ }, urlBase );
44
+
45
+ } );
46
+
47
+ it( 'creates an html file for a pattern variant', ( done ) => {
48
+ const routesArr = [
49
+ 'components/c-button/brand-basic'
50
+ ];
51
+
52
+ generateStatic( routesArr, buildPath, () => {
53
+ expect(
54
+ fs.existsSync( path.join( buildPath, 'components/c-button/brand-basic/index.html' ) )
55
+ ).toBe( true );
56
+ done();
57
+ }, urlBase );
58
+
59
+ } );
60
+
61
+ it( 'contains content for the pattern', ( done ) => {
62
+ const routesArr = [
63
+ 'modules/footer',
64
+ ];
65
+
66
+ generateStatic( routesArr, buildPath, () => {
67
+ expect(
68
+ // Hacky way to test that the response actually contains
69
+ // the content, not an error.
70
+ fs.readFileSync(
71
+ path.join( buildPath, routesArr[0] + '/index.html' ),
72
+ { encoding: 'utf8' }
73
+ ).indexOf( 'footer_classes' )
74
+ ).not.toBe( -1 );
75
+ done();
76
+ }, urlBase );
77
+ } );
78
+
79
+ it( 'copies static assets', ( done ) => {
80
+ const routesArr = [
81
+ 'components/c-button/brand-basic'
82
+ ];
83
+
84
+ generateStatic( routesArr, buildPath, () => {
85
+
86
+ // This is kinda sloppy and may be annoying to maintain, and there is
87
+ // surely a more elegant way to test this functionality than checking
88
+ // if the file exists...
89
+
90
+ // JS
91
+ expect(
92
+ fs.existsSync( path.join( buildPath, '../assets/build/js/larva-ui.js' ) )
93
+ ).toBe( true );
94
+
95
+ // CSS
96
+ expect(
97
+ fs.existsSync( path.join( buildPath, '../assets/build/css/common.inline.css' ) )
98
+ ).toBe( true );
99
+
100
+ // Images
101
+ expect(
102
+ fs.existsSync( path.join( buildPath, '../assets/build/images/test.png' ) )
103
+ ).toBe( true );
104
+
105
+ // SVG
106
+ expect(
107
+ fs.existsSync( path.join( buildPath, '../assets/build/svg/defs/sprite.svg' ) )
108
+ ).toBe( true );
109
+
110
+ // Public dir
111
+ expect(
112
+ fs.existsSync( path.join( buildPath, '../assets/public/some-library.js' ) )
113
+ ).toBe( true );
114
+
115
+ done();
116
+
117
+ }, urlBase );
118
+
119
+ } );
120
+
121
+ afterEach( ( done ) => {
122
+
123
+ const htmlDir = path.join( buildPath, '../' );
124
+
125
+ exec( 'rm -r ' + htmlDir, ( err ) => {
126
+ if ( err ) {
127
+ console.error( err );
128
+ }
129
+ done();
130
+ } );
131
+
132
+ } );
133
+
134
+ } );
135
+
136
+ afterAll( async ( done ) => {
137
+ const server = app.listen();
138
+ server.close();
139
+ done();
140
+ });
@@ -1,19 +1,23 @@
1
- const assert = require( 'assert' );
2
1
  const path = require( 'path' );
3
- const fixture = path.join( __dirname, '../../fixtures' );
4
-
5
2
  const clonePatternData = require( '../../../lib/utils/clonePatternData' );
6
- const originalPatternData = require( fixture + '/src/patterns/04-components/c-nav-link/c-nav-link.prototype' );
3
+ const getConfig = require( '../../../lib/utils/getAppConfiguration' );
4
+ const { projectPatternsDir, larvaPatternsDir } = getConfig( 'patterns' );
7
5
 
8
6
  describe( 'clonePatternData', () => {
9
- const clonedPatternData = clonePatternData( fixture + '/src/patterns/04-components/c-nav-link/c-nav-link.prototype' );
10
7
 
11
- it( 'when cloned data is modified it does not affect the source object', () => {
12
- clonedPatternData.modifier_class = "changed-class";
13
- assert.notEqual( clonedPatternData.modifier_class, originalPatternData.modifier_class );
8
+ it( 'gets object from project patterns dir first', () => {
9
+
10
+ const expected = require( path.join( projectPatternsDir, '/components/c-tagline/c-tagline.prototype' ) );
11
+ const c_tagline = clonePatternData( 'components/c-tagline/c-tagline.prototype');
12
+
13
+ expect( c_tagline ).toStrictEqual( expected );
14
14
  });
15
-
16
- it( 'contains default data provided by the initial object', () => {
17
- assert.equal( clonedPatternData.o_nav_title_text, originalPatternData.o_nav_title_text );
15
+
16
+ it( 'falls back to object from larva patterns dir', () => {
17
+ const expected = require( path.join( larvaPatternsDir, '/components/c-button/c-button.prototype' ) );
18
+ const c_button = clonePatternData( 'components/c-button/c-button.prototype');
19
+
20
+ expect( c_button ).toStrictEqual( expected );
18
21
  });
19
- });
22
+
23
+ });
@@ -0,0 +1,45 @@
1
+ const path = require( 'path' );
2
+ const getAppConfiguration = require( '../../../lib/utils/getAppConfiguration' );
3
+ const getAllPatternsObj = require( '../../../lib/utils/getAllPatternsObj' );
4
+
5
+ const expectedPatterns = {
6
+ '__tests__' : {},
7
+ 'components': {
8
+ 'c-nav-link': [
9
+ 'featured.aia',
10
+ 'featured',
11
+ 'prototype'
12
+ ],
13
+ 'c-tagline': [
14
+ 'prototype'
15
+ ]
16
+ },
17
+ 'modules': {
18
+ 'test-module': [
19
+ 'featured',
20
+ 'prototype'
21
+ ]
22
+ },
23
+ 'objects': {
24
+ 'o-crap': [],
25
+ 'o-nav': []
26
+ },
27
+ 'one-offs': {
28
+ 'newswire': [
29
+ 'prototype'
30
+ ]
31
+ }
32
+ }
33
+ const config = getAppConfiguration( 'patterns' );
34
+
35
+ describe( 'getAllPatternsObj', () => {
36
+
37
+ it( 'returns an object containing all patterns and variants', () => {
38
+
39
+ expect(
40
+ getAllPatternsObj( config.projectPatternsDir )
41
+ ).toEqual(
42
+ expectedPatterns
43
+ );
44
+ });
45
+ });
@@ -0,0 +1,13 @@
1
+ const path = require( 'path' );
2
+ const fixture = path.join( __dirname, '../../fixtures' );
3
+
4
+ const getAppConfiguration = require( '../../../lib/utils/getAppConfiguration' );
5
+ const expectedLarvaConfig = require( fixture + '/larva.config.js' );
6
+
7
+ describe( 'getAppConfiguration', () => {
8
+
9
+ it( 'Get Larva Configuration', () => {
10
+ expect(getAppConfiguration( 'backstop' )).toStrictEqual( expectedLarvaConfig.backstop );
11
+ });
12
+
13
+ });
@@ -0,0 +1,23 @@
1
+ const getModuleNamesFromDirectory = require( '../../../lib/utils/getModuleNamesFromDirectory' );
2
+ const getAppConfiguration = require( '../../../lib/utils/getAppConfiguration' );
3
+
4
+ const config = getAppConfiguration( 'patterns' );
5
+
6
+ describe( 'getModuleNamesFromDirectory', () => {
7
+ it( 'gets an array of modules', () => {
8
+ expect( getModuleNamesFromDirectory( config.projectPatternsDir, config.ignoredModules ) ).toEqual( expect.arrayContaining( [ 'test-module' ] ) );
9
+ });
10
+
11
+ it( 'ignored modules with underscores', () => {
12
+ expect( getModuleNamesFromDirectory( config.projectPatternsDir, config.ignoredModules ) ).toEqual( expect.not.arrayContaining( [ '_also-ignored' ] ) );
13
+ });
14
+
15
+ it( 'ignores modules listed in larva.config.ignoredModules', () => {
16
+ expect( getModuleNamesFromDirectory( config.projectPatternsDir, config.ignoredModules ) ).toEqual( expect.not.arrayContaining( [ 'ignore-me' ] ) );
17
+ });
18
+
19
+ it( 'gets module names from larva', () => {
20
+ expect( getModuleNamesFromDirectory( config.larvaPatternsDir, config.ignoredModules ) ).toEqual( expect.arrayContaining( [ 'pmc-footer' ] ) );
21
+ });
22
+
23
+ });
@@ -7,21 +7,48 @@ const getPatternData = require( '../../../lib/utils/getPatternData' );
7
7
  const appConfiguration = require( '../../../lib/utils/getAppConfiguration' )('patterns');
8
8
 
9
9
  const expectedSchema = require( fixture + '/src/patterns/components/c-nav-link/c-nav-link.prototype.js' );
10
+ const expectedVariantSchema = require( fixture + '/src/patterns/components/c-nav-link/c-nav-link.featured.js' );
10
11
  const expectedSchemaFromJson = require( fixture + '/src/patterns/objects/o-crap/o-crap.json' );
11
12
  const expectedPath = fixture + '/src/patterns/objects/o-nav/o-nav.json';
13
+ const expectedOneOffSchema = require( fixture + '/src/patterns/one-offs/newswire/newswire.prototype.js' );
14
+
15
+ let compStub = {
16
+ name: 'c-nav-link',
17
+ type: 'components',
18
+ variant: 'prototype'
19
+ };
20
+
21
+ const objStub = {
22
+ name: 'o-crap',
23
+ type: 'objects',
24
+ variant: 'prototype'
25
+ };
26
+
27
+ const oneOffStub = {
28
+ name: 'newswire',
29
+ type: 'one-offs',
30
+ variant: 'prototype'
31
+ };
12
32
 
13
33
  describe( 'getPatternData', () => {
14
- it( 'throws an error if no pattern prototype is found', () => {
15
- assert.throws( () => getPatternData( fixture, { type: 'objects', name: 'o-nav' } ), Error );
34
+
35
+ it( 'first returns the pattern object if the schema is found', () => {
36
+ assert.equal( getPatternData( fixture + '/src/patterns', compStub ), expectedSchema );
16
37
  });
17
38
 
18
- it( 'first returns the pattern object if the schema is found', () => {
19
- assert.equal( getPatternData( fixture + '/src/patterns', { name: 'c-nav-link' } ), expectedSchema );
39
+ it( 'returns the pattern object for one-offs', () => {
40
+ assert.equal( getPatternData( fixture + '/src/patterns', oneOffStub ), expectedOneOffSchema );
20
41
  });
21
42
 
22
43
  it( 'returns the pattern json object if no prototype is found', () => {
23
- assert.equal( getPatternData( fixture + '/src/patterns', { name: 'o-crap' } ), expectedSchemaFromJson );
44
+ assert.equal( getPatternData( fixture + '/src/patterns', objStub ), expectedSchemaFromJson );
24
45
  });
46
+
47
+ it( 'gets a variant specified in params', () => {
48
+ compStub.variant = 'featured';
49
+ assert.equal( getPatternData( fixture + '/src/patterns', compStub ), expectedVariantSchema );
50
+ });
51
+
25
52
  });
26
53
 
27
54