From 5227c326c7dff3efc80eb8b4050019178d0b7478 Mon Sep 17 00:00:00 2001 From: Geoff Pleiss and Matt Royal Date: Tue, 23 Jun 2015 17:39:41 -0700 Subject: [PATCH] fix(packages): add missing license content to all react components - Refactor code for generating react package json files [Fixes #97441574] --- .../react-component-helper-spec.js | 75 +++++++++++++++++++ tasks/helpers/css-components-helper.js | 17 +---- tasks/helpers/package-json-helper.js | 21 ++++++ tasks/helpers/react-components-helper.js | 4 + tasks/react-components.js | 36 +++++---- templates/react/package.json.js | 6 +- 6 files changed, 125 insertions(+), 34 deletions(-) create mode 100644 spec/task-helpers/react-component-helper-spec.js create mode 100644 tasks/helpers/package-json-helper.js create mode 100644 tasks/helpers/react-components-helper.js diff --git a/spec/task-helpers/react-component-helper-spec.js b/spec/task-helpers/react-component-helper-spec.js new file mode 100644 index 000000000..27592248d --- /dev/null +++ b/spec/task-helpers/react-component-helper-spec.js @@ -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' + } + })); + }); + }); +}); diff --git a/tasks/helpers/css-components-helper.js b/tasks/helpers/css-components-helper.js index f72e24825..d6f420fff 100644 --- a/tasks/helpers/css-components-helper.js +++ b/tasks/helpers/css-components-helper.js @@ -5,24 +5,11 @@ import promisify from 'es6-promisify'; import File from 'vinyl'; import readmeTemplate from '../../templates/css/README'; import packageTemplate from '../../templates/css/package.json'; +import packageJsonHelper from './package-json-helper'; var readFile = promisify(fs.readFile); -export function packageJson() { - 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); - } - }); -} +export const packageJson = packageJsonHelper(packageTemplate); export function readme() { return map(async (folder, callback) => { diff --git a/tasks/helpers/package-json-helper.js b/tasks/helpers/package-json-helper.js new file mode 100644 index 000000000..317c0786d --- /dev/null +++ b/tasks/helpers/package-json-helper.js @@ -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); + } + }); + }; +} diff --git a/tasks/helpers/react-components-helper.js b/tasks/helpers/react-components-helper.js new file mode 100644 index 000000000..6d84bcfbb --- /dev/null +++ b/tasks/helpers/react-components-helper.js @@ -0,0 +1,4 @@ +import packageJsonHelper from './package-json-helper'; +import packageTemplate from '../../templates/react/package.json'; + +export const packageJson = packageJsonHelper(packageTemplate); diff --git a/tasks/react-components.js b/tasks/react-components.js index 9920354c4..d83529c3c 100644 --- a/tasks/react-components.js +++ b/tasks/react-components.js @@ -1,13 +1,14 @@ -var del = require('del'); -var highland = require('highland'); -var gulp = require('gulp'); -var packageTemplate = require('../templates/react/package.json'); -var readmeTemplate = require('../templates/react/README'); -var path = require('path'); +import license from './helpers/license-helper'; +import del from 'del'; +import highland from 'highland'; +import gulp from 'gulp'; +import readmeTemplate from '../templates/react/README'; +import path from 'path'; +import runSequence from 'run-sequence'; +import {componentDocs} from '../helpers/documentation_helper'; +import {packageJson} from './helpers/react-components-helper'; + var plugins = require('gulp-load-plugins')(); -var runSequence = require('run-sequence'); -var {componentDocs} = require('../helpers/documentation_helper'); -var {license, packageJson} = require('./helpers/packaging-helper'); const COPYRIGHT = '/*(c) Copyright 2015 Pivotal Software, Inc. All Rights Reserved.*/\n'; const componentsGlob = 'src/pivotal-ui-react/*'; @@ -21,9 +22,17 @@ gulp.task('react-build-src', function() { .pipe(gulp.dest(buildFolder)); }); -gulp.task('react-build-license', license(componentsGlob, buildFolder)); +gulp.task('react-build-license', () => + gulp.src(componentsGlob) + .pipe(license()) + .pipe(gulp.dest(buildFolder)) +); -gulp.task('react-build-package-json', packageJson(componentsGlob, buildFolder, packageTemplate)); +gulp.task('react-build-package-json', () => + gulp.src('src/pivotal-ui-react/*/package.json') + .pipe(packageJson()) + .pipe(gulp.dest(buildFolder)) +); gulp.task('react-build-readme', function() { return highland(gulp.src(componentsGlob)) @@ -55,8 +64,3 @@ gulp.task('react-build', callback => runSequence('react-clean', [ 'react-build-license', 'react-build-readme' ], callback)); - -gulp.task('react-watch', ['react-build'], function() { - gulp.watch('src/pivotal-ui-react/**/*.js', ['react-build-src']); - gulp.watch('src/pivotal-ui-react/**/*.json', ['react-build-package-json']); -}); diff --git a/templates/react/package.json.js b/templates/react/package.json.js index ccf063578..5786456dd 100644 --- a/templates/react/package.json.js +++ b/templates/react/package.json.js @@ -6,7 +6,7 @@ var packageTemplate = function(name, ...overrides) { main: `${name}.js`, repository: { type: 'git', - url: 'https://github.com/pivotal-cf/pivotal-ui-react.git' + url: 'https://github.com/pivotal-cf/pivotal-ui.git' }, keywords: [ 'bootstrap', @@ -17,9 +17,9 @@ var packageTemplate = function(name, ...overrides) { author: 'Pivotal Software, Inc', license: 'MIT', bugs: { - url: "https://github.com/pivotal-cf/pivotal-ui-react/issues" + url: "https://github.com/pivotal-cf/pivotal-ui/issues" }, - homepage: "https://github.com/pivotal-cf/pivotal-ui-react", + homepage: "https://github.com/pivotal-cf/pivotal-ui", peerDependencies: { react: '^0.13.0' }