Skip to content

Commit b47cd0e

Browse files
Merge pull request microsoft#3875 from Microsoft/nightly
Create a 'publish-nightly' task in our Jakefile
2 parents 2030655 + b443cfe commit b47cd0e

File tree

5 files changed

+125
-13
lines changed

5 files changed

+125
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tests/baselines/reference/projectOutput/*
2525
tests/baselines/local/projectOutput/*
2626
tests/services/baselines/prototyping/local/*
2727
tests/services/browser/typescriptServices.js
28+
scripts/configureNightly.js
2829
scripts/processDiagnosticMessages.d.ts
2930
scripts/processDiagnosticMessages.js
3031
scripts/importDefinitelyTypedTests.js

Jakefile.js

+47-9
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic
313313
var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json");
314314
var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts");
315315

316-
file(processDiagnosticMessagesTs)
316+
file(processDiagnosticMessagesTs);
317317

318318
// processDiagnosticMessages script
319319
compileFile(processDiagnosticMessagesJs,
@@ -338,12 +338,50 @@ file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson],
338338
complete();
339339
});
340340
ex.run();
341-
}, {async: true})
341+
}, {async: true});
342342

343343
desc("Generates a diagnostic file in TypeScript based on an input JSON file");
344-
task("generate-diagnostics", [diagnosticInfoMapTs])
344+
task("generate-diagnostics", [diagnosticInfoMapTs]);
345345

346346

347+
// Publish nightly
348+
var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
349+
var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
350+
var packageJson = "package.json";
351+
var programTs = path.join(compilerDirectory, "program.ts");
352+
353+
file(configureNightlyTs);
354+
355+
compileFile(/*outfile*/configureNightlyJs,
356+
/*sources*/ [configureNightlyTs],
357+
/*prereqs*/ [configureNightlyTs],
358+
/*prefixes*/ [],
359+
/*useBuiltCompiler*/ false,
360+
/*noOutFile*/ false,
361+
/*generateDeclarations*/ false,
362+
/*outDir*/ undefined,
363+
/*preserveConstEnums*/ undefined,
364+
/*keepComments*/ false,
365+
/*noResolve*/ false,
366+
/*stripInternal*/ false);
367+
368+
task("setDebugMode", function() {
369+
useDebugMode = true;
370+
});
371+
372+
task("configure-nightly", [configureNightlyJs], function() {
373+
var cmd = "node " + configureNightlyJs + " " + packageJson + " " + programTs;
374+
console.log(cmd);
375+
exec(cmd);
376+
}, { async: true });
377+
378+
desc("Configure, build, test, and publish the nightly release.");
379+
task("publish-nightly", ["configure-nightly", "LKG", "clean", "setDebugMode", "runtests"], function () {
380+
var cmd = "npm publish --tag next";
381+
console.log(cmd);
382+
exec(cmd);
383+
});
384+
347385
// Local target to build the compiler and services
348386
var tscFile = path.join(builtLocalDirectory, compilerFilename);
349387
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
@@ -440,11 +478,11 @@ file(specMd, [word2mdJs, specWord], function () {
440478
child_process.exec(cmd, function () {
441479
complete();
442480
});
443-
}, {async: true})
481+
}, {async: true});
444482

445483

446484
desc("Generates a Markdown version of the Language Specification");
447-
task("generate-spec", [specMd])
485+
task("generate-spec", [specMd]);
448486

449487

450488
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
@@ -576,7 +614,7 @@ task("runtests", ["tests", builtLocalDirectory], function() {
576614
exec(cmd, deleteTemporaryProjectOutput);
577615
}, {async: true});
578616

