Skip to content

Commit 319cb3a

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

17 files changed

+476
-321
lines changed

.eslintignore

+1
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

+4-13
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';
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

+4-13
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

-82
This file was deleted.

addon/ng2/tasks/install.ts

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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';
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+
this.ui.startProgress(chalk.green('Searching and installing typings'), chalk.green('.'));
53+
this.packages = this.packages.filter(p => !/node-sass|stylus|less|compass-importer/.test(p));
54+
55+
let typingsList = [];
56+
57+
return new Promise(resolve => {
58+
return Promise.all(this.packages.map(p => {
59+
return new Promise(res => {
60+
search.search({ query: p }).then(resp => {
61+
if (resp.results.length) {
62+
let names = resp.results.map(x => {
63+
if (x.source === 'dt') { return x.name; }
64+
}).filter(x => !!x);
65+
typingsList = typingsList.concat(names);
66+
}
67+
res();
68+
});
69+
});
70+
}))
71+
.then(() => {
72+
return Promise.all(typingsList.map(t => {
73+
return new Promise(res => {
74+
let installOpts = { cwd: process.env.PWD, save: true, ambient: true };
75+
typings.installDependencyRaw(t, installOpts).then(() => { res(); });
76+
});
77+
}))
78+
.then(() => {
79+
this.ui.stopProgress();
80+
resolve();
81+
})
82+
});
83+
});
84+
},
85+
86+
storeInSystemJSConfig: function(packages) {
87+
const systemPath = path.resolve(process.cwd(), 'src', 'config', 'system.config.js');
88+
let json = systemJS.loadSystemJson(systemPath);
89+
90+
packages = packages.filter(p => {
91+
return (!/node-sass|stylus|less|compass-importer/.test(p));
92+
});
93+
94+
let mappings = json.map || {};
95+
packages.forEach(pkg => {
96+
mappings[pkg] = 'libs/' + pkg + '/' + pkg + '.js';
97+
});
98+
json.map = mappings;
99+
systemJS.saveSystemJson(systemPath, json);
100+
101+
return Promise.resolve();
102+
}
103+
104+
});

addon/ng2/tasks/typings-install.js

-16
This file was deleted.

addon/ng2/tasks/typings-uninstall.js

-16
This file was deleted.

addon/ng2/tasks/uninstall.js

-66
This file was deleted.

0 commit comments

Comments
 (0)