diff --git a/.gitignore b/.gitignore index 93889ab..91158e8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ node_modules bower_components .sass-cache .git +.idea diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6a5e490 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +### 0.2.0 +- cleaned up code +- build timer *(it says how many seconds antelope takes for each build)* +- consistent watch mode *(if you get a compilation error during build, antelope will watch files anyway instead of exiting)* +- improved error tips +- improved `antelope install` command *(it will install project and core `npm` deps)* + +### 0.1.0 +This is the first public release od Antelope. diff --git a/lib/automation/collector.js b/lib/automation/collector.js index 4a39ace..1a7d99e 100644 --- a/lib/automation/collector.js +++ b/lib/automation/collector.js @@ -57,6 +57,7 @@ function collect(searchSubjects, searchPaths, basePattern) { module.exports = { manifests: () => { return collect('manifests (package.json)', [ + path.join(cwd, `./package.json`), path.join(cwd, `./vendor/spryker/**/assets/package.json`) ]); }, diff --git a/lib/automation/compiler.js b/lib/automation/compiler.js index 1c9a470..6c2d418 100644 --- a/lib/automation/compiler.js +++ b/lib/automation/compiler.js @@ -12,14 +12,17 @@ let webpack = require('webpack'); let context = require('../context'); let errors = require('../errors'); let cwd = process.cwd(); +let watching = false; module.exports = { build: (config) => { return new Promise((resolve, reject) => { console.error('- building assets using webpack...'.gray); - webpack(config, function(err, stats) { + webpack(config, function(err, stats, eee) { let withWarnings = false; + let withErrors = false; + let withModuleNotFound = false; try { if (err) { @@ -27,11 +30,15 @@ module.exports = { } if (!!stats.compilation.errors && stats.compilation.errors.length > 0) { + withErrors = true; R.forEach(function(compilationErr) { + withModuleNotFound = (compilationErr.name === 'ModuleNotFoundError'); console.error(' - %s'.red, compilationErr); }, stats.compilation.errors); - throw errors.enrich(new Error('CompilationError'), 'assets compilation'); + if (!config.watch) { + throw errors.enrich(new Error('CompilationError'), 'assets compilation'); + } } if (!!stats.compilation.fileDependencies) { @@ -55,13 +62,29 @@ module.exports = { } } - console.log('- build completed'.gray, (withWarnings ? 'with some warning'.yellow : 'successfully'.green)); + if (withErrors) { + console.error('- build failed'.gray, 'due to errors'.red); + + if (withModuleNotFound) { + console.error(' [!] something is missing: did you run'.red, 'antelope install', 'before building?'.red); + console.error(' if you did, then it may be a typo...'.red); + } + } else if (withWarnings) { + console.warn('- build completed'.gray, 'with some warning'.yellow); + } else { + console.log('- build completed'.gray, 'successfully'.green, 'in'.gray, `${(stats.endTime - stats.startTime) / 1000}`.cyan, 'seconds'.gray); + } } catch (err) { reject(errors.enrich(err, 'compilation report')); } if (config.watch) { - console.info('- watching assets for changes...'.cyan, '[Ctrl+C to quite]'.gray); + if (watching) { + console.info('\n- still watching...'.cyan); + } else { + watching = true; + console.info('- watching assets for changes...'.cyan, '[Ctrl+C to quite]'.gray); + } } else { return resolve(); } diff --git a/lib/automation/webpack/config.yves.js b/lib/automation/webpack/config.yves.js index d683e92..0307de9 100644 --- a/lib/automation/webpack/config.yves.js +++ b/lib/automation/webpack/config.yves.js @@ -34,6 +34,9 @@ module.exports = { output: { path: path.join(cwd, './public/Yves/assets/unknown-theme') }, + watchOptions: { + poll: true + }, plugins: [], progress: true, failOnError: false, diff --git a/lib/cli.js b/lib/cli.js index d877be2..f13146e 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -13,8 +13,6 @@ let errors = require('./errors'); let install = require('./install'); let test = require('./test'); let automation = require('./automation'); -// let licenses = require('./licenses'); -let provider = require('./provider'); let pkg = require('../package.json'); let cwd = process.cwd(); let start = new Date().getTime(); @@ -104,13 +102,9 @@ function runAutomation(target, options) { console.info('- watch:'.grey, `${context.has('watch')}`.cyan); if (context.has('debug')) { - automationPromise = test.full().then(() => { - return automation.run(); - }); + automationPromise = test.full().then(() => automation.run()); } else { - automationPromise = test.base().then(() => { - return automation.run(); - }); + automationPromise = test.base().then(() => automation.run()); } automationPromise.then(() => { @@ -120,29 +114,6 @@ function runAutomation(target, options) { }); } -// function runLicensesCrawler(options) { -// context.init('licenses', options); - -// if (!context.isLicensesPrinting()) { -// printInfo(); -// console.info('\nLicenses'.bold.gray); -// console.info('Search for external modules licenses'.gray); -// console.info('-'.gray, 'green'.green, 'is for found and declared licenses'.gray); -// console.info('-'.gray, 'yellow'.yellow, 'is for found but not declared licenses, or viceversa'.gray); -// console.info('-'.gray, 'red'.red, 'is for unknown licenses\n'.gray); -// } - -// licenses.find().then(() => { -// if (context.isLicensesPrinting()) { -// return exit(0); -// } - -// return exitAndLog(); -// }).catch((err) => { -// return exitAndLog(errors.log('licenses', err)); -// }); -// } - function runProvider(options) { context.init('provider', options); @@ -179,25 +150,6 @@ commander .option('--production', 'enable the production mode') .action(runAutomation); -// commander -// .command('licenses') -// .description('Crowl through the project and output all npm modules licenses') -// .option('-m, --manifest', 'export the license manifest content (where available)') -// .option('-j, --json', 'output a json formatted list of licenses') -// .option('-c, --csv', 'output a csv formatted table of licenses') -// .option('-s, --separator', 'define the csv separator char (default is ;)') -// .action(runLicensesCrawler) -// .on('--help', () => { -// console.log(` Follow these tips if you want to to write licenses into a file:`, '\n'); -// console.log(` $ antelope licenses --json > json_filename.json`); -// console.log(` $ antelope licenses --manifest --csv > csv_filename.csv`, '\n'); -// }); - -// commander -// .command('provider') -// .description('Output all the modules Antelope provide internally') -// .action(runProvider); - module.exports = { init: () => { if (process.argv.length < 3) { diff --git a/lib/errors.js b/lib/errors.js index 5debbda..1277769 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -9,10 +9,6 @@ let R = require('ramda'); let errors = { - licenses: { - name: 'License crawler error', - description: 'Something went wrong during licenses crawl' - }, test: { name: 'Test error' }, diff --git a/lib/licenses.js b/lib/licenses.js deleted file mode 100644 index 8a5b4a4..0000000 --- a/lib/licenses.js +++ /dev/null @@ -1,126 +0,0 @@ -/** - * This file is part of Antelope 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 fs = require('graceful-fs'); -let R = require('ramda'); -let globby = require('globby'); -let context = require('./context'); -let errors = require('./errors'); -let cwd = process.cwd(); - -function toCSV(json) { - let sep = context.get('separator'); - let headers = `Name${sep}Url${sep}License Terms${sep}License Type${sep}Version${sep}Type${sep}Labeling${sep}\n`; - - return R.reduce((output, key) => { - let pkg = json[key]; - output += `"${key}"${sep}"${pkg.url}"${sep}${sep}"${pkg.license.type}"${sep}"${pkg.version}"${sep}"${pkg.type}"${sep}"${pkg.license.terms}"${sep}\n`; - return output; - }, headers, R.keys(json)); -} - -module.exports = { - find: () => { - return new Promise((resolve, reject) => { - globby([ - '**/package.json', - '!package.json' - ], { - cwd: cwd, - nocase: true - }).then((pkgs) => { - let json = R.reduce((licenses, pkgRelPath) => { - try { - let pkgPath = path.join(cwd, pkgRelPath); - let pkgDir = path.dirname(pkgPath); - let pkg = require(pkgPath); - - let license = { - type: '', - path: '', - terms: '', - found: false, - declared: false - }; - - let termsFiles = globby.sync([ - '**license*', - '**licence*' - ], { - cwd: pkgDir, - nocase: true - }); - - R.forEach((termsFile) => { - let termsAbsPath = path.join(pkgDir, termsFile); - license.path += `${path.relative(cwd, termsAbsPath)}, `; - - if (context.has('manifest')) { - license.terms += `${fs.readFileSync(termsAbsPath, 'utf8')}\n\n`; - } - }, termsFiles); - - if (pkg.licenses && pkg.licenses.length > 0) { - license.type = R.reduce((type, details) => type + `${details.type} `, '', pkg.licenses).trim(); - license.declared = !!license.type; - } else { - license.declared = !!pkg.license; - license.type = pkg.license || 'unknown'; - } - - license.found = !!license.path; - license.path = license.found ? license.path.trim().replace(/,$/, '') : 'not found'; - - licenses[pkg.name] = { - type: 'npm', - version: pkg.version || 'unknown', - url: pkg.homepage, - license: license, - }; - - return licenses; - } catch (err) { - throw errors.enrich(err, 'license crawler'); - } - }, {}, pkgs); - - if (context.has('json')) { - console.info(JSON.stringify(json)); - return resolve(json); - } - - if (context.has('csv')) { - console.info(toCSV(json)); - return resolve(json); - } - - R.forEach((key) => { - let pkg = json[key]; - let licenceType = pkg.license.type.green; - - if (!pkg.license.declared && pkg.license.found) { - licenceType = pkg.license.path.yellow; - } - - if (pkg.license.declared && !pkg.license.found) { - licenceType = pkg.license.type.yellow; - } - - if (!pkg.license.declared && !pkg.license.found) { - licenceType = pkg.license.type.red; - } - - console.info('-'.gray, key.magenta, pkg.version.cyan, '->'.gray, licenceType); - }, R.keys(json)); - - return resolve(json); - }); - }); - } -}; diff --git a/lib/provider.js b/lib/provider.js deleted file mode 100644 index 35baf46..0000000 --- a/lib/provider.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * This file is part of Antelope 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 R = require('ramda'); -let pkg = require('../package.json'); - -module.exports = { - show: () => { - R.forEach((key) => { - console.log('-'.gray, key.magenta, pkg.dependencies[key].cyan); - }, R.keys(pkg.dependencies)); - } -} diff --git a/lib/test.js b/lib/test.js index 09b1de6..f5b2fd1 100644 --- a/lib/test.js +++ b/lib/test.js @@ -6,15 +6,15 @@ 'use strict'; -// let manifestTest = require('./test/manifest'); -// let dependencyTest = require('./test/dependency'); +let projectTest = require('./test/project'); let collectorTest = require('./test/collector'); module.exports = { base: () => { - return Promise.resolve(); + return projectTest.run(); }, full: () => { - return collectorTest.run(); + return projectTest.run() + .then(collectorTest.run); } }; diff --git a/lib/test/manifest.js b/lib/test/manifest.js deleted file mode 100644 index a3a533e..0000000 --- a/lib/test/manifest.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This file is part of Antelope 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 errors = require('../errors'); -let cwd = process.cwd(); - -module.exports = { - run: () => { - return new Promise((resolve, reject) => { - console.log('\nManifest test'.bold.gray); - console.log('Check for package.json in cwd'.gray); - console.log('|'.gray); - - try { - let projectPkg = require(path.join(cwd, './package.json')); - console.log('| Manifest found:'.gray, `${projectPkg.name || 'no name'} (${projectPkg.version || 'no version'})`.cyan); - - return resolve(); - } catch (err) { - console.error('|'.gray, `[!] No manifest found`.red); - console.error('|'.gray, ' Run'.red, 'npm init', 'to create a new one'.red); - - throw errors.enrich(err, 'manifest test'); - } - }); - } -}; diff --git a/lib/test/project.js b/lib/test/project.js new file mode 100644 index 0000000..cd6f9f1 --- /dev/null +++ b/lib/test/project.js @@ -0,0 +1,33 @@ +/** + * This file is part of Antelope 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 fs = require('graceful-fs'); +let errors = require('../errors'); +let cwd = process.cwd(); + +module.exports = { + run: () => { + return new Promise((resolve, reject) => { + console.log('\nProject test'.bold.gray); + console.log('Check for current workin directory'.gray); + console.log('You must run antelope from project root folder'.gray); + console.log('|'.gray); + + fs.stat(`${cwd}/public`, (err, stats) => { + if (err) { + console.error('|'.gray, `[!] It seems that you are not in the project root folder...`.red); + return reject(errors.enrich(new Error("Antelope is running from the wrong folder: run it again from the root folder of your project."), 'project test')); + } else { + console.log('| Check completed'.gray, 'successfully'.green); + return resolve(); + } + }); + }); + } +}; diff --git a/package.json b/package.json index c932580..3f0332e 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "antelope", - "version": "0.1.0", + "version": "0.2.0", "description": "Spryker frontend automation tool", "main": "antelope.js", "preferGlobal": "true", "scripts": { - "test": "node antelope test" + "test": "node antelope.js test" }, "author": { "name": "Spryker Systems GmbH",