Skip to content

Commit 1f83231

Browse files
committed
Code Builds
1 parent b2567f3 commit 1f83231

File tree

12 files changed

+114
-56
lines changed

12 files changed

+114
-56
lines changed

.storybook/main.js

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import path from 'path';
2-
import PATHS from '../config/paths';
2+
import PATHS from '../config/paths.js';
33

44
import { config } from 'dotenv';
55
config({
6-
path: path.join(PATHS.root, '.env')
6+
path: path.join(PATHS.root, '.env'),
77
});
88

9-
const BUILD_FOR_IE11 = process.env.UI5_WEBCOMPONENTS_FOR_REACT_BUILD_IE11 === 'true';
9+
const BUILD_FOR_IE11 =
10+
process.env.UI5_WEBCOMPONENTS_FOR_REACT_BUILD_IE11 === 'true';
1011

1112
const DEPENDENCY_REGEX = BUILD_FOR_IE11
1213
? /node_modules/
1314
: /node_modules\/(@ui5\/webcomponents(-(base|core|fiori|icons|theme-base))?|lit-html)\//;
1415

15-
export const stories = ['../docs/**/*.stories.mdx', '../packages/**/*.stories.@(tsx|jsx|mdx)'];
16+
export const stories = [
17+
'../docs/**/*.stories.mdx',
18+
'../packages/**/*.stories.@(tsx|jsx|mdx)',
19+
];
1620

1721
export const addons = [
1822
'@storybook/addon-toolbars',
1923
'@storybook/addon-docs',
2024
'@storybook/addon-controls',
21-
'@storybook/addon-actions'
25+
'@storybook/addon-actions',
2226
];
2327
export async function webpack(config, { configType }) {
2428
// `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
@@ -28,7 +32,7 @@ export async function webpack(config, { configType }) {
2832
config.module.rules.push({
2933
test: /assets\/.*\.json$/,
3034
use: 'file-loader',
31-
type: 'javascript/auto'
35+
type: 'javascript/auto',
3236
});
3337

3438
if (configType === 'PRODUCTION' || BUILD_FOR_IE11) {
@@ -53,18 +57,18 @@ export async function webpack(config, { configType }) {
5357
// Do not transform modules to CJS
5458
modules: false,
5559
// Exclude transforms that make all code slower
56-
exclude: ['transform-typeof-symbol']
57-
}
58-
]
60+
exclude: ['transform-typeof-symbol'],
61+
},
62+
],
5963
],
6064
plugins: [
6165
[
6266
'@babel/plugin-transform-runtime',
6367
{
6468
version: require('@babel/runtime/package.json').version,
65-
useESModules: true
66-
}
67-
]
69+
useESModules: true,
70+
},
71+
],
6872
],
6973
cacheDirectory: true,
7074
cacheCompression: false,
@@ -73,18 +77,43 @@ export async function webpack(config, { configType }) {
7377
// because it was compiled. Thus, we don't want the browser
7478
// debugger to show the original code. Instead, the code
7579
// being evaluated would be much more helpful.
76-
sourceMaps: false
77-
}
80+
sourceMaps: false,
81+
},
7882
});
7983
}
8084
config.resolve.alias = {
8185
...config.resolve.alias,
8286
'@shared': path.join(PATHS.root, 'shared'),
83-
'@ui5/webcomponents-react/dist': path.join(PATHS.root, 'packages', 'main', 'dist'),
84-
'@ui5/webcomponents-react': path.join(PATHS.root, 'packages', 'main', 'src'),
85-
'@ui5/webcomponents-react-charts': path.join(PATHS.root, 'packages', 'charts', 'src'),
86-
'@ui5/webcomponents-react-base/types': path.join(PATHS.root, 'packages', 'base', 'types'),
87-
'@ui5/webcomponents-react-base': path.join(PATHS.root, 'packages', 'base', 'src')
87+
'@ui5/webcomponents-react/dist': path.join(
88+
PATHS.root,
89+
'packages',
90+
'main',
91+
'dist'
92+
),
93+
'@ui5/webcomponents-react': path.join(
94+
PATHS.root,
95+
'packages',
96+
'main',
97+
'src'
98+
),
99+
'@ui5/webcomponents-react-charts': path.join(
100+
PATHS.root,
101+
'packages',
102+
'charts',
103+
'src'
104+
),
105+
'@ui5/webcomponents-react-base/types': path.join(
106+
PATHS.root,
107+
'packages',
108+
'base',
109+
'types'
110+
),
111+
'@ui5/webcomponents-react-base': path.join(
112+
PATHS.root,
113+
'packages',
114+
'base',
115+
'src'
116+
),
88117
};
89118

90119
return config;

config/paths.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
import { dirname } from 'path';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
27

38
const root = path.resolve(__dirname, '..');
49
const PATHS = {
@@ -10,7 +15,7 @@ const PATHS = {
1015
coverage: path.join(root, 'coverage'),
1116
nycOutput: path.join(root, '.nyc_output'),
1217
nodeModules: path.join(root, 'node_modules'),
13-
packages: path.join(root, 'packages')
18+
packages: path.join(root, 'packages'),
1419
};
1520

1621
export default PATHS;

packages/base/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"scripts": {
2222
"clean": "rimraf cjs Device hooks lib polyfill styling utils index.esm.js index.d.ts",
23-
"build:rollup": "rollup -c rollup.config.js",
23+
"build:rollup": "rollup -c rollup.config.mjs",
2424
"build:polyfills": "tsc ./src/polyfill/*.ts --outDir ./polyfill --skipLibCheck",
2525
"build": "npm-run-all -s build:rollup build:polyfills",
2626
"build:types": "tsc --declaration --emitDeclarationOnly --declarationDir . --removeComments false"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rollupConfigFactory from '../../scripts/rollup/configFactory';
1+
import rollupConfigFactory from '../../scripts/rollup/configFactory.js';
22

33
const config = rollupConfigFactory('base');
44
export default config;

packages/base/scripts/cssVariables/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { writeFileSync } from 'fs';
22
import { root } from '@sap-theming/theming-base-content/content/Base/baseLib/sap_fiori_3/variables.json';
3-
import PATHS from '../../../../config/paths';
3+
import PATHS from '../../../../config/paths.js';
44
import path from 'path';
55
import prettier from 'prettier';
66
import prettierConfig from '../../../../prettier.config.cjs';

packages/charts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"sideEffects": false,
1717
"scripts": {
1818
"clean": "rimraf cjs components interfaces internal lib util index.esm.js index.d.ts config.d.ts hooks",
19-
"build": "rollup -c rollup.config.js",
19+
"build": "rollup -c rollup.config.mjs",
2020
"build:types": "tsc --declaration --emitDeclarationOnly --declarationDir . --removeComments false || exit 0"
2121
},
2222
"dependencies": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rollupConfigFactory from '../../scripts/rollup/configFactory';
1+
import rollupConfigFactory from '../../scripts/rollup/configFactory.js';
22

33
const config = rollupConfigFactory('charts', ['@ui5/webcomponents', '@ui5/webcomponents-base']);
44
export default config;

packages/main/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"scripts": {
2424
"clean": "rimraf cjs components enums interfaces internal lib webComponents index.esm.js index.d.ts dist",
2525
"build": "npm-run-all -s build:i18n build:rollup",
26-
"build:rollup": "rollup -c rollup.config.js",
26+
"build:rollup": "rollup -c rollup.config.mjs",
2727
"build:i18n": "npm-run-all -s build:i18n-bundles build:i18n-default build:i18n-imports build:assets",
2828
"build:i18n-bundles": "mkdirp dist/assets/i18n && node ../../node_modules/@ui5/webcomponents-tools/lib/i18n/toJSON.js src/i18n dist/assets/i18n",
2929
"build:i18n-default": "node ../../node_modules/@ui5/webcomponents-tools/lib/i18n/defaults.js src/i18n dist/assets/i18n && tsc dist/assets/i18n/i18n-defaults.js --allowJs --declaration --emitDeclarationOnly --declarationDir dist/assets/i18n",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import rollupConfigFactory from '../../scripts/rollup/configFactory';
1+
import rollupConfigFactory from '../../scripts/rollup/configFactory.js';
22

33
export default rollupConfigFactory('main', ['@ui5/webcomponents-base']);

packages/main/scripts/create-library-export.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import PATHS from '../../../config/paths';
3+
import PATHS from '../../../config/paths.js';
44

55
const LIB_BASE_PATH = path.resolve(PATHS.packages, 'main', 'src', 'lib');
66
const INTERNAL_COMPONENTS = ['ScrollContext'];
@@ -33,4 +33,7 @@ fileContent += `
3333
};
3434
`;
3535

36-
fs.writeFileSync(path.join(PATHS.packages, 'main', 'src', 'index.ts'), fileContent);
36+
fs.writeFileSync(
37+
path.join(PATHS.packages, 'main', 'src', 'index.ts'),
38+
fileContent
39+
);

scripts/rollup/configFactory.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { nodeResolve } from '@rollup/plugin-node-resolve';
22
import commonjs from '@rollup/plugin-commonjs';
3-
import { babel } from '@rollup/plugin-babel';
3+
import Babel from '@rollup/plugin-babel';
44
import path from 'path';
55
import fs from 'fs';
66
import json from '@rollup/plugin-json';
77
import micromatch from 'micromatch';
8-
import PATHS from '../../config/paths';
9-
import { asyncCopyTo, highlightLog } from '../utils';
8+
import PATHS from '../../config/paths.js';
9+
import { asyncCopyTo, highlightLog } from '../utils.js';
1010
import replace from '@rollup/plugin-replace';
1111
import glob from 'glob';
1212
import { terser } from 'rollup-plugin-terser';
1313

14+
const { babel } = Babel;
15+
1416
process.env.BABEL_ENV = 'production';
1517
process.env.NODE_ENV = 'production';
1618

@@ -20,30 +22,33 @@ const rollupConfigFactory = (pkgName, externals = []) => {
2022

2123
const allFilesAndFolders = glob.sync(`${LIB_BASE_PATH}/**/*`);
2224

23-
const allLibFiles = allFilesAndFolders.filter((file) => fs.statSync(file).isFile());
24-
25+
const allLibFiles = allFilesAndFolders.filter((file) =>
26+
fs.statSync(file).isFile()
27+
);
2528
const plugins = [
2629
nodeResolve({
27-
extensions: ['.mjs', '.js', '.json', '.node', '.jsx', '.ts', '.tsx']
30+
extensions: ['.mjs', '.js', '.json', '.node', '.jsx', '.ts', '.tsx'],
2831
}),
2932
commonjs(),
3033
json(),
3134
babel({
3235
extensions: ['.js', '.jsx', '.ts', '.tsx'],
3336
babelHelpers: 'runtime',
34-
configFile: path.resolve(PATHS.root, 'babel.config.cjs')
37+
configFile: path.resolve(PATHS.root, 'babel.config.cjs'),
3538
}),
3639
// Turn __DEV__ and process.env checks into constants.
3740
replace({
3841
exclude: 'node_modules/**',
3942
values: {
4043
__DEV__: 'false',
41-
'process.env.NODE_ENV': "'production'"
42-
}
43-
})
44+
'process.env.NODE_ENV': "'production'",
45+
},
46+
}),
4447
];
4548

46-
const packageJson = require(path.resolve(PKG_BASE_PATH, 'package.json'));
49+
const packageJson = JSON.parse(
50+
fs.readFileSync(path.resolve(PKG_BASE_PATH, 'package.json'), 'utf8')
51+
);
4752
const externalModules = Array.from(
4853
new Set([
4954
'react',
@@ -52,25 +57,33 @@ const rollupConfigFactory = (pkgName, externals = []) => {
5257
packageJson.name,
5358
...Object.keys(packageJson.dependencies || {}),
5459
...Object.keys(packageJson.peerDependencies || {}),
55-
...externals
60+
...externals,
5661
])
5762
);
5863

5964
highlightLog(`Build lib folder for ${pkgName}`);
6065

6166
console.info('Copy License');
62-
fs.copyFileSync(path.resolve(PATHS.root, 'LICENSE'), path.resolve(PKG_BASE_PATH, `LICENSE`));
67+
fs.copyFileSync(
68+
path.resolve(PATHS.root, 'LICENSE'),
69+
path.resolve(PKG_BASE_PATH, `LICENSE`)
70+
);
6371

6472
console.info('Copy index file');
65-
asyncCopyTo(path.resolve(PKG_BASE_PATH, 'src', 'index.ts'), path.resolve(PKG_BASE_PATH, `index.esm.js`));
73+
asyncCopyTo(
74+
path.resolve(PKG_BASE_PATH, 'src', 'index.ts'),
75+
path.resolve(PKG_BASE_PATH, `index.esm.js`)
76+
);
6677

6778
const external = (id) => {
6879
const containsThisModule = (pkg) => id === pkg || id.startsWith(pkg + '/');
6980
return externalModules.some(containsThisModule);
7081
};
7182
const treeshake = {
7283
moduleSideEffects:
73-
packageJson.sideEffects === false ? false : (id) => micromatch.isMatch(id, packageJson.sideEffects)
84+
packageJson.sideEffects === false
85+
? false
86+
: (id) => micromatch.isMatch(id, packageJson.sideEffects),
7487
};
7588
return [
7689
...allLibFiles.map((file) => ({
@@ -82,13 +95,15 @@ const rollupConfigFactory = (pkgName, externals = []) => {
8295
file: path.resolve(
8396
PKG_BASE_PATH,
8497
'lib',
85-
file.replace(`${LIB_BASE_PATH}${path.sep}`, '').replace(/\.ts$/, '.js')
98+
file
99+
.replace(`${LIB_BASE_PATH}${path.sep}`, '')
100+
.replace(/\.ts$/, '.js')
86101
),
87102
format: 'es',
88-
sourcemap: true
89-
}
103+
sourcemap: true,
104+
},
90105
],
91-
plugins
106+
plugins,
92107
})),
93108
{
94109
input: path.resolve(PKG_BASE_PATH, 'src', 'index.ts'),
@@ -98,15 +113,19 @@ const rollupConfigFactory = (pkgName, externals = []) => {
98113
output: [
99114
{
100115
file: path.resolve(PKG_BASE_PATH, 'cjs', `${pkgName}.development.js`),
101-
format: 'cjs'
116+
format: 'cjs',
102117
},
103118
{
104-
file: path.resolve(PKG_BASE_PATH, 'cjs', `${pkgName}.production.min.js`),
119+
file: path.resolve(
120+
PKG_BASE_PATH,
121+
'cjs',
122+
`${pkgName}.production.min.js`
123+
),
105124
format: 'cjs',
106-
plugins: [terser()]
107-
}
108-
]
109-
}
125+
plugins: [terser()],
126+
},
127+
],
128+
},
110129
];
111130
};
112131

scripts/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { ncp } from 'ncp';
3+
import ncp from 'ncp';
44
import path from 'path';
55
import mkdirp from 'mkdirp';
66
import rimraf from 'rimraf';
@@ -78,7 +78,9 @@ export function highlightLog(projectName) {
7878
let whitespacesPerSide = (width - 6 - projectName.length) / 2;
7979
whitespacesPerSide = Math.max(whitespacesPerSide, 1);
8080
console.log(
81-
`###${' '.repeat(Math.ceil(whitespacesPerSide))}${projectName}${' '.repeat(Math.floor(whitespacesPerSide))}###`
81+
`###${' '.repeat(Math.ceil(whitespacesPerSide))}${projectName}${' '.repeat(
82+
Math.floor(whitespacesPerSide)
83+
)}###`
8284
);
8385
console.log('#'.repeat(width));
8486
console.log('');

0 commit comments

Comments
 (0)