Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclude paths as config for typings #4721

Merged
merged 4 commits into from
Apr 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 42 additions & 25 deletions scripts/gulpfiles/typings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,62 @@ var fs = require('fs');
var rimraf = require('rimraf');
var execSync = require('child_process').execSync;

/**
* Recursively generates a list of file paths with the specified extension
* contained within the specified basePath.
* @param {string} basePath The base path to use.
* @param {string} filter The extension name to filter for.
* @param {Array<string>} excludePaths The paths to exclude from search.
* @return {Array<string>} The generated file paths.
*/
function getFilePath(basePath, filter, excludePaths) {
const files = [];
const dirContents = fs.readdirSync(basePath);
dirContents.forEach((fn) => {
const filePath = path.join(basePath, fn);
const excluded =
!excludePaths.every((exPath) => !filePath.startsWith(exPath));
if (excluded) {
return;
}
const stat = fs.lstatSync(filePath);
if (stat.isDirectory()) {
files.push(...getFilePath(filePath, filter, excludePaths));
} else if (filePath.endsWith(filter)) {
files.push(filePath);
}
});
return files;
}

// Generates the TypeScript definition file (d.ts) for Blockly.
// As well as generating the typings of each of the files under core/ and msg/,
// the script also pulls in a number of part files from typings/parts.
// This includes the header (incl License), additional useful interfaces
// including Blockly Options and Google Closure typings.
function typings() {
const tmpDir = './typings/tmp';
const blocklySrcs = [
"core/",
"core/events",
"core/keyboard_nav",
"core/renderers/common",
"core/renderers/measurables",
"core/theme",
"core/toolbox",
"core/interfaces",
"core/utils",
"msg/"
];

// Clean directory if exists.
if (fs.existsSync(tmpDir)) {
rimraf.sync(tmpDir);
}
fs.mkdirSync(tmpDir);

const excludePaths = [
"core/renderers/geras",
"core/renderers/minimalist",
"core/renderers/thrasos",
"core/renderers/zelos",
];
const blocklySrcs = [
'core',
'msg'
]
// Find all files that will be included in the typings file.
let files = [];
blocklySrcs.forEach((src) => {
files = files.concat(fs.readdirSync(src)
.filter(fn => fn.endsWith('.js'))
.map(fn => path.join(src, fn)));
blocklySrcs.forEach((basePath) => {
files.push(...getFilePath(basePath, '.js', excludePaths));
});

// Generate typings file for each file.
Expand All @@ -64,15 +89,7 @@ function typings() {
const srcs = [
'typings/templates/blockly-header.template',
'typings/templates/blockly-interfaces.template',
`${tmpDir}/core/**`,
`${tmpDir}/core/interfaces/**`,
`${tmpDir}/core/events/**`,
`${tmpDir}/core/keyboard_nav/**`,
`${tmpDir}/core/renderers/common/**`,
`${tmpDir}/core/renderers/measurables/**`,
`${tmpDir}/core/utils/**`,
`${tmpDir}/core/toolbox/**`,
`${tmpDir}/core/theme/**`,
`${tmpDir}/core/**/*`,
`${tmpDir}/msg/**`
];
return gulp.src(srcs)
Expand Down