mirror of https://gitee.com/cf-fz/WebCAD.git
parent
0c4825bb11
commit
545a4c1867
@ -1,104 +0,0 @@
|
||||
//拯救type错误的问题
|
||||
let http = require('https');
|
||||
|
||||
let fs = require('fs');
|
||||
|
||||
let path = require('path');
|
||||
|
||||
function downLoadFile(url, path)
|
||||
{
|
||||
if (fs.existsSync(path)) {
|
||||
fs.unlinkSync(path);
|
||||
}
|
||||
let file = fs.createWriteStream(path);
|
||||
let request = http.get(url, function (response)
|
||||
{
|
||||
response.pipe(file);
|
||||
});
|
||||
}
|
||||
|
||||
function copyFileSync(source, target)
|
||||
{
|
||||
|
||||
let targetFile = target;
|
||||
|
||||
//if target is a directory a new file with the same name will be created
|
||||
if (fs.existsSync(target)) {
|
||||
if (fs.lstatSync(target).isDirectory()) {
|
||||
targetFile = path.join(target, path.basename(source));
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(targetFile, fs.readFileSync(source));
|
||||
console.log('targetFile: ', targetFile);
|
||||
}
|
||||
|
||||
function copyFolderRecursiveSync(source, target)
|
||||
{
|
||||
|
||||
let files = [];
|
||||
|
||||
//check if folder needs to be created or integrated
|
||||
let targetFolder = path.join(target, path.basename(source));
|
||||
if (!fs.existsSync(targetFolder)) {
|
||||
fs.mkdirSync(targetFolder);
|
||||
}
|
||||
|
||||
//copy
|
||||
if (fs.lstatSync(source).isDirectory()) {
|
||||
files = fs.readdirSync(source);
|
||||
files.forEach(function (file)
|
||||
{
|
||||
let curSource = path.join(source, file);
|
||||
if (fs.lstatSync(curSource).isDirectory()) {
|
||||
copyFolderRecursiveSync(curSource, targetFolder);
|
||||
} else {
|
||||
copyFileSync(curSource, targetFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// let filePath = "./@types/";
|
||||
// let modules_path = "./node_modules/";
|
||||
|
||||
// copyFolderRecursiveSync(filePath, modules_path);
|
||||
|
||||
function downloadTypes(downFiles)
|
||||
{
|
||||
filePath = path.resolve("./node_modules/@types/" + downFiles.name) + "\\";
|
||||
console.log('filePath: ', filePath);
|
||||
for (let file of downFiles.files) {
|
||||
console.log(downFiles.urlPath + file);
|
||||
try {
|
||||
downLoadFile(downFiles.urlPath + file, filePath + file);
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
downloadTypes(
|
||||
{
|
||||
name: "three",
|
||||
urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/three/",
|
||||
files: [
|
||||
// "index.d.ts",
|
||||
"three-core.d.ts",
|
||||
// "three-outlinepass.d.ts",
|
||||
// "three-smaapass.d.ts"
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
downloadTypes(
|
||||
{
|
||||
name: "jquery",
|
||||
urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/jquery/",
|
||||
files: [
|
||||
"index.d.ts"
|
||||
]
|
||||
}
|
||||
);
|
@ -0,0 +1,112 @@
|
||||
import * as path from 'path';
|
||||
import * as http from 'https';
|
||||
import * as fs from "fs";
|
||||
|
||||
//修正d.ts中类型定义出现错误的问题,临时修复,因为d.ts并不能完全快速的合并我们的类型修复PR.
|
||||
|
||||
/**
|
||||
* 下载文件到指定的文件地址
|
||||
*
|
||||
* @param {string} url
|
||||
* @param {string} filePath
|
||||
*/
|
||||
function downLoadFile(url: string, filePath: string)
|
||||
{
|
||||
if (fs.existsSync(filePath))
|
||||
fs.unlinkSync(filePath);
|
||||
else
|
||||
fs.mkdirSync(path.dirname(filePath));
|
||||
let file = fs.createWriteStream(filePath);
|
||||
http.get(url, function (response)
|
||||
{
|
||||
response.pipe(file);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件.
|
||||
*
|
||||
* @param {*} source 目标文件的地址
|
||||
* @param {*} targetFile 拷贝到新的地址
|
||||
*/
|
||||
function copyFileSync(source: string, targetFile: string)
|
||||
{
|
||||
//if target is a directory a new file with the same name will be created
|
||||
if (fs.existsSync(targetFile))
|
||||
{
|
||||
if (fs.lstatSync(targetFile).isDirectory())
|
||||
{
|
||||
targetFile = path.join(targetFile, path.basename(source));
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(targetFile, fs.readFileSync(source));
|
||||
console.log('targetFile: ', targetFile);
|
||||
}
|
||||
|
||||
function copyFolderRecursiveSync(source, target)
|
||||
{
|
||||
let files = [];
|
||||
//check if folder needs to be created or integrated
|
||||
let targetFolder = path.join(target, path.basename(source));
|
||||
if (!fs.existsSync(targetFolder))
|
||||
{
|
||||
fs.mkdirSync(targetFolder);
|
||||
}
|
||||
//copy
|
||||
if (fs.lstatSync(source).isDirectory())
|
||||
{
|
||||
files = fs.readdirSync(source);
|
||||
files.forEach(function (file)
|
||||
{
|
||||
let curSource = path.join(source, file);
|
||||
if (fs.lstatSync(curSource).isDirectory())
|
||||
{
|
||||
copyFolderRecursiveSync(curSource, targetFolder);
|
||||
} else
|
||||
{
|
||||
copyFileSync(curSource, targetFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// copyFolderRecursiveSync("./@types/", "./node_modules/");
|
||||
|
||||
function downloadTypes(downFiles)
|
||||
{
|
||||
let filePath = path.resolve("./node_modules/@types/" + downFiles.name) + "\\";
|
||||
console.log('filePath: ', filePath);
|
||||
for (let file of downFiles.files)
|
||||
{
|
||||
console.log(downFiles.urlPath + file);
|
||||
try
|
||||
{
|
||||
downLoadFile(downFiles.urlPath + file, filePath + file);
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
downloadTypes({
|
||||
name: "three",
|
||||
urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/three/",
|
||||
files: [
|
||||
// "index.d.ts",
|
||||
"three-core.d.ts",
|
||||
// "three-outlinepass.d.ts",
|
||||
// "three-smaapass.d.ts"
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
downloadTypes({
|
||||
name: "jquery",
|
||||
urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/jquery/",
|
||||
files: [
|
||||
"index.d.ts"
|
||||
]
|
||||
});
|
Loading…
Reference in new issue