Skip to content

Commit fb79927

Browse files
committed
Blindly do some magics with extensions before publishing olcs
1 parent 91b6b7a commit fb79927

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

buildtools/fix_paths.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
function handleFile(filePath) {
5+
fs.readFile(filePath, 'utf-8', (error, content) => {
6+
if (error) {
7+
console.error('Error reading the file:', error);
8+
return;
9+
}
10+
const split = content.split('\n');
11+
let changed = false;
12+
const newSplit = split.map((line) => {
13+
if (!line.startsWith('import') || line.endsWith(".js';") || line.includes("from 'cesium")) {
14+
return line;
15+
}
16+
let newline = undefined;
17+
if (line.endsWith(".ts';")) {
18+
newline = line.replace(".ts';", ".js';");
19+
} else if (line.includes("from './")) {
20+
newline = line.replace("';", ".js';");
21+
} else {
22+
console.error('XX', filePath, line);
23+
throw new Error('pb', line);
24+
}
25+
console.log('changed:', line, '->', newline);
26+
changed = true;
27+
return newline;
28+
});
29+
if (changed) {
30+
fs.writeFileSync(filePath, newSplit.join('\n'), {
31+
encoding: 'utf-8'
32+
});
33+
console.log('wrote', filePath);
34+
}
35+
});
36+
}
37+
38+
function listFilesRecursively(dir) {
39+
const files = fs.readdirSync(dir);
40+
41+
files.forEach((file) => {
42+
const filePath = path.join(dir, file);
43+
44+
const stat = fs.statSync(filePath);
45+
46+
if (stat.isFile()) {
47+
handleFile(filePath);
48+
} else if (stat.isDirectory()) {
49+
listFilesRecursively(filePath);
50+
}
51+
});
52+
}
53+
54+
const startingDirectory = process.argv[2];
55+
listFilesRecursively(startingDirectory);

buildtools/release.sh

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cp ./css/olcs.css $BUILD
1818
cp package.json $BUILD
1919
sed -i 's/ol-cesium/olcs/g' $BUILD/package.json
2020
sed -i '/"main"/d' $BUILD/package.json
21+
node buildtools/fix_paths.js $BUILD
2122

2223
echo
2324
ls $BUILD

src/olcs/RasterSynchronizer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
* @module olcs.RasterSynchronizer
33
*/
4-
import Map from 'ol/Map';
4+
import Map from 'ol/Map.js';
55
import {getUid, stableSort} from './util.js';
66
import olcsAbstractSynchronizer from './AbstractSynchronizer';
77
import {type LayerWithParents, tileLayerToImageryLayer, updateCesiumLayerProperties} from './core';
88
import type {Scene, ImageryLayer, ImageryLayerCollection} from 'cesium';
9-
import type BaseLayer from 'ol/layer/Base';
10-
import type Projection from 'ol/proj/Projection';
11-
import BaseVectorLayer from 'ol/layer/BaseVector';
9+
import type BaseLayer from 'ol/layer/Base.js';
10+
import type Projection from 'ol/proj/Projection.js';
11+
import BaseVectorLayer from 'ol/layer/BaseVector.js';
1212
import LayerGroup from 'ol/layer/Group.js';
1313

1414
class RasterSynchronizer extends olcsAbstractSynchronizer<ImageryLayer> {

0 commit comments

Comments
 (0)