-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from LiamAttClarke/chore/linter-config
chore: adjust linter config
- Loading branch information
Showing
74 changed files
with
9,022 additions
and
9,581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
[*.{json,js,ts,html,css}] | ||
indent_style = space | ||
indent_size = 2 | ||
indent_size = 4 | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
max_line_length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
demo/main-bundle.js | ||
dist/* | ||
docs/* | ||
.eslintrc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,62 @@ | ||
const isProduction = process.env.NODE_ENV === 'production'; | ||
const isProduction = process.env.NODE_ENV === "production"; | ||
|
||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true, | ||
browser: true | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
sourceType: 'module', | ||
ecmaVersion: 2020, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
node: { | ||
extensions: ['.js', '.ts', '.d.ts'], | ||
paths: ['node_modules/', 'node_modules/@types/'], | ||
} | ||
} | ||
}, | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'airbnb-typescript/base', | ||
], | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
rules: { | ||
'no-console': isProduction ? 'error' : 'warn', | ||
'import/extensions': 'off', | ||
'@typescript-eslint/type-annotation-spacing': 2, | ||
} | ||
root: true, | ||
env: { | ||
node: true, | ||
browser: true | ||
}, | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
sourceType: "module", | ||
ecmaVersion: 2020, | ||
}, | ||
settings: { | ||
"import/resolver": { | ||
node: { | ||
extensions: [".js", ".ts", ".d.ts"], | ||
paths: ["node_modules/", "node_modules/@types/"], | ||
} | ||
} | ||
}, | ||
extends: [ | ||
"plugin:@typescript-eslint/recommended", | ||
"google", | ||
], | ||
plugins: [ | ||
"@typescript-eslint", | ||
], | ||
rules: { | ||
"no-console": isProduction ? 2 : 1, | ||
"import/extensions": 0, | ||
"@typescript-eslint/type-annotation-spacing": 2, | ||
"indent": ["error", 4], | ||
"max-len": ["error", 100], | ||
"quotes": ["error", "double"], | ||
"operator-linebreak": [2, "before"], | ||
"require-jsdoc": 0, | ||
"object-curly-spacing": [2, "always"], | ||
"valid-jsdoc": 0, | ||
}, | ||
overrides: [ | ||
{ | ||
files: [ | ||
"bin/**/*.js", | ||
"demo/**/*.js", | ||
], | ||
rules: { | ||
"@typescript-eslint/no-var-requires": 0, | ||
"no-console": 0, | ||
} | ||
}, | ||
{ | ||
files: [ | ||
"tests/**/*", | ||
], | ||
rules: { | ||
"max-len": 0 | ||
} | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,90 @@ | ||
#!/usr/bin/env node | ||
|
||
const commander = require('commander'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { convertSVG } = require('../dist'); | ||
const commander = require("commander"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { convertSVG } = require("../dist"); | ||
|
||
commander | ||
.version('0.0.0') | ||
.usage('<input> [outputPath] [options]') | ||
.option('-c, --center [center]', 'Geographic coordinate to center the SVG geometry around. (default: 0,0)') | ||
.option('-w, --width [width]', 'Width in metres (default: 1000e3 ie. 1000km)') | ||
.option('-b, --bearing [bearing]', 'Angle in degrees to rotate geometry clockwise around it\'s center. (default: 0)') | ||
.option('-t, --subdivide-threshold [subdivideThreshold]', 'Angle in degrees at which to subdivide curves. Decrease this number for smoother curves. (Default: 5)') | ||
.option('-p, --pretty', 'Pretty print output') | ||
.parse(process.argv); | ||
.version("0.0.0") | ||
.usage("<input> [outputPath] [options]") | ||
// eslint-disable-next-line max-len | ||
.option("-c, --center [center]", "Geographic coordinate to center the SVG geometry around. (default: 0,0)") | ||
.option("-w, --width [width]", "Width in metres (default: 1000e3 ie. 1000km)") | ||
// eslint-disable-next-line max-len | ||
.option("-b, --bearing [bearing]", "Angle in degrees to rotate geometry clockwise around it's center. (default: 0)") | ||
// eslint-disable-next-line max-len | ||
.option("-t, --subdivide-threshold [subdivideThreshold]", "Angle in degrees at which to subdivide curves. Decrease this number for smoother curves. (Default: 5)") | ||
.option("-p, --pretty", "Pretty print output") | ||
.parse(process.argv); | ||
|
||
const options = commander.opts(); | ||
|
||
// Validate arguments | ||
|
||
if (commander.args.length < 1) { | ||
console.error('No input file specified.'); | ||
process.exit(1); | ||
console.error("No input file specified."); | ||
process.exit(1); | ||
} | ||
|
||
if (!fs.statSync(commander.args[0]).isFile() || path.extname(commander.args[0]) !== '.svg') { | ||
console.error('Input argument must be an SVG file.'); | ||
process.exit(1); | ||
if (!fs.statSync(commander.args[0]).isFile() || path.extname(commander.args[0]) !== ".svg") { | ||
console.error("Input argument must be an SVG file."); | ||
process.exit(1); | ||
} | ||
|
||
if (options.center && !options.center.match(/(\-)?\d+(\.\d+)?\(\-)?\d+(\.\d+)?/)) { | ||
console.error('\'center\' must be in the form: {latitude},{longitude}'); | ||
console.error("'center' must be in the form: {latitude},{longitude}"); | ||
} | ||
|
||
if (options.width) { | ||
const width = parseFloat(options.width); | ||
if (!width || width <= 0) { | ||
console.error('\'scale\' must be greater than zero.'); | ||
process.exit(1); | ||
} | ||
const width = parseFloat(options.width); | ||
if (!width || width <= 0) { | ||
console.error("'scale' must be greater than zero."); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
if (options.subdivideThreshold && parseFloat(options.subdivideThreshold) <= 0) { | ||
console.error('\'subdivideThreshold\' must be greater than zero.'); | ||
process.exit(1); | ||
console.error("'subdivideThreshold' must be greater than zero."); | ||
process.exit(1); | ||
} | ||
|
||
// Process SVG | ||
|
||
const inputPath = commander.args[0]; | ||
const inputDir = path.dirname(inputPath); | ||
const outputFileName = path.basename(inputPath, '.svg') + '.geojson'; | ||
const outputFileName = path.basename(inputPath, ".svg") + ".geojson"; | ||
let outputPath; | ||
if (commander.args.length > 1) { | ||
outputPath = commander.args[1]; | ||
if (!path.extname(outputPath)) { | ||
outputPath = path.join(outputPath, outputFileName); | ||
} | ||
outputPath = commander.args[1]; | ||
if (!path.extname(outputPath)) { | ||
outputPath = path.join(outputPath, outputFileName); | ||
} | ||
} else { | ||
outputPath = path.join(inputDir, outputFileName); | ||
outputPath = path.join(inputDir, outputFileName); | ||
} | ||
|
||
const svg = fs.readFileSync(inputPath, 'utf8'); | ||
const svg = fs.readFileSync(inputPath, "utf8"); | ||
const convertOptions = {}; | ||
if (options.center) { | ||
convertOptions.center = options.center.split(',').map(coord => parseFloat(coord)); | ||
convertOptions.center = options.center.split(",").map((coord) => parseFloat(coord)); | ||
} | ||
if (options.width) { | ||
convertOptions.width = parseFloat(options.width); | ||
convertOptions.width = parseFloat(options.width); | ||
} | ||
if (options.wbearingidth) { | ||
convertOptions.bearing = parseFloat(options.bearing); | ||
convertOptions.bearing = parseFloat(options.bearing); | ||
} | ||
if (options.subdivideThreshold) { | ||
convertOptions.subdivideThreshold = parseFloat(options.subdivideThreshold); | ||
convertOptions.subdivideThreshold = parseFloat(options.subdivideThreshold); | ||
} | ||
try { | ||
const { geojson, errors } = convertSVG(svg, convertOptions) | ||
errors.forEach((e) => { | ||
console.warn(e); | ||
}); | ||
fs.writeFileSync(outputPath, JSON.stringify(geojson, null, options.pretty ? 2 : 0)); | ||
console.info('Converted SVG to GeoJSON.'); | ||
const { geojson, errors } = convertSVG(svg, convertOptions); | ||
errors.forEach((e) => { | ||
console.warn(e); | ||
}); | ||
fs.writeFileSync(outputPath, JSON.stringify(geojson, null, options.pretty ? 2 : 0)); | ||
console.info("Converted SVG to GeoJSON."); | ||
} catch (e) { | ||
console.error(e); | ||
console.error(e); | ||
} |
Oops, something went wrong.