Skip to content

Commit

Permalink
minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Apr 28, 2022
1 parent 54157d6 commit a7e6128
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const modules = process.env.BABEL_MODE === 'cjs' ? 'auto' : false;
const targets = process.env.BABEL_MODE === 'esm' ? { chrome: '100' } : 'defaults';

module.exports = {
compact: false,
ignore: [
'./lib/codemod/src/transforms/__testfixtures__',
'./lib/postinstall/src/__testfixtures__',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"scripts": {
"await-serve-storybooks": "wait-on http://localhost:8001",
"bootstrap": "node ./scripts/bootstrap.js",
"build": "node ./scripts/build-package.js",
"build": "NODE_ENV=production node ./scripts/build-package.js",
"build-manager": "node -r esm ./scripts/build-manager.js",
"build-storybooks": "cross-env STORYBOOK_DISPLAY_WARNING=true DISPLAY_WARNING=true node -r esm ./scripts/build-storybooks.js",
"changelog": "pr-log --sloppy --cherry-pick",
Expand Down Expand Up @@ -315,6 +315,7 @@
"ts-dedent": "^2.0.0",
"ts-jest": "^26.4.4",
"ts-node": "^10.4.0",
"tsup": "^5.12.6",
"typescript": "^4.6.3",
"wait-on": "^5.2.1",
"web-component-analyzer": "^1.1.6",
Expand Down
29 changes: 13 additions & 16 deletions scripts/build-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

/* eslint-disable global-require */
const { resolve } = require('path');
const execa = require('execa');
const terminalSize = require('window-size');
const { readJSON } = require('fs-extra');

const getStorybookPackages = async () => {
const { stdout } = await execa.command(`yarn workspaces list --json`);

const packages = stdout
.toString()
.split('\n')
.map((v) => JSON.parse(v))
.filter((v) => v.name.match(/@storybook\/(.)*/g))
.sort();

return packages;
const workspaceJSON = await readJSON(resolve(__dirname, '..', 'workspace.json'));
return Object.entries(workspaceJSON.projects).map(([k, v]) => ({ location: v.root, name: k }));
};

async function run() {
Expand Down Expand Up @@ -82,7 +73,7 @@ async function run() {
name: 'todo',
min: 1,
hint: 'You can also run directly with package name like `yarn build core`, or `yarn build --all` for all packages!',
optionsPerPage: terminalSize.height - 3, // 3 lines for extra info
optionsPerPage: require('window-size').height - 3, // 3 lines for extra info
choices: packages.map(({ name: key }) => ({
value: key,
title: tasks[key].name || key,
Expand All @@ -101,10 +92,16 @@ async function run() {
.filter((item) => item.name !== 'watch' && item.value === true);
}

selection.filter(Boolean).forEach((v) => {
const sub = execa.command(`yarn prepare${watchMode ? ' --watch' : ''}`, {
cwd: resolve(__dirname, '..', v.location),
selection.filter(Boolean).forEach(async (v) => {
const commmand = (await readJSON(resolve(v.location, 'package.json'))).scripts.prepare;
const cwd = resolve(__dirname, '..', v.location);
const sub = require('execa').command(`yarn ${commmand}${watchMode ? ' --watch' : ''}`, {
cwd,
buffer: false,
shell: true,
env: {
NODE_ENV: 'production',
},
});

sub.stdout.on('data', (data) => {
Expand Down
7 changes: 6 additions & 1 deletion scripts/bundle-package.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path, { resolve } from 'path';
import { bold, gray, greenBright } from 'chalk';
import chalk from 'chalk';
import execa from 'execa';
import { rollup, OutputOptions, watch, RollupOptions } from 'rollup';
import readPkgUp from 'read-pkg-up';
Expand All @@ -13,6 +13,8 @@ import { terser } from 'rollup-plugin-terser';
import { generateDtsBundle } from 'dts-bundle-generator';
import * as dtsLozalize from './dts-localize';

const { bold, gray, greenBright } = chalk;

interface Options {
input: string;
externals: string[];
Expand Down Expand Up @@ -82,6 +84,7 @@ async function build(options: Options) {
babel({
babelHelpers: 'external',
skipPreflightCheck: true,
compact: false,
}),
json(),
rollupTypescript({ lib: ['es2015', 'dom', 'esnext'], target: 'es6' }),
Expand All @@ -96,6 +99,7 @@ async function build(options: Options) {
preferConst: true,
plugins: [
getBabelOutputPlugin({
compact: false,
presets: [
[
'@babel/preset-env',
Expand All @@ -117,6 +121,7 @@ async function build(options: Options) {
format: 'commonjs',
plugins: [
getBabelOutputPlugin({
compact: false,
presets: [
[
'@babel/preset-env',
Expand Down
2 changes: 1 addition & 1 deletion scripts/dts-localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import fs from 'fs-extra';
import { sync } from 'read-pkg-up';

import * as ts from 'typescript';
import ts from 'typescript';

const parseConfigHost = {
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
Expand Down

0 comments on commit a7e6128

Please sign in to comment.