forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (57 loc) · 1.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const cli = require('ember-cli/lib/cli');
const path = require('path');
// This file hooks up on require calls to transpile TypeScript.
const fs = require('fs');
const ts = require('typescript');
const old = require.extensions['.ts'];
require.extensions['.ts'] = function(m, filename) {
// If we're in node module, either call the old hook or simply compile the
// file without transpilation. We do not touch node_modules/**.
if (!filename.match(/angular-cli/) && filename.match(/node_modules/)) {
if (old) {
return old(m, filename);
}
return m._compile(fs.readFileSync(filename), filename);
}
// Node requires all require hooks to be sync.
const source = fs.readFileSync(filename).toString();
try {
const result = ts.transpile(source, {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJs,
});
// Send it to node to execute.
return m._compile(result, filename);
} catch (err) {
console.error('Error while running script "' + filename + '":');
console.error(err.stack);
throw err;
}
};
module.exports = function(options) {
const oldStdoutWrite = process.stdout.write;
process.stdout.write = function(line) {
line = line.toString();
if (line.match(/version:|WARNING:/)) {
return;
}
line = line.replace(/ember-cli(?!.com)/g, 'angular-cli')
.replace(/ember(?!-cli.com)/g, 'ng');
return oldStdoutWrite.apply(process.stdout, arguments);
};
const oldStderrWrite = process.stderr.write;
process.stderr.write = function(line) {
line = line.toString()
.replace(/ember-cli(?!.com)/g, 'angular-cli')
.replace(/ember(?!-cli.com)/g, 'ng');
return oldStderrWrite.apply(process.stdout, arguments);
};
options.cli = {
name: 'ng',
root: path.join(__dirname, '..', '..'),
npmPackage: 'angular-cli'
};
// ensure the environemnt variable for dynamic paths
process.env.PWD = process.env.PWD || process.cwd();
return cli(options);
}