-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lerna init, move src/* and test/* into enzyme
- Loading branch information
1 parent
e7ec246
commit 7a17518
Showing
85 changed files
with
780 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
_book/ | ||
build/ | ||
node_modules/ |
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 |
---|---|---|
|
@@ -34,3 +34,5 @@ _book | |
|
||
# Only apps should have lockfiles | ||
package-lock.json | ||
|
||
packages/*/build/ |
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,96 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const child_process = require('child_process'); | ||
const rimraf = require('rimraf'); | ||
|
||
const promisify = fn => new Promise((res, rej) => { | ||
const done = (err, val) => (err ? rej(err) : res(val)); | ||
fn(done); | ||
}); | ||
const getJSON = fpath => getFile(fpath).then(json => JSON.parse(json)); | ||
const getFile = fpath => promisify(cb => fs.readFile(fpath, 'utf8', cb)); | ||
const getFiles = fpath => promisify(cb => fs.readdir(fpath, cb)); | ||
const writeFile = (fpath, src) => promisify(cb => fs.writeFile(fpath, src, cb)); | ||
const writeJSON = (fpath, json, pretty = false) => writeFile( | ||
fpath, | ||
pretty | ||
? JSON.stringify(json, null, 2) | ||
: JSON.stringify(json) | ||
); | ||
const primraf = path => promisify(cb => rimraf(path, cb)); | ||
const run = cmd => promisify(cb => child_process.exec(cmd, cb)); | ||
|
||
// This script is executed with a single argument, indicating the version of | ||
// react and adapters etc. that we want to set ourselves up for testing. | ||
// should be "14" for "enzyme-adapter-react-14", "15.4" for "enzyme-adapter-react-15.4", etc. | ||
const version = process.argv[2]; | ||
|
||
// This script will do the following: | ||
// | ||
// 1. remove / uninstall all relevant modules | ||
// 2. find the adapter for the passed in version | ||
// 3. get the package.json for the adapter | ||
// 4. add the adapter to the dev-deps for enzyme-test-suite package | ||
// 5. call lerna bootstrap to link all the packages | ||
// 6. install all of the package's peer deps at the top level | ||
|
||
var root = process.cwd(); | ||
var adapterName = 'enzyme-adapter-react-' + version; | ||
var adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json'); | ||
var testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json'); | ||
|
||
if (!fs.statSync(adapterPackageJsonPath)) { | ||
throw new Error('Adapter not found: "' + adapterName + '"'); | ||
} | ||
|
||
const packagesToRemove = [ | ||
'react', | ||
'react-dom', | ||
'react-addons-test-utils', | ||
'react-test-renderer', | ||
'create-react-class', | ||
].map(s => `./node_modules/${s}`); | ||
|
||
const additionalDirsToRemove = [ | ||
'node_modules/.bin/npm', | ||
'node_modules/.bin/npm.cmd', | ||
]; | ||
|
||
const rmrfArgs = [] | ||
.concat(packagesToRemove) | ||
.concat(additionalDirsToRemove) | ||
.join(' '); | ||
|
||
Promise.resolve() | ||
.then(() => primraf(rmrfArgs)) | ||
.then(() => run('npm i')) | ||
.then(() => Promise.all([ | ||
getJSON(adapterPackageJsonPath), | ||
getJSON(testPackageJsonPath), | ||
])) | ||
.then(([adapterJson, testJson]) => { | ||
const peerDeps = adapterJson.peerDependencies; | ||
const installs = Object.keys(peerDeps) | ||
.filter(key => !key.startsWith('enzyme')) | ||
.map(key => `${key}@'${peerDeps[key]}'`) | ||
.join(' '); | ||
|
||
testJson.dependencies[adapterName] = adapterJson.version; | ||
|
||
return Promise.all([ | ||
// npm install the peer deps at the root | ||
run(`npm i --no-save ${installs}`), | ||
|
||
// add the adapter to the dependencies of the test suite | ||
writeJSON(testPackageJsonPath, testJson, true), | ||
]); | ||
}) | ||
.then(() => run('lerna bootstrap')) | ||
.then(() => getJSON(testPackageJsonPath)) | ||
.then(testJson => { | ||
// now that we've lerna bootstrapped, we can remove the adapter from the | ||
// package.json so there is no diff | ||
delete testJson.dependencies[adapterName]; | ||
return writeJSON(testPackageJsonPath, testJson, true); | ||
}) | ||
.catch(err => console.error(err)); |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
{ | ||
"lerna": "2.0.0", | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "2.9.1" | ||
} |
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,6 @@ | ||
{ | ||
"presets": ["airbnb"], | ||
"plugins": [ | ||
["transform-replace-object-assign", "object.assign"], | ||
], | ||
} |
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,2 @@ | ||
_book/ | ||
build/ |
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,13 @@ | ||
{ | ||
"rules": { | ||
"react/no-find-dom-node": 0, | ||
"react/no-multi-comp": 0, | ||
"no-underscore-dangle": 0, | ||
"class-methods-use-this": 0 | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "0.13.0" | ||
} | ||
} | ||
} |
Oops, something went wrong.