Skip to content

Commit 2bd7aee

Browse files
committed
fix(setup): add setup sass back as a command for v1 projects.
1 parent afc2a21 commit 2bd7aee

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

lib/config/commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var affordances = {
3232
var orderedListOfCommands = [
3333
'start',
3434
'serve',
35+
'setup',
3536
'generate',
3637
'platform',
3738
'prepare',

lib/ionic/setup.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
require('colors');
4+
5+
var extend = require('../utils/extend');
6+
var Q = require('q');
7+
var IonicAppLib = require('ionic-app-lib');
8+
var appLibUtils = IonicAppLib.utils;
9+
var log = IonicAppLib.logging.logger;
10+
var appLibSetup = IonicAppLib.setup;
11+
12+
var settings = {
13+
title: 'setup',
14+
name: 'setup',
15+
summary: 'Configure the project with a build tool ' + '(beta)'.yellow,
16+
args: {
17+
'[sass]': 'Setup the project to use Sass CSS precompiling'
18+
},
19+
isProjectTask: true
20+
}
21+
22+
function run(ionic, argv) {
23+
var taskName = argv._[1];
24+
if(!taskName) {
25+
appLibUtils.fail('Missing setup task command.', 'setup');
26+
return Q();
27+
}
28+
if (taskName !== 'sass') {
29+
appLibUtils.fail('Invalid setup task command: ' + taskName, 'setup');
30+
return Q();
31+
}
32+
33+
return appLibSetup.sassSetup(process.cwd())
34+
.then(function() {
35+
log.info('Ionic setup complete'.green);
36+
})
37+
.catch(function(error) {
38+
log.error('Error from setup - ' + error);
39+
})
40+
};
41+
42+
module.exports = extend(settings, {
43+
run: run
44+
});

spec/tasks/setup.spec.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
'use strict';
2+
3+
var optimist = require('optimist');
4+
var setup = require('../../lib/ionic/setup');
5+
var IonicAppLib = require('ionic-app-lib');
6+
var appLibUtils = IonicAppLib.utils;
7+
var appLibSetup = IonicAppLib.setup;
8+
var log = IonicAppLib.logging.logger;
9+
var Q = require('q');
10+
11+
describe('setup command', function() {
12+
describe('command settings', function() {
13+
it('should have a title', function() {
14+
expect(setup.title).toBeDefined();
15+
expect(setup.title).not.toBeNull();
16+
expect(setup.title.length).toBeGreaterThan(0);
17+
});
18+
19+
it('should have a summary', function() {
20+
expect(setup.summary).toBeDefined();
21+
expect(setup.summary).not.toBeNull();
22+
expect(setup.summary.length).toBeGreaterThan(0);
23+
});
24+
25+
it('should have a an option of sass', function() {
26+
expect(setup.args).toEqual(jasmine.any(Object));
27+
expect(setup.args['[sass]']).toEqual(jasmine.any(String));
28+
});
29+
});
30+
31+
describe('run function', function() {
32+
it('should fail if a command is not passed', function(done) {
33+
var processArguments = ['node', 'ionic', 'setup'];
34+
var rawCliArguments = processArguments.slice(2);
35+
var argv = optimist(rawCliArguments).argv;
36+
37+
spyOn(appLibUtils, 'fail');
38+
39+
// Expect failure
40+
setup.run(null, argv, rawCliArguments).then(function() {
41+
expect(appLibUtils.fail).toHaveBeenCalledWith('Missing setup task command.', 'setup');
42+
done();
43+
});
44+
});
45+
46+
it('should fail if a an invalid command passed', function(done) {
47+
var processArguments = ['node', 'ionic', 'setup', 'stuff'];
48+
var rawCliArguments = processArguments.slice(2);
49+
var argv = optimist(rawCliArguments).argv;
50+
51+
spyOn(appLibUtils, 'fail');
52+
53+
// Expect failure
54+
setup.run(null, argv, rawCliArguments).then(function() {
55+
expect(appLibUtils.fail).toHaveBeenCalledWith('Invalid setup task command: stuff', 'setup');
56+
done();
57+
});
58+
});
59+
60+
it('should succeed if sass was passed and sassSetup returns success', function(done) {
61+
var processArguments = ['node', 'ionic', 'setup', 'sass'];
62+
var rawCliArguments = processArguments.slice(2);
63+
var argv = optimist(rawCliArguments).argv;
64+
var dir = '/project/dir/path';
65+
66+
spyOn(appLibUtils, 'fail');
67+
spyOn(log, 'info');
68+
spyOn(log, 'error');
69+
spyOn(process, 'cwd').andReturn(dir);
70+
spyOn(appLibSetup, 'sassSetup').andReturn(Q(true));
71+
72+
// Expect success
73+
setup.run(null, argv, rawCliArguments).then(function() {
74+
expect(appLibSetup.sassSetup).toHaveBeenCalledWith(dir);
75+
expect(log.info).toHaveBeenCalled();
76+
expect(log.error).not.toHaveBeenCalled();
77+
done();
78+
});
79+
80+
});
81+
82+
it('should fail if sass was passed and sassSetup returns an error', function(done) {
83+
var processArguments = ['node', 'ionic', 'setup', 'sass'];
84+
var rawCliArguments = processArguments.slice(2);
85+
var argv = optimist(rawCliArguments).argv;
86+
var dir = '/project/dir/path';
87+
88+
spyOn(appLibUtils, 'fail');
89+
spyOn(log, 'info');
90+
spyOn(log, 'error');
91+
spyOn(process, 'cwd').andReturn(dir);
92+
spyOn(appLibSetup, 'sassSetup').andReturn(Q.reject('error occurred'));
93+
94+
// Expect success
95+
setup.run(null, argv, rawCliArguments).then(function() {
96+
expect(appLibSetup.sassSetup).toHaveBeenCalledWith(dir);
97+
expect(log.info).not.toHaveBeenCalled();
98+
expect(log.error).toHaveBeenCalled();
99+
done();
100+
});
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)