579-
desc("Generates code coverage data via instanbul")
617+
desc("Generates code coverage data via instanbul");
580618
task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
581619
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run;
582620
console.log(cmd);
@@ -619,7 +657,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
619657
function getDiffTool() {
620658
var program = process.env['DIFF']
621659
if (!program) {
622-
fail("Add the 'DIFF' environment variable to the path of the program you want to use.")
660+
fail("Add the 'DIFF' environment variable to the path of the program you want to use.");
623661
}
624662
return program;
625663
}
@@ -628,14 +666,14 @@ function getDiffTool() {
628666
desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable");
629667
task('diff', function () {
630668
var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline;
631-
console.log(cmd)
669+
console.log(cmd);
632670
exec(cmd);
633671
}, {async: true});
634672

635673
desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable");
636674
task('diff-rwc', function () {
637675
var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline;
638-
console.log(cmd)
676+
console.log(cmd);
639677
exec(cmd);
640678
}, {async: true});
641679

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "http://typescriptlang.org/",
5-
"version": "1.5.3",
5+
"version": "1.6.0",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

scripts/configureNightly.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/// <reference path="../src/compiler/sys.ts" />
2+
3+
/**
4+
* A minimal description for a parsed package.json object.
5+
*/
6+
interface PackageJson {
7+
name: string;
8+
version: string;
9+
keywords: string[];
10+
}
11+
12+
function main(): void {
13+
const sys = ts.sys;
14+
if (sys.args.length < 2) {
15+
sys.write("Usage:" + sys.newLine)
16+
sys.write("\tnode configureNightly.js <package.json location> <file containing version>" + sys.newLine);
17+
return;
18+
}
19+
20+
// Acquire the version from the package.json file and modify it appropriately.
21+
const packageJsonFilePath = ts.normalizePath(sys.args[0]);
22+
const packageJsonContents = sys.readFile(packageJsonFilePath);
23+
const packageJsonValue: PackageJson = JSON.parse(packageJsonContents);
24+
25+
const nightlyVersion = getNightlyVersionString(packageJsonValue.version);
26+
27+
// Modify the package.json structure
28+
packageJsonValue.version = nightlyVersion;
29+
30+
// Acquire and modify the source file that exposes the version string.
31+
const tsFilePath = ts.normalizePath(sys.args[1]);
32+
const tsFileContents = sys.readFile(tsFilePath);
33+
const versionAssignmentRegExp = /export\s+const\s+version\s+=\s+".*";/;
34+
const modifiedTsFileContents = tsFileContents.replace(versionAssignmentRegExp, `export const version = "${nightlyVersion}";`);
35+
36+
// Ensure we are actually changing something - the user probably wants to know that the update failed.
37+
if (tsFileContents === modifiedTsFileContents) {
38+
let err = `\n '${tsFilePath}' was not updated while configuring for a nightly publish.\n `;
39+
40+
if (tsFileContents.match(versionAssignmentRegExp)) {
41+
err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`;
42+
}
43+
else {
44+
err += `The file seems to no longer have a string matching '${versionAssignmentRegExp}'.`;
45+
}
46+
47+
throw err + "\n";
48+
}
49+
50+
// Finally write the changes to disk.
51+
sys.writeFile(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4))
52+
sys.writeFile(tsFilePath, modifiedTsFileContents);
53+
}
54+
55+
function getNightlyVersionString(versionString: string): string {
56+
// If the version string already contains "-nightly",
57+
// then get the base string and update based on that.
58+
const dashNightlyPos = versionString.indexOf("-dev");
59+
if (dashNightlyPos >= 0) {
60+
versionString = versionString.slice(0, dashNightlyPos);
61+
}
62+
63+
// We're going to append a representation of the current time at the end of the current version.
64+
// String.prototype.toISOString() returns a 24-character string formatted as 'YYYY-MM-DDTHH:mm:ss.sssZ',
65+
// but we'd prefer to just remove separators and limit ourselves to YYYYMMDD.
66+
// UTC time will always be implicit here.
67+
const now = new Date();
68+
const timeStr = now.toISOString().replace(/:|T|\.|-/g, "").slice(0, 8);
69+
70+
return `${versionString}-dev.${timeStr}`;
71+
}
72+
73+
main();

src/compiler/program.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ts {
88
/* @internal */ export let ioWriteTime = 0;
99

1010
/** The version of the TypeScript compiler release */
11-
export const version = "1.5.3";
11+
export const version = "1.6.0";
1212

1313
export function findConfigFile(searchPath: string): string {
1414
let fileName = "tsconfig.json";
@@ -341,7 +341,7 @@ namespace ts {
341341
});
342342
}
343343

344-
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
344+
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
345345
return runWithCancellationToken(() => {
346346
if (!isDeclarationFile(sourceFile)) {
347347
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
@@ -350,7 +350,7 @@ namespace ts {
350350
return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
351351
}
352352
});
353-
}
353+
}
354354

355355
function getOptionsDiagnostics(): Diagnostic[] {
356356
let allDiagnostics: Diagnostic[] = [];

0 commit comments

Comments
 (0)