forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves the import path by creating a package.json inside the build directory so the library can be published with a flattened root folder. The lib root package.json is transformed into a minimal version and the README, CHANGELOG and LICENSE are copied over. Resolves: mui#2679
- Loading branch information
1 parent
0f37bd5
commit 7052d8f
Showing
5 changed files
with
119 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* eslint-disable no-console */ | ||
import path from 'path'; | ||
import fse from 'fs-extra'; | ||
|
||
const files = [ | ||
'README.md', | ||
'CHANGELOG.md', | ||
'LICENSE', | ||
]; | ||
|
||
Promise.all( | ||
files.map((file) => copyFile(file)) | ||
) | ||
.then(() => createPackageFile()); | ||
|
||
function copyFile(file) { | ||
const buildPath = resolveBuildPath(file); | ||
return new Promise((resolve) => { | ||
fse.copy( | ||
file, | ||
buildPath, | ||
(err) => { | ||
if (err) throw err; | ||
resolve(); | ||
} | ||
); | ||
}) | ||
.then(() => console.log(`Copied ${file} to ${buildPath}`)); | ||
} | ||
|
||
function resolveBuildPath(file) { | ||
return path.resolve(__dirname, '../build/', path.basename(file)); | ||
} | ||
|
||
function createPackageFile() { | ||
return new Promise((resolve) => { | ||
fse.readFile(path.resolve(__dirname, '../package.json'), 'utf8', (err, data) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
resolve(data); | ||
}); | ||
}) | ||
.then((data) => JSON.parse(data)) | ||
.then((packageData) => { | ||
const { | ||
author, | ||
version, | ||
description, | ||
keywords, | ||
repository, | ||
license, | ||
bugs, | ||
homepage, | ||
peerDependencies, | ||
dependencies, | ||
} = packageData; | ||
|
||
const minimalPackage = { | ||
name: 'material-ui', | ||
author, | ||
version, | ||
description, | ||
main: './index.js', | ||
keywords, | ||
repository, | ||
license, | ||
bugs, | ||
homepage, | ||
peerDependencies, | ||
dependencies, | ||
}; | ||
|
||
return new Promise((resolve) => { | ||
const buildPath = path.resolve(__dirname, '../build/package.json'); | ||
const data = JSON.stringify(minimalPackage, null, 2); | ||
fse.writeFile(buildPath, data, (err) => { | ||
if (err) throw (err); | ||
console.log(`Created package.json in ${buildPath}`); | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters