Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Jan 3, 2024
1 parent 37b6dc7 commit c95c350
Show file tree
Hide file tree
Showing 26 changed files with 742 additions and 614 deletions.
23 changes: 13 additions & 10 deletions gulp/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
// under the License.

import args from 'command-line-args';
const argv = args([
{ name: `all`, type: Boolean },
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: `target`, type: String, defaultValue: `` },
{ name: `module`, type: String, defaultValue: `` },
{ name: `coverage`, type: Boolean, defaultValue: false },
{ name: `tests`, type: String, multiple: true, defaultValue: [`spec/*`] },
{ name: `targets`, alias: `t`, type: String, multiple: true, defaultValue: [] },
{ name: `modules`, alias: `m`, type: String, multiple: true, defaultValue: [] },
], { partial: true });
const argv = args(
[
{ name: `all`, type: Boolean },
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: `target`, type: String, defaultValue: `` },
{ name: `module`, type: String, defaultValue: `` },
{ name: `coverage`, type: Boolean, defaultValue: false },
{ name: `tests`, type: String, multiple: true, defaultValue: [`spec/*`] },
{ name: `targets`, alias: `t`, type: String, multiple: true, defaultValue: [] },
{ name: `modules`, alias: `m`, type: String, multiple: true, defaultValue: [] },
],
{ partial: true }
);

const { targets, modules } = argv;

Expand Down
151 changes: 78 additions & 73 deletions gulp/bundle-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,91 +46,96 @@ const __dirname = dirname(__filename);
const bundleDir = resolve(__dirname, '../spec/bundle');

const fileNames = readdirSync(bundleDir)
.filter(fileName => fileName.endsWith('.js'))
.map(fileName => fileName.replace(/\.js$/, ''));
.filter((fileName) => fileName.endsWith('.js'))
.map((fileName) => fileName.replace(/\.js$/, ''));

const bundlesGlob = join(bundleDir, '**.js');
const esbuildDir = join(bundleDir, 'esbuild');
export const esbuildTask = (minify = true) => () => observableFromStreams(
gulp.src(bundlesGlob),
gulpEsbuild({
bundle: true,
minify,
treeShaking: true,
plugins: [
esbuildAlias({
[npmPkgName]: resolve(__dirname, `../targets/${npmPkgName}/${mainExport}.dom.mjs`),
}),
],
}),
gulpRename((p) => { p.basename += '-bundle'; }),
gulp.dest(esbuildDir),
size({ gzip: true })
);

const rollupDir = join(bundleDir, 'rollup');
export const rollupTask = (minify = true) => () => ObservableForkJoin(
fileNames.map(fileName => observableFromStreams(
rollupStream({
input: join(bundleDir, `${fileName}.js`),
output: { format: 'commonjs' },
export const esbuildTask = (minify = true) => () =>
observableFromStreams(
gulp.src(bundlesGlob),
gulpEsbuild({
bundle: true,
minify,
treeShaking: true,
plugins: [
rollupAlias({
entries: { [npmPkgName]: resolve(__dirname, `../targets/es2015/esm/`) }
esbuildAlias({
[npmPkgName]: resolve(__dirname, `../targets/${npmPkgName}/${mainExport}.dom.mjs`),
}),
nodeResolve()
],
onwarn: (message) => {
if (message.code === 'CIRCULAR_DEPENDENCY') return
console.error(message);
}
}),
source(`${fileName}-bundle.js`),
buffer(),
...(minify ? [terser()] : []),
gulp.dest(rollupDir),
gulpRename((p) => {
p.basename += '-bundle';
}),
gulp.dest(esbuildDir),
size({ gzip: true })
))
)
);

const rollupDir = join(bundleDir, 'rollup');
export const rollupTask = (minify = true) => () =>
ObservableForkJoin(
fileNames.map((fileName) =>
observableFromStreams(
rollupStream({
input: join(bundleDir, `${fileName}.js`),
output: { format: 'commonjs' },
plugins: [
rollupAlias({
entries: { [npmPkgName]: resolve(__dirname, `../targets/es2015/esm/`) },
}),
nodeResolve(),
],
onwarn: (message) => {
if (message.code === 'CIRCULAR_DEPENDENCY') return;
console.error(message);
},
}),
source(`${fileName}-bundle.js`),
buffer(),
...(minify ? [terser()] : []),
gulp.dest(rollupDir),
size({ gzip: true })
)
)
);

const webpackDir = join(bundleDir, 'webpack');
export const webpackTask = (opts = { minify: true, analyze: false }) => () => observableFromStreams(
gulp.src(bundlesGlob),
named(),
webpack({
mode: opts?.minify == false ? 'development' : 'production',
optimization: {
usedExports: true
},
output: {
filename: '[name]-bundle.js'
},
module: {
rules: [
{
resolve: {
fullySpecified: false,
mainFields: ['module', 'main']
}
}
]
},
resolve: {
alias: { [npmPkgName]: resolve(__dirname, `../targets/es2015/esm/`) }
},
stats: 'errors-only',
plugins: opts?.analyze ? [new BundleAnalyzerPlugin()] : []
}),
gulp.dest(webpackDir),
size({ gzip: true })
);
export const webpackTask = (opts = { minify: true, analyze: false }) => () =>
observableFromStreams(
gulp.src(bundlesGlob),
named(),
webpack({
mode: opts?.minify == false ? 'development' : 'production',
optimization: {
usedExports: true,
},
output: {
filename: '[name]-bundle.js',
},
module: {
rules: [
{
resolve: {
fullySpecified: false,
mainFields: ['module', 'main'],
},
},
],
},
resolve: {
alias: { [npmPkgName]: resolve(__dirname, `../targets/es2015/esm/`) },
},
stats: 'errors-only',
plugins: opts?.analyze ? [new BundleAnalyzerPlugin()] : [],
}),
gulp.dest(webpackDir),
size({ gzip: true })
);

export const execBundleTask = () => () => observableFromStreams(
gulp.src(join(bundleDir, '**/**-bundle.js')),
async (generator) => {
export const execBundleTask = () => () =>
observableFromStreams(gulp.src(join(bundleDir, '**/**-bundle.js')), async (generator) => {
for await (const file of generator) {
console.log(`executing ${file.path}`);
execSync(`node ${file.path}`);
}
}
);
});
13 changes: 5 additions & 8 deletions gulp/clean-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ import del from 'del';
import { targetDir } from './util.js';
import memoizeTask from './memoize-task.js';
import { catchError } from 'rxjs/operators/index.js';
import {
from as ObservableFrom,
empty as ObservableEmpty,
} from 'rxjs';
import { from as ObservableFrom, empty as ObservableEmpty } from 'rxjs';

export const cleanTask = ((cache) => memoizeTask(cache, function clean(target, format) {
export const cleanTask = ((cache) =>
memoizeTask(cache, function clean(target, format) {
const dir = targetDir(target, format);
return ObservableFrom(del(dir))
.pipe(catchError((e) => ObservableEmpty()));
}))({});
return ObservableFrom(del(dir)).pipe(catchError((e) => ObservableEmpty()));
}))({});

export default cleanTask;
Loading

0 comments on commit c95c350

Please sign in to comment.