Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Commit

Permalink
Support web projects without bower.json
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed May 11, 2020
1 parent be797d3 commit ebb9a05
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ See [contributing guide](.github/CONTRIBUTING.md)

| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2020-05-11 | v1.3.1 | Support web projects without bower.json |
| 2020-05-11 | v1.3.0 | Update CI and ES6 syntax |
| 2019-10-07 | v1.2.1 | Update eslint rules |
| 2018-06-14 | v1.1.11 | Common karma config |
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2020-05-11 | v1.3.1 | Support web projects without bower.json |
| 2020-05-11 | v1.3.0 | Update CI and ES6 syntax |
| 2019-10-07 | v1.2.1 | Update eslint rules |
| 2018-06-14 | v1.1.11 | Common karma config |
Expand Down
12 changes: 0 additions & 12 deletions lib/grunt/config/init-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const fs = require('fs');
const path = require('path');
const extend = require('node.extend');

Expand Down Expand Up @@ -67,17 +66,6 @@ module.exports = function (grunt, options, projectConfig) {
//load package json
options.buildConfig.packageJSON = require(path.join(options.buildConfig.projectRoot, 'package.json'));

//load bower json if found
const bowerJSONFile = path.join(options.buildConfig.projectRoot, 'bower.json');

/*jslint stupid: true*/
/*eslint-disable no-sync*/
if (fs.existsSync(bowerJSONFile)) {
options.buildConfig.bowerJSON = require(bowerJSONFile);
}
/*eslint-enable no-sync*/
/*jslint stupid: false*/

if (options.buildConfig.es6Support === undefined) {
options.buildConfig.es6Support = (options.buildConfig.nodeMajorVersion >= 4);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/grunt/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ module.exports = {
'*.js',
'<%=buildConfig.libDirectory%>/**/*.js'
]);
} else if (buildConfig.bowerJSON && buildConfig.bowerJSON.main) {
src.push(buildConfig.bowerJSON.main);
} else if (buildConfig.packageJSON && buildConfig.packageJSON.main) {
src.push(buildConfig.packageJSON.main);
}
}

Expand All @@ -190,8 +190,8 @@ module.exports = {
let src;
if (buildConfig.nodeProject) {
src = '<%=buildConfig.libDirectory%>/**/*.js';
} else if (buildConfig.bowerJSON) {
src = buildConfig.bowerJSON.main;
} else if (buildConfig.packageJSON) {
src = buildConfig.packageJSON.main;
}

return src;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-project-commons",
"version": "1.3.0",
"version": "1.3.1",
"description": "Common web and node.js grunt tasks/lint configs/md templates and so on...",
"author": {
"name": "Sagie Gur-Ari",
Expand Down
3 changes: 0 additions & 3 deletions test/helper/bower.json

This file was deleted.

3 changes: 2 additions & 1 deletion test/helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"type": "git",
"url": "http://github.com/sagiegurari/js-project-commons.git"
},
"test": true
"test": true,
"main": "main.js"
}
7 changes: 3 additions & 4 deletions test/spec/grunt/config/init-config-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('Grunt initConfig Tests', function () {
assert.isTrue(validated);
});

it('web, with bower.json', function () {
it('web, with main', function () {
let validated = false;
const gruntMock = {
registerTask() {
Expand All @@ -266,11 +266,10 @@ describe('Grunt initConfig Tests', function () {
type: 'git',
url: 'http://github.com/sagiegurari/js-project-commons.git'
},
test: true
});
assert.deepEqual(config.buildConfig.bowerJSON, {
test: true,
main: 'main.js'
});
assert.strictEqual(config.buildConfig.packageJSON.main, 'main.js');

assert.isDefined(config.clean);
assert.isDefined(config.karma);
Expand Down
36 changes: 18 additions & 18 deletions test/spec/grunt/helper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe('Helper Tests', function () {
]);
});

it('web all, no bower.json', function () {
it('web all', function () {
const src = helper.getProjectSources({
nodeProject: false
}, {
Expand All @@ -261,15 +261,15 @@ describe('Helper Tests', function () {
]);
});

it('web defaults, no bower.json', function () {
it('web defaults', function () {
const src = helper.getProjectSources({
nodeProject: false
});

assert.deepEqual(src, []);
});

it('web only lib, no bower.json', function () {
it('web only lib', function () {
const src = helper.getProjectSources({
nodeProject: false
}, {
Expand All @@ -279,7 +279,7 @@ describe('Helper Tests', function () {
assert.deepEqual(src, []);
});

it('web only build, no bower.json', function () {
it('web only build', function () {
const src = helper.getProjectSources({
nodeProject: false
}, {
Expand All @@ -292,7 +292,7 @@ describe('Helper Tests', function () {
]);
});

it('web only test, no bower.json', function () {
it('web only test', function () {
const src = helper.getProjectSources({
nodeProject: false
}, {
Expand All @@ -305,10 +305,10 @@ describe('Helper Tests', function () {
]);
});

it('web all', function () {
it('web all, with main', function () {
const src = helper.getProjectSources({
nodeProject: false,
bowerJSON: {
packageJSON: {
main: 'test.js'
}
}, {
Expand All @@ -324,10 +324,10 @@ describe('Helper Tests', function () {
]);
});

it('web defaults', function () {
it('web defaults, with main', function () {
const src = helper.getProjectSources({
nodeProject: false,
bowerJSON: {
packageJSON: {
main: 'test.js'
}
});
Expand All @@ -337,10 +337,10 @@ describe('Helper Tests', function () {
]);
});

it('web only lib', function () {
it('web only lib, with main', function () {
const src = helper.getProjectSources({
nodeProject: false,
bowerJSON: {
packageJSON: {
main: 'test.js'
}
}, {
Expand All @@ -352,10 +352,10 @@ describe('Helper Tests', function () {
]);
});

it('web only build', function () {
it('web only build, with main', function () {
const src = helper.getProjectSources({
nodeProject: false,
bowerJSON: {
packageJSON: {
main: 'test.js'
}
}, {
Expand All @@ -368,10 +368,10 @@ describe('Helper Tests', function () {
]);
});

it('web only test', function () {
it('web only test, with main', function () {
const src = helper.getProjectSources({
nodeProject: false,
bowerJSON: {
packageJSON: {
main: 'test.js'
}
}, {
Expand All @@ -394,18 +394,18 @@ describe('Helper Tests', function () {
assert.equal(src, '<%=buildConfig.libDirectory%>/**/*.js');
});

it('web, no bower.json', function () {
it('web', function () {
const src = helper.getAPISources({
nodeProject: false
}, false);

assert.isUndefined(src);
});

it('web', function () {
it('web, with main', function () {
const src = helper.getAPISources({
nodeProject: false,
bowerJSON: {
packageJSON: {
main: 'test.js'
}
}, false);
Expand Down

0 comments on commit ebb9a05

Please sign in to comment.