Move externs to types folder
Also support auto-load all types from types folder for template test. Change-Id: I113d9dd69b6f1b1e016dcf0b00e942446bbb6a6f
This commit is contained in:
@@ -1,47 +1,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const twinkie = require('fried-twinkie');
|
const twinkie = require('fried-twinkie');
|
||||||
|
|
||||||
/**
|
|
||||||
* For the purposes of template type checking, externs should be added for
|
|
||||||
* anything set on the window object. Note that sub-properties of these
|
|
||||||
* declared properties are considered something separate.
|
|
||||||
*/
|
|
||||||
const EXTERN_NAMES = [
|
|
||||||
'Gerrit',
|
|
||||||
'GrAnnotation',
|
|
||||||
'GrAttributeHelper',
|
|
||||||
'GrChangeActionsInterface',
|
|
||||||
'GrChangeReplyInterface',
|
|
||||||
'GrDiffBuilder',
|
|
||||||
'GrDiffBuilderImage',
|
|
||||||
'GrDiffBuilderSideBySide',
|
|
||||||
'GrDiffBuilderUnified',
|
|
||||||
'GrDiffGroup',
|
|
||||||
'GrDiffLine',
|
|
||||||
'GrDomHooks',
|
|
||||||
'GrEditConstants',
|
|
||||||
'GrEtagDecorator',
|
|
||||||
'GrFileListConstants',
|
|
||||||
'GrGapiAuth',
|
|
||||||
'GrGerritAuth',
|
|
||||||
'GrLinkTextParser',
|
|
||||||
'GrPluginEndpoints',
|
|
||||||
'GrPopupInterface',
|
|
||||||
'GrRangeNormalizer',
|
|
||||||
'GrReporting',
|
|
||||||
'GrReviewerUpdatesParser',
|
|
||||||
'GrCountStringFormatter',
|
|
||||||
'GrThemeApi',
|
|
||||||
'SiteBasedCache',
|
|
||||||
'FetchPromisesCache',
|
|
||||||
'GrRestApiHelper',
|
|
||||||
'GrDisplayNameUtils',
|
|
||||||
'GrReviewerSuggestionsProvider',
|
|
||||||
'moment',
|
|
||||||
'page',
|
|
||||||
'util',
|
|
||||||
];
|
|
||||||
|
|
||||||
fs.readdir('./polygerrit-ui/temp/behaviors/', (err, data) => {
|
fs.readdir('./polygerrit-ui/temp/behaviors/', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('error /polygerrit-ui/temp/behaviors/ directory');
|
console.log('error /polygerrit-ui/temp/behaviors/ directory');
|
||||||
@@ -89,37 +48,39 @@ fs.readdir('./polygerrit-ui/temp/behaviors/', (err, data) => {
|
|||||||
mappings = mappingSpecificFile;
|
mappings = mappingSpecificFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
additionalSources.push({
|
/**
|
||||||
path: 'custom-externs.js',
|
* Types in Gerrit.
|
||||||
src: '/** @externs */' +
|
* All types should be under `./polygerrit-ui/app/types` folder and end with `js`.
|
||||||
EXTERN_NAMES.map( name => { return `var ${name};`; }).join(' '),
|
*/
|
||||||
});
|
fs.readdir('./polygerrit-ui/app/types/', (err, typeFiles) => {
|
||||||
|
for (const typeFile of typeFiles) {
|
||||||
/** Types in Gerrit */
|
if (!typeFile.endsWith('.js')) continue;
|
||||||
additionalSources.push({
|
additionalSources.push({
|
||||||
path: './polygerrit-ui/app/types/types.js',
|
path: `./polygerrit-ui/app/types/${typeFile}`,
|
||||||
src: fs.readFileSync(
|
src: fs.readFileSync(
|
||||||
`./polygerrit-ui/app/types/types.js`, 'utf-8'),
|
`./polygerrit-ui/app/types/${typeFile}`, 'utf-8'),
|
||||||
});
|
|
||||||
|
|
||||||
const toCheck = [];
|
|
||||||
for (key of Object.keys(mappings)) {
|
|
||||||
if (mappings[key].html && mappings[key].js) {
|
|
||||||
toCheck.push({
|
|
||||||
htmlSrcPath: mappings[key].html,
|
|
||||||
jsSrcPath: mappings[key].js,
|
|
||||||
jsModule: 'polygerrit.' + mappings[key].package,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
twinkie.checkTemplate(toCheck, additionalSources)
|
const toCheck = [];
|
||||||
.then(() => {}, joinedErrors => {
|
for (key of Object.keys(mappings)) {
|
||||||
if (joinedErrors) {
|
if (mappings[key].html && mappings[key].js) {
|
||||||
|
toCheck.push({
|
||||||
|
htmlSrcPath: mappings[key].html,
|
||||||
|
jsSrcPath: mappings[key].js,
|
||||||
|
jsModule: 'polygerrit.' + mappings[key].package,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
twinkie.checkTemplate(toCheck, additionalSources)
|
||||||
|
.then(() => {}, joinedErrors => {
|
||||||
|
if (joinedErrors) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
});
|
||||||
}).catch(e => {
|
});
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
63
polygerrit-ui/app/types/custom-externs.js
Normal file
63
polygerrit-ui/app/types/custom-externs.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the purposes of template type checking, externs should be added for
|
||||||
|
* anything set on the window object. Note that sub-properties of these
|
||||||
|
* declared properties are considered something separate.
|
||||||
|
*
|
||||||
|
* This file is only for template type checking, not used in Gerrit code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable no-var */
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
/** @externs */
|
||||||
|
// @unused
|
||||||
|
|
||||||
|
var Gerrit;
|
||||||
|
var GrAnnotation;
|
||||||
|
var GrAttributeHelper;
|
||||||
|
var GrChangeActionsInterface;
|
||||||
|
var GrChangeReplyInterface;
|
||||||
|
var GrDiffBuilder;
|
||||||
|
var GrDiffBuilderImage;
|
||||||
|
var GrDiffBuilderSideBySide;
|
||||||
|
var GrDiffBuilderUnified;
|
||||||
|
var GrDiffGroup;
|
||||||
|
var GrDiffLine;
|
||||||
|
var GrDomHooks;
|
||||||
|
var GrEditConstants;
|
||||||
|
var GrEtagDecorator;
|
||||||
|
var GrFileListConstants;
|
||||||
|
var GrGapiAuth;
|
||||||
|
var GrGerritAuth;
|
||||||
|
var GrLinkTextParser;
|
||||||
|
var GrPluginEndpoints;
|
||||||
|
var GrPopupInterface;
|
||||||
|
var GrRangeNormalizer;
|
||||||
|
var GrReporting;
|
||||||
|
var GrReviewerUpdatesParser;
|
||||||
|
var GrCountStringFormatter;
|
||||||
|
var GrThemeApi;
|
||||||
|
var SiteBasedCache;
|
||||||
|
var FetchPromisesCache;
|
||||||
|
var GrRestApiHelper;
|
||||||
|
var GrDisplayNameUtils;
|
||||||
|
var GrReviewerSuggestionsProvider;
|
||||||
|
var moment;
|
||||||
|
var page;
|
||||||
|
var util;
|
Reference in New Issue
Block a user