diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 669dc66..0000000 --- a/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = true - -[*.js] -indent_style = space -indent_size = 2 \ No newline at end of file diff --git a/.eslintignore b/.eslintignore index b8c2665..e69de29 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +0,0 @@ -/lib -/examples/commonjs/satellite-js-migration.js -/examples/mjs/satellite-js-migration.mjs \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3455d50..b2ad347 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ .idea .vscode/settings.json coverage -/commonjs/ -/lib/ +dist node_modules *.log diff --git a/.npmignore b/.npmignore index d9cd177..fe2bccb 100644 --- a/.npmignore +++ b/.npmignore @@ -1,14 +1,13 @@ +# Directories .github .vscode coverage examples node_modules scripts -src/* test # Files -.editorconfig .eslintignore .eslintrc .gitattributes @@ -16,9 +15,7 @@ test .npmignore .prettierrc babel.config.js -codecov.yml jest.config.js package-lock.json -sandbox.html tsconfig.* diff --git a/.prettierrc b/.prettierrc index 5d4c011..b7d285b 100644 --- a/.prettierrc +++ b/.prettierrc @@ -13,5 +13,8 @@ "proseWrap": "always", "htmlWhitespaceSensitivity": "ignore", "endOfLine": "lf", - "embeddedLanguageFormatting": "off" + "embeddedLanguageFormatting": "off", + "plugins": [ + "prettier-plugin-organize-imports" + ] } \ No newline at end of file diff --git a/examples/README.md b/examples/README.md index 9d1eb9d..ce5533b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,14 +2,10 @@ Run the examples using tsx as below: -## Typescript +## TypeScript npx tsx ./examples/typescript/satellite-js-migration.ts -## ES6 Module +## JavaScript -npx tsx ./examples/es6/satellite-js-migration.mjs - -## CommonJs - -node ./examples/commonjs/satellite-js-migration.cjs +npx tsx ./examples/javascript/satellite-js-migration.mjs diff --git a/examples/commonjs/satellite-js-migration.cjs b/examples/commonjs/satellite-js-migration.cjs deleted file mode 100644 index 0cd0859..0000000 --- a/examples/commonjs/satellite-js-migration.cjs +++ /dev/null @@ -1,120 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* eslint-disable multiline-comment-style */ -/* eslint-disable no-console */ - -const { Satellite, Sgp4, GroundPosition, calcGmst, DEG2RAD } = require('../../commonjs/index.js'); - -// Example Date -const exampleDate = new Date(1705109326817); - -// Sample TLE -const tle1 = '1 56006U 23042W 24012.45049317 .00000296 00000-0 36967-4 0 9992'; -const tle2 = '2 56006 43.0043 13.3620 0001137 267.5965 92.4747 15.02542972 44491'; - -// Initialize a Satellite Object -const satellite = new Satellite({ - tle1, - tle2, -}); - -// You can still propagate a satellite using time since epoch (in minutes), but it's not recommended. -const timeSinceTleEpochMinutes = 10; -let positionAndVelocity = Sgp4.propagate(satellite.satrec, timeSinceTleEpochMinutes); - -// Use a Date object instead -positionAndVelocity = satellite.eci(new Date(2024, 0, 1)); -// Or use the current time -positionAndVelocity = satellite.eci(); - -// The position_velocity result is a key-value pair of ECI coordinates. -// These are the base results from which all other coordinates are derived. -const positionEci = positionAndVelocity.position; -const velocityEci = positionAndVelocity.velocity; - -// Set the Observer at 71°W, 41°N, 0.37 km altitude using DEGREES because who likes using Radians? -const observer = new GroundPosition({ - lon: -71.0308, - lat: 41.9613422, - alt: 0.37, -}); - -// You can still calculate GMST if you want to, but unlike satellite.js it's not required. -const { gmst, j } = calcGmst(new Date()); - -// You can get ECF, Geodetic, Look Angles, and Doppler Factor. -const positionEcf = satellite.ecf(exampleDate); -const observerEcf = observer.ecf(); -const positionGd = satellite.lla(exampleDate); -const lookAngles = satellite.rae(observer, exampleDate); -// This never worked in satellite.js, but it does now! -const uplinkFreq = 420e6; -const dopplerFactor = satellite.dopplerFactor(observer, exampleDate); -let dopplerShiftedFrequency = uplinkFreq * dopplerFactor; - -dopplerShiftedFrequency = satellite.applyDoppler(uplinkFreq, observer, exampleDate); - -// The coordinates are all stored in strongly typed key-value pairs. -// ECI and ECF are accessed by `x`, `y`, `z` properties. -const position = satellite.eci(exampleDate).position; -const satelliteX = position.x; -const satelliteY = position.y; -const satelliteZ = position.z; - -// Look Angles may be accessed by `azimuth`, `elevation`, `range` properties. -const azimuth = lookAngles.azimuth; // Radians -const azimuthDegrees = lookAngles.azimuthDegrees; // Degrees -const elevation = lookAngles.elevation; // Radians -const elevationDegrees = lookAngles.elevationDegrees; // Degrees -const rangeSat = lookAngles.range; // Kilometers -const rangeRate = lookAngles.rangeRate; // Kilometers/Second - -// There is a built in cache to allow fast retrieval of repeated calculations. -// This means you can make repeat calls to `.rae()` for minimal performance hit. -const rangeCache = satellite.rae(observer, exampleDate).range; -const azimuthCached = satellite.rae(observer, exampleDate).azimuth; -const elevationCached = satellite.rae(observer, exampleDate).elevation; -const latitudeCached = satellite.lla(exampleDate).lat; -const longitudeCached = satellite.lla(exampleDate).lon; -const heightCached = satellite.lla(exampleDate).alt; - -// Geodetic coords are accessed via `longitude`, `latitude`, `height`. -const longitude = positionGd.lon; // longitude is in degrees -const latitude = positionGd.lat; // latitude is in degrees -const height = positionGd.alt; // height is in kilometers - -// Convert the degrees to radians if you want. -const longitudeRad = longitude * DEG2RAD; -const latitudeRad = latitude * DEG2RAD; - -// There is no need to use the units seen in TypeScript examples. -// const longitudeRad = (longitude * DEG2RAD) as Radians; -// const latitudeRad = (latitude * DEG2RAD) as Radians; - -console.log('Satellite.js Migration Example'); -console.log('======================================'); -console.log('TLE: ', tle1); -console.log(' ', tle2); -console.log('======================================'); -console.log('Position (ECI):'); -console.log(' x: ', satelliteX); -console.log(' y: ', satelliteY); -console.log(' z: ', satelliteZ); -console.log('Position (ECF):'); -console.log(' x: ', positionEcf.x); -console.log(' y: ', positionEcf.y); -console.log(' z: ', positionEcf.z); -console.log('Position (Geodetic):'); -console.log(' longitude: ', longitude); -console.log(' latitude: ', latitude); -console.log(' height: ', height); -console.log('Look Angles:'); -console.log(' azimuth: ', azimuthDegrees); -console.log(' elevation: ', elevationDegrees); -console.log(' rangeSat: ', rangeSat); -console.log(' rangeRate: ', rangeRate); -console.log('Doppler Factor:'); -console.log(' dopplerFactor: ', dopplerFactor); -dopplerShiftedFrequency /= 1e6; // Hz to MHz -console.log(' 420MHz: ', `${dopplerShiftedFrequency.toPrecision(6)} MHz`); -console.log('======================================'); diff --git a/examples/es6/satellite-js-migration.mjs b/examples/javascript/satellite-js-migration.mjs similarity index 99% rename from examples/es6/satellite-js-migration.mjs rename to examples/javascript/satellite-js-migration.mjs index 38f24dc..f75449b 100644 --- a/examples/es6/satellite-js-migration.mjs +++ b/examples/javascript/satellite-js-migration.mjs @@ -3,7 +3,7 @@ /* eslint-disable multiline-comment-style */ /* eslint-disable no-console */ -import { calcGmst, DEG2RAD, GroundPosition, Satellite, Sgp4 } from '../../lib/index.js'; +import { calcGmst, DEG2RAD, GroundPosition, Satellite, Sgp4 } from '../../dist/index.js'; // Example Date const exampleDate = new Date(1705109326817); diff --git a/package-lock.json b/package-lock.json index 0f9884d..ccb9f94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,11 +23,8 @@ "jest": "^28.1.3", "prettier": "^3.2.1", "prettier-plugin-organize-imports": "^3.2.3", - "tsconfig-paths": "^4.2.0", "tsx": "^4.7.0", - "ttypescript": "^1.5.15", - "typescript": "^4.9.5", - "typescript-transform-paths": "^3.4.6" + "typescript": "^4.9.5" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -1831,6 +1828,7 @@ "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", "dev": true, + "optional": true, "peer": true, "dependencies": { "@jridgewell/trace-mapping": "0.3.9" @@ -1844,6 +1842,7 @@ "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", "dev": true, + "optional": true, "peer": true, "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", @@ -4278,6 +4277,7 @@ "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", "dev": true, + "optional": true, "peer": true }, "node_modules/@tsconfig/node12": { @@ -4285,6 +4285,7 @@ "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", "dev": true, + "optional": true, "peer": true }, "node_modules/@tsconfig/node14": { @@ -4292,6 +4293,7 @@ "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", "dev": true, + "optional": true, "peer": true }, "node_modules/@tsconfig/node16": { @@ -4299,6 +4301,7 @@ "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true, + "optional": true, "peer": true }, "node_modules/@types/babel__core": { @@ -4937,6 +4940,7 @@ "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true, + "optional": true, "peer": true, "engines": { "node": ">=0.4.0" @@ -5061,6 +5065,7 @@ "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true, + "optional": true, "peer": true }, "node_modules/argparse": { @@ -5620,6 +5625,7 @@ "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true, + "optional": true, "peer": true }, "node_modules/cross-spawn": { @@ -5688,6 +5694,7 @@ "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true, + "optional": true, "peer": true, "engines": { "node": ">=0.3.1" @@ -10236,6 +10243,7 @@ "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true, + "optional": true, "peer": true }, "node_modules/makeerror": { @@ -11406,6 +11414,7 @@ "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, + "optional": true, "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", @@ -11445,29 +11454,6 @@ } } }, - "node_modules/tsconfig-paths": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", - "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", - "dev": true, - "dependencies": { - "json5": "^2.2.2", - "minimist": "^1.2.6", - "strip-bom": "^3.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/tsconfig-paths/node_modules/strip-bom": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -11494,23 +11480,6 @@ "fsevents": "~2.3.3" } }, - "node_modules/ttypescript": { - "version": "1.5.15", - "resolved": "https://registry.npmjs.org/ttypescript/-/ttypescript-1.5.15.tgz", - "integrity": "sha512-48ykDNHzFnPMnv4hYX1P8Q84TvCZyL1QlFxeuxsuZ48X2+ameBgPenvmCkHJtoOSxpoWTWi8NcgNrRnVDOmfSg==", - "dev": true, - "dependencies": { - "resolve": ">=1.9.0" - }, - "bin": { - "ttsc": "bin/tsc", - "ttsserver": "bin/tsserver" - }, - "peerDependencies": { - "ts-node": ">=8.0.2", - "typescript": ">=3.2.2" - } - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -11557,18 +11526,6 @@ "node": ">=4.2.0" } }, - "node_modules/typescript-transform-paths": { - "version": "3.4.6", - "resolved": "https://registry.npmjs.org/typescript-transform-paths/-/typescript-transform-paths-3.4.6.tgz", - "integrity": "sha512-qdgpCk9oRHkIBhznxaHAapCFapJt5e4FbFik7Y4qdqtp6VyC3smAIPoDEIkjZ2eiF7x5+QxUPYNwJAtw0thsTw==", - "dev": true, - "dependencies": { - "minimatch": "^3.0.4" - }, - "peerDependencies": { - "typescript": ">=3.6.5" - } - }, "node_modules/uglify-js": { "version": "3.12.4", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.4.tgz", @@ -11666,6 +11623,7 @@ "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true, + "optional": true, "peer": true }, "node_modules/v8-to-istanbul": { @@ -11929,6 +11887,7 @@ "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true, + "optional": true, "peer": true, "engines": { "node": ">=6" diff --git a/package.json b/package.json index ef8b19c..30774c1 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,7 @@ "type": "module", "description": "Orbital Object Toolkit. A modern typed replacement for satellite.js including SGP4 propagation, TLE parsing, Sun and Moon calculations, and more.", "scripts": { - "js": "npx ttsc -p tsconfig.build.json -m esnext", - "cjs": "npx ttsc -p tsconfig.c.json -m commonjs", - "build": "node ./scripts/cleanup.mjs && npm run js && npm run cjs && node ./scripts/makeMjs.mjs", + "build": "node ./scripts/cleanup.mjs && npx tsc -p tsconfig.build.json -m esnext", "lint": "npx eslint src", "lint:fix": "npx eslint src --fix", "test": "jest", @@ -52,11 +50,8 @@ "jest": "^28.1.3", "prettier": "^3.2.1", "prettier-plugin-organize-imports": "^3.2.3", - "tsconfig-paths": "^4.2.0", "tsx": "^4.7.0", - "ttypescript": "^1.5.15", - "typescript": "^4.9.5", - "typescript-transform-paths": "^3.4.6" + "typescript": "^4.9.5" }, "homepage": "https://github.com/thkruz/ootk" } \ No newline at end of file diff --git a/scripts/cleanup.mjs b/scripts/cleanup.mjs index 7e209e6..0d6b859 100644 --- a/scripts/cleanup.mjs +++ b/scripts/cleanup.mjs @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { rmSync } from 'fs'; console.log('Removing ./lib...'); @@ -6,10 +7,3 @@ try { } catch (error) { // Intentionally left blank } - -console.log('Removing ./commonjs...'); -try { - rmSync('./commonjs', { recursive: true }); -} catch (error) { - // Intentionally left blank -} diff --git a/scripts/makeMjs.mjs b/scripts/makeMjs.mjs deleted file mode 100644 index e6db7e7..0000000 --- a/scripts/makeMjs.mjs +++ /dev/null @@ -1,7 +0,0 @@ -import { cpSync } from 'fs'; - -cpSync('./lib/index.js', './lib/index.mjs'); -cpSync('./lib/index.js.map', './lib/index.mjs.map'); -cpSync('./lib/index.d.ts', './lib/index.d.mts'); - -cpSync('./scripts/package.commonjs.json', './commonjs/package.json'); diff --git a/scripts/package.commonjs.json b/scripts/package.commonjs.json deleted file mode 100644 index c9a4422..0000000 --- a/scripts/package.commonjs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "commonjs" -} \ No newline at end of file diff --git a/tsconfig.build.json b/tsconfig.build.json index 6263796..34bd0c1 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,14 +1,13 @@ /** - * This is the tsconfig extension that only applies to webpack. + * This is the tsconfig extension that only applies to ES Modules. */ { "extends": "./tsconfig.base.json", "compilerOptions": { - "outDir": "./lib" /* Redirect output structure to the directory. */, + "outDir": "./dist", "target": "ES2022", "module": "ESNext", - "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, - "plugins": [{ "transform": "typescript-transform-paths" }], + "rootDir": "./src", "declaration": true, "isolatedModules": true, "strict": true diff --git a/tsconfig.c.json b/tsconfig.c.json deleted file mode 100644 index 3c3a77c..0000000 --- a/tsconfig.c.json +++ /dev/null @@ -1,17 +0,0 @@ -/** - * This is the tsconfig extension that only applies to webpack. - */ -{ - "extends": "./tsconfig.base.json", - "compilerOptions": { - "outDir": "./commonjs" /* Redirect output structure to the directory. */, - "target": "ES2022", - "module": "CommonJS", - "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, - "plugins": [{ "transform": "typescript-transform-paths" }], - "declaration": true, - "isolatedModules": true - }, - "include": ["./src/**/*.ts"], - "filesGlob": ["./src/**/*.ts"] -}