Skip to content

Commit 7318c0d

Browse files
committed
chore(test): e2e css preprocessor tests
1 parent de3c89b commit 7318c0d

17 files changed

+517
-290
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addon/ng2/blueprints/ng2/files/src/config/system.config.js

addon/ng2/commands/install.js renamed to addon/ng2/commands/install.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
/* jshint node: true, esnext: true */
2-
'use strict';
3-
4-
const Command = require('ember-cli/lib/models/command');
5-
const SilentError = require('silent-error');
6-
const Promise = require('ember-cli/lib/ext/promise');
7-
const InstallTask = require('../tasks/install');
1+
import * as Command from 'ember-cli/lib/models/command';
2+
import * as SlientError from 'silent-error';
3+
import * as InstallTask from '../tasks/install.ts';
84

95
module.exports = Command.extend({
106
name: 'install',
117
description: 'Adds 3rd party library to existing project',
128
works: 'insideProject',
139

14-
availableOptions: [
15-
{ name: 'typings', type: String, aliases: ['t'], description: 'Installs specified typings' }
16-
],
17-
1810
run: function (commandOptions, rawArgs) {
1911
if (!rawArgs.length) {
2012
const msg = 'The `ng install` command must take an argument with ' +
@@ -30,8 +22,7 @@ module.exports = Command.extend({
3022
});
3123

3224
return installTask.run({
33-
packages: rawArgs,
34-
typings: commandOptions.typings || null
25+
packages: rawArgs
3526
});
3627
}
3728
});

addon/ng2/commands/uninstall.js renamed to addon/ng2/commands/uninstall.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
/* jshint node: true, esnext: true */
2-
'use strict';
3-
4-
const Command = require('ember-cli/lib/models/command');
5-
const SilentError = require('silent-error');
6-
const Promise = require('ember-cli/lib/ext/promise');
7-
const UninstallTask = require('../tasks/uninstall');
1+
import * as Command from 'ember-cli/lib/models/command';
2+
import * as SilentError from 'silent-error';
3+
import * as UninstallTask from '../tasks/uninstall';
84

95
module.exports = Command.extend({
106
name: 'uninstall',
117
description: 'Removes 3rd party library from existing project',
128
works: 'insideProject',
139

14-
availableOptions: [
15-
{ name: 'typings', type: String, aliases: ['t'], description: 'Removes specified typings' }
16-
],
17-
1810
run: function (commandOptions, rawArgs) {
1911
if (!rawArgs.length) {
2012
const msg = 'The `ng uninstall` command must take an argument with ' +
@@ -30,8 +22,7 @@ module.exports = Command.extend({
3022
});
3123

3224
return uninstallTask.run({
33-
packages: rawArgs,
34-
typings: commandOptions.typings || null
25+
packages: rawArgs
3526
});
3627
}
3728
});

addon/ng2/tasks/install.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

addon/ng2/tasks/install.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import * as Task from 'ember-cli/lib/models/task';
2+
import * as npmTask from 'ember-cli/lib/tasks/npm-task';
3+
import * as chalk from 'chalk';
4+
import * as path from 'path';
5+
import { EventEmitter } from 'events';
6+
import * as search from 'typings-core/dist/search';
7+
import * as typings from 'typings-core/dist/install';
8+
import * as systemJS from '../utilities/systemjs-helper.ts';
9+
10+
module.exports = Task.extend({
11+
completionOKMessage: 'Successfully installed.',
12+
completionErrorMessage: 'Error installing package.',
13+
14+
run: function(options) {
15+
this.packages = options.packages;
16+
17+
if (this.packages.indexOf('sass') !== -1) {
18+
this.packages[this.packages.indexOf('sass')] = 'node-sass';
19+
}
20+
21+
if (this.packages.indexOf('compass') !== -1) {
22+
this.packages[this.packages.indexOf('compass')] = 'compass-importer';
23+
if (this.packages.indexOf('sass') === -1 || this.packages.indexOf('node-sass')) {
24+
this.packages.push('node-sass');
25+
}
26+
}
27+
28+
return this.installProcedure();
29+
},
30+
31+
installProcedure: function() {
32+
const that = this;
33+
34+
const NpmTask = new npmTask({
35+
command: 'install',
36+
ui: this.ui,
37+
analytics: this.analytics,
38+
project: this.project,
39+
startProgressMessage: 'Installing packages: ' + this.packages,
40+
completionMessage: 'Packages successfully installed.'
41+
});
42+
43+
return NpmTask.run({
44+
packages: this.packages,
45+
verbose: false
46+
})
47+
.then(() => this.storeInSystemJSConfig(this.packages))
48+
.then(() => this.installTypings());
49+
},
50+
51+
installTypings: function() {
52+
const that = this;
53+
54+
that.ui.startProgress(chalk.green('Searching and installing typings'), chalk.green('.'));
55+
let typingsList = [];
56+
57+
return new Promise(resolve => {
58+
let promises = [];
59+
60+
that.packages.forEach(p => {
61+
let promise = new Promise(res => {
62+
search.search({ query: p }).then(resp => {
63+
if (resp.results.length) {
64+
let names = resp.results.map(x => {
65+
if (x.source === 'dt') {
66+
return x.name;
67+
}
68+
}).filter(x => !!x);
69+
70+
typingsList = typingsList.concat(names);
71+
}
72+
73+
res();
74+
});
75+
});
76+
77+
promises.push(promise);
78+
});
79+
80+
Promise.all(promises).then(() => {
81+
if (typingsList.length) {
82+
let promises = [];
83+
84+
typingsList.forEach(t => {
85+
let installOpts = {
86+
cwd: process.env.PWD,
87+
save: true,
88+
ambient: true
89+
};
90+
91+
let promise = new Promise(res => {
92+
typings.installDependencyRaw(t, installOpts).then(() => { res(); });
93+
});
94+
95+
promises.push(promise);
96+
});
97+
98+
Promise.all(promises).then(() => {
99+
that.ui.stopProgress();
100+
resolve();
101+
});
102+
} else {
103+
that.ui.stopProgress();
104+
resolve();
105+
}
106+
});
107+
});
108+
},
109+
110+
storeInSystemJSConfig: function(packages) {
111+
const systemPath = path.resolve(process.cwd(), 'src', 'config', 'system.config.js');
112+
let json = systemJS.loadSystemJson(systemPath);
113+
114+
packages = packages.filter(p => {
115+
return (!/node-sass|stylus|less|compass-importer/.test(p));
116+
});
117+
118+
let mappings = json.map || {};
119+
packages.forEach(pkg => {
120+
mappings[pkg] = 'libs/' + pkg + '/' + pkg + '.js';
121+
});
122+
json.map = mappings;
123+
systemJS.saveSystemJson(systemPath, json);
124+
125+
return Promise.resolve();
126+
}
127+
128+
});

addon/ng2/tasks/typings-install.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

addon/ng2/tasks/typings-uninstall.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

addon/ng2/tasks/uninstall.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)