重写了一下areaDebug的生成和引用

This commit is contained in:
Xu Chang 2022-10-15 20:51:31 +08:00
parent 3e4e6b5325
commit 189680e447
15 changed files with 131 additions and 62 deletions

3
.gitignore vendored
View File

@ -65,4 +65,5 @@ jspm_packages/
build
package-lock.json
src/general-app-domain
scripts/getAmapArea.ts
scripts/local
areaDebug.json

File diff suppressed because one or more lines are too long

36
lib/data/area.d.ts vendored
View File

@ -1,35 +1 @@
declare const area: ({
code: string;
level: string;
parentId: null;
name: string;
depth: number;
id: string;
center: {
type: string;
coordinate: number[];
};
} | {
code: string;
level: string;
parentId: string;
name: string;
depth: number;
id: string;
center: {
type: string;
coordinate: number[];
};
} | {
code: number;
level: string;
parentId: string;
name: string;
depth: number;
id: number;
center: {
type: string;
coordinate: number[];
};
})[];
export { area, };
export { area, } from './area.dev';

24
lib/data/area.dev.d.ts vendored Normal file
View File

@ -0,0 +1,24 @@
declare const area: ({
code: string;
level: string;
parentId: string;
name: string;
depth: number;
id: string;
center: {
type: string;
coordinate: number[];
};
} | {
code: string;
level: string;
parentId: null;
name: string;
depth: number;
id: string;
center: {
type: string;
coordinate: number[];
};
})[];
export { area, };

8
lib/data/area.dev.js Normal file
View File

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.area = void 0;
var tslib_1 = require("tslib");
// import area2 from './area.json';
var areaDebug_json_1 = tslib_1.__importDefault(require("./areaDebug.json"));
var area = areaDebug_json_1.default;
exports.area = area;

View File

@ -1,8 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.area = void 0;
var tslib_1 = require("tslib");
// import area2 from './area.json';
var area_debug_json_1 = tslib_1.__importDefault(require("./area-debug.json"));
var area = area_debug_json_1.default;
exports.area = area;
console.log('走不到这里');
var area_dev_1 = require("./area.dev");
Object.defineProperty(exports, "area", { enumerable: true, get: function () { return area_dev_1.area; } });

File diff suppressed because one or more lines are too long

3
lib/data/area.prod.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
import { CreateOperationData } from '../general-app-domain/Area/Schema';
declare const area: CreateOperationData[];
export { area, };

5
lib/data/area.prod.js Normal file
View File

@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.area = void 0;
var area = [];
exports.area = area;

15
lib/data/index.d.ts vendored
View File

@ -9,7 +9,7 @@ declare const _default: {
area: ({
code: string;
level: string;
parentId: null;
parentId: string;
name: string;
depth: number;
id: string;
@ -20,7 +20,7 @@ declare const _default: {
} | {
code: string;
level: string;
parentId: string;
parentId: null;
name: string;
depth: number;
id: string;
@ -28,17 +28,6 @@ declare const _default: {
type: string;
coordinate: number[];
};
} | {
code: number;
level: string;
parentId: string;
name: string;
depth: number;
id: number;
center: {
type: string;
coordinate: number[];
};
})[];
};
export default _default;

View File

@ -67,7 +67,7 @@
"clean": "rimraf lib/*",
"copy-files": "copyfiles -u 1 src/**/*.less lib/ & copyfiles -u 1 src/**/*.wxml lib/ & copyfiles -u 1 src/**/*.wxs lib/ & copyfiles -u 1 src/miniprogram_npm/**/*.js lib/ ",
"build": "tsc && npm run copy-files",
"get:area": "ts-node ./scripts/getAmapArea.ts",
"gen:areaDebug": "ts-node ./scripts/generateAreaDebug.ts",
"clean:dir": "ts-node ./scripts/cleanDtsAndJs",
"test": "ts-node ./test/test.ts",
"prepare": "rimraf node_modules/react & rimraf node_modules/react-dom & rimraf node_modules/react-router"

View File

@ -0,0 +1,68 @@
import areaTotal from './area.json';
import fs from 'fs';
const provinceName = process.argv[2] || '浙江省';
const level = process.argv[3] || 'district';
const cityNumber = process.argv[4] ? parseInt(process.argv[4]) : 2;
type Area = {
id: string;
level: 'country' | 'province' | 'city' | 'district' | 'street';
parentId: string;
name: string;
};
function outputData(output: Area[]) {
fs.writeFileSync(`${__dirname}/../src/data/areaDebug.json`, JSON.stringify(output));
console.log(`输出areaDebug.json完成共输出了${output.length}行数据`);
}
// 输出
function main() {
console.log(`准备输出${provinceName}的前${cityNumber}个市的地区数据,输出到${level}层为止`);
const areaTotal2 = areaTotal as Area[];
const output = [] as Area[];
const province = areaTotal2.find(
ele => ele.level === 'province' && ele.name === provinceName
);
if (!province) {
console.error(`找不到名为${provinceName}的省`);
return;
}
output.push(province);
const country = areaTotal2.find(
ele => ele.id === province.parentId
);
output.push(country!);
const cities = areaTotal2.filter(
ele => ele.parentId === province.id
).sort(
(ele1, ele2) => parseInt(ele1.id) - parseInt(ele2.id)
);
const cities2 = cities.slice(0, cityNumber);
output.push(...cities2);
if (level === 'city') {
outputData(output);
return;
}
const districts = areaTotal2.filter(
ele => cities2.find(city => ele.parentId === city.id)
);
output.push(...districts);
if (level === 'district') {
outputData(output);
return;
}
const streets = areaTotal2.filter(
ele => districts.find(district => ele.parentId === district.id)
);
output.push(...streets);
outputData(output);
}
main();

7
src/data/area.dev.ts Normal file
View File

@ -0,0 +1,7 @@
// import area2 from './area.json';
import area_debug from './areaDebug.json';
const area = area_debug;
export {
area,
};

5
src/data/area.prod.ts Normal file
View File

@ -0,0 +1,5 @@
import { CreateOperationData } from '../general-app-domain/Area/Schema';
const area = [] as CreateOperationData[];
export {
area,
};

View File

@ -1,7 +1,4 @@
// import area2 from './area.json';
import area_debug from './area-debug.json';
const area = area_debug;
console.log('走不到这里');
export {
area,
};
} from './area.dev';