mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Include d.ts files in tns-core-modules package.
- Generate a combined tns-core-modules.d.ts file for user projects. (Will be included in tsconfig.json files by the `tns` tool automagically.) - Test the integrity of the generated combined file by compiling it. - Remove all traces of the obsoleted tns-definitions package.
This commit is contained in:
91
gruntfile.js
91
gruntfile.js
@@ -80,18 +80,6 @@ module.exports = function(grunt) {
|
|||||||
packageObject.keywords = packageObject.keywords.concat(newKeywords);
|
packageObject.keywords = packageObject.keywords.concat(newKeywords);
|
||||||
};
|
};
|
||||||
|
|
||||||
var updateDefinitionsPackageDef = function(content, srcPath) {
|
|
||||||
return updatePackageDef(content, function(contentAsObject) {
|
|
||||||
contentAsObject.version = localCfg.packageVersion;
|
|
||||||
contentAsObject.name = "tns-definitions";
|
|
||||||
contentAsObject.description = "NativeScript Module definitions";
|
|
||||||
contentAsObject.license = "Apache-2.0";
|
|
||||||
if (localCfg.commitSHA) {
|
|
||||||
contentAsObject.repository.url += "/commit/" + localCfg.commitSHA;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var getCommitSha = function() {
|
var getCommitSha = function() {
|
||||||
if (process.env.GIT_COMMIT) {
|
if (process.env.GIT_COMMIT) {
|
||||||
return process.env.GIT_COMMIT;
|
return process.env.GIT_COMMIT;
|
||||||
@@ -142,11 +130,6 @@ module.exports = function(grunt) {
|
|||||||
outModulesDir: "./bin/dist/modules",
|
outModulesDir: "./bin/dist/modules",
|
||||||
outAppsDir: "./bin/dist/apps",
|
outAppsDir: "./bin/dist/apps",
|
||||||
outTsAppsDir: "./bin/dist/ts-apps",
|
outTsAppsDir: "./bin/dist/ts-apps",
|
||||||
outDefinitionsDir: "./bin/dist/definitions",
|
|
||||||
|
|
||||||
excludedModules: [
|
|
||||||
"!./ui/slide-out/**/*.*"
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var nodeTestEnv = JSON.parse(JSON.stringify(process.env));
|
var nodeTestEnv = JSON.parse(JSON.stringify(process.env));
|
||||||
@@ -170,7 +153,7 @@ module.exports = function(grunt) {
|
|||||||
];
|
];
|
||||||
localCfg.typeScriptSrc = [
|
localCfg.typeScriptSrc = [
|
||||||
"./**/*.ts"
|
"./**/*.ts"
|
||||||
].concat(localCfg.defaultExcludes).concat(localCfg.excludedModules);
|
].concat(localCfg.defaultExcludes);
|
||||||
localCfg.typeScriptSrcForTsLint = localCfg.typeScriptSrc.concat([
|
localCfg.typeScriptSrcForTsLint = localCfg.typeScriptSrc.concat([
|
||||||
"!./ios.d.ts",
|
"!./ios.d.ts",
|
||||||
"!./android17.d.ts",
|
"!./android17.d.ts",
|
||||||
@@ -217,12 +200,12 @@ module.exports = function(grunt) {
|
|||||||
jsLibs: {
|
jsLibs: {
|
||||||
expand: true,
|
expand: true,
|
||||||
src: [
|
src: [
|
||||||
"./js-libs/**/*.js",
|
"js-libs/**/*.js",
|
||||||
"./fetch/**/*.js",
|
"fetch/**/*.js",
|
||||||
"./css/**/*.js",
|
"css/**/*.js",
|
||||||
"./css-value/**/*.js",
|
"css-value/**/*.js",
|
||||||
],
|
],
|
||||||
dest: "<%= localCfg.outModulesDir %>/",
|
dest: localCfg.outModulesDir,
|
||||||
cwd: localCfg.srcDir
|
cwd: localCfg.srcDir
|
||||||
},
|
},
|
||||||
license: {
|
license: {
|
||||||
@@ -242,11 +225,16 @@ module.exports = function(grunt) {
|
|||||||
definitionFiles: {
|
definitionFiles: {
|
||||||
src: [
|
src: [
|
||||||
localCfg.srcDir + "/**/*.d.ts",
|
localCfg.srcDir + "/**/*.d.ts",
|
||||||
pathModule.join(localCfg.srcDir, "LICENSE"),
|
|
||||||
//Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there!
|
//Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there!
|
||||||
"!" + localCfg.srcDir + "/apps/**"
|
"!" + localCfg.srcDir + "/apps/**",
|
||||||
].concat(localCfg.defaultExcludes).concat(localCfg.excludedModules),
|
"!" + localCfg.srcDir + "/node-tests/**",
|
||||||
dest: localCfg.outDefinitionsDir + "/",
|
"!" + localCfg.srcDir + "/org.nativescript.widgets.d.ts",
|
||||||
|
"!" + localCfg.srcDir + "/android17.d.ts",
|
||||||
|
"!" + localCfg.srcDir + "/**/*.android.d.ts",
|
||||||
|
"!" + localCfg.srcDir + "/ios.d.ts",
|
||||||
|
"!" + localCfg.srcDir + "/**/*.ios.d.ts",
|
||||||
|
].concat(localCfg.defaultExcludes),
|
||||||
|
dest: localCfg.outModulesDir + "/",
|
||||||
expand: true,
|
expand: true,
|
||||||
options: {
|
options: {
|
||||||
process: filterTypeScriptFiles
|
process: filterTypeScriptFiles
|
||||||
@@ -260,13 +248,6 @@ module.exports = function(grunt) {
|
|||||||
process: updateModulesPackageDef
|
process: updateModulesPackageDef
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
definitionsPackageDef: {
|
|
||||||
src: localCfg.packageJsonFilePath,
|
|
||||||
dest: localCfg.outDefinitionsDir + "/",
|
|
||||||
options: {
|
|
||||||
process: updateDefinitionsPackageDef
|
|
||||||
}
|
|
||||||
},
|
|
||||||
appPackageDef: {
|
appPackageDef: {
|
||||||
expand: true,
|
expand: true,
|
||||||
flatten: true,
|
flatten: true,
|
||||||
@@ -285,7 +266,7 @@ module.exports = function(grunt) {
|
|||||||
"!./bin/**/*.*",
|
"!./bin/**/*.*",
|
||||||
"!./Tests/**/*.*",
|
"!./Tests/**/*.*",
|
||||||
"!" + localCfg.outDir + "/**/*.*"
|
"!" + localCfg.outDir + "/**/*.*"
|
||||||
].concat(localCfg.excludedModules),
|
],
|
||||||
dest: localCfg.outModulesDir + "/"
|
dest: localCfg.outModulesDir + "/"
|
||||||
},
|
},
|
||||||
rawAppsFiles: {
|
rawAppsFiles: {
|
||||||
@@ -352,6 +333,13 @@ module.exports = function(grunt) {
|
|||||||
],
|
],
|
||||||
outDir: localCfg.outModulesDir,
|
outDir: localCfg.outModulesDir,
|
||||||
options: tsOptions
|
options: tsOptions
|
||||||
|
},
|
||||||
|
testCombinedDts: {
|
||||||
|
src: [
|
||||||
|
pathModule.join(localCfg.outModulesDir, 'tns-core-modules.d.ts'),
|
||||||
|
],
|
||||||
|
outDir: localCfg.outModulesDir,
|
||||||
|
options: tsOptions
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tslint: {
|
tslint: {
|
||||||
@@ -369,10 +357,6 @@ module.exports = function(grunt) {
|
|||||||
cmd: "npm pack",
|
cmd: "npm pack",
|
||||||
cwd: localCfg.outModulesDir + "/"
|
cwd: localCfg.outModulesDir + "/"
|
||||||
},
|
},
|
||||||
packDefinitions: {
|
|
||||||
cmd: "npm pack",
|
|
||||||
cwd: localCfg.outDefinitionsDir + "/"
|
|
||||||
},
|
|
||||||
packApp: {
|
packApp: {
|
||||||
cmd: "npm pack",
|
cmd: "npm pack",
|
||||||
cwd: "__dummy__"
|
cwd: "__dummy__"
|
||||||
@@ -487,11 +471,6 @@ module.exports = function(grunt) {
|
|||||||
"multidest:copyLicenseFiles"
|
"multidest:copyLicenseFiles"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Does nothing to avoid copying the same files twice. Instead,
|
|
||||||
// the distribute-definition-files tasks copies the d.ts files
|
|
||||||
// from the source root directly to the output folder.
|
|
||||||
grunt.registerTask("collect-definitions-raw-files", []);
|
|
||||||
|
|
||||||
grunt.registerTask("collect-modules-raw-files", [
|
grunt.registerTask("collect-modules-raw-files", [
|
||||||
"copy:jsLibs",
|
"copy:jsLibs",
|
||||||
"copy:license"
|
"copy:license"
|
||||||
@@ -512,11 +491,22 @@ module.exports = function(grunt) {
|
|||||||
grunt.registerTask("distribute-ts-apps-files", [
|
grunt.registerTask("distribute-ts-apps-files", [
|
||||||
"copy:readyTsAppFiles"
|
"copy:readyTsAppFiles"
|
||||||
]);
|
]);
|
||||||
grunt.registerTask("distribute-definition-files", [
|
grunt.registerTask("generate-tns-core-modules-dts", function() {
|
||||||
"copy:definitionFiles"
|
var dtsFiles = grunt.file.expand({cwd: localCfg.outModulesDir}, ['**/*.d.ts']);
|
||||||
]);
|
dtsFiles.sort()
|
||||||
|
|
||||||
|
var dtsLines = dtsFiles.map(function(dtsFile) {
|
||||||
|
return '/// <reference path="' + dtsFile + '" />';
|
||||||
|
});
|
||||||
|
var combinedDtsPath = pathModule.join(localCfg.outModulesDir, 'tns-core-modules.d.ts');
|
||||||
|
grunt.file.write(combinedDtsPath, dtsLines.join('\n'));
|
||||||
|
});
|
||||||
grunt.registerTask("pack-modules", [
|
grunt.registerTask("pack-modules", [
|
||||||
"copy:modulesPackageDef",
|
"copy:modulesPackageDef",
|
||||||
|
"copy:definitionFiles",
|
||||||
|
"copy:jsLibs",
|
||||||
|
"generate-tns-core-modules-dts",
|
||||||
|
"ts:testCombinedDts",
|
||||||
"exec:packModules"
|
"exec:packModules"
|
||||||
]);
|
]);
|
||||||
grunt.registerTask("pack-apps", [
|
grunt.registerTask("pack-apps", [
|
||||||
@@ -525,10 +515,6 @@ module.exports = function(grunt) {
|
|||||||
grunt.registerTask("pack-ts-apps", [
|
grunt.registerTask("pack-ts-apps", [
|
||||||
"processEachApp:" + localCfg.outTsAppsDir + ":-ts"
|
"processEachApp:" + localCfg.outTsAppsDir + ":-ts"
|
||||||
]);
|
]);
|
||||||
grunt.registerTask("pack-definitions", [
|
|
||||||
"copy:definitionsPackageDef",
|
|
||||||
"exec:packDefinitions"
|
|
||||||
]);
|
|
||||||
grunt.registerTask("get-ready-packages", [
|
grunt.registerTask("get-ready-packages", [
|
||||||
"copy:readyPackages"
|
"copy:readyPackages"
|
||||||
]);
|
]);
|
||||||
@@ -538,7 +524,6 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
"pack-apps",
|
"pack-apps",
|
||||||
"pack-ts-apps",
|
"pack-ts-apps",
|
||||||
"pack-definitions",
|
|
||||||
"get-ready-packages"
|
"get-ready-packages"
|
||||||
]));
|
]));
|
||||||
|
|
||||||
@@ -547,13 +532,11 @@ module.exports = function(grunt) {
|
|||||||
"shell:getGitSHA",
|
"shell:getGitSHA",
|
||||||
|
|
||||||
"collect-apps-raw-files",
|
"collect-apps-raw-files",
|
||||||
"collect-definitions-raw-files",
|
|
||||||
"collect-modules-raw-files",
|
"collect-modules-raw-files",
|
||||||
|
|
||||||
"compile-ts",
|
"compile-ts",
|
||||||
"distribute-apps-files",
|
"distribute-apps-files",
|
||||||
"distribute-ts-apps-files",
|
"distribute-ts-apps-files",
|
||||||
"distribute-definition-files",
|
|
||||||
|
|
||||||
"pack-modules"
|
"pack-modules"
|
||||||
]));
|
]));
|
||||||
|
|||||||
Reference in New Issue
Block a user