mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Remove old scripts (#13967)
This commit is contained in:
parent
8e08375093
commit
1852aeb3cb
@ -1,40 +0,0 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const home = path.join(__dirname, '..');
|
||||
|
||||
function forEachTypingDir(callback: (fullPath: string, dirName: string) => void) {
|
||||
fs.readdir(home, (err, dirs) => {
|
||||
if (err) throw err;
|
||||
for (const dir of dirs) {
|
||||
const fullPath = path.join(home, dir);
|
||||
fs.lstat(fullPath, (err, stats) => {
|
||||
if (err) throw err;
|
||||
if (stats.isDirectory()) {
|
||||
callback(fullPath, dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
forEachTypingDir(typingPath => {
|
||||
fs.readdir(typingPath, (err, files) => {
|
||||
if(err) throw err;
|
||||
for(const file of files) {
|
||||
if (/tscparams$/.test(file)) {
|
||||
const fullPath = path.join(typingPath, file);
|
||||
|
||||
fs.readFile(fullPath, 'utf-8', (err, paramText) => {
|
||||
if(err) throw err;
|
||||
|
||||
if (paramText.length <= 2) {
|
||||
fs.unlink(fullPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1,50 +0,0 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const home = path.join(__dirname, '..');
|
||||
|
||||
function forEachTypingDir(callback: (fullPath: string, dirName: string) => void) {
|
||||
fs.readdir(home, (err, dirs) => {
|
||||
if (err) throw err;
|
||||
for (const dir of dirs) {
|
||||
const fullPath = path.join(home, dir);
|
||||
fs.lstat(fullPath, (err, stats) => {
|
||||
if (err) throw err;
|
||||
if (stats.isDirectory()) {
|
||||
callback(fullPath, dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const referenceRegex = /^\/\/\/\s?\<reference path=["'](.*)["'] \/\>(\s*)$/gm;
|
||||
|
||||
forEachTypingDir(typingPath => {
|
||||
fs.readdir(typingPath, (err, files) => {
|
||||
if (err) throw err;
|
||||
for (const file of files) {
|
||||
if (/\.ts(x?)$/.test(file)) {
|
||||
const fullPath = path.join(typingPath, file);
|
||||
|
||||
console.log('Read ' + fullPath);
|
||||
let fileContent = fs.readFileSync(fullPath, 'utf-8');
|
||||
let match = referenceRegex.exec(fileContent);
|
||||
while(match !== null) {
|
||||
const referand = match[1];
|
||||
const referandFullPath = path.join(path.dirname(fullPath), referand);
|
||||
if (!fs.existsSync(referandFullPath)) {
|
||||
console.log(`${fullPath} references missing file ${referandFullPath}`);
|
||||
fileContent = fileContent.replace(match[0], '');
|
||||
fs.writeFileSync(fullPath, fileContent, 'utf-8');
|
||||
}
|
||||
|
||||
match = referenceRegex.exec(fileContent);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1,70 +0,0 @@
|
||||
/// <reference path="../node/index.d.ts" />
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
function repeat(s: string, count: number) {
|
||||
return Array(count + 1).join(s);
|
||||
}
|
||||
|
||||
function checkDir(home: string, count: number) {
|
||||
fs.readdir(home, (err, dirs) => {
|
||||
if (err) throw err;
|
||||
|
||||
for (const dir of dirs.map(d => path.join(home, d))) {
|
||||
fs.lstat(dir, (err, stats) => {
|
||||
if(dir.indexOf('.git') > 0) return;
|
||||
|
||||
if (err) throw err;
|
||||
if (stats.isDirectory()) {
|
||||
checkDir(dir, count + 1);
|
||||
fs.readdir(dir, (err, files) => {
|
||||
if (err) throw err;
|
||||
const target = path.join(dir, 'tsconfig.json');
|
||||
fs.exists(target, exists => {
|
||||
if (exists) {
|
||||
const old = JSON.parse(fs.readFileSync(target, 'utf-8'));
|
||||
|
||||
let entryPoint: string;
|
||||
let definitionFiles = files.filter(f => (f.indexOf('.d.ts') > 0));
|
||||
if (definitionFiles.length === 1) {
|
||||
entryPoint = definitionFiles[0];
|
||||
} else if(fs.existsSync(path.join(dir, 'index.d.ts'))) {
|
||||
entryPoint = 'index.d.ts';
|
||||
} else {
|
||||
entryPoint = path.basename(dir) + '.d.ts';
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path.join(dir, entryPoint))) {
|
||||
console.log('No file ' + entryPoint + ' exists in ' + dir + ' so deleting it');
|
||||
fs.unlink(target);
|
||||
return;
|
||||
}
|
||||
|
||||
let testFile: string | undefined = path.join(dir, path.basename(dir) + '-tests.ts');
|
||||
if (!fs.existsSync(testFile)) {
|
||||
let onlyTest = files.filter(f => f.toLowerCase().indexOf('-tests.ts') > 0)[0];
|
||||
if (onlyTest) {
|
||||
testFile = path.join(dir, onlyTest);
|
||||
} else {
|
||||
testFile = undefined;
|
||||
}
|
||||
}
|
||||
if (testFile) {
|
||||
old['files'] = ['index.d.ts', path.basename(testFile)];
|
||||
} else {
|
||||
old['files'] = ['index.d.ts'];
|
||||
}
|
||||
|
||||
fs.writeFileSync(target, JSON.stringify(old, undefined, 4));
|
||||
console.log('Write to ' + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkDir(path.join(__dirname, '..'), 1);
|
||||
@ -1,18 +0,0 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(path.join(__dirname, '../../publish-typings/data/definitions.json'), 'utf-8'));
|
||||
|
||||
Object.keys(data).forEach(libName => {
|
||||
const libData = data[libName];
|
||||
if(libData.kind === 'ProperModule') {
|
||||
if (libData.definitionFilename !== 'index.d.ts') {
|
||||
console.log(`${libName} needs renaming from ${libData.definitionFilename}`);
|
||||
const src = path.join(__dirname, '..', libName, libData.definitionFilename);
|
||||
const dst = path.join(__dirname, '..', libName, 'index.d.ts');
|
||||
fs.rename(src, dst);
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user