Skip to content

Commit

Permalink
Fix(ish) codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Feb 23, 2018
1 parent b669d83 commit 901d4d2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
45 changes: 22 additions & 23 deletions build/generate-struct-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

'use strict'; // eslint-disable-line strict

require('flow-remove-types/register');

const fs = require('fs');

require = require('@std/esm')(module, {"cjs":true, "esm":"js"});

const ejs = require('ejs');
const util = require('../src/util/util');
const {createLayout, viewTypes} = require('../src/util/struct_array');
const util = require('../src_untyped/util/util');
const {createLayout, viewTypes} = require('../src_untyped/util/struct_array');

import type {ViewType, StructArrayLayout} from '../src/util/struct_array';
import type {ViewType, StructArrayLayout} from '../src_untyped/util/struct_array';

const structArrayLayoutJs = ejs.compile(fs.readFileSync('src/util/struct_array_layout.js.ejs', 'utf8'), {strict: true});
const structArrayJs = ejs.compile(fs.readFileSync('src/util/struct_array.js.ejs', 'utf8'), {strict: true});
Expand Down Expand Up @@ -72,7 +73,7 @@ function createStructArrayType(name: string, layout: StructArrayLayout, includeS
includeStructAccessors
});
} else {
arrayTypeEntries.add(`${arrayClass}: ${layoutClass}`);
arrayTypeEntries.add(`${layoutClass} as ${arrayClass}`);
}
}

Expand Down Expand Up @@ -118,16 +119,16 @@ function camelize (str) {

global.camelize = camelize;

import posAttributes from '../src/data/pos_attributes';
import rasterBoundsAttributes from '../src/data/raster_bounds_attributes';
const posAttributes = require('../src_untyped/data/pos_attributes').default;
const rasterBoundsAttributes = require('../src_untyped/data/raster_bounds_attributes').default;

createStructArrayType('pos', posAttributes);
createStructArrayType('raster_bounds', rasterBoundsAttributes);

import circleAttributes from '../src/data/bucket/circle_attributes';
import fillAttributes from '../src/data/bucket/fill_attributes';
import fillExtrusionAttributes from '../src/data/bucket/fill_extrusion_attributes' ;
import lineAttributes from '../src/data/bucket/line_attributes';
const circleAttributes = require('../src_untyped/data/bucket/circle_attributes').default;
const fillAttributes = require('../src_untyped/data/bucket/fill_attributes').default;
const fillExtrusionAttributes = require('../src_untyped/data/bucket/fill_extrusion_attributes').default ;
const lineAttributes = require('../src_untyped/data/bucket/line_attributes').default;

// layout vertex arrays
const layoutAttributes = {
Expand All @@ -142,7 +143,7 @@ for (const name in layoutAttributes) {
}

// symbol layer specific arrays
import symbolAttributes from '../src/data/bucket/symbol_attributes';
const symbolAttributes = require('../src_untyped/data/bucket/symbol_attributes').default;
createStructArrayType(`symbol_layout`, symbolAttributes.symbolLayoutAttributes);
createStructArrayType(`symbol_dynamic_layout`, symbolAttributes.dynamicLayoutAttributes);
createStructArrayType(`symbol_opacity`, symbolAttributes.placementOpacityAttributes);
Expand Down Expand Up @@ -203,19 +204,17 @@ fs.writeFileSync('src/data/array_types.js',
`// This file is generated. Edit build/generate-struct-arrays.js, then run \`yarn run codegen\`.
// @flow
const assert = require('assert');
const {StructArray} = require('../util/struct_array');
const {Struct} = require('../util/struct_array');
const {register} = require('../util/web_worker_transfer');
const Point = require('@mapbox/point-geometry');
import assert from 'assert';
import {StructArray} from '../util/struct_array';
import {Struct} from '../util/struct_array';
import {register} from '../util/web_worker_transfer';
import Point from '@mapbox/point-geometry';
${layouts.map(structArrayLayoutJs).join('\n')}
${arraysWithStructAccessors.map(structArrayJs).join('\n')}
module.exports = {
${layouts.map(layout => layout.className).join(',\n ')},
${[...arrayTypeEntries].join(',\n ')},
${arraysWithStructAccessors.map(array => array.arrayClass).join(',\n ')}
};\n`);
export {
${[...arrayTypeEntries].join(',\n ')}
};`);

6 changes: 4 additions & 2 deletions build/generate-style-code.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';

require('flow-remove-types/register');

const fs = require('fs');

require = require('@std/esm')(module, {"cjs":true, "esm":"js"});

const ejs = require('ejs');
const spec = require('../src/style-spec/reference/v8');
const Color = require('../src/style-spec/util/color');
const Color = require('../src_untyped/style-spec/util/color');

global.camelize = function (str) {
return str.replace(/(?:^|-)(.)/g, function (_, x) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@mapbox/batfish": "^0.13.3",
"@mapbox/mapbox-gl-rtl-text": "^0.1.1",
"@mapbox/mapbox-gl-test-suite": "file:test/integration",
"@std/esm": "^0.21.7",
"babel-eslint": "^7.0.0",
"benchmark": "~2.1.0",
"browserify": "^14.0.0",
Expand Down Expand Up @@ -156,6 +157,7 @@
"test-flow-cov": "flow-coverage-report -i 'src/**/*.js' -t html",
"test-cov": "nyc --require=flow-remove-types/register --reporter=text-summary --reporter=lcov --cache run-s test-unit test-expressions test-query test-render",
"prepublish": "in-publish && run-s build-dev build-min || not-in-publish",
"remove-flow-types": "flow-remove-types -i node_modules -d src_untyped src",
"codegen": "node build/generate-style-code.js && flow-node build/generate-struct-arrays.js"
},
"files": [
Expand Down
8 changes: 4 additions & 4 deletions src/style/style_layer/layer_properties.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
// @flow
/* eslint-disable */

const styleSpec = require('../../style-spec/reference/latest');
import styleSpec from '../../style-spec/reference/latest';

const {
import {
Properties,
DataConstantProperty,
DataDrivenProperty,
CrossFadedProperty,
HeatmapColorProperty
} = require('../properties');
} from '../properties';

import type Color from '../../style-spec/util/color';

Expand Down Expand Up @@ -47,4 +47,4 @@ const paint: Properties<PaintProps> = new Properties({
<% } -%>
});

module.exports = { paint<% if (layoutProperties.length) { %>, layout<% } %> };
export default { paint<% if (layoutProperties.length) { %>, layout<% } %> };
2 changes: 1 addition & 1 deletion src/util/struct_array.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type <%=StructTypeClass.replace('Struct', '')%> = <%=StructTypeClass%>;
/**
* @private
*/
class <%=StructArrayClass%> extends <%=StructArrayLayoutClass%> {
export class <%=StructArrayClass%> extends <%=StructArrayLayoutClass%> {
<%
if (StructArrayClass === 'GlyphOffsetArray' || StructArrayClass === 'SymbolLineVertexArray') {
// component getters
Expand Down
2 changes: 1 addition & 1 deletion src/util/struct_array_layout.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for (const member of members) {
*
* @private
*/
class <%=StructArrayLayoutClass%> extends StructArray {
export class <%=StructArrayLayoutClass%> extends StructArray {
<%
for (const type of usedTypes) {
-%>
Expand Down

0 comments on commit 901d4d2

Please sign in to comment.