@@ -9,7 +9,10 @@ const fg = require("fast-glob");
9
9
10
10
module . exports = defineConfig ( {
11
11
async constraints ( { Yarn } ) {
12
- // Fetch a list of all the component workspaces using a glob pattern
12
+ /**
13
+ * Fetch a list of all the component workspaces using a glob pattern
14
+ * @type {string[] } components
15
+ */
13
16
const components = fg . sync ( "components/*" , {
14
17
cwd : __dirname ,
15
18
onlyDirectories : true ,
@@ -49,7 +52,47 @@ module.exports = defineConfig({
49
52
return [ "design-system" , "spectrum" , "spectrum-css" , "adobe" , "adobe-spectrum" , ...additionalKeywords ] ;
50
53
}
51
54
52
- for ( const workspace of Yarn . workspaces ( ) ) {
55
+ /**
56
+ * This function rolls up all the component package.json
57
+ * requirements for all workspaces into a single function
58
+ * to simplify into a readable set of operations
59
+ * @param {Workspace } workspace
60
+ * @param {string } folderName
61
+ * @returns {void }
62
+ */
63
+ function validateComponentPackageJson ( workspace , folderName ) {
64
+ // Only update the homepage if it does not already exist
65
+ if ( ! workspace . manifest . homepage ) {
66
+ workspace . set ( "homepage" , `https://opensource.adobe.com/spectrum-css/?path=/docs/components-${ folderName } --docs` ) ;
67
+ }
68
+
69
+ workspace . set ( "publishConfig.access" , "public" ) ;
70
+ workspace . set ( "keywords" , keywords ( [ "component" , "css" ] ) ) ;
71
+ workspace . set ( "main" , "dist/index.css" ) ;
72
+ workspace . set ( "exports" , {
73
+ "." : "./dist/index.css" ,
74
+ "./*.md" : "./*.md" ,
75
+ "./dist/*" : "./dist/*" ,
76
+ "./index-*.css" : "./dist/index-*.css" ,
77
+ "./index.css" : "./dist/index.css" ,
78
+ "./metadata.json" : "./dist/metadata.json" ,
79
+ "./package.json" : "./package.json" ,
80
+ "./stories/*" : "./stories/*"
81
+ } ) ;
82
+ }
83
+
84
+ /**
85
+ * This function rolls up all the package.json requirements
86
+ * for all workspaces into a single function to simplify
87
+ * the workspace for loop into a readable set of operations
88
+ * @param {Workspace } workspace
89
+ * @returns {void }
90
+ */
91
+ function validatePackageJson ( workspace ) {
92
+ const isRoot = workspace . cwd === "." ;
93
+ const isComponent = components . includes ( workspace . cwd ) ;
94
+ const isToken = workspace . cwd === "tokens" ;
95
+
53
96
/**
54
97
* -------------- GLOBAL --------------
55
98
* Global configuration for all workspaces
@@ -61,45 +104,24 @@ module.exports = defineConfig({
61
104
workspace . set ( "repository.url" , "https://github.com/adobe/spectrum-css.git" ) ;
62
105
63
106
// We don't need to set the directory for the root workspace
64
- if ( workspace . cwd !== "." ) {
65
- workspace . set ( "repository.directory" , workspace . cwd ) ;
66
- }
107
+ if ( ! isRoot ) workspace . set ( "repository.directory" , workspace . cwd ) ;
67
108
68
109
workspace . set ( "bugs.url" , "https://github.com/adobe/spectrum-css/issues" ) ;
69
110
70
111
/**
71
112
* -------------- COMPONENTS --------------
72
113
* Process the components workspaces with component-specific configuration
73
114
*/
74
- if ( components . includes ( workspace . cwd ) ) {
115
+ if ( isComponent ) {
75
116
const folderName = workspace . cwd ?. split ( "/" ) ?. [ 1 ] ;
76
-
77
- // Only update the homepage if it does not already exist
78
- if ( ! workspace . manifest . homepage ) {
79
- workspace . set ( "homepage" , `https://opensource.adobe.com/spectrum-css/?path=/docs/components-${ folderName } --docs` ) ;
80
- }
81
-
82
- workspace . set ( "publishConfig.access" , "public" ) ;
83
- workspace . set ( "keywords" , keywords ( [ "component" , "css" ] ) ) ;
84
- workspace . set ( "main" , "dist/index.css" ) ;
85
- workspace . set ( "exports" , {
86
- "." : "./dist/index.css" ,
87
- "./*.md" : "./*.md" ,
88
- "./dist/*" : "./dist/*" ,
89
- "./index-*.css" : "./dist/index-*.css" ,
90
- "./index.css" : "./dist/index.css" ,
91
- "./metadata.json" : "./dist/metadata.json" ,
92
- "./package.json" : "./package.json" ,
93
- "./stories/*" : "./stories/*"
94
- } ) ;
95
-
117
+ validateComponentPackageJson ( workspace , folderName ) ;
96
118
validateLocalPackages ( workspace ) ;
97
119
}
98
120
/**
99
121
* -------------- TOKENS --------------
100
122
* Process the tokens workspace with token-specific configuration
101
123
*/
102
- else if ( workspace . cwd === "tokens" ) {
124
+ else if ( isToken ) {
103
125
workspace . set ( "homepage" , "https://opensource.adobe.com/spectrum-css" ) ;
104
126
workspace . set ( "publishConfig.access" , "public" ) ;
105
127
workspace . set ( "keywords" , keywords ( [ "tokens" , "css" ] ) ) ;
@@ -113,13 +135,21 @@ module.exports = defineConfig({
113
135
* All other workspaces should have at least the following configuration
114
136
*/
115
137
if ( ! workspace . manifest . keywords ) {
116
- workspace . set ( "keywords" , keywords ( [ ] ) ) ;
138
+ workspace . set ( "keywords" , keywords ( ) ) ;
117
139
}
118
140
119
141
if ( ! workspace . manifest . homepage ) {
120
142
workspace . set ( "homepage" , "https://opensource.adobe.com/spectrum-css/" ) ;
121
143
}
122
144
}
123
145
}
146
+
147
+ /**
148
+ * This loop iterates over all the workspaces in the project
149
+ * and updates the package.json file with the necessary
150
+ */
151
+ for ( const workspace of Yarn . workspaces ( ) ) {
152
+ validatePackageJson ( workspace ) ;
153
+ }
124
154
} ,
125
155
} ) ;
0 commit comments