Skip to content

Commit 6136d93

Browse files
samelhusseinicpcallen
authored andcommitted
Fix msg typings script and move to typings build directory
1 parent 89cf049 commit 6136d93

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ tests/screenshot/outputs/*
1616
local_build/*compiler*.jar
1717
local_build/local_*_compressed.js
1818
chromedriver
19-
typings/tmp/*
2019
build/
2120
dist/

scripts/gulpfiles/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ module.exports = {
2525
// Directory in which to assemble (and from which to publish) the
2626
// blockly npm package.
2727
RELEASE_DIR: 'dist',
28+
29+
// Directory to write typings output to.
30+
TYPINGS_BUILD_DIR: path.join('build', 'typings'),
2831
};

scripts/gulpfiles/package_tasks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var path = require('path');
1919
var fs = require('fs');
2020
var rimraf = require('rimraf');
2121
var {getPackageJson} = require('./helper_tasks');
22-
var {BUILD_DIR, RELEASE_DIR} = require('./config');
22+
var {BUILD_DIR, RELEASE_DIR, TYPINGS_BUILD_DIR} = require('./config');
2323

2424
// Path to template files for gulp-umd.
2525
const TEMPLATE_DIR = 'scripts/package/templates';
@@ -77,9 +77,9 @@ function checkBuildDir(done) {
7777
}
7878
// Check files built by typings.typings exist in BUILD_DIR.
7979
for (const fileName of ['blockly.d.ts', 'msg/en.d.ts']) {
80-
if (!fs.existsSync(`${BUILD_DIR}/${fileName}`)) {
80+
if (!fs.existsSync(`${TYPINGS_BUILD_DIR}/${fileName}`)) {
8181
done(new Error(
82-
`Your ${BUILD_DIR} directory does not contain ${fileName}. ` +
82+
`Your ${TYPINGS_BUILD_DIR} directory does not contain ${fileName}. ` +
8383
'Has typings.typings been run? Try "npm run typings".'));
8484
return;
8585
}
@@ -403,11 +403,11 @@ function packageDTS() {
403403
'typings/msg/msg.d.ts',
404404
];
405405
const builtSrcs = [
406-
`${BUILD_DIR}/blockly.d.ts`, // Use freshly-built one instead.
407-
`${BUILD_DIR}/msg/*.d.ts`,
406+
`${TYPINGS_BUILD_DIR}/blockly.d.ts`, // Use freshly-built one instead.
407+
`${TYPINGS_BUILD_DIR}/msg/*.d.ts`,
408408
];
409409
return gulp.src(handwrittenSrcs, {base: 'typings'})
410-
.pipe(gulp.src(builtSrcs, {base: BUILD_DIR}))
410+
.pipe(gulp.src(builtSrcs, {base: TYPINGS_BUILD_DIR}))
411411
.pipe(gulp.dest(RELEASE_DIR));
412412
};
413413

scripts/gulpfiles/typings.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var path = require('path');
1616
var fs = require('fs');
1717
var rimraf = require('rimraf');
1818
var execSync = require('child_process').execSync;
19-
var {BUILD_DIR} = require('./config');
19+
var {TYPINGS_BUILD_DIR} = require('./config');
2020

2121
/**
2222
* Recursively generates a list of file paths with the specified extension
@@ -52,13 +52,13 @@ function getFilePath(basePath, filter, excludePaths) {
5252
// This includes the header (incl License), additional useful interfaces
5353
// including Blockly Options and Google Closure typings.
5454
function typings() {
55-
const tmpDir = './typings/tmp';
55+
const tmpDir = path.join(TYPINGS_BUILD_DIR, 'tmp');
5656

5757
// Clean directory if exists.
5858
if (fs.existsSync(tmpDir)) {
5959
rimraf.sync(tmpDir);
6060
}
61-
fs.mkdirSync(tmpDir);
61+
fs.mkdirSync(tmpDir, {recursive: true});
6262

6363
const excludePaths = [
6464
"core/renderers/geras",
@@ -95,7 +95,7 @@ function typings() {
9595
];
9696
return gulp.src(srcs)
9797
.pipe(gulp.concat('blockly.d.ts'))
98-
.pipe(gulp.dest(BUILD_DIR))
98+
.pipe(gulp.dest(TYPINGS_BUILD_DIR))
9999
.on('end', function () {
100100
// Clean up tmp directory.
101101
if (fs.existsSync(tmpDir)) {
@@ -108,10 +108,14 @@ function typings() {
108108
function msgTypings(cb) {
109109
const template = fs.readFileSync(path.join('typings/templates/msg.template'), 'utf-8');
110110
const msgFiles = fs.readdirSync(path.join('msg', 'json'));
111+
const msgDir = path.join(TYPINGS_BUILD_DIR, 'msg');
112+
if (!fs.existsSync(msgDir)) {
113+
fs.mkdirSync(msgDir, {recursive: true});
114+
}
111115
msgFiles.forEach(msg => {
112116
const localeName = msg.substring(0, msg.indexOf('.json'));
113117
const msgTypings = template.slice().replace(/<%= locale %>/gi, localeName);
114-
fs.writeFileSync(path.join(BUILD_DIR, 'msg', localeName + '.d.ts'), msgTypings, 'utf-8');
118+
fs.writeFileSync(path.join(TYPINGS_BUILD_DIR, 'msg', localeName + '.d.ts'), msgTypings, 'utf-8');
115119
})
116120
cb();
117121
}
@@ -122,8 +126,8 @@ function msgTypings(cb) {
122126
*/
123127
function checkinTypings() {
124128
return gulp.src([
125-
`${BUILD_DIR}/**.d.ts`,
126-
`${BUILD_DIR}/**/**.d.ts`,
129+
`${TYPINGS_BUILD_DIR}/**.d.ts`,
130+
`${TYPINGS_BUILD_DIR}/**/**.d.ts`,
127131
]).pipe(gulp.dest('typings'));
128132
};
129133

typings/msg/bs.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @fileoverview Type definitions for the Blockly bs locale.
9+
* @author [email protected] (Sam El-Husseini)
10+
*/
11+
12+
/// <reference path="msg.d.ts" />
13+
14+
import BlocklyMsg = Blockly.Msg;
15+
export = BlocklyMsg;
16+

0 commit comments

Comments
 (0)