forked from JakubMrozek/generator-angular-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-base.js
More file actions
82 lines (68 loc) · 2.36 KB
/
Copy pathscript-base.js
File metadata and controls
82 lines (68 loc) · 2.36 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var angularUtils = require('./util.js');
module.exports = Generator;
function Generator() {
yeoman.generators.NamedBase.apply(this, arguments);
try {
this.appname = this._.camelize(require(path.join(process.cwd(), 'component.json')).name);
} catch (e) {
this.appname = path.basename(process.cwd());
}
if (typeof this.env.options.appPath === 'undefined') {
try {
this.env.options.appPath = require(path.join(process.cwd(), 'component.json')).appPath;
} catch (e) {}
this.env.options.appPath = this.env.options.appPath || 'app';
}
if (typeof this.env.options.testPath === 'undefined') {
try {
this.env.options.testPath = require(path.join(process.cwd(), 'component.json')).testPath;
} catch (e) {}
this.env.options.testPath = this.env.options.testPath || 'test/spec';
}
this.options.typescript = true;
this.options.minsafe = true;
this.env.options.typescript = true;
this.env.options.minsafe = true;
this.option('typescript');
var sourceRoot = '/templates/typescript';
this.scriptSuffix = '.ts';
this.sourceRoot(path.join(__dirname, sourceRoot));
}
util.inherits(Generator, yeoman.generators.NamedBase);
Generator.prototype.appTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.env.options.appPath, dest) + this.scriptSuffix
]);
};
Generator.prototype.testTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.env.options.testPath, dest) + this.scriptSuffix
]);
};
Generator.prototype.htmlTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src,
path.join(this.env.options.appPath, dest)
]);
};
Generator.prototype.addScriptToIndex = function (script) {
try {
var appPath = this.env.options.appPath;
var fullPath = path.join(appPath, 'index.html');
angularUtils.rewriteFile({
file: fullPath,
needle: '<!-- endbuild -->',
splicable: [
'<script src="scripts/' + script + '.js"></script>'
]
});
} catch (e) {
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + script + '.js ' + 'not added.\n'.yellow);
}
};