Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ executors:
parameters:
current_golden_images_hash:
type: string
default: 738614fb9802d7227ca7e469f9e6c0256edf0bb9
default: de8ce09ade2a1ea8ad7058a84fa1a4b04998636c
commands:
downstream:
steps:
Expand Down
11 changes: 9 additions & 2 deletions custom-elements-manifest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ governing permissions and limitations under the License.
*/

export default {
globs: ['**/*.ts'],
exclude: ['**/*.d.ts', '**/stories/**', '**/test/**'],
globs: ['**/sp-*.ts', '**/src/[A-Z]*.ts'],
exclude: [
'**/sp-icon-*.ts',
'**/*.d.ts',
'**/stories/**',
'**/test/**',
'node_modules/*',
'**/*.dev.*',
],
outdir: '.',
litelement: true,
};
9 changes: 6 additions & 3 deletions packages/thumbnail/stories/images.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions projects/documentation/content/_data/site.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ module.exports = {
shortDesc:
'Spectrum Web Components provide interface components as custom elements to help teams work more efficiently and to make applications more consistent.',
url,
WATCH_MODE: process.env.WATCH_MODE === 'true',
};
2 changes: 2 additions & 0 deletions projects/documentation/content/_includes/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
{% block content %}
{{ content | safe }}
{% endblock %}
{% if site.WATCH_MODE !== true %}
<script async defer>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js');
});
}
</script>
{% endif %}
</body>
</html>
2 changes: 1 addition & 1 deletion projects/documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"copy-docs": "node scripts/copy-component-docs.js",
"prebuild": "rimraf _site && mkdir -p _site/src/components && rimraf dist && mkdir dist && yarn copy-docs",
"prewatch": "yarn build",
"watch": "run-p 'build:tsc -w' 'build:eleventy --watch' watch:move-css build:postcss 'build:postcss --watch' 'build:rollup --watch' watch:serve",
"watch": "WATCH_MODE=true run-p 'build:tsc -w' 'build:eleventy --watch' watch:move-css build:postcss 'build:postcss --watch' 'build:rollup --watch' watch:serve",
"watch:move-css": "yarn build:move-css && node scripts/watch-css.js",
"watch:serve": "wds --root-dir=dist --watch"
},
Expand Down
58 changes: 30 additions & 28 deletions projects/documentation/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,34 +196,36 @@ module.exports = async () => {
],
})
);
mpaConfig.plugins.push(
injectManifest({
swSrc: path.join(process.cwd(), '_site', 'serviceWorker.js'),
swDest: path.join(process.cwd(), 'dist', 'sw.js'),
globDirectory: path.join(process.cwd(), 'dist'),
globPatterns: ['**/*.{html,js,css,png,svg,ico,webmanifest}'],
globIgnores: [
'*nomodule*',
// 'components/*/index.html',
'components/*/api/index.html',
'components/*/content/index.html',
'components/*/api-content/index.html',
'storybook/**/*',
'src/components/*.css',
],
additionalManifestEntries: [
{
url: 'index.html?homescreen',
revision: '4',
},
{
url: 'searchIndex.json',
revision: `${Date.now()}`,
},
],
mode: 'production',
})
);
if (process.env.ROLLUP_WATCH !== 'true') {
mpaConfig.plugins.push(
injectManifest({
swSrc: path.join(process.cwd(), '_site', 'serviceWorker.js'),
swDest: path.join(process.cwd(), 'dist', 'sw.js'),
globDirectory: path.join(process.cwd(), 'dist'),
globPatterns: ['**/*.{html,js,css,png,svg,ico,webmanifest}'],
globIgnores: [
'*nomodule*',
// 'components/*/index.html',
'components/*/api/index.html',
'components/*/content/index.html',
'components/*/api-content/index.html',
'storybook/**/*',
'src/components/*.css',
],
additionalManifestEntries: [
{
url: 'index.html?homescreen',
revision: '4',
},
{
url: 'searchIndex.json',
revision: `${Date.now()}`,
},
],
mode: 'production',
})
);
}

mpaConfig.plugins.push(
copy({
Expand Down
46 changes: 7 additions & 39 deletions tasks/build-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,17 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import path from 'path';
import fs from 'fs';
import fg from 'fast-glob';
import postcss from 'postcss';
import cssProcessing from '../scripts/css-processing.cjs';
import { fileURLToPath } from 'url';

const { postCSSPlugins, wrapCSSResult } = cssProcessing;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const configPath = path.resolve(path.join(__dirname, '..', 'config'));
let header;
try {
header = fs.readFileSync(path.join(configPath, 'license.js'), 'utf8');
} catch (error) {
throw new Error(error);
}

header = header.replace('<%= YEAR %>', new Date().getFullYear());

export const processCSS = async (cssPath) => {
let wrappedCSS = header;
const originCSS = fs.readFileSync(cssPath, 'utf8');
const processedCSS = await postcss(postCSSPlugins(cssPath, true))
.process(originCSS, {
from: cssPath,
})
.then((result) => {
return result;
})
.catch((error) => {
console.error(error?.message || error);
});
wrappedCSS += wrapCSSResult(processedCSS);
fs.writeFileSync(cssPath + '.ts', wrappedCSS, 'utf-8');
};
import { processCSS } from './css-tools.js';

const buildCSS = async () => {
for (const cssPath of await fg(`./packages/*/src/**/*.css`)) {
processCSS(cssPath);
}
for (const cssPath of await fg(`./tools/*/src/*.css`)) {
processCSS(cssPath);
for (const cssPath of await fg([
'./packages/*/src/**/*.css',
'./tools/*/src/*.css',
])) {
await processCSS(cssPath);
}
process.exit(0);
};

buildCSS();
46 changes: 46 additions & 0 deletions tasks/css-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import path from 'path';
import fs from 'fs';
import postcss from 'postcss';
import cssProcessing from '../scripts/css-processing.cjs';
import { fileURLToPath } from 'url';

const { postCSSPlugins, wrapCSSResult } = cssProcessing;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const configPath = path.resolve(path.join(__dirname, '..', 'config'));
let header;
try {
header = fs.readFileSync(path.join(configPath, 'license.js'), 'utf8');
} catch (error) {
throw new Error(error);
}

header = header.replace('<%= YEAR %>', new Date().getFullYear());

export const processCSS = async (cssPath) => {
let wrappedCSS = header;
const originCSS = fs.readFileSync(cssPath, 'utf8');
const processedCSS = await postcss(postCSSPlugins(cssPath, true))
.process(originCSS, {
from: cssPath,
})
.then((result) => {
return result;
})
.catch((error) => {
console.error(error?.message || error);
});
wrappedCSS += wrapCSSResult(processedCSS);
fs.writeFileSync(cssPath + '.ts', wrappedCSS, 'utf-8');
};
16 changes: 12 additions & 4 deletions tasks/watch-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ governing permissions and limitations under the License.

import chokidar from 'chokidar';
import debounce from 'debounce';
import { processCSS } from './build-css.js';
import { processCSS } from './css-tools.js';

const debounceProcessCSS = debounce.debounce(processCSS, 200);

// One-liner for current directory
chokidar
.watch(['./packages/*/src/*.css', './tools/*/src/*.css'])
.on('change', debounceProcessCSS)
.on('add', debounceProcessCSS);
.watch(['./packages/*/src/*.css', './tools/*/src/*.css'], {
ignoreInitial: true,
})
.on('change', (path) => {
console.log(`Process CSS change in: ${path}`);
debounceProcessCSS(path);
})
.on('add', (path) => {
console.log(`Process CSS added at: ${path}`);
debounceProcessCSS(path);
});

console.log('Listening to CSS...');
3 changes: 2 additions & 1 deletion tsconfig-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./",
"declaration": false
"declaration": false,
"incremental": true
},
"include": [
"packages/**/*.ts",
Expand Down
28 changes: 25 additions & 3 deletions wds-storybook.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
Expand All @@ -12,14 +11,17 @@ governing permissions and limitations under the License.
import { fromRollup } from '@web/dev-server-rollup';
import rollupJson from '@rollup/plugin-json';
import { storybookPlugin } from '@web/dev-server-storybook';
import { watchSWC } from './web-test-runner.utils.js';
// import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';

const json = fromRollup(rollupJson);

export default {
nodeResolve: {
exportConditions: ['browser', 'development'],
moduleDirectories: ['node_modules', 'packages', 'projects', 'tools'],
},
clearTerminalOnReload: false,
watch: true,
open: true,
mimeTypes: {
Expand All @@ -28,9 +30,29 @@ export default {
plugins: [
json(),
storybookPlugin({ type: 'web-components' }),
watchSWC(),
// hmrPlugin({
// include: ['[packages]/**/*'],
// presets: [presets.litElement],
// include: ['{packages,projects,tools}/**/*.js'],
// presets: [presets.lit],
// }),
],
http2: true,
middleware: [
async (ctx, next) => {
await next();

if (
// Icon packages
ctx.url.search('/icons-') > -1 ||
// Node modules
(ctx.url.search('/node_modules/') > -1 &&
ctx.url.search('/@spectrum-web-components') === -1)
) {
ctx.set(
'Cache-Control',
'public, max-age=604800, stale-while-revalidate=86400'
);
}
},
],
};
20 changes: 20 additions & 0 deletions web-test-runner.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { playwrightLauncher } from '@web/test-runner-playwright';
import { visualRegressionPlugin } from '@web/test-runner-visual-regression/plugin';
import fs from 'fs';
import path from 'path';
import fg from 'fast-glob';

const tools = fs
.readdirSync('tools')
Expand Down Expand Up @@ -149,3 +150,22 @@ export const configuredVisualRegressionPlugin = () =>
);
},
});

export function watchSWC() {
return {
name: 'watch-swc-plugin',
async serverStart({ fileWatcher }) {
// register SWC output files to be watched
const files = await fg('{packages,projects,tools}/**/*.js', {
ignore: ['**/*.map', '**/*.vrt.js', '**/spectrum-config.js'],
});
for (const file of files) {
fileWatcher.add(process.cwd() + file);
}
// Use the following for reviewing the file changes that are reacted to here...
// fileWatcher.on('change', (path) => {
// console.log(`Process change in: ${path}`);
// });
},
};
}