mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-07 17:42:27 +03:00
update repo structure
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@local/rollup",
|
||||
"exports": {
|
||||
".": "./src/createRollupConfig.js",
|
||||
"./playwright": "./src/playwright/createPlaywrightRollupConfig.js"
|
||||
},
|
||||
"version": "0.0.0"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
loose: true,
|
||||
bugfixes: true,
|
||||
targets: {
|
||||
esmodules: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
loose: true,
|
||||
targets: {
|
||||
ie: '11',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,135 @@
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
const { execSync } = require("child_process");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const glob = require('glob');
|
||||
const resolve = require('@local/config/resolve');
|
||||
const defaultOptions = require('./defaultOptions');
|
||||
const pipelineBuild = require('./pipeline.build');
|
||||
const pipelineDev = require('./pipeline.dev');
|
||||
|
||||
const workspaceRoot = path.dirname(execSync('npm root').toString());
|
||||
const pkg = require(`${workspaceRoot}/package.json`);
|
||||
|
||||
const appendExtension = (file) =>
|
||||
path.extname(file) === ''
|
||||
? file + resolve.extensions.find((ext) => fs.existsSync(path.resolve(`${file}${ext}`)))
|
||||
: file;
|
||||
|
||||
const normalizePath = (pathName) =>
|
||||
pathName ? pathName.split(path.sep).join(path.posix.sep) : pathName;
|
||||
|
||||
const resolvePath = (basePath, pathToResolve, appendExt) => {
|
||||
const result = pathToResolve
|
||||
? path.isAbsolute(pathToResolve)
|
||||
? pathToResolve
|
||||
: path.resolve(basePath, pathToResolve)
|
||||
: null;
|
||||
return normalizePath(result && appendExt ? appendExtension(result) : result);
|
||||
};
|
||||
|
||||
const getWorkspaceAliases = () =>
|
||||
pkg.workspaces
|
||||
.map((pattern) => glob.sync(pattern, { cwd: workspaceRoot }))
|
||||
.flat()
|
||||
.reduce((obj, resolvedPath) => {
|
||||
let projTsConfig;
|
||||
const absolutePath = path.resolve(workspaceRoot, resolvedPath);
|
||||
try {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
projTsConfig = require(`${path.resolve(workspaceRoot, resolvedPath)}/tsconfig.json`);
|
||||
} catch {}
|
||||
|
||||
obj[`@/${path.basename(absolutePath)}`] = `${normalizePath(
|
||||
path.resolve(
|
||||
absolutePath,
|
||||
projTsConfig?.compilerOptions?.baseUrl || defaultOptions.paths.src
|
||||
)
|
||||
)}`;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
const mergeAndResolveOptions = (userOptions) => {
|
||||
const {
|
||||
mode: defaultMode,
|
||||
paths: defaultPaths,
|
||||
versions: defaultVersions,
|
||||
alias: defaultAlias,
|
||||
rollup: defaultRollup,
|
||||
extractStyle: defaultExtractStyle,
|
||||
} = defaultOptions;
|
||||
const {
|
||||
project,
|
||||
mode: rawMode,
|
||||
paths: rawPaths = {},
|
||||
versions: rawVersions = {},
|
||||
alias: rawAlias = {},
|
||||
rollup: rawRollup = {},
|
||||
extractStyle: rawExtractStyle,
|
||||
} = userOptions;
|
||||
const projectPath = process.cwd();
|
||||
const mergedOptions = {
|
||||
project: project || path.basename(projectPath),
|
||||
mode: rawMode || defaultMode,
|
||||
repoRoot: workspaceRoot,
|
||||
extractStyle: rawExtractStyle ?? defaultExtractStyle,
|
||||
paths: {
|
||||
...defaultPaths,
|
||||
...rawPaths,
|
||||
},
|
||||
versions: {
|
||||
...defaultVersions,
|
||||
...rawVersions,
|
||||
},
|
||||
alias: {
|
||||
...getWorkspaceAliases(),
|
||||
...defaultAlias,
|
||||
...rawAlias,
|
||||
},
|
||||
rollup: {
|
||||
...defaultRollup,
|
||||
...rawRollup,
|
||||
output: {
|
||||
...defaultRollup.output,
|
||||
...(rawRollup.output || {}),
|
||||
},
|
||||
},
|
||||
};
|
||||
const { src, dist, types } = mergedOptions.paths;
|
||||
|
||||
mergedOptions.paths.src = resolvePath(projectPath, src);
|
||||
mergedOptions.paths.dist = resolvePath(projectPath, dist);
|
||||
mergedOptions.paths.types = resolvePath(projectPath, types);
|
||||
|
||||
mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true);
|
||||
mergedOptions.rollup.output = {
|
||||
...(mergedOptions.rollup.output || {}),
|
||||
name: mergedOptions.rollup.output?.name || mergedOptions.project,
|
||||
file: mergedOptions.rollup.output?.file || mergedOptions.project.toLocaleLowerCase(),
|
||||
};
|
||||
|
||||
return mergedOptions;
|
||||
};
|
||||
|
||||
const createConfig = (userOptions = {}) => {
|
||||
const options = mergeAndResolveOptions(userOptions);
|
||||
const { project, mode, versions } = options;
|
||||
const { module: buildModuleVersion } = versions;
|
||||
const isBuild = mode === 'build';
|
||||
|
||||
if (isBuild) {
|
||||
console.log('');
|
||||
console.log('PROJECT : ', project);
|
||||
console.log('OPTIONS : ', options);
|
||||
|
||||
const umd = pipelineBuild(resolve, false, options, { declarationFiles: true, outputStyle: true });
|
||||
const esm = buildModuleVersion ? pipelineBuild(resolve, true, options) : null;
|
||||
|
||||
return [umd, esm].filter((build) => !!build);
|
||||
}
|
||||
|
||||
return [pipelineDev(resolve, options)];
|
||||
};
|
||||
|
||||
module.exports = createConfig;
|
||||
@@ -0,0 +1,22 @@
|
||||
module.exports = {
|
||||
project: null,
|
||||
mode: 'build',
|
||||
paths: {
|
||||
src: './src',
|
||||
dist: './dist',
|
||||
types: './types',
|
||||
},
|
||||
versions: {
|
||||
minified: true,
|
||||
module: true,
|
||||
},
|
||||
extractStyle: false,
|
||||
alias: {},
|
||||
rollup: {
|
||||
input: './src/index',
|
||||
output: {
|
||||
sourcemap: true,
|
||||
exports: 'auto',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,129 @@
|
||||
const path = require('path');
|
||||
const { babel: rollupBabelInputPlugin } = require('@rollup/plugin-babel');
|
||||
const { terser: rollupTerser } = require('rollup-plugin-terser');
|
||||
const { summary } = require('rollup-plugin-summary');
|
||||
const rollupTs = require('rollup-plugin-ts');
|
||||
|
||||
const babelConfigUmd = require('./babel.config.umd');
|
||||
const babelConfigEsm = require('./babel.config.esm');
|
||||
const {
|
||||
rollupCommonjs,
|
||||
rollupResolve,
|
||||
rollupAlias,
|
||||
rollupScss,
|
||||
} = require('./pipeline.common.plugins');
|
||||
|
||||
const createOutputWithMinifiedVersion = (output, esm, buildMinifiedVersion) =>
|
||||
[output].concat(
|
||||
buildMinifiedVersion
|
||||
? [
|
||||
{
|
||||
...output,
|
||||
compact: true,
|
||||
file: output.file.replace('.js', '.min.js'),
|
||||
sourcemap: false,
|
||||
plugins: [
|
||||
...(output.plugins || []),
|
||||
rollupTerser({
|
||||
ecma: esm ? 2015 : 5,
|
||||
safari10: true,
|
||||
compress: {
|
||||
evaluate: false,
|
||||
module: !!esm,
|
||||
passes: 3,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
]
|
||||
: []
|
||||
);
|
||||
|
||||
module.exports = (resolve, esm, options, { declarationFiles = false, outputStyle = false } = {}) => {
|
||||
const { rollup, paths, versions, alias, extractStyle } = options;
|
||||
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
|
||||
const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
|
||||
const { minified: buildMinifiedVersion } = versions;
|
||||
const { src: srcPath, dist: distPath, types: typesPath } = paths;
|
||||
const sourcemap = rawSourcemap;
|
||||
|
||||
const output = createOutputWithMinifiedVersion(
|
||||
{
|
||||
...outputConfig,
|
||||
...(!esm && {
|
||||
name,
|
||||
globals,
|
||||
exports,
|
||||
}),
|
||||
sourcemap,
|
||||
format: esm ? 'esm' : 'umd',
|
||||
generatedCode: esm ? 'es2015' : 'es5',
|
||||
file: path.resolve(distPath, `${file}${esm ? '.esm' : ''}.js`),
|
||||
},
|
||||
esm,
|
||||
buildMinifiedVersion
|
||||
);
|
||||
|
||||
return {
|
||||
input,
|
||||
output,
|
||||
treeshake: {
|
||||
propertyReadSideEffects: false,
|
||||
moduleSideEffects: false,
|
||||
},
|
||||
...rollupOptions,
|
||||
plugins: [
|
||||
summary({
|
||||
showGzippedSize: true,
|
||||
showBrotliSize: true,
|
||||
showMinifiedSize: false,
|
||||
warnLow: 33000,
|
||||
totalLow: 33000,
|
||||
warnHigh: 36000,
|
||||
totalHigh: 36000,
|
||||
}),
|
||||
rollupAlias(alias),
|
||||
rollupScss(extractStyle, outputStyle),
|
||||
rollupTs({
|
||||
tsconfig: (resolvedConfig) => ({
|
||||
...resolvedConfig,
|
||||
declaration: declarationFiles,
|
||||
declarationDir: typesPath,
|
||||
}),
|
||||
include: ['*.ts+(|x)', '**/*.ts+(|x)'],
|
||||
exclude: ['node_modules', '**/node_modules/*'],
|
||||
}),
|
||||
rollupResolve(srcPath, resolve),
|
||||
rollupCommonjs(sourcemap, resolve),
|
||||
rollupBabelInputPlugin({
|
||||
...(esm ? babelConfigEsm : babelConfigUmd),
|
||||
assumptions: {
|
||||
enumerableModuleMeta: false,
|
||||
constantReexports: true,
|
||||
iterableIsArray: true,
|
||||
objectRestNoSymbols: true,
|
||||
noNewArrows: true,
|
||||
noClassCalls: true,
|
||||
ignoreToPrimitiveHint: true,
|
||||
ignoreFunctionLength: true,
|
||||
// privateFieldsAsProperties: true,
|
||||
// setPublicClassFields: true,
|
||||
setSpreadProperties: true,
|
||||
pureGetters: true,
|
||||
},
|
||||
plugins: [
|
||||
'@babel/plugin-transform-runtime',
|
||||
['@babel/plugin-proposal-class-properties', { loose: true }],
|
||||
['@babel/plugin-proposal-private-methods', { loose: true }],
|
||||
],
|
||||
babelHelpers: 'runtime',
|
||||
shouldPrintComment: () => false,
|
||||
caller: {
|
||||
name: 'babel-rollup-build',
|
||||
},
|
||||
extensions: resolve.extensions,
|
||||
}),
|
||||
...plugins,
|
||||
].filter(Boolean),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
const postcss = require('postcss');
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const { nodeResolve: rollupPluginResolve } = require('@rollup/plugin-node-resolve');
|
||||
const rollupPluginScss = require('rollup-plugin-scss');
|
||||
const rollupPluginIgnoreImport = require('rollup-plugin-ignore-import');
|
||||
const rollupPluginCommonjs = require('@rollup/plugin-commonjs');
|
||||
const rollupPluginAlias = require('@rollup/plugin-alias');
|
||||
|
||||
module.exports = {
|
||||
rollupAlias: (aliasEntries) =>
|
||||
rollupPluginAlias({
|
||||
entries: aliasEntries,
|
||||
}),
|
||||
rollupCommonjs: (sourcemap, resolve) =>
|
||||
rollupPluginCommonjs({
|
||||
sourceMap: sourcemap,
|
||||
extensions: resolve.extensions,
|
||||
}),
|
||||
rollupResolve: (srcPath, resolve) =>
|
||||
rollupPluginResolve({
|
||||
mainFields: ['browser', 'umd:main', 'module', 'main'],
|
||||
rootDir: srcPath,
|
||||
moduleDirectories: resolve.directories,
|
||||
extensions: resolve.extensions,
|
||||
}),
|
||||
rollupScss: (extractStyleOption, output) => {
|
||||
if (extractStyleOption) {
|
||||
return output
|
||||
? rollupPluginScss({
|
||||
output,
|
||||
processor: () => postcss([autoprefixer()]),
|
||||
})
|
||||
: rollupPluginIgnoreImport({
|
||||
extensions: ['.scss', '.sass', '.css'],
|
||||
body: 'export default undefined;',
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
const path = require('path');
|
||||
const { default: rollupEsBuild } = require('rollup-plugin-esbuild');
|
||||
const {
|
||||
rollupCommonjs,
|
||||
rollupResolve,
|
||||
rollupAlias,
|
||||
rollupScss,
|
||||
} = require('./pipeline.common.plugins');
|
||||
|
||||
module.exports = (resolve, options) => {
|
||||
const { rollup, paths, alias, extractStyle } = options;
|
||||
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
|
||||
const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
|
||||
const { src: srcPath, dist: distPath } = paths;
|
||||
const sourcemap = rawSourcemap;
|
||||
|
||||
const output = {
|
||||
...outputConfig,
|
||||
sourcemap: true,
|
||||
format: 'esm',
|
||||
generatedCode: 'es2015',
|
||||
file: path.resolve(distPath, `${file}.js`),
|
||||
};
|
||||
|
||||
return {
|
||||
input,
|
||||
output,
|
||||
...rollupOptions,
|
||||
plugins: [
|
||||
rollupAlias(alias),
|
||||
rollupScss(extractStyle),
|
||||
rollupEsBuild({
|
||||
include: /\.[jt]sx?$/,
|
||||
sourceMap: true,
|
||||
target: 'es6',
|
||||
tsconfig: './tsconfig.json',
|
||||
}),
|
||||
rollupResolve(srcPath, resolve),
|
||||
rollupCommonjs(sourcemap, resolve),
|
||||
...plugins,
|
||||
].filter(Boolean),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const rollupPluginStyles = require('rollup-plugin-styles');
|
||||
const rollupPluginServe = require('rollup-plugin-serve');
|
||||
// const rollupPluginLivereload = require('rollup-plugin-livereload');
|
||||
|
||||
const rollupPluginHtml = require('./rollup.pluginHtml');
|
||||
const createRollupConfig = require('../createRollupConfig');
|
||||
// const rollupAdditionalWatchFiles = require('./rollup.pluginAdditionalWatchFiles');
|
||||
|
||||
const portRange = {
|
||||
min: 20000,
|
||||
max: 60000,
|
||||
};
|
||||
|
||||
const meta = {
|
||||
dist: './.build',
|
||||
html: './index.html',
|
||||
input: './index.browser',
|
||||
};
|
||||
|
||||
module.exports = (testDir, mode = 'dev', onListening = null) => {
|
||||
const name = path.basename(testDir);
|
||||
const htmlFilePath = path.resolve(testDir, meta.html);
|
||||
const dist = path.resolve(testDir, meta.dist);
|
||||
const htmlName = `${name}.html`;
|
||||
const { min, max } = portRange;
|
||||
const port = Math.floor(Math.random() * (max - min + 1) + min);
|
||||
|
||||
return createRollupConfig({
|
||||
project: name,
|
||||
mode,
|
||||
paths: {
|
||||
dist,
|
||||
src: path.resolve(testDir, './'),
|
||||
},
|
||||
versions: {
|
||||
minified: false,
|
||||
module: false,
|
||||
},
|
||||
extractStyle: false,
|
||||
rollup: {
|
||||
input: path.resolve(testDir, meta.input),
|
||||
context: 'this',
|
||||
moduleContext: () => 'this',
|
||||
output: {
|
||||
sourcemap: true,
|
||||
},
|
||||
treeshake: true,
|
||||
plugins: [
|
||||
rollupPluginStyles(),
|
||||
rollupPluginHtml(`Playwright: ${name}`, htmlName, () =>
|
||||
fs.existsSync(htmlFilePath) ? fs.readFileSync(htmlFilePath, 'utf8') : null
|
||||
),
|
||||
...(onListening
|
||||
? [
|
||||
// rollupAdditionalWatchFiles([htmlFilePath]),
|
||||
rollupPluginServe({
|
||||
contentBase: dist,
|
||||
historyApiFallback: `/${htmlName}`,
|
||||
host: '127.0.0.1',
|
||||
port,
|
||||
onListening,
|
||||
}),
|
||||
/*
|
||||
rollupPluginLivereload({
|
||||
watch: dist,
|
||||
port: port - 1,
|
||||
verbose: false,
|
||||
}),
|
||||
*/
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = (files) => ({
|
||||
buildStart() {
|
||||
if (files) {
|
||||
files.forEach((file) => {
|
||||
if (fs.existsSync(file)) {
|
||||
this.addWatchFile(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
const rollupPluginHtml = require('@rollup/plugin-html');
|
||||
|
||||
const makeHtmlAttributes = (attributes) => {
|
||||
if (!attributes) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const keys = Object.keys(attributes);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
// eslint-disable-next-line no-return-assign
|
||||
return keys.reduce((result, key) => (result += ` ${key}="${attributes[key]}"`), '');
|
||||
};
|
||||
|
||||
const genHtmlTemplateFunc = (contentOrContentFn) => ({
|
||||
attributes,
|
||||
files,
|
||||
meta,
|
||||
publicPath,
|
||||
title,
|
||||
}) => {
|
||||
const scripts = (files.js || [])
|
||||
.map(
|
||||
({ fileName }) =>
|
||||
`<script src="${publicPath}${fileName}"${makeHtmlAttributes(attributes.script)}></script>`
|
||||
)
|
||||
.join('\n');
|
||||
|
||||
const links = (files.css || [])
|
||||
.map(
|
||||
({ fileName }) =>
|
||||
`<link href="${publicPath}${fileName}" rel="stylesheet"${makeHtmlAttributes(
|
||||
attributes.link
|
||||
)}>`
|
||||
)
|
||||
.join('\n');
|
||||
|
||||
const metas = meta.map((input) => `<meta${makeHtmlAttributes(input)}>`).join('\n');
|
||||
|
||||
return `<!doctype html>
|
||||
<html${makeHtmlAttributes(attributes.html)}>
|
||||
<head>
|
||||
${metas}
|
||||
<title>${title}</title>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
* {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
#testResult {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
padding: 5px;
|
||||
background: white;
|
||||
}
|
||||
#testResult.passed {
|
||||
display: block;
|
||||
background: lime;
|
||||
}
|
||||
#testResult.passed::before {
|
||||
content: 'passed';
|
||||
}
|
||||
#testResult.failed {
|
||||
display: block;
|
||||
background: red;
|
||||
}
|
||||
#testResult.failed::before {
|
||||
content: 'failed';
|
||||
}
|
||||
</style>
|
||||
${links}
|
||||
</head>
|
||||
<body>
|
||||
${(typeof contentOrContentFn === 'function' ? contentOrContentFn() : contentOrContentFn) || ''}
|
||||
${scripts}
|
||||
<div id="testResult"></div>
|
||||
</body>
|
||||
</html>`;
|
||||
};
|
||||
|
||||
module.exports = (title, fileName, getHtmlContent) =>
|
||||
rollupPluginHtml({
|
||||
title,
|
||||
fileName,
|
||||
template: genHtmlTemplateFunc(getHtmlContent),
|
||||
meta: [{ charset: 'utf-8' }, { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }],
|
||||
});
|
||||
Reference in New Issue
Block a user