mirror of
https://github.com/chenasraf/DefinitelyTyped-tools.git
synced 2026-05-18 01:49:03 +00:00
work work
This commit is contained in:
committed by
Andrew Branch
parent
1fac0e537a
commit
7ad6ae4035
@@ -1,3 +1,7 @@
|
||||
# Quick Recap
|
||||
|
||||
|
||||
|
||||
# Overview
|
||||
|
||||
To update the types packages, the following steps must be performed:
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"clean": "node scripts/clean-output.js",
|
||||
"build": "node node_modules/typescript/lib/tsc.js",
|
||||
"generate-search": "npm run build && npm run _generate-search",
|
||||
"_generate-search": "node bin/createSearchIndex.js"
|
||||
"parse": "node bin/parse-definitions.js",
|
||||
"generate": "node bin/generate-packages.js",
|
||||
"index": "node bin/create-search-index.js",
|
||||
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
11
packages/types-publisher/scripts/clean-output.js
Normal file
11
packages/types-publisher/scripts/clean-output.js
Normal file
@@ -0,0 +1,11 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var rmdir = require('rmdir');
|
||||
|
||||
var outputPath = path.join(__dirname, '..', 'output');
|
||||
console.log('Clean ' + outputPath);
|
||||
fs.readdirSync(function(err, dirs) {
|
||||
dirs.forEach(function (dir) {
|
||||
rmdir(path.join(outputPath. dir));
|
||||
});
|
||||
});
|
||||
@@ -13,5 +13,9 @@ if (typeData === undefined) {
|
||||
log.push(` * ${packageName}`);
|
||||
result.log.forEach(line => log.push(` * ${line}`));
|
||||
});
|
||||
Object.keys(typeData).forEach(packageName => {
|
||||
const typing = typeData[packageName];
|
||||
generator.shrinkwrap(typing);
|
||||
});
|
||||
common.writeLogSync('package-generator.md', log);
|
||||
}
|
||||
|
||||
@@ -147,3 +147,11 @@ export function getOutputPath(typing: TypingsData) {
|
||||
const outputPath = path.join(settings.outputPath, typing.typingsPackageName);
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
export function getOutputPathByPackageName(scopedPackageTypingName: string) {
|
||||
// turns '@types/foo' into 'foo'
|
||||
const index = scopedPackageTypingName.indexOf('/');
|
||||
if(index < 0) throw new Error('Expected to find / in ' + scopedPackageTypingName);
|
||||
const unqualified = scopedPackageTypingName.substr(index + 1);
|
||||
return path.join(settings.outputPath, unqualified);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,38 @@
|
||||
import { TypingsData, DefinitionFileKind, mkdir, settings, getOutputPath } from './common';
|
||||
import { TypingsData, DefinitionFileKind, mkdir, settings, getOutputPath, getOutputPathByPackageName } from './common';
|
||||
import * as fs from 'fs';
|
||||
import * as crypto from 'crypto';
|
||||
import * as path from 'path';
|
||||
import * as child_process from 'child_process';
|
||||
import * as request from 'request';
|
||||
|
||||
/** Make concrete version references */
|
||||
export function shrinkwrap(typing: TypingsData) {
|
||||
const outputPath = getOutputPath(typing);
|
||||
|
||||
const packageJSON = JSON.parse(fs.readFileSync(path.join(outputPath, 'package.json'), 'utf-8'));
|
||||
Object.keys(packageJSON.dependencies).forEach(depName => {
|
||||
const depPackageJSON = readPackageJSON(depName);
|
||||
if (depPackageJSON) {
|
||||
// apply concrete version
|
||||
packageJSON.dependencies[depName] = depPackageJSON['version'];
|
||||
} else {
|
||||
// delete unresolved dependency
|
||||
delete packageJSON.dependencies[depName];
|
||||
}
|
||||
});
|
||||
fs.writeFileSync(path.join(outputPath, 'package.json'), JSON.stringify(packageJSON, undefined, 4), 'utf-8');
|
||||
|
||||
function readPackageJSON(typingName: string) {
|
||||
const filename = path.join(getOutputPathByPackageName(typingName), 'package.json');
|
||||
if(fs.existsSync(filename)) {
|
||||
return JSON.parse(fs.readFileSync(filename, 'utf-8'));
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Generates the package to disk */
|
||||
export function generatePackage(typing: TypingsData): { log: string[] } {
|
||||
const log: string[] = [];
|
||||
|
||||
@@ -82,19 +110,26 @@ function createPackageJSON(typing: TypingsData, fileVersion: number): string {
|
||||
|
||||
function createReadme(typing: TypingsData) {
|
||||
const lines: string[] = [];
|
||||
lines.push('# Installation');
|
||||
lines.push('> `npm install --save-dev ' + `@${settings.scopeName}/${typing.typingsPackageName.toLowerCase()}`);
|
||||
lines.push('');
|
||||
|
||||
lines.push('# Summary');
|
||||
lines.push(`This package contains type definitions for ${typing.libraryName}.`)
|
||||
if (typing.projectName) {
|
||||
lines.push('');
|
||||
lines.push(`The project URL or description is ${typing.projectName}`);
|
||||
}
|
||||
lines.push('');
|
||||
|
||||
lines.push('# Credits');
|
||||
if (typing.authors) {
|
||||
lines.push('');
|
||||
lines.push(`These definitions were written by ${typing.authors}.`);
|
||||
}
|
||||
|
||||
lines.push('');
|
||||
|
||||
lines.push('# Details');
|
||||
lines.push(`Typings were exported from ${typing.sourceRepoURL} in the ${typing.typingsPackageName} directory.`);
|
||||
|
||||
lines.push('');
|
||||
|
||||
@@ -55,9 +55,7 @@ function createMinifiedSearchRecord(data: SearchRecord): MinifiedSearchRecord {
|
||||
}
|
||||
|
||||
interface NpmResult {
|
||||
[packageName: string]: {
|
||||
downloads: number;
|
||||
}
|
||||
downloads: number;
|
||||
}
|
||||
|
||||
export function createSearchRecords(info: TypingsData, done: (full: SearchRecord, min: MinifiedSearchRecord) => void) {
|
||||
@@ -75,8 +73,7 @@ export function createSearchRecords(info: TypingsData, done: (full: SearchRecord
|
||||
request.get(url, (err: any, resp: any, data: string) => {
|
||||
const json: NpmResult = JSON.parse(data);
|
||||
if (err) throw err;
|
||||
const result = json[pkg];
|
||||
const record = createSearchRecord(info, result ? result.downloads : 0);
|
||||
const record = createSearchRecord(info, json.downloads || 0);
|
||||
done(record, createMinifiedSearchRecord(record));
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user