Skip to content

Commit

Permalink
fix(packages): add missing license content to all react components
Browse files Browse the repository at this point in the history
- 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
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 34 deletions.
75 changes: 75 additions & 0 deletions spec/task-helpers/react-component-helper-spec.js
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'
}
}));
});
});
});
17 changes: 2 additions & 15 deletions tasks/helpers/css-components-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
21 changes: 21 additions & 0 deletions tasks/helpers/package-json-helper.js
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);
}
});
};
}
4 changes: 4 additions & 0 deletions tasks/helpers/react-components-helper.js
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);
36 changes: 20 additions & 16 deletions tasks/react-components.js
Original file line number Diff line number Diff line change
@@ -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/*';
Expand All @@ -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))
Expand Down Expand Up @@ -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']);
});
6 changes: 3 additions & 3 deletions templates/react/package.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
}
Expand Down

0 comments on commit 5227c32

Please sign in to comment.