From 6d9ac7be627f7d766d3fb01e84c8e92d763cc83f Mon Sep 17 00:00:00 2001 From: Martin Gansler Date: Wed, 13 Feb 2019 15:06:59 +0100 Subject: [PATCH 1/5] Add typescript definition related bits --- .../material-ui-icons/scripts/copy-files.js | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 packages/material-ui-icons/scripts/copy-files.js diff --git a/packages/material-ui-icons/scripts/copy-files.js b/packages/material-ui-icons/scripts/copy-files.js new file mode 100644 index 00000000000000..591e6b3f33dcfb --- /dev/null +++ b/packages/material-ui-icons/scripts/copy-files.js @@ -0,0 +1,69 @@ +/* eslint-disable no-console */ + +import path from 'path'; +import fse from 'fs-extra'; +import glob from 'glob'; + +async function copyFile(file) { + const buildPath = path.resolve(__dirname, '../build/', path.basename(file)); + await fse.copy(file, buildPath); + console.log(`Copied ${file} to ${buildPath}`); +} + +async function createPackageFile() { + const packageData = await fse.readFile(path.resolve(__dirname, '../package.json'), 'utf8'); + const { scripts, devDependencies, ...packageDataOther } = JSON.parse(packageData); + const newPackageData = { + ...packageDataOther, + main: './index.js', + module: './index.es.js', + private: false, + typings: './index.d.ts', + }; + const buildPath = path.resolve(__dirname, '../build/package.json'); + + await fse.writeFile(buildPath, JSON.stringify(newPackageData, null, 2), 'utf8'); + console.log(`Created package.json in ${buildPath}`); + + return newPackageData; +} + +function typescriptCopy(from, to) { + const files = glob.sync('**/*.d.ts', { cwd: from }); + const cmds = files.map(file => fse.copy(path.resolve(from, file), path.resolve(to, file))); + return Promise.all(cmds); +} + +async function prepend(file, string) { + const data = await fse.readFile(file, 'utf8'); + await fse.writeFile(file, string + data, 'utf8'); +} + +async function addLicense(packageData) { + const license = `/** @license Material-UI v${packageData.version} + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +`; + await Promise.all( + ['../build/index.js', '../build/index.es.js'].map(file => + prepend(path.resolve(__dirname, file), license), + ), + ); +} + +async function run() { + await ['README.md', '../../LICENSE'].map(file => copyFile(file)); + const packageData = await createPackageFile(); + await addLicense(packageData); + + // TypeScript + const from = path.resolve(__dirname, '../src'); + await Promise.all([ + typescriptCopy(from, path.resolve(__dirname, '../build')), + typescriptCopy(from, path.resolve(__dirname, '../build/es')), + ]); +} + +run(); From 3537a65cc7a408b96c23c851eadae8cc1e119b48 Mon Sep 17 00:00:00 2001 From: Martin Gansler Date: Wed, 13 Feb 2019 16:21:22 +0100 Subject: [PATCH 2/5] Avoid creating an es/ directory --- packages/material-ui-icons/scripts/copy-files.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/material-ui-icons/scripts/copy-files.js b/packages/material-ui-icons/scripts/copy-files.js index 591e6b3f33dcfb..fb5d4b8abaca35 100644 --- a/packages/material-ui-icons/scripts/copy-files.js +++ b/packages/material-ui-icons/scripts/copy-files.js @@ -60,10 +60,7 @@ async function run() { // TypeScript const from = path.resolve(__dirname, '../src'); - await Promise.all([ - typescriptCopy(from, path.resolve(__dirname, '../build')), - typescriptCopy(from, path.resolve(__dirname, '../build/es')), - ]); + await Promise.all([typescriptCopy(from, path.resolve(__dirname, '../build'))]); } run(); From 6521a372d5b81956044868d9431e10997147acfd Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Thu, 14 Feb 2019 11:04:58 +0100 Subject: [PATCH 3/5] remove the @material-ui/icons/es folder to make yarn install faster --- .../material-ui-icons/scripts/copy-files.js | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 packages/material-ui-icons/scripts/copy-files.js diff --git a/packages/material-ui-icons/scripts/copy-files.js b/packages/material-ui-icons/scripts/copy-files.js deleted file mode 100644 index fb5d4b8abaca35..00000000000000 --- a/packages/material-ui-icons/scripts/copy-files.js +++ /dev/null @@ -1,66 +0,0 @@ -/* eslint-disable no-console */ - -import path from 'path'; -import fse from 'fs-extra'; -import glob from 'glob'; - -async function copyFile(file) { - const buildPath = path.resolve(__dirname, '../build/', path.basename(file)); - await fse.copy(file, buildPath); - console.log(`Copied ${file} to ${buildPath}`); -} - -async function createPackageFile() { - const packageData = await fse.readFile(path.resolve(__dirname, '../package.json'), 'utf8'); - const { scripts, devDependencies, ...packageDataOther } = JSON.parse(packageData); - const newPackageData = { - ...packageDataOther, - main: './index.js', - module: './index.es.js', - private: false, - typings: './index.d.ts', - }; - const buildPath = path.resolve(__dirname, '../build/package.json'); - - await fse.writeFile(buildPath, JSON.stringify(newPackageData, null, 2), 'utf8'); - console.log(`Created package.json in ${buildPath}`); - - return newPackageData; -} - -function typescriptCopy(from, to) { - const files = glob.sync('**/*.d.ts', { cwd: from }); - const cmds = files.map(file => fse.copy(path.resolve(from, file), path.resolve(to, file))); - return Promise.all(cmds); -} - -async function prepend(file, string) { - const data = await fse.readFile(file, 'utf8'); - await fse.writeFile(file, string + data, 'utf8'); -} - -async function addLicense(packageData) { - const license = `/** @license Material-UI v${packageData.version} - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ -`; - await Promise.all( - ['../build/index.js', '../build/index.es.js'].map(file => - prepend(path.resolve(__dirname, file), license), - ), - ); -} - -async function run() { - await ['README.md', '../../LICENSE'].map(file => copyFile(file)); - const packageData = await createPackageFile(); - await addLicense(packageData); - - // TypeScript - const from = path.resolve(__dirname, '../src'); - await Promise.all([typescriptCopy(from, path.resolve(__dirname, '../build'))]); -} - -run(); From f4e064f01858b1a9457a89aa57a5cdf449acdd7c Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Thu, 14 Feb 2019 11:12:33 +0100 Subject: [PATCH 4/5] [icons] Add remove es folder --- packages/material-ui-icons/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui-icons/package.json b/packages/material-ui-icons/package.json index bcfd458f836aa0..611d736b8ed110 100644 --- a/packages/material-ui-icons/package.json +++ b/packages/material-ui-icons/package.json @@ -25,7 +25,7 @@ "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:typings && 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:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"", + "build:es": "echo 'skip es folder' & exit 0", "build:copy-files": "node ../../scripts/copy-files.js", "build:typings": "babel-node --config-file ../../babel.config.js ./scripts/create-typings.js", "prebuild": "rimraf material-design-icons && rimraf build", From 59e0ceb189caab77b05c5f4de6ad9226e54c3248 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Thu, 14 Feb 2019 11:54:21 +0100 Subject: [PATCH 5/5] seb review --- packages/material-ui-icons/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui-icons/package.json b/packages/material-ui-icons/package.json index 611d736b8ed110..0ee6731f673f44 100644 --- a/packages/material-ui-icons/package.json +++ b/packages/material-ui-icons/package.json @@ -25,7 +25,7 @@ "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:typings && 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:es": "echo 'skip es folder' & exit 0", + "build:es": "echo 'skip es folder'", "build:copy-files": "node ../../scripts/copy-files.js", "build:typings": "babel-node --config-file ../../babel.config.js ./scripts/create-typings.js", "prebuild": "rimraf material-design-icons && rimraf build",