Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a35851

Browse files
committed
feat: genMaps script
1 parent8bf9068 commit2a35851

File tree

11 files changed

+734
-3
lines changed

11 files changed

+734
-3
lines changed

‎.eslintignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
next.config.js
44
blog
55
snippets
6-
next-seo.config.js
6+
next-seo.config.js
7+
genMapFiles.js

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
3-
.next
3+
.next
4+
temp

‎components/Landing/MapShowContainer.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ export const mapDt: MapShowcaseType[] = [
4747
text:'Germany, Based on Mercator Projection.',
4848
link:'/germany'
4949
},
50+
{
51+
name:'France',
52+
text:'France, Based on Mercator Projection.',
53+
link:'/france'
54+
},
55+
{
56+
name:'Brazil',
57+
text:'Brazil, Based on Mercator Projection.',
58+
link:'/brazil'
59+
},
5060
{
5161
name:'Australia',
5262
text:'Australia, Based on Mercator Projection.',

‎data/Brazil/Brazil.map.tsx‎

Lines changed: 43 additions & 0 deletions
Large diffs are not rendered by default.

‎data/Brazil/BrazilStateCodes.tsx‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
exportconstBrazilStateCodes={
2+
"BRA1294":"Goiás",
3+
"BRA1311":"São Paulo",
4+
"BRA1313":"Pernambuco",
5+
"BRA576":"Acre",
6+
"BRA592":"Amazonas",
7+
"BRA593":"Maranhão",
8+
"BRA594":"Pará",
9+
"BRA595":"Rondônia",
10+
"BRA596":"Tocantins",
11+
"BRA599":"Distrito Federal",
12+
"BRA600":"Mato Grosso do Sul",
13+
"BRA601":"Minas Gerais",
14+
"BRA602":"Mato Grosso",
15+
"BRA612":"Rio Grande do Sul",
16+
"BRA613":"Paraná",
17+
"BRA614":"Santa Catarina",
18+
"BRA621":"Ceará",
19+
"BRA622":"Piauí",
20+
"BRA623":"Alagoas",
21+
"BRA624":"Bahia",
22+
"BRA625":"Espírito Santo",
23+
"BRA626":"Paraíba",
24+
"BRA627":"Rio de Janeiro",
25+
"BRA628":"Rio Grande do Norte",
26+
"BRA629":"Sergipe",
27+
"BRA670":"Roraima",
28+
"BRA681":"Amapá"
29+
}

‎data/France/France.map.tsx‎

Lines changed: 397 additions & 0 deletions
Large diffs are not rendered by default.

‎data/France/FranceStateCodes.tsx‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
exportconstFranceStateCodes={
2+
FRA5262:'Ain',
3+
FRA5263:'Aisne',
4+
FRA5264:'Allier',
5+
FRA5265:'Alpes-de-Haute-Provence',
6+
FRA5266:'Alpes-Maritimes',
7+
FRA5267:'Ardèche',
8+
FRA5268:'Ardennes',
9+
FRA5269:'Ariège',
10+
FRA5270:'Aube',
11+
FRA5271:'Aude',
12+
FRA5272:'Aveyron',
13+
FRA5273:'Bas-Rhin',
14+
FRA5274:'Bouches-du-Rhône',
15+
FRA5275:'Calvados',
16+
FRA5276:'Cantal',
17+
FRA5277:'Charente',
18+
FRA5278:'Charente-Maritime',
19+
FRA5279:'Cher',
20+
FRA5280:'Corrèze',
21+
FRA5281:'Corse-du-Sud',
22+
FRA5282:"Côte-d'Or",
23+
FRA5283:"Côtes-d'Armor",
24+
FRA5284:'Creuse',
25+
FRA5285:'Deux-Sèvres',
26+
FRA5286:'Dordogne',
27+
FRA5287:'Doubs',
28+
FRA5288:'Drôme',
29+
FRA5289:'Essonne',
30+
FRA5290:'Eure',
31+
FRA5291:'Eure-et-Loir',
32+
FRA5292:'Finistère',
33+
FRA5293:'Gard',
34+
FRA5294:'Gers',
35+
FRA5295:'Gironde',
36+
FRA5296:'Haute-Rhin',
37+
FRA5297:'Haute-Corse',
38+
FRA5298:'Haute-Garonne',
39+
FRA5299:'Haute-Loire',
40+
FRA5300:'Haute-Marne',
41+
FRA5301:'Haute-Saône',
42+
FRA5302:'Haute-Savoie',
43+
FRA5303:'Haute-Vienne',
44+
FRA5304:'Hautes-Alpes',
45+
FRA5305:'Hautes-Pyrénées',
46+
FRA5306:'Hauts-de-Seine',
47+
FRA5307:'Hérault',
48+
FRA5308:'Ille-et-Vilaine',
49+
FRA5309:'Indre',
50+
FRA5310:'Indre-et-Loire',
51+
FRA5311:'Isère',
52+
FRA5312:'Jura',
53+
FRA5313:'Landes',
54+
FRA5314:'Loir-et-Cher',
55+
FRA5315:'Loire',
56+
FRA5316:'Loire-Atlantique',
57+
FRA5317:'Loiret',
58+
FRA5318:'Lot',
59+
FRA5319:'Lot-et-Garonne',
60+
FRA5320:'Lozère',
61+
FRA5321:'Maine-et-Loire',
62+
FRA5322:'Manche',
63+
FRA5323:'Marne',
64+
FRA5324:'Mayenne',
65+
FRA5325:'Meurhe-et-Moselle',
66+
FRA5326:'Meuse',
67+
FRA5327:'Morbihan',
68+
FRA5328:'Moselle',
69+
FRA5329:'Nièvre',
70+
FRA5330:'Nord',
71+
FRA5331:'Oise',
72+
FRA5332:'Orne',
73+
FRA5333:'Paris',
74+
FRA5334:'Pas-de-Calais',
75+
FRA5335:'Puy-de-Dôme',
76+
FRA5336:'Pyrénées-Atlantiques',
77+
FRA5337:'Pyrénées-Orientales',
78+
FRA5338:'Rhône',
79+
FRA5339:'Saône-et-Loire',
80+
FRA5340:'Sarthe',
81+
FRA5341:'Savoie',
82+
FRA5342:'Seien-et-Marne',
83+
FRA5343:'Seine-Maritime',
84+
FRA5344:'Seine-Saint-Denis',
85+
FRA5345:'Somme',
86+
FRA5346:'Tarn',
87+
FRA5347:'Tarn-et-Garonne',
88+
FRA5348:'Territoire de Belfort',
89+
FRA5349:"Val-d'Oise",
90+
FRA5350:'Val-de-Marne',
91+
FRA5351:'Var',
92+
FRA5352:'Vaucluse',
93+
FRA5353:'Vendée',
94+
FRA5354:'Vienne',
95+
FRA5355:'Vosges',
96+
FRA5356:'Yonne',
97+
FRA5357:'Yvelines'
98+
};

‎genMapFiles.js‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
constchalk=require('chalk');
2+
constfs=require('fs');
3+
4+
constcountry=process.argv[2];
5+
constviewBoxW=process.argv[3];
6+
constviewBoxH=process.argv[3];
7+
8+
constcapFirst=(str)=>str.charAt(0).toUpperCase()+str.slice(1);
9+
10+
constcapName=capFirst(country);
11+
12+
constdir=`./data/${capName}`;
13+
14+
constsvgData=fs.readFileSync(`./temp/${country}.svg`,'utf8',(err,data)=>{
15+
if(err){
16+
console.error(err);
17+
return;
18+
}
19+
returndata;
20+
});
21+
conststateData=fs.readFileSync(`./temp/${country}.data`,'utf8',(err,data)=>{
22+
if(err){
23+
console.error(err);
24+
return;
25+
}
26+
returndata;
27+
});
28+
29+
constfilesArr=[
30+
{
31+
file:`${capName}.map.tsx`,
32+
content:`
33+
import MapLayout from '@/layouts/MapLayout';
34+
import React from 'react';
35+
import {${capName}StateCodes } from './${capName}StateCodes';
36+
37+
const${capName}Map = () => (
38+
<MapLayout name="${country}" width={650} viewBox={[0, 0,${viewBoxW},${viewBoxH}]} stateCodes={${capName}StateCodes}>
39+
${svgData}
40+
</MapLayout>
41+
);
42+
43+
export default${capName}Map;
44+
`
45+
},
46+
{
47+
file:`${capName}StateCodes.tsx`,
48+
content:`export const${capName}StateCodes ={
49+
${stateData}
50+
}`
51+
}
52+
];
53+
54+
constgenTemplate=(country)=>{
55+
// Create folder
56+
if(!fs.existsSync(dir)){
57+
fs.mkdirSync(dir);
58+
filesArr.forEach((el)=>{
59+
fs.writeFile(
60+
`${dir}/${el.file}`,
61+
el.content,
62+
{
63+
encoding:'utf8',
64+
flag:'w',
65+
mode:0o666
66+
},
67+
(err)=>{
68+
if(err)console.log(err);
69+
else{
70+
console.log(chalk.green(`Created:${chalk.blue.bold(el.file)}`));
71+
}
72+
}
73+
);
74+
});
75+
// Generate Pages file
76+
fs.writeFile(
77+
`./pages/${country}.tsx`,
78+
`import ControlContainer from '@/components/ControlContainer';
79+
import${capName}Map from '@/data/${capName}/${capName}.map';
80+
import {${capName}StateCodes } from '@/data/${capName}/${capName}StateCodes';
81+
import MainLayout from '@/layouts/MainLayout';
82+
import React from 'react';
83+
84+
const${capName} = () => (
85+
<MainLayout>
86+
<div className="flex justify-between container">
87+
<ControlContainer stateCodes={${capName}StateCodes} mapId="${country}-map" />
88+
<${capName}Map />
89+
</div>
90+
</MainLayout>
91+
);
92+
93+
export default${capName};`,
94+
{
95+
encoding:'utf8',
96+
flag:'w',
97+
mode:0o666
98+
},
99+
(err)=>{
100+
if(err)console.log(err);
101+
else{
102+
console.log(chalk.green(`Created:${chalk.blue.bold(`pages/${country}.tsx`)}`));
103+
}
104+
}
105+
);
106+
}else{
107+
console.log(chalk.red('Folder Already Exists'));
108+
console.log(chalk.red('Delete and Run the Script Again '));
109+
}
110+
};
111+
112+
constnoArgsFunc=()=>{
113+
console.log(chalk.red(`Please Pass Map Name as an Argument.`));
114+
console.log(chalk.blue('Example :'));
115+
console.log(chalk.green('yarn generate india 1000 1000 \n'));
116+
};
117+
118+
country!==undefined ?genTemplate(country.toLowerCase()) :noArgsFunc();
119+
module.exports=genTemplate;

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"build":"next build",
2727
"start":"next start",
2828
"lint":"eslint\"{components,lib}/**/*.{js,ts,tsx}\"",
29-
"format":"prettier --write 'components/**/*.{js,jsxts,tsx,scss,css,json}'"
29+
"format":"prettier --write 'components/**/*.{js,jsxts,tsx,scss,css,json}'",
30+
"generate":"node ./genMapFiles.js $*"
3031
},
3132
"files": [
3233
"/dist",

‎pages/brazil.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
importControlContainerfrom'@/components/ControlContainer';
2+
importBrazilMapfrom'@/data/Brazil/Brazil.map';
3+
import{BrazilStateCodes}from'@/data/Brazil/BrazilStateCodes';
4+
importMainLayoutfrom'@/layouts/MainLayout';
5+
importReactfrom'react';
6+
7+
constBrazil=()=>(
8+
<MainLayout>
9+
<divclassName="flex justify-between container">
10+
<ControlContainerstateCodes={BrazilStateCodes}mapId="brazil-map"/>
11+
<BrazilMap/>
12+
</div>
13+
</MainLayout>
14+
);
15+
16+
exportdefaultBrazil;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp