lincd-cli 0.2.42 → 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/post-merge +4 -0
- package/.husky/pre-commit +4 -0
- package/.prettierignore +4 -0
- package/.prettierrc.json +24 -0
- package/defaults/app-static/capacitor.config.ts +31 -81
- package/defaults/app-static/src/index-static.tsx +28 -0
- package/defaults/capacitor/scripts/fix-namespace.js +41 -0
- package/lib/cli-methods.js +1468 -1198
- package/lib/cli.js +98 -85
- package/lib/config-grunt.js +298 -229
- package/lib/config-webpack.js +358 -344
- package/lib/index.js +67 -29
- package/lib/interfaces.js +2 -2
- package/lib/plugins/declaration-plugin.js +209 -193
- package/lib/plugins/externalise-modules.js +167 -163
- package/lib/plugins/watch-run.js +16 -14
- package/lib/utils.js +326 -274
- package/package.json +17 -3
- package/defaults/app-static/frontend/src/index-static.tsx +0 -16
- /package/defaults/app-static/{frontend/web → web}/apple-touch-icon-144x144.png +0 -0
- /package/defaults/app-static/{frontend/web → web}/apple-touch-icon-57x57.png +0 -0
- /package/defaults/app-static/{frontend/web → web}/apple-touch-icon-72x72.png +0 -0
- /package/defaults/app-static/{frontend/web → web}/index.html +0 -0
package/lib/index.js
CHANGED
|
@@ -1,29 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
var __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m)
|
|
26
|
+
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
var __importDefault =
|
|
29
|
+
(this && this.__importDefault) ||
|
|
30
|
+
function (mod) {
|
|
31
|
+
return mod && mod.__esModule ? mod : {default: mod};
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, '__esModule', {value: true});
|
|
34
|
+
exports.generateWebpackConfig =
|
|
35
|
+
exports.generateGruntConfig =
|
|
36
|
+
exports.externaliseModules =
|
|
37
|
+
exports.DeclarationPlugin =
|
|
38
|
+
void 0;
|
|
39
|
+
var declaration_plugin_1 = require('./plugins/declaration-plugin');
|
|
40
|
+
Object.defineProperty(exports, 'DeclarationPlugin', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return __importDefault(declaration_plugin_1).default;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
var externalise_modules_1 = require('./plugins/externalise-modules');
|
|
47
|
+
Object.defineProperty(exports, 'externaliseModules', {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return __importDefault(externalise_modules_1).default;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
var config_grunt_1 = require('./config-grunt');
|
|
54
|
+
Object.defineProperty(exports, 'generateGruntConfig', {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return __importDefault(config_grunt_1).default;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const config_webpack_1 = require('./config-webpack');
|
|
61
|
+
Object.defineProperty(exports, 'generateWebpackConfig', {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return config_webpack_1.generateWebpackConfig;
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
__exportStar(require('./utils'), exports);
|
package/lib/interfaces.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true});
|
|
@@ -1,204 +1,220 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true});
|
|
3
3
|
/// <reference path="colors.d.ts" />
|
|
4
|
-
const colors = require(
|
|
5
|
-
const path = require(
|
|
4
|
+
const colors = require('colors');
|
|
5
|
+
const path = require('path');
|
|
6
6
|
const webpack = require('webpack');
|
|
7
|
-
const {
|
|
7
|
+
const {Compilation} = webpack;
|
|
8
|
+
|
|
8
9
|
class DeclarationPlugin {
|
|
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
|
-
this.debug('Didn\'t build .d.ts file because no declaration assets were emitted during build process.'.yellow);
|
|
62
|
-
this.debug('This is likely because webpack is using cache.'.yellow);
|
|
63
|
-
this.debug('In watch mode, declaration assets will be emitted once you change a ts(x) source file'.yellow);
|
|
64
|
-
// this.log('Make sure to run '.yellow + 'tsc'.blue + ' before running webpack'.yellow);
|
|
65
|
-
// this.log(
|
|
66
|
-
// 'Make sure to test for '.yellow +
|
|
67
|
-
// '/(?!.*.d.ts).ts(x?)$/'.blue.bold['underline'] +
|
|
68
|
-
// ' in the ts-loader in webpack.config.json'.yellow,
|
|
69
|
-
// );
|
|
70
|
-
// this.log(('Assets: ' + Object.keys(compilation.assets).toString()).yellow);
|
|
71
|
-
// callback();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
//combine them into one declaration file
|
|
75
|
-
var combinedDeclaration = this.generateCombinedDeclaration(this.declarationFiles); //moduleConfig
|
|
76
|
-
//and insert that back into the assets
|
|
77
|
-
// compilation.assets[this.options.out] = {
|
|
78
|
-
// source: function() {
|
|
79
|
-
// return combinedDeclaration;
|
|
80
|
-
// },
|
|
81
|
-
// size: function() {
|
|
82
|
-
// return combinedDeclaration.length;
|
|
83
|
-
// },
|
|
84
|
-
// };
|
|
85
|
-
// As suggested by @JonWallsten here: https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-800032753
|
|
86
|
-
compilation.emitAsset(this.options.out, new webpack.sources.RawSource(combinedDeclaration));
|
|
87
|
-
//get meta data from module exports
|
|
88
|
-
/*var metaRdfJson = this.generateMetaRdfJson(compilation,moduleConfig);
|
|
89
|
-
//and insert that back into the assets as [module_name].meta.json
|
|
90
|
-
compilation.assets[this.options.out.replace(".d.ts",".meta.rdf.json")] = {
|
|
91
|
-
source: function() {
|
|
92
|
-
return metaRdfJson;
|
|
93
|
-
},
|
|
94
|
-
size: function() {
|
|
95
|
-
return metaRdfJson.length;
|
|
96
|
-
}
|
|
97
|
-
};*/
|
|
98
|
-
//}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
debug(...msgs) {
|
|
103
|
-
msgs.unshift('declarations:');
|
|
104
|
-
if (this.logMessages) {
|
|
105
|
-
console.log.apply(null, msgs);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
log(...msgs) {
|
|
109
|
-
msgs.unshift('declarations:');
|
|
110
|
-
console.log.apply(null, msgs);
|
|
111
|
-
}
|
|
112
|
-
generateCombinedDeclaration(declarationFiles) {
|
|
113
|
-
this.debug('generating combined declaration');
|
|
114
|
-
var declarations = '';
|
|
115
|
-
//this.debug("daCore: using config ",moduleConfig);
|
|
116
|
-
//this.debug("Combining these files:"+Object.keys(declarationFiles).toString());
|
|
117
|
-
//get current directory that webpack is run from (base of project), and replace backward slashes by forward ones to compare
|
|
118
|
-
var basePath = process.cwd().replace(/\\/g, '/') + '/';
|
|
119
|
-
this.debug('Base path:', colors.blue(basePath));
|
|
120
|
-
var npmModuleName = this.modulePackageInfo.name;
|
|
121
|
-
// let moduleName = npmModuleName.replace(/\@\w+\//, '');
|
|
122
|
-
var importMap = {};
|
|
123
|
-
for (var declarationFileName in declarationFiles) {
|
|
124
|
-
//this.debug("Parsing "+declarationFileName);
|
|
125
|
-
var declarationFile = declarationFiles[declarationFileName];
|
|
126
|
-
var data = declarationFile.source.source();
|
|
127
|
-
if (!data.split) {
|
|
128
|
-
console.warn(typeof data, declarationFileName + ' - cannot split declaration contents. Not a string?');
|
|
129
|
-
continue;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.logMessages = true;
|
|
12
|
+
this.exportRoot = '/lib';
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.options['out'] = options.out ? options.out : './builds/declarations.d.ts';
|
|
15
|
+
this.options['config'] = options.config ? options.config : process.cwd() + '/daconfig.js';
|
|
16
|
+
//var moduleConfig = this.getModuleConfig();
|
|
17
|
+
this.options['root'] = options.root || this.exportRoot; //'/lib'
|
|
18
|
+
this.logMessages = options.debug ? options.debug : false;
|
|
19
|
+
this.modulePackageInfo = require(process.cwd() + '/package.json');
|
|
20
|
+
// this.debug('found package name: '+this.modulePackageInfo.name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// apply(compiler) {
|
|
24
|
+
// // Specify the event hook to attach to
|
|
25
|
+
// compiler.hooks.emit.tapAsync(
|
|
26
|
+
// 'MyExampleWebpackPlugin',
|
|
27
|
+
// (compilation, callback) => {
|
|
28
|
+
//
|
|
29
|
+
// }
|
|
30
|
+
apply(compiler) {
|
|
31
|
+
this.debug('applying ');
|
|
32
|
+
//when the compiler is ready to emit files
|
|
33
|
+
// compiler.plugin('emit', (compilation,callback) =>
|
|
34
|
+
compiler.hooks.compilation.tap('DeclarationPlugin', (compilation) => {
|
|
35
|
+
//NOTE: even though the stage comes from the processAssets hook and not the afterProcessAssets hook
|
|
36
|
+
// somehow this only works WITH the stage defined
|
|
37
|
+
compilation.hooks.afterProcessAssets.tap(
|
|
38
|
+
{
|
|
39
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
|
40
|
+
name: 'DeclarationPlugin',
|
|
41
|
+
},
|
|
42
|
+
() => {
|
|
43
|
+
// this.debug('indexing and removing declaration assets');
|
|
44
|
+
//collect all generated declaration files
|
|
45
|
+
//and remove them from the assets that will be emitted
|
|
46
|
+
//NOTE: at some point we decided to overwrite declaration files between emits because sometimes only one new declaration file is emitted
|
|
47
|
+
//this may cause issues when you remove a file during the continuous building process, but better than the other way around for now
|
|
48
|
+
if (!this.declarationFiles) {
|
|
49
|
+
this.declarationFiles = {};
|
|
50
|
+
}
|
|
51
|
+
compilation.getAssets().forEach((asset, key) => {
|
|
52
|
+
// this.debug('key '+key.toString())
|
|
53
|
+
// this.debug('value '+Object.getOwnPropertyNames(asset).join(", "))
|
|
54
|
+
// this.debug('asset: ' + asset.name);
|
|
55
|
+
if (asset.name.indexOf('.d.ts') !== -1) {
|
|
56
|
+
if (this.declarationFiles[asset.name]) {
|
|
57
|
+
this.debug('overwriting ' + asset.name);
|
|
58
|
+
}
|
|
59
|
+
this.declarationFiles[asset.name] = asset;
|
|
60
|
+
this.debug('indexed and removed asset: ' + colors.green(asset.name));
|
|
61
|
+
compilation.deleteAsset(asset.name);
|
|
130
62
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
lines[i] = line.replace('declare ', '');
|
|
171
|
-
}
|
|
172
|
-
//add tab
|
|
173
|
-
lines[i] = lines[i];
|
|
174
|
-
}
|
|
63
|
+
});
|
|
64
|
+
if (Object.keys(this.declarationFiles).length == 0) {
|
|
65
|
+
this.debug(
|
|
66
|
+
"Didn't build .d.ts file because no declaration assets were emitted during build process.".yellow,
|
|
67
|
+
);
|
|
68
|
+
this.debug('This is likely because webpack is using cache.'.yellow);
|
|
69
|
+
this.debug('In watch mode, declaration assets will be emitted once you change a ts(x) source file'.yellow);
|
|
70
|
+
// this.log('Make sure to run '.yellow + 'tsc'.blue + ' before running webpack'.yellow);
|
|
71
|
+
// this.log(
|
|
72
|
+
// 'Make sure to test for '.yellow +
|
|
73
|
+
// '/(?!.*.d.ts).ts(x?)$/'.blue.bold['underline'] +
|
|
74
|
+
// ' in the ts-loader in webpack.config.json'.yellow,
|
|
75
|
+
// );
|
|
76
|
+
// this.log(('Assets: ' + Object.keys(compilation.assets).toString()).yellow);
|
|
77
|
+
// callback();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
//combine them into one declaration file
|
|
81
|
+
var combinedDeclaration = this.generateCombinedDeclaration(this.declarationFiles); //moduleConfig
|
|
82
|
+
//and insert that back into the assets
|
|
83
|
+
// compilation.assets[this.options.out] = {
|
|
84
|
+
// source: function() {
|
|
85
|
+
// return combinedDeclaration;
|
|
86
|
+
// },
|
|
87
|
+
// size: function() {
|
|
88
|
+
// return combinedDeclaration.length;
|
|
89
|
+
// },
|
|
90
|
+
// };
|
|
91
|
+
// As suggested by @JonWallsten here: https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-800032753
|
|
92
|
+
compilation.emitAsset(this.options.out, new webpack.sources.RawSource(combinedDeclaration));
|
|
93
|
+
//get meta data from module exports
|
|
94
|
+
/*var metaRdfJson = this.generateMetaRdfJson(compilation,moduleConfig);
|
|
95
|
+
//and insert that back into the assets as [module_name].meta.json
|
|
96
|
+
compilation.assets[this.options.out.replace(".d.ts",".meta.rdf.json")] = {
|
|
97
|
+
source: function() {
|
|
98
|
+
return metaRdfJson;
|
|
99
|
+
},
|
|
100
|
+
size: function() {
|
|
101
|
+
return metaRdfJson.length;
|
|
175
102
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
103
|
+
};*/
|
|
104
|
+
//}
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
debug(...msgs) {
|
|
111
|
+
msgs.unshift('declarations:');
|
|
112
|
+
if (this.logMessages) {
|
|
113
|
+
console.log.apply(null, msgs);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
log(...msgs) {
|
|
118
|
+
msgs.unshift('declarations:');
|
|
119
|
+
console.log.apply(null, msgs);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
generateCombinedDeclaration(declarationFiles) {
|
|
123
|
+
this.debug('generating combined declaration');
|
|
124
|
+
var declarations = '';
|
|
125
|
+
//this.debug("daCore: using config ",moduleConfig);
|
|
126
|
+
//this.debug("Combining these files:"+Object.keys(declarationFiles).toString());
|
|
127
|
+
//get current directory that webpack is run from (base of project), and replace backward slashes by forward ones to compare
|
|
128
|
+
var basePath = process.cwd().replace(/\\/g, '/') + '/';
|
|
129
|
+
this.debug('Base path:', colors.blue(basePath));
|
|
130
|
+
var npmModuleName = this.modulePackageInfo.name;
|
|
131
|
+
// let moduleName = npmModuleName.replace(/\@\w+\//, '');
|
|
132
|
+
var importMap = {};
|
|
133
|
+
for (var declarationFileName in declarationFiles) {
|
|
134
|
+
//this.debug("Parsing "+declarationFileName);
|
|
135
|
+
var declarationFile = declarationFiles[declarationFileName];
|
|
136
|
+
var data = declarationFile.source.source();
|
|
137
|
+
if (!data.split) {
|
|
138
|
+
console.warn(typeof data, declarationFileName + ' - cannot split declaration contents. Not a string?');
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
var lines = data.split('\n');
|
|
142
|
+
var i = lines.length;
|
|
143
|
+
while (i--) {
|
|
144
|
+
var line = lines[i];
|
|
145
|
+
//exclude empty lines
|
|
146
|
+
var excludeLine = line == '';
|
|
147
|
+
//if importing something, or re-exporting something
|
|
148
|
+
if (/import ([a-z0-9A-Z_\-\*\{\}\s,]+)/.test(line) || /export ([a-z0-9A-Z_-\{\}\s,\*]+) from/.test(line)) {
|
|
149
|
+
var fileImports = line.indexOf('"') !== -1 ? line.match(/\"([^\"]+)\"/) : line.match(/\'([^\']+)\'/);
|
|
150
|
+
if (fileImports && fileImports.length > 1) {
|
|
151
|
+
var importPath = fileImports[1];
|
|
152
|
+
//if it is importing a relative path and it is a new one
|
|
153
|
+
if ((importPath.substr(0, 2) == './' || importPath.substr(0, 3) == '../') && !importMap[importPath]) {
|
|
154
|
+
//we will replace it with the local npm module later, calc and save the absolute path for now
|
|
155
|
+
//we parse from builds, because now TS-LOADER gives paths relative to its output folder
|
|
156
|
+
let parsed = path.parse('./builds/' + declarationFileName);
|
|
157
|
+
let fileDirectory = parsed.dir;
|
|
158
|
+
var absoluteImportPath = path.resolve(fileDirectory, importPath);
|
|
159
|
+
// this.debug('declarationfilename '+declarationFileName);
|
|
160
|
+
// this.debug('filedir '+fileDirectory);
|
|
161
|
+
this.debug('import ' + colors.blue(importPath), ' -> ' + colors.green(absoluteImportPath));
|
|
162
|
+
importMap[importPath] = absoluteImportPath;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
182
165
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
166
|
+
//exclude re-exports
|
|
167
|
+
//excludeLine = excludeLine || (/export ([a-z0-9A-Z_-\{\}\s,\*]+) from/).test(line);
|
|
168
|
+
//exclude unnamed local imports like: import "./some.scss" or import "./someFile"t
|
|
169
|
+
excludeLine = excludeLine || /import ["'][a-z0-9A-Z_\-.\/\\]+["']/.test(line);
|
|
170
|
+
//if defined, check for excluded references
|
|
171
|
+
if (!excludeLine && this.excludedReferences && line.indexOf('<reference') !== -1) {
|
|
172
|
+
excludeLine = this.excludedReferences.some((reference) => line.indexOf(reference) !== -1);
|
|
189
173
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
174
|
+
if (excludeLine) {
|
|
175
|
+
this.debug('Excluding line ' + i + ': ' + line);
|
|
176
|
+
lines.splice(i, 1);
|
|
177
|
+
} else {
|
|
178
|
+
if (line.indexOf('declare ') !== -1) {
|
|
179
|
+
lines[i] = line.replace('declare ', '');
|
|
180
|
+
}
|
|
181
|
+
//add tab
|
|
182
|
+
lines[i] = lines[i];
|
|
200
183
|
}
|
|
201
|
-
|
|
184
|
+
}
|
|
185
|
+
//TS Loader now uses paths relative to output dir. so here we remove a single ../ from the path (which is in there because /builds is the output dir and /lib is the relative path of the file)
|
|
186
|
+
let fixedDeclarationPath = declarationFileName.replace(/\\/g, '/').replace('../', '').replace('.d.ts', '');
|
|
187
|
+
var moduleDeclaration = npmModuleName + '/' + fixedDeclarationPath;
|
|
188
|
+
//this.debug('basePath:'+basePath);
|
|
189
|
+
declarations += "declare module '" + moduleDeclaration + "' {\n\t" + lines.join('\n\t') + '\n}\n\n';
|
|
190
|
+
this.debug('Defining module ' + colors.yellow(moduleDeclaration) + ' from ' + colors.blue(declarationFileName));
|
|
191
|
+
}
|
|
192
|
+
for (var relativeImportPath in importMap) {
|
|
193
|
+
let absoluteImportPath = importMap[relativeImportPath];
|
|
194
|
+
let npmImportModule =
|
|
195
|
+
npmModuleName + '/' + absoluteImportPath.substr(basePath.length).replace('.d.ts', '').replace(/\\/g, '/');
|
|
196
|
+
this.debug('Replacing ' + colors.blue(relativeImportPath) + ' with ' + colors.yellow(npmImportModule));
|
|
197
|
+
//wrap in quotes to omit problems with replacing partials and having to fix order of replacements
|
|
198
|
+
declarations = declarations.replace(
|
|
199
|
+
new RegExp('(\'|")' + relativeImportPath + '(\'|")', 'g'),
|
|
200
|
+
'"' + npmImportModule + '"',
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
let indexModulePath = this.modulePackageInfo.name + this.exportRoot + '/index';
|
|
204
|
+
this.debug(
|
|
205
|
+
'Replacing index ' + colors.yellow(indexModulePath) + ' with ' + colors.yellow(this.modulePackageInfo.name),
|
|
206
|
+
);
|
|
207
|
+
declarations = declarations.replace("'" + indexModulePath + "'", "'" + this.modulePackageInfo.name + "'");
|
|
208
|
+
//replace alias
|
|
209
|
+
if (this.options.alias) {
|
|
210
|
+
for (let aliasKey in this.options.alias) {
|
|
211
|
+
//declarations = declarations.replace(aliasKey,this.options.alias[aliasKey]);
|
|
212
|
+
this.debug('Replacing alias ' + aliasKey + ' with ' + this.options.alias[aliasKey]);
|
|
213
|
+
declarations = declarations.replace(new RegExp(aliasKey, 'g'), this.options.alias[aliasKey]);
|
|
214
|
+
}
|
|
202
215
|
}
|
|
216
|
+
return declarations;
|
|
217
|
+
}
|
|
203
218
|
}
|
|
219
|
+
|
|
204
220
|
exports.default = DeclarationPlugin;
|