Skip to content

Commit 35170a1

Browse files
committed
fix: update yarn new-package to not depend on spectrum-css
1 parent c4f765c commit 35170a1

File tree

6 files changed

+82
-30
lines changed

6 files changed

+82
-30
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"npm-run-all2": "^6.0.0",
186186
"patch-package": "^8.0.0",
187187
"pinst": "^3.0.0",
188+
"plop": "^4.0.1",
188189
"prettier": "^3.0.0",
189190
"prettier-plugin-package": "^1.3.0",
190191
"pretty-bytes": "^6.1.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Copyright 2024 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
/* This is where you'd put any system overrides that needs different styling in different themes */
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
@import './spectrum-{{ name }}.css';
1+
/*
2+
Copyright 2024 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
@import './spectrum-{{ name }}.css';
14+
@import './{{ name }}-overrides.css';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Copyright 2024 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
/* This is where you'd put any Spectrum CSS variables and rules */

projects/templates/plopfile.js

+39-28
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ module.exports = function (plop) {
2525
const capitalized = camel.charAt(0).toUpperCase() + camel.substring(1);
2626
return capitalized;
2727
});
28-
// name of Spectrum CSS package
29-
plop.setHelper('spectrumCSS', function (name) {
30-
return name.replace(/-/g, '');
31-
});
3228
// name used as title in storybook and documentation
3329
plop.setHelper('displayName', function (name) {
3430
const camel = name.replace(/-([a-z])/g, (g) => {
@@ -40,22 +36,43 @@ module.exports = function (plop) {
4036
});
4137

4238
plop.setActionType('install deps', function (answers) {
43-
execSync(
44-
`cd ../../ && yarn lerna add @spectrum-web-components/base --scope=@spectrum-web-components/${answers.name} --no-bootstrap`
45-
);
46-
execSync(
47-
`cd ../../ && yarn lerna add @spectrum-web-components/${answers.name} --scope=@spectrum-web-components/bundle --no-bootstrap`
48-
);
49-
if (answers.spectrum)
39+
try {
40+
// Add base as a workspace dependency to the new package
41+
execSync(
42+
`cd ../../ && yarn workspace @spectrum-web-components/${answers.name} add @spectrum-web-components/base@workspace:^`
43+
);
44+
// Add the new package to bundle with a fixed version
5045
execSync(
51-
`cd ../../ && yarn lerna add @spectrum-css/${answers.spectrum} --scope=@spectrum-web-components/${answers.name} --dev --no-bootstrap`
46+
`cd ../../ && yarn workspace @spectrum-web-components/bundle add @spectrum-web-components/${answers.name}@0.0.1`
5247
);
48+
} catch (error) {
49+
// Silently fail, dependencies will need to be added manually
50+
}
5351
});
5452

5553
plop.setActionType('format files', function (answers) {
56-
execSync(
57-
`cd ../../ && yarn prettier --write packages/${answers.name} && yarn eslint --fix -f pretty packages/${answers.name} && yarn stylelint --fix packages/${answers.name}`
58-
);
54+
try {
55+
// Run formatters separately so one failing doesn't block the others
56+
execSync(
57+
`cd ../../ && yarn prettier --write packages/${answers.name}`
58+
);
59+
} catch (error) {
60+
// Continue if prettier fails
61+
}
62+
try {
63+
execSync(
64+
`cd ../../ && yarn eslint --fix -f pretty packages/${answers.name}`
65+
);
66+
} catch (error) {
67+
// Continue if eslint fails
68+
}
69+
try {
70+
execSync(
71+
`cd ../../ && yarn stylelint --fix packages/${answers.name}/src/*.css`
72+
);
73+
} catch (error) {
74+
// Continue if stylelint fails
75+
}
5976
});
6077

6178
plop.setGenerator('component', {
@@ -73,17 +90,6 @@ module.exports = function (plop) {
7390
// Convert the input into kebab case if not provided as such and strip swc- prefixing if present
7491
filter: (response) => kebabCase(response.replace(/^sp-/, '')),
7592
},
76-
{
77-
type: 'input',
78-
name: 'spectrum',
79-
message: 'Spectrum CSS package name (i.e. colorarea)',
80-
// Remove the package prefix if provided and strip out any dashes or spaces in the result
81-
filter: (response) => {
82-
return response
83-
.replace(/^\@spectrum-css\//, '')
84-
.replace(/[-|\s]/g, '');
85-
},
86-
},
8793
],
8894
actions: [
8995
{
@@ -108,8 +114,13 @@ module.exports = function (plop) {
108114
},
109115
{
110116
type: 'add',
111-
path: '../../packages/{{name}}/src/spectrum-config.js',
112-
templateFile: 'plop-templates/spectrum-config.js.hbs',
117+
path: '../../packages/{{name}}/src/spectrum-{{name}}.css',
118+
templateFile: 'plop-templates/spectrum-component.css.hbs',
119+
},
120+
{
121+
type: 'add',
122+
path: '../../packages/{{name}}/src/{{name}}-overrides.css',
123+
templateFile: 'plop-templates/component-overrides.css.hbs',
113124
},
114125
{
115126
type: 'add',

yarn.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ __metadata:
294294
npm-run-all2: "npm:^6.0.0"
295295
patch-package: "npm:^8.0.0"
296296
pinst: "npm:^3.0.0"
297+
plop: "npm:^4.0.1"
297298
prettier: "npm:^3.0.0"
298299
prettier-plugin-package: "npm:^1.3.0"
299300
pretty-bytes: "npm:^6.1.1"
@@ -27970,7 +27971,7 @@ __metadata:
2797027971
languageName: node
2797127972
linkType: hard
2797227973

27973-
"plop@npm:^4.0.0":
27974+
"plop@npm:^4.0.0, plop@npm:^4.0.1":
2797427975
version: 4.0.1
2797527976
resolution: "plop@npm:4.0.1"
2797627977
dependencies:

0 commit comments

Comments
 (0)