Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
antelope first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Bellini committed Mar 10, 2016
0 parents commit 8258b89
Show file tree
Hide file tree
Showing 24 changed files with 1,451 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# general
#
.DS_Store
logs
*.log
pids
*.pid
*.seed
.grunt
node_modules
bower_components
.sass-cache
.git

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2016 Spryker Systems GmbH

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Antelope
Frontend automation tool (useful for Spryker projects)

### Requirements
- `node.js` 5.0.0 or above;
- `npm` 3.6.0 or above;
- the tool *should* be installed as global module: you may need admin privileges.

### Setup
```
$ npm install -g github:spryker/antelope
```

### Documentation
You can read it on [spryker.github.io](http://spryker.github.io).
12 changes: 12 additions & 0 deletions antelope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This file is part of SPY frontend automation tool
* (c) Spryker Systems GmbH
* For full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

'use strict';

require('colors'); // enable colors everywhere - no need to require again
let cli = require('./lib/cli');

cli.init();
2 changes: 2 additions & 0 deletions bin/antelope
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../antelope.js');
117 changes: 117 additions & 0 deletions lib/automation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* This file is part of SPY frontend automation tool
* (c) Spryker Systems GmbH
* For full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

'use strict';

let path = require('path');
let R = require('ramda');
let context = require('./context');
let errors = require('./errors');
let collector = require('./automation/collector');
let provider = require('./automation/provider');
let compiler = require('./automation/compiler');
let themes = require('./automation/themes');
let cwd = process.cwd();

function processAssets(targetConfigName, configurator, targetPattern, theme) {
return new Promise((resolve, reject) => {
return Promise.all([
collector.entryPoints(targetPattern, theme),
collector.extensions(targetPattern, theme),
collector.manifests()
]).then((results) => {
let entryPoints = results[0];
let extensions = results[1];
let manifests = results[2];
let defaultConfig;
let config;

console.info(`\n${targetConfigName.toUpperCase()}`.bold.gray);

if (!!theme) {
console.info(`${theme.toUpperCase()} theme`.gray);
}

console.info(`- entry points:`.gray,
`${entryPoints.count.valid} valid`.green,
'|'.gray,
`${entryPoints.count.duplicates} duplicates`.yellow,
'|'.gray,
`${entryPoints.count.total} total`.cyan);

try {
defaultConfig = configurator.load(entryPoints.valid, manifests.valid);
} catch (err) {
reject(errors.enrich(err, 'loading default configuration'));
}

if (extensions.count.valid > 0) {
if (extensions.count.valid > 1) {
console.info('- warning: more than one extension for the same application/theme - first will be processed, the others ignored'.yellow);
}

try {
let extensionName = R.keys(extensions.valid)[0];
let extension = provider.import(path.join(cwd, extensions.valid[extensionName]));
config = R.merge(defaultConfig, extension);

if (!config) {
reject(errors.enrich(new Error('undefined/null/invalid configuration extension returned'), 'extending configuration'));
}

console.info('- custom configuration loaded:'.gray, extensions.valid[extensionName].magenta);
} catch (extensionErr) {
config = R.clone(defaultConfig);
console.error('- custom configuration ignored due to error: %s'.red, extensionErr);
}

if (context.has('debug')) {
provider.report();
}
} else {
config = R.clone(defaultConfig);
console.info('- default configuration loaded'.gray);
}

compiler.build(config).then(resolve, reject);
}, reject);
});
}

function automation(targetConfigName, targetPattern, themePattern) {
let configurator = require(`./automation/webpack/config.${targetConfigName}.js`);

if (targetConfigName === 'zed') {
return processAssets(targetConfigName, configurator, targetPattern, themePattern);
}

return R.reduce((promise, theme) => {
return promise.then(() => {
return processAssets(targetConfigName, configurator, targetPattern, theme);
});
}, Promise.resolve(), themes.getFromPattern(themePattern));
}

module.exports = {
run: () => {
let targetPatterns = context.patterns.target();
let themePatterns = context.patterns.theme();

if (context.isAll()) {
return automation('yves', targetPatterns.yves, themePatterns.yves).then(() => {
return automation('zed', targetPatterns.zed);
});
}

if (context.isYves()) {
return automation('yves', targetPatterns.yves, themePatterns.yves);
}

if (context.isZed()) {
return automation('zed', targetPatterns.zed);
}
}
};
85 changes: 85 additions & 0 deletions lib/automation/collector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* This file is part of SPY frontend automation tool
* (c) Spryker Systems GmbH
* For full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

'use strict';

let path = require('path');
let R = require('ramda');
let globby = require('globby');
let context = require('../context');
let errors = require('../errors');
let cwd = process.cwd();

function collect(searchSubjects, searchPaths, basePattern) {
return new Promise((resolve, reject) => {
globby(searchPaths, {
cwd: cwd,
follow: context.has('follow'),
nocase: true
}).then((foundPaths) => {
try {
let duplicatesCountersMap = {};
let results = {
valid: {},
duplicates: {},
count: {
valid: 0,
duplicates: 0,
total: foundPaths.length
}
};

R.forEach((foundPath) => {
let name = basePattern ? path.basename(foundPath, basePattern) : foundPath;
foundPath = `./${path.relative(cwd, foundPath)}`;

if (duplicatesCountersMap[name] >= 1) {
results.duplicates[`${name} (${duplicatesCountersMap[name]++})`] = foundPath;
results.count.duplicates++;
} else {
results.valid[name] = foundPath;
results.count.valid++;
duplicatesCountersMap[name] = 1;
}
}, foundPaths);

return resolve(results);
} catch (err) {
reject(errors.enrich(err, `${searchSubjects} collector`));
}
}, reject);
});
}

module.exports = {
manifests: () => {
return collect('manifests (package.json)', [
path.join(cwd, `./vendor/spryker/**/assets/package.json`)
]);
},
extensions: (targetPattern, themePattern) => {
targetPattern = targetPattern || '';
themePattern = themePattern || '';

return collect('extensions', [
path.join(cwd, `./assets/**/*${targetPattern}*${themePattern}*${context.patterns.extension()}`)
], context.patterns.extension());
},
entryPoints: (targetPattern, themePattern) => {
targetPattern = targetPattern || '';

if (!!themePattern) {
return collect('entry points', [
path.join(cwd, `./assets/${targetPattern}/${themePattern}/**/*${context.patterns.entry()}`)
], context.patterns.entry());
}

return collect('entry points', [
path.join(cwd, `./assets/${targetPattern}/**/*${context.patterns.entry()}`),
path.join(cwd, `./vendor/spryker/**/assets/${targetPattern}/**/*${context.patterns.entry()}`)
], context.patterns.entry());
}
};
71 changes: 71 additions & 0 deletions lib/automation/compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* This file is part of SPY frontend automation tool
* (c) Spryker Systems GmbH
* For full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

'use strict';

let path = require('path');
let R = require('ramda');
let webpack = require('webpack');
let context = require('../context');
let errors = require('../errors');
let cwd = process.cwd();

module.exports = {
build: (config) => {
return new Promise((resolve, reject) => {
console.error('- building assets using webpack...'.gray);

webpack(config, function(err, stats) {
let withWarnings = false;

try {
if (err) {
throw errors.enrich(err, 'webpack');
}

if (!!stats.compilation.errors && stats.compilation.errors.length > 0) {
R.forEach(function(compilationErr) {
console.error(' - %s'.red, compilationErr);
}, stats.compilation.errors);

throw errors.enrich(new Error('CompilationError'), 'assets compilation');
}

if (!!stats.compilation.fileDependencies) {
console.info(' - built:'.gray, `${stats.compilation.fileDependencies.length}`.green);

if (context.has('debug') && stats.compilation.fileDependencies.length > 0) {
R.forEach(function(file) {
console.log(' -'.gray, `${path.relative(cwd, file)}`.magenta);
}, stats.compilation.fileDependencies);
}
}

if (!!stats.compilation.missingDependencies) {
console.warn(' - missing:'.gray, `${stats.compilation.missingDependencies.length}`.yellow);

if (stats.compilation.missingDependencies.length) {
withWarnings = true;
R.forEach(function(file) {
console.warn(` - ${path.relative(cwd, file)}`.yellow);
}, stats.compilation.missingDependencies);
}
}

console.log('- build completed'.gray, (withWarnings ? 'with some warning'.yellow : 'successfully'.green));
} catch (err) {
reject(errors.enrich(err, 'compilation report'));
}

if (config.watch) {
console.info('- watching assets for changes...'.cyan, '[Ctrl+C to quite]'.gray);
} else {
return resolve();
}
});
});
}
};
17 changes: 17 additions & 0 deletions lib/automation/provider.dummy-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This file is part of SPY frontend automation tool
* (c) Spryker Systems GmbH
* For full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

'use strict';

let cwd = process.cwd();

module.exports = (id) => {
let context = module;
context.id = id;
context.exports = {};
context.paths.push(`${cwd}/node_modules`);
return context;
}
Loading

0 comments on commit 8258b89

Please sign in to comment.