Skip to content

Commit

Permalink
compileDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Balestra committed May 10, 2017
1 parent 960377c commit 8a3e382
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/cli/domain/init-template/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const path = require('path');
const _ = require('underscore');

const blueprint = require('./blueprint');
const installTemplate = require('./installTemplate');
const createComponentDir = require('./createComponentDir');
Expand Down
29 changes: 20 additions & 9 deletions src/cli/domain/init-template/installTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const Spinner = require('cli-spinner').Spinner;
const spawn = require('cross-spawn');
const colors = require('colors/safe');
const path = require('path');
const _ = require('lodash');
const process = require('process');

module.exports = function installTemplate(config, blueprint) {
const templateType = config.templateType;
Expand All @@ -15,7 +17,7 @@ module.exports = function installTemplate(config, blueprint) {
const callback = config.callback;
const installPath = path.resolve(componentPath, '../');

const installing = new Spinner(`🚚 Installing ${packageName} from ${local ? 'local' : 'npm'}...`);
const installing = new Spinner(`Installing ${packageName} from ${local ? 'local' : 'npm'}...`);
installing.start();

const args = {
Expand All @@ -26,8 +28,8 @@ module.exports = function installTemplate(config, blueprint) {
local ? path.resolve(process.cwd(), templateType) : templateType,
]
};
const installProc = spawn(cli, args[cli], {silent: true, cwd: installPath});

const installProc = spawn(cli, args[cli], {stdio: 'inherit', silent: true, cwd: installPath});

installProc.on('error', () => callback('template type not valid'));
installProc.on('close', code => {
Expand All @@ -40,21 +42,30 @@ module.exports = function installTemplate(config, blueprint) {
);

// install devDependencies
const installedTemplatePath = path.resolve(installPath, 'node_modules', templateType)
const installedTemplatePath = path.resolve(installPath, 'node_modules', packageName);
const compileDependencies = require(path.join(installedTemplatePath, 'package.json')).compileDependencies;

logger.log(
`🚚 Installing required devDependencies`
`Installing required dependencies to compile ${packageName} components...`
);

const installDevDeps = spawn(cli, ['install'], {stdio: 'inherit', silent: true, cwd: installedTemplatePath});
const modulesToInstall = _.keys(compileDependencies).map((name) => {
const version = compileDependencies[name];
const depToInstall = version.length > 0 ? `${name}@${version}` : name;
return depToInstall;
});

const args = ["install"].concat(modulesToInstall);
const installCompileDependencies = spawn(cli, args, {stdio: 'inherit', silent: true, cwd: installedTemplatePath});

installDevDeps.on('close', code => {
installCompileDependencies.on('close', code => {
if (code !== 0) {
return callback('template type not valid');
}
logger.log(
`${colors.green('✔')} Installed ${packageName}'s devDependencies`
`${colors.green('✔')} Installed required dependencies to compile ${packageName} components`
);
return blueprint(config);
})
});
});
};
19 changes: 12 additions & 7 deletions test/unit/cli-domain-init-template--installTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('cli : domain : init-template installTemplate', () => {
templateType: 'oc-template-jade',
cli: 'npm',
componentPath: 'path/to/component',
local: true,
local: false,
packageName: 'myComponent',
logger: {
log: sinon.spy()
Expand All @@ -37,18 +37,23 @@ describe('cli : domain : init-template installTemplate', () => {
installTemplate(config, callback);

it('should spawn the right process', () => {
expect(deps['cross-spawn'].calledWith(
'npm',
['install', "--save", "--save-exact", "oc-template-jade"],
{"cwd": "path/to/component", "silent": true}
)).to.equal(true);
expect(deps['cross-spawn'].args[0][0]).to.equal('npm');
expect(deps['cross-spawn'].args[0][1]).to.deep.equal(['install', '--save', '--save-exact', 'oc-template-jade']);
expect(deps['cross-spawn'].args[0][2].stdio).to.equal("inherit");
expect(deps['cross-spawn'].args[0][2].silent).to.equal(true);
});
it('should correctly start the spinner', () => {
expect(deps['cli-spinner'].Spinner.args[0][0]).to.equal('Installing myComponent from local...');
expect(deps['cli-spinner'].Spinner.args[0][0]).to.equal('Installing myComponent from npm...');
});
it('should correctly setup on error and on close listeners', () => {
expect(proc.args[0][0]).to.equal('error');
expect(proc.args[1][0]).to.equal('close');
});
});
});


// 'npm',
// ['install', "--save", "--save-exact", "oc-template-jade"],
// {"stdio": "inherit", "cwd": "path/to/component", "silent": true}
// )).to.equal(true);

0 comments on commit 8a3e382

Please sign in to comment.