Skip to content

Commit 2972b94

Browse files
authored
vectormaputils: remove node version from the DevExtreme (#33364)
1 parent 4af0055 commit 2972b94

16 files changed

Lines changed: 63 additions & 786 deletions

File tree

packages/devextreme/build/gulp/vectormap.js

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,71 @@ const compressionPipes = require('./compression-pipes.js');
1717
const VECTORMAP_UTILS_PATH = 'js/viz/vector_map.utils';
1818
const VECTORMAP_UTILS_RESULT_PATH = path.join(context.RESULT_JS_PATH, 'vectormap-utils');
1919
const VECTORMAP_DATA_RESULT_PATH = path.join(context.RESULT_JS_PATH, 'vectormap-data');
20+
const VECTORMAP_SOURCES_PATH = 'build/vectormap-sources';
2021

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

2526
gulp.task('vectormap-utils', function() {
2627
return merge(
27-
createVectorMapUtilsStream('browser', '.debug', false),
28-
createVectorMapUtilsStream('browser', '', true),
29-
createVectorMapUtilsStream('node', '', false)
28+
createBrowserVectorMapUtilsStream('.debug', false),
29+
createBrowserVectorMapUtilsStream('', true),
3030
);
3131
});
3232

33-
gulp.task('vectormap-data', gulp.series('vectormap-utils', function() {
34-
const stream = merge();
35-
const processFiles = require(path.join('../..', VECTORMAP_UTILS_RESULT_PATH, 'dx.vectormaputils.node.js')).processFiles;
33+
function toArrayBuffer(buffer) {
34+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
35+
}
36+
37+
function collectShpFiles(dir) {
38+
return fs.readdirSync(dir)
39+
.filter(name => path.extname(name).toLowerCase() === '.shp')
40+
.map(name => path.basename(name, '.shp'));
41+
}
42+
43+
gulp.task('vectormap-data', gulp.series('vectormap-utils', function generateData() {
44+
const parse = require(path.join('../..', VECTORMAP_UTILS_RESULT_PATH, 'dx.vectormaputils.debug.js')).parse;
45+
const settings = require(path.join('../..', VECTORMAP_SOURCES_PATH, '_settings.js'));
46+
const precision = settings.precision >= 0 ? Math.round(settings.precision) : 4;
3647

3748
if(!fs.existsSync(VECTORMAP_DATA_RESULT_PATH)) {
3849
fs.mkdirSync(VECTORMAP_DATA_RESULT_PATH);
3950
}
4051

41-
processFiles('build/vectormap-sources', {
42-
output: VECTORMAP_DATA_RESULT_PATH,
43-
settings: 'build/vectormap-sources/_settings.js'
44-
}, function() {
45-
const files = fs.readdirSync(VECTORMAP_DATA_RESULT_PATH);
46-
47-
files.forEach(file => {
48-
const data = fs.readFileSync(path.join(VECTORMAP_DATA_RESULT_PATH, file), 'utf8');
49-
50-
stream.add(
51-
gulp.src('build/gulp/vectormapdata-template.jst')
52-
.pipe(template({ data: data }))
53-
.pipe(rename(file))
54-
.pipe(headerPipes.useStrict())
55-
.pipe(gulp.dest(VECTORMAP_DATA_RESULT_PATH))
56-
);
57-
});
52+
const sourceDir = path.resolve(VECTORMAP_SOURCES_PATH);
53+
const files = collectShpFiles(sourceDir);
54+
55+
files.forEach(name => {
56+
const shpBuffer = fs.readFileSync(path.join(sourceDir, name + '.shp'));
57+
const dbfBuffer = fs.readFileSync(path.join(sourceDir, name + '.dbf'));
58+
59+
const shapeData = parse(
60+
{ shp: toArrayBuffer(shpBuffer), dbf: toArrayBuffer(dbfBuffer) },
61+
{ precision },
62+
);
63+
64+
if(shapeData) {
65+
const content = name + ' = ' + JSON.stringify(shapeData) + ';';
66+
fs.writeFileSync(path.join(VECTORMAP_DATA_RESULT_PATH, name + '.js'), content);
67+
}
5868
});
69+
70+
const stream = merge();
71+
const dataFiles = fs.readdirSync(VECTORMAP_DATA_RESULT_PATH);
72+
73+
dataFiles.forEach(file => {
74+
const data = fs.readFileSync(path.join(VECTORMAP_DATA_RESULT_PATH, file), 'utf8');
75+
76+
stream.add(
77+
gulp.src('build/gulp/vectormapdata-template.jst')
78+
.pipe(template({ data: data }))
79+
.pipe(rename(file))
80+
.pipe(headerPipes.useStrict())
81+
.pipe(gulp.dest(VECTORMAP_DATA_RESULT_PATH))
82+
);
83+
});
84+
5985
return stream;
6086
}));
6187

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

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

76-
if(name === 'browser') {
77-
return stream.pipe(tap(file => {
78-
patchVectorMapUtilsStream(gulp.src('build/gulp/vectormaputils-template.jst')
79-
.pipe(template({ data: file.contents }))
80-
.pipe(rename(path.basename(file.path))), isMinify);
81-
}));
82-
}
83-
return patchVectorMapUtilsStream(stream, isMinify);
102+
return stream.pipe(tap(file => {
103+
patchVectorMapUtilsStream(gulp.src('build/gulp/vectormaputils-template.jst')
104+
.pipe(template({ data: file.contents }))
105+
.pipe(rename(path.basename(file.path))), isMinify);
106+
}));
84107
}
85108

86109
gulp.task('vectormap', gulp.series('vectormap-utils', 'vectormap-data'));

packages/devextreme/build/gulp/vectormaputils-template.jst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
} else if(typeof module === "object" && module.exports) {
77
factory(exports);
88
} else {
9-
var exports = root.DevExpress = root.DevExpress || {};
10-
exports = exports.viz = exports.viz || {};
11-
exports = exports.vectormaputils = {};
12-
factory(exports);
9+
var browserExports = root.DevExpress = root.DevExpress || {};
10+
browserExports = browserExports.viz = browserExports.viz || {};
11+
browserExports = browserExports.vectormaputils = {};
12+
factory(browserExports);
1313
}
1414
}(this, function(exports) {
1515
<%= data %>

packages/devextreme/js/viz/vector_map.utils/_settings.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,5 @@
99
"files": [
1010
"js-stream"
1111
]
12-
},
13-
"node": {
14-
"fileName": "dx.vectormaputils.node",
15-
"files": [
16-
"node-stream",
17-
"node-cmd"
18-
]
1912
}
2013
}

packages/devextreme/js/viz/vector_map.utils/node-cmd.js

Lines changed: 0 additions & 181 deletions
This file was deleted.

packages/devextreme/js/viz/vector_map.utils/node-stream.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/devextreme/ports.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"qunit": "20060",
3-
"vectormap-utils-tester": "20061"
2+
"qunit": "20060"
43
}

packages/devextreme/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@
685685
"{projectRoot}/build/gulp/vectormap.js"
686686
],
687687
"outputs": [
688+
"{projectRoot}/artifacts/js/vectormap-utils",
688689
"{projectRoot}/artifacts/js/vectormap-data"
689690
]
690691
},
@@ -732,7 +733,6 @@
732733
"{projectRoot}/build/gulp/vendor.js"
733734
],
734735
"outputs": [
735-
"{projectRoot}/artifacts/js/vectormap-utils",
736736
"{projectRoot}/artifacts/js/cldr"
737737
]
738738
},

packages/devextreme/testing/content/VectorMapData/_processFileContent.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/devextreme/testing/content/VectorMapData/_settings.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)