Skip to content

Commit

Permalink
alternative implementation proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 5, 2019
1 parent f7edf98 commit 1896f8a
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 50 deletions.
2 changes: 1 addition & 1 deletion packages/material-ui-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": "yarn build:cjs && yarn build:esm && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui-docs",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build",
"test": "exit 0"
Expand Down
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion packages/material-ui-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui-icons",
"build:typings": "babel-node --config-file ../../babel.config.js ./scripts/create-typings.js",
"prebuild": "rimraf material-design-icons && rimraf build",
"release": "yarn build && npm publish build",
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui-lab",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui-lab/**/*.test.js' --exclude '**/node_modules/**'",
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui-styles",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui-styles/**/*.test.js' --exclude '**/node_modules/**'",
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui-system",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui-system/**/*.test.js' --exclude '**/node_modules/**'"
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui-utils",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui-utils/**/*.test.js' --exclude '**/node_modules/**'"
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"build/umd/material-ui.production.min.js": {
"bundled": 868516,
"minified": 320858,
"gzipped": 84838
"bundled": 867738,
"minified": 320738,
"gzipped": 84774
}
}
2 changes: 1 addition & 1 deletion packages/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:umd": "cross-env BABEL_ENV=production-umd rollup -c scripts/rollup.config.js",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:copy-files": "cd ../../ && babel-node scripts/copy-files.js packages/material-ui",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui/**/*.test.js' --exclude '**/node_modules/**'",
Expand Down
91 changes: 51 additions & 40 deletions scripts/copy-files.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* eslint-disable no-console */
const path = require('path');
const fse = require('fs-extra');
const glob = require('glob');
import path from 'path';
import fse from 'fs-extra';
import glob from 'glob';

const workspacePath = process.cwd();
const buildPath = path.join(workspacePath, './build');
const srcPath = path.join(workspacePath, './src');
const packagePath = path.join(__dirname, '../', process.argv[2]);
const buildPath = path.join(packagePath, './build');
const srcPath = path.join(packagePath, './src');

async function includeFileInBuild(file) {
const sourcePath = path.resolve(packagePath, file);
const targetPath = path.resolve(buildPath, path.basename(file));
await fse.copy(file, targetPath);
console.log(`Copied ${file} to ${targetPath}`);
await fse.copy(sourcePath, targetPath);
console.log(`Copied ${sourcePath} to ${targetPath}`);
}

/**
Expand All @@ -23,10 +24,10 @@ async function includeFileInBuild(file) {
*
* @param {string} rootDir
*/
function createModulePackages(srcDir, outDir) {
async function createModulePackages(srcDir, outDir) {
const directoryPackages = glob.sync('*/index.js', { cwd: srcDir }).map(path.dirname);

return Promise.all(
await Promise.all(
directoryPackages.map(directoryPackage => {
const packageJson = {
sideEffects: false,
Expand All @@ -47,7 +48,7 @@ function createModulePackages(srcDir, outDir) {
);
}

async function typescriptCopy(from, to) {
async function typescriptCopy({ from, to }) {
if (!(await fse.exists(to))) {
console.warn(`path ${to} does not exists`);
return [];
Expand All @@ -59,15 +60,15 @@ async function typescriptCopy(from, to) {
}

async function createPackageFile() {
const packageData = await fse.readFile(path.resolve(workspacePath, './package.json'), 'utf8');
const packageData = await fse.readFile(path.resolve(packagePath, './package.json'), 'utf8');
const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } = JSON.parse(
packageData,
);
const newPackageData = {
...packageDataOther,
private: false,
main: './index.js',
module: './esm/index.js',
private: false,
typings: './index.d.ts',
};
const targetPath = path.resolve(buildPath, './package.json');
Expand Down Expand Up @@ -96,36 +97,46 @@ async function addLicense(packageData) {
'./esm/index.js',
'./umd/material-ui.development.js',
'./umd/material-ui.production.min.js',
].map(file =>
prepend(path.resolve(buildPath, file), license).catch(() =>
console.log(`Skipped license for ${file}`),
),
),
].map(async file => {
try {
await prepend(path.resolve(buildPath, file), license)
} catch (err) {
if (err.code === 'ENOENT') {
console.log(`Skipped license for ${file}`)
} else {
throw err
}
}
}),
);
}

async function run() {
const packageData = await createPackageFile();

// use enhanced readme from workspace root for `@material-ui/core`
const readmePath = packageData.name === '@material-ui/core' ? '../../README.md' : './README.md';
await Promise.all(
[readmePath, '../../CHANGELOG.md', '../../LICENSE'].map(file => includeFileInBuild(file)),
);

await addLicense(packageData);

// TypeScript
const from = srcPath;
await Promise.all([
typescriptCopy(from, buildPath),
typescriptCopy(from, path.resolve(buildPath, './es')),
]);

await createModulePackages(srcPath, buildPath);
try {
const packageData = await createPackageFile();

await Promise.all(
[
// use enhanced readme from workspace root for `@material-ui/core`
packageData.name === '@material-ui/core' ? '../../README.md' : './README.md',
'../../CHANGELOG.md',
'../../LICENSE',
].map(file => includeFileInBuild(file)),
);

await addLicense(packageData);

// TypeScript
await Promise.all([
typescriptCopy({ from: srcPath, to: buildPath }),
typescriptCopy({ from: srcPath, to: path.resolve(buildPath, './es') }),
]);

await createModulePackages(srcPath, buildPath);
} catch (err) {
console.error(err);
process.exit(1);
}
}

run().catch(error => {
console.error(error);
process.exit(1);
});
run();

2 comments on commit 1896f8a

@eps1lon
Copy link
Member

@eps1lon eps1lon commented on 1896f8a Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It boggles my mind the amount of time and changed code you put into this to do nothing. It's ridiculous.

@oliviertassinari
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

Please sign in to comment.