-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(packages): add missing license content to all react components
- Refactor code for generating react package json files [Fixes #97441574]
- Loading branch information
Geoff Pleiss and Matt Royal
committed
Jun 24, 2015
1 parent
42cfa08
commit 5227c32
Showing
6 changed files
with
125 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import {readArray, writeArray} from 'event-stream'; | ||
import path from 'path'; | ||
import File from 'vinyl'; | ||
import {packageJson} from '../../tasks/helpers/react-components-helper'; | ||
|
||
describe('packageJson', () => { | ||
let result; | ||
|
||
function generatePackageJson(name, packageJsonOverrides, callback) { | ||
const readmeStream = readArray([new File({ | ||
path: path.join(__dirname, '..', '..', 'src', 'pivotal-ui-react', name, 'package.json'), | ||
contents: new Buffer(JSON.stringify(packageJsonOverrides, null, 2)) | ||
})]).pipe(packageJson()); | ||
|
||
readmeStream.on('error', (error) => { | ||
console.error(error); | ||
callback(); | ||
}); | ||
|
||
readmeStream.pipe(writeArray((error, data) => { | ||
result = data; | ||
callback(); | ||
})); | ||
} | ||
|
||
describe('with no overrides', function() { | ||
beforeEach(done => generatePackageJson('foo', {}, done)); | ||
|
||
it('returns a package json file with default values', function() { | ||
expect(result[0].path).toEqual('foo/package.json'); | ||
|
||
const jsonContents = JSON.parse(result[0].contents.toString()); | ||
expect(jsonContents).toEqual(jasmine.objectContaining({ | ||
name: 'pui-react-foo', | ||
version: '0.0.1', | ||
description: 'foo', | ||
main: 'foo.js', | ||
repository: {type: 'git', url: 'https://github.com/pivotal-cf/pivotal-ui.git'}, | ||
keywords: ['bootstrap', 'react', 'pivotal ui', 'pivotal ui modularized'], | ||
author: 'Pivotal Software, Inc', | ||
license: 'MIT', | ||
bugs: {url: 'https://github.com/pivotal-cf/pivotal-ui/issues'}, | ||
homepage: 'https://github.com/pivotal-cf/pivotal-ui', | ||
peerDependencies: { react: '^0.13.0' } | ||
})); | ||
}); | ||
|
||
it('does not have a style attribute', function() { | ||
const jsonContents = JSON.parse(result[0].contents.toString()); | ||
expect(jsonContents.style).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('with some overrides', function() { | ||
beforeEach(done => generatePackageJson('foo', { | ||
description: 'custom description', | ||
version: '1.2.3', | ||
dependencies: { | ||
'foo': '1.0.0', | ||
'bar': '2.0.0' | ||
} | ||
}, done)); | ||
|
||
it('returns a package json file with the override values', function() { | ||
expect(JSON.parse(result[0].contents.toString())).toEqual(jasmine.objectContaining({ | ||
description: 'custom description', | ||
version: '1.2.3', | ||
dependencies: { | ||
'foo': '1.0.0', | ||
'bar': '2.0.0' | ||
} | ||
})); | ||
}); | ||
}); | ||
}); |
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,21 @@ | ||
import {map} from 'event-stream'; | ||
import path from 'path'; | ||
import File from 'vinyl'; | ||
|
||
export default function(packageTemplate) { | ||
return () => { | ||
return map(async (packageJsonOverridesFile, callback) => { | ||
try { | ||
const name = path.basename(path.dirname(packageJsonOverridesFile.path)); | ||
const finalContents = packageTemplate(name, JSON.parse(packageJsonOverridesFile.contents.toString())); | ||
callback(null, new File({ | ||
contents: new Buffer(finalContents), | ||
path: path.join(name, 'package.json') | ||
})); | ||
} | ||
catch(e) { | ||
callback(e); | ||
} | ||
}); | ||
}; | ||
} |
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,4 @@ | ||
import packageJsonHelper from './package-json-helper'; | ||
import packageTemplate from '../../templates/react/package.json'; | ||
|
||
export const packageJson = packageJsonHelper(packageTemplate); |
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