Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 56 additions & 33 deletions packages/devextreme/build/gulp/vectormap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,71 @@ const compressionPipes = require('./compression-pipes.js');
const VECTORMAP_UTILS_PATH = 'js/viz/vector_map.utils';
const VECTORMAP_UTILS_RESULT_PATH = path.join(context.RESULT_JS_PATH, 'vectormap-utils');
const VECTORMAP_DATA_RESULT_PATH = path.join(context.RESULT_JS_PATH, 'vectormap-data');
const VECTORMAP_SOURCES_PATH = 'build/vectormap-sources';

function transformFileName(fileName) {
return path.join(VECTORMAP_UTILS_PATH, fileName) + '.js';
}

gulp.task('vectormap-utils', function() {
return merge(
createVectorMapUtilsStream('browser', '.debug', false),
createVectorMapUtilsStream('browser', '', true),
createVectorMapUtilsStream('node', '', false)
createBrowserVectorMapUtilsStream('.debug', false),
createBrowserVectorMapUtilsStream('', true),
);
});
Comment thread
pharret31 marked this conversation as resolved.

gulp.task('vectormap-data', gulp.series('vectormap-utils', function() {
const stream = merge();
const processFiles = require(path.join('../..', VECTORMAP_UTILS_RESULT_PATH, 'dx.vectormaputils.node.js')).processFiles;
function toArrayBuffer(buffer) {
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
}

function collectShpFiles(dir) {
return fs.readdirSync(dir)
.filter(name => path.extname(name).toLowerCase() === '.shp')
.map(name => path.basename(name, '.shp'));
}

gulp.task('vectormap-data', gulp.series('vectormap-utils', function generateData() {
const parse = require(path.join('../..', VECTORMAP_UTILS_RESULT_PATH, 'dx.vectormaputils.debug.js')).parse;
const settings = require(path.join('../..', VECTORMAP_SOURCES_PATH, '_settings.js'));
Comment thread
pharret31 marked this conversation as resolved.
const precision = settings.precision >= 0 ? Math.round(settings.precision) : 4;

if(!fs.existsSync(VECTORMAP_DATA_RESULT_PATH)) {
fs.mkdirSync(VECTORMAP_DATA_RESULT_PATH);
}

processFiles('build/vectormap-sources', {
output: VECTORMAP_DATA_RESULT_PATH,
settings: 'build/vectormap-sources/_settings.js'
}, function() {
const files = fs.readdirSync(VECTORMAP_DATA_RESULT_PATH);

files.forEach(file => {
const data = fs.readFileSync(path.join(VECTORMAP_DATA_RESULT_PATH, file), 'utf8');

stream.add(
gulp.src('build/gulp/vectormapdata-template.jst')
.pipe(template({ data: data }))
.pipe(rename(file))
.pipe(headerPipes.useStrict())
.pipe(gulp.dest(VECTORMAP_DATA_RESULT_PATH))
);
});
const sourceDir = path.resolve(VECTORMAP_SOURCES_PATH);
const files = collectShpFiles(sourceDir);

files.forEach(name => {
const shpBuffer = fs.readFileSync(path.join(sourceDir, name + '.shp'));
const dbfBuffer = fs.readFileSync(path.join(sourceDir, name + '.dbf'));

const shapeData = parse(
{ shp: toArrayBuffer(shpBuffer), dbf: toArrayBuffer(dbfBuffer) },
{ precision },
);

if(shapeData) {
const content = name + ' = ' + JSON.stringify(shapeData) + ';';
fs.writeFileSync(path.join(VECTORMAP_DATA_RESULT_PATH, name + '.js'), content);
}
});

const stream = merge();
const dataFiles = fs.readdirSync(VECTORMAP_DATA_RESULT_PATH);

dataFiles.forEach(file => {
const data = fs.readFileSync(path.join(VECTORMAP_DATA_RESULT_PATH, file), 'utf8');

stream.add(
gulp.src('build/gulp/vectormapdata-template.jst')
.pipe(template({ data: data }))
.pipe(rename(file))
.pipe(headerPipes.useStrict())
.pipe(gulp.dest(VECTORMAP_DATA_RESULT_PATH))
);
});

return stream;
}));

Expand All @@ -67,20 +93,17 @@ function patchVectorMapUtilsStream(stream, isMinify) {
.pipe(gulp.dest(VECTORMAP_UTILS_RESULT_PATH));
}

function createVectorMapUtilsStream(name, suffix, isMinify) {
function createBrowserVectorMapUtilsStream(suffix, isMinify) {
const settings = require(path.join('../..', VECTORMAP_UTILS_PATH, '_settings.json'));
const part = settings[name];
const part = settings['browser'];
const stream = gulp.src(settings.commonFiles.concat(part.files).map(transformFileName))
.pipe(concat(part.fileName + suffix + '.js'));

if(name === 'browser') {
return stream.pipe(tap(file => {
patchVectorMapUtilsStream(gulp.src('build/gulp/vectormaputils-template.jst')
.pipe(template({ data: file.contents }))
.pipe(rename(path.basename(file.path))), isMinify);
}));
}
return patchVectorMapUtilsStream(stream, isMinify);
return stream.pipe(tap(file => {
patchVectorMapUtilsStream(gulp.src('build/gulp/vectormaputils-template.jst')
.pipe(template({ data: file.contents }))
.pipe(rename(path.basename(file.path))), isMinify);
}));
Comment thread
pharret31 marked this conversation as resolved.
}
Comment thread
pharret31 marked this conversation as resolved.

gulp.task('vectormap', gulp.series('vectormap-utils', 'vectormap-data'));
8 changes: 4 additions & 4 deletions packages/devextreme/build/gulp/vectormaputils-template.jst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
} else if(typeof module === "object" && module.exports) {
factory(exports);
} else {
var exports = root.DevExpress = root.DevExpress || {};
exports = exports.viz = exports.viz || {};
exports = exports.vectormaputils = {};
factory(exports);
var browserExports = root.DevExpress = root.DevExpress || {};
browserExports = browserExports.viz = browserExports.viz || {};
browserExports = browserExports.vectormaputils = {};
factory(browserExports);
}
}(this, function(exports) {
<%= data %>
Expand Down
7 changes: 0 additions & 7 deletions packages/devextreme/js/viz/vector_map.utils/_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,5 @@
"files": [
"js-stream"
]
},
"node": {
"fileName": "dx.vectormaputils.node",
"files": [
"node-stream",
"node-cmd"
]
}
}
181 changes: 0 additions & 181 deletions packages/devextreme/js/viz/vector_map.utils/node-cmd.js

This file was deleted.

29 changes: 0 additions & 29 deletions packages/devextreme/js/viz/vector_map.utils/node-stream.js

This file was deleted.

3 changes: 1 addition & 2 deletions packages/devextreme/ports.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"qunit": "20060",
"vectormap-utils-tester": "20061"
"qunit": "20060"
}
2 changes: 1 addition & 1 deletion packages/devextreme/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
"{projectRoot}/build/gulp/vectormap.js"
],
"outputs": [
"{projectRoot}/artifacts/js/vectormap-utils",
"{projectRoot}/artifacts/js/vectormap-data"
]
},
Expand Down Expand Up @@ -732,7 +733,6 @@
"{projectRoot}/build/gulp/vendor.js"
],
"outputs": [
"{projectRoot}/artifacts/js/vectormap-utils",
"{projectRoot}/artifacts/js/cldr"
]
},
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading