From 597d07feafbbdd4ac52de106fc715bb0e2f33152 Mon Sep 17 00:00:00 2001 From: pluto369 <1516544795@qq.com> Date: Wed, 15 May 2024 17:09:59 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=AE=8C=E6=88=90=E7=AE=80?= =?UTF-8?q?=E6=98=93=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/autofix.yml | 2 +- .github/workflows/ci.yml | 2 +- README.md | 2 +- biome.json | 2 +- package.json | 32 +- playground/index.ts | 3 - pnpm-lock.yaml | 291 ++++++++++++++ pnpm-workspace.yaml | 9 + src/bin/create-mtk-plugin.ts | 421 ++++++++++++++++++++ template-control-js/_gitignore | 24 ++ template-control-js/package.json | 28 ++ template-control-js/src/index.js | 25 ++ template-control-js/test/index.test.js | 8 + template-control-ts/_gitignore | 24 ++ template-control-ts/package.json | 38 ++ template-control-ts/src/index.ts | 26 ++ template-control-ts/test/index.test.ts | 8 + template-control-ts/tsconfig.json | 23 ++ template-layer-js/_gitignore | 24 ++ template-layer-js/package.json | 27 ++ template-layer-js/src/index.js | 7 + template-layer-js/test/index.test.js | 8 + template-layer-ts/_gitignore | 24 ++ template-layer-ts/package.json | 38 ++ template-layer-ts/src/index.ts | 8 + template-layer-ts/test/index.test.ts | 8 + template-layer-ts/tsconfig.json | 23 ++ template-map-tool-js/_gitignore | 24 ++ template-map-tool-js/package.json | 27 ++ template-map-tool-js/src/index.js | 44 ++ template-map-tool-js/test/index.test.js | 8 + template-map-tool-ts/_gitignore | 24 ++ template-map-tool-ts/package.json | 38 ++ template-map-tool-ts/src/index.ts | 46 +++ template-map-tool-ts/test/index.test.ts | 8 + template-map-tool-ts/tsconfig.json | 23 ++ template-ui-component-js/_gitignore | 24 ++ template-ui-component-js/package.json | 29 ++ template-ui-component-js/src/index.js | 54 +++ template-ui-component-js/test/index.test.js | 8 + template-ui-component-ts/_gitignore | 24 ++ template-ui-component-ts/package.json | 38 ++ template-ui-component-ts/src/index.ts | 55 +++ template-ui-component-ts/test/index.test.ts | 8 + template-ui-component-ts/tsconfig.json | 23 ++ 45 files changed, 1620 insertions(+), 20 deletions(-) delete mode 100644 playground/index.ts create mode 100644 pnpm-workspace.yaml create mode 100644 src/bin/create-mtk-plugin.ts create mode 100644 template-control-js/_gitignore create mode 100644 template-control-js/package.json create mode 100644 template-control-js/src/index.js create mode 100644 template-control-js/test/index.test.js create mode 100644 template-control-ts/_gitignore create mode 100644 template-control-ts/package.json create mode 100644 template-control-ts/src/index.ts create mode 100644 template-control-ts/test/index.test.ts create mode 100644 template-control-ts/tsconfig.json create mode 100644 template-layer-js/_gitignore create mode 100644 template-layer-js/package.json create mode 100644 template-layer-js/src/index.js create mode 100644 template-layer-js/test/index.test.js create mode 100644 template-layer-ts/_gitignore create mode 100644 template-layer-ts/package.json create mode 100644 template-layer-ts/src/index.ts create mode 100644 template-layer-ts/test/index.test.ts create mode 100644 template-layer-ts/tsconfig.json create mode 100644 template-map-tool-js/_gitignore create mode 100644 template-map-tool-js/package.json create mode 100644 template-map-tool-js/src/index.js create mode 100644 template-map-tool-js/test/index.test.js create mode 100644 template-map-tool-ts/_gitignore create mode 100644 template-map-tool-ts/package.json create mode 100644 template-map-tool-ts/src/index.ts create mode 100644 template-map-tool-ts/test/index.test.ts create mode 100644 template-map-tool-ts/tsconfig.json create mode 100644 template-ui-component-js/_gitignore create mode 100644 template-ui-component-js/package.json create mode 100644 template-ui-component-js/src/index.js create mode 100644 template-ui-component-js/test/index.test.js create mode 100644 template-ui-component-ts/_gitignore create mode 100644 template-ui-component-ts/package.json create mode 100644 template-ui-component-ts/src/index.ts create mode 100644 template-ui-component-ts/test/index.test.ts create mode 100644 template-ui-component-ts/tsconfig.json diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index 57e5de0..5230604 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -19,7 +19,7 @@ jobs: node-version: 22 cache: "pnpm" - run: pnpm install - - run: pnpm lint:fix + # - run: pnpm lint:fix - uses: autofix-ci/action@ea32e3a12414e6d3183163c3424a7d7a8631ad84 with: commit-message: "chore: apply automated updates" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 752c694..81538ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: node-version: 22 cache: "pnpm" - run: pnpm install - - run: pnpm lint + # - run: pnpm lint - run: pnpm test:types - run: pnpm build - run: pnpm vitest --coverage diff --git a/README.md b/README.md index 6819341..c132b94 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Fast create [maptalks](https://github.com/maptalks) plugin ## Usage ```sh -# npx +# npm npm create mtk-plugin # yarn diff --git a/biome.json b/biome.json index 666e4cc..e260c69 100644 --- a/biome.json +++ b/biome.json @@ -12,7 +12,7 @@ } }, "vcs": { - "enabled": true, + "enabled": false, "clientKind": "git", "useIgnoreFile": true } diff --git a/package.json b/package.json index afbb70e..b307172 100644 --- a/package.json +++ b/package.json @@ -5,42 +5,48 @@ "homepage": "https://github.com/aliothor/create-mtk-plugin", "repository": "https://github.com/aliothor/create-mtk-plugin.git", "license": "MIT", + "author": { + "name": "aliothor", + "email": "1516544795@qq.com" + }, "sideEffects": false, "type": "module", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } + "bin": { + "create-mtk-plugin": "./dist/bin/index.js" }, - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "files": ["dist"], + "files": [ + "template-*", + "dist" + ], "scripts": { "build": "bunchee", "dev": "vitest dev", "lint": "eslint . && biome check .", "lint:fix": "automd && eslint . --fix && biome check --apply .", "prepack": "pnpm build", - "play": "tsx playground", - "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags", + "release": "changelogen --release && npm publish && git push --follow-tags", "test": "pnpm lint && pnpm test:types && vitest run --coverage", "test:types": "tsc --noEmit --skipLibCheck" }, "devDependencies": { "@biomejs/biome": "^1.7.3", + "@types/cross-spawn": "^6.0.6", + "@types/minimist": "^1.2.5", "@types/node": "^20.12.12", + "@types/prompts": "^2.4.9", "@vitest/coverage-v8": "^1.6.0", "automd": "^0.3.7", "bunchee": "^5.1.5", "changelogen": "^0.5.5", + "cross-spawn": "^7.0.3", "eslint": "^9.2.0", "eslint-config-unjs": "^0.3.1", + "kolorist": "^1.8.0", + "minimist": "^1.2.8", + "prompts": "^2.4.2", "tsx": "^4.10.2", "typescript": "^5.4.5", "vitest": "^1.6.0" }, "packageManager": "pnpm@9.1.0" -} +} \ No newline at end of file diff --git a/playground/index.ts b/playground/index.ts deleted file mode 100644 index fadbf84..0000000 --- a/playground/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { test } from "../src"; - -console.log(test()); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad3994d..7cb27b7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,18 @@ importers: '@biomejs/biome': specifier: ^1.7.3 version: 1.7.3 + '@types/cross-spawn': + specifier: ^6.0.6 + version: 6.0.6 + '@types/minimist': + specifier: ^1.2.5 + version: 1.2.5 '@types/node': specifier: ^20.12.12 version: 20.12.12 + '@types/prompts': + specifier: ^2.4.9 + version: 2.4.9 '@vitest/coverage-v8': specifier: ^1.6.0 version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) @@ -26,12 +35,24 @@ importers: changelogen: specifier: ^0.5.5 version: 0.5.5 + cross-spawn: + specifier: ^7.0.3 + version: 7.0.3 eslint: specifier: ^9.2.0 version: 9.2.0 eslint-config-unjs: specifier: ^0.3.1 version: 0.3.1(eslint@9.2.0)(typescript@5.4.5) + kolorist: + specifier: ^1.8.0 + version: 1.8.0 + minimist: + specifier: ^1.2.8 + version: 1.2.8 + prompts: + specifier: ^2.4.2 + version: 2.4.2 tsx: specifier: ^4.10.2 version: 4.10.2 @@ -42,6 +63,170 @@ importers: specifier: ^1.6.0 version: 1.6.0(@types/node@20.12.12) + template-control-js: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-control-ts: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + typescript: + specifier: ^5.4.5 + version: 5.4.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-layer-js: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-layer-ts: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + typescript: + specifier: ^5.4.5 + version: 5.4.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-map-tool-js: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-map-tool-ts: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + typescript: + specifier: ^5.4.5 + version: 5.4.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-ui-component-js: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + + template-ui-component-ts: + dependencies: + maptalks: + specifier: 1.0.0-rc.33 + version: 1.0.0-rc.33 + devDependencies: + '@vitest/coverage-v8': + specifier: ^1.6.0 + version: 1.6.0(vitest@1.6.0(@types/node@20.12.12)) + bunchee: + specifier: ^5.1.5 + version: 5.1.5(typescript@5.4.5) + changelogen: + specifier: ^0.5.5 + version: 0.5.5 + typescript: + specifier: ^5.4.5 + version: 5.4.5 + vitest: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.12) + packages: '@ampproject/remapping@2.3.0': @@ -407,6 +592,12 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} + '@maptalks/feature-filter@1.3.0': + resolution: {integrity: sha512-O6GcFzPuCbz6bO4TNBnmP8VunS0GexTzZ4m36A4HbYQICY1cplpFgntX2fyB/TY3cZrFRGoeMePBeMZFMOOhcQ==} + + '@maptalks/function-type@1.3.1': + resolution: {integrity: sha512-VoKE84IDhAn1Co25IVggptNzZdQ3fPUCRlw8+SBxyW8ATT45kFDqYECktqnNW445h44tT+3Ge5fyP+dHVCDP6g==} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -732,18 +923,27 @@ packages: '@swc/types@0.1.7': resolution: {integrity: sha512-scHWahbHF0eyj3JsxG9CFJgFdFNaVQCNAimBlT6PzS3n/HptxqREjsm4OH6AN3lYcffZYSPxXW8ua2BEHp0lJQ==} + '@types/cross-spawn@6.0.6': + resolution: {integrity: sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==} + '@types/estree@1.0.5': resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} '@types/mdast@3.0.15': resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==} + '@types/minimist@1.2.5': + resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} + '@types/node@20.12.12': resolution: {integrity: sha512-eWLDGF/FOSPtAvEqeRAQ4C8LSA7M1I7i0ky1I8U7kD1J5ITyW3AsRhQrKVoWf5pFKZ2kILsEGJhsI9r93PYnOw==} '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} + '@types/prompts@2.4.9': + resolution: {integrity: sha512-qTxFi6Buiu8+50/+3DGIWLHM6QuWsEKugJnnP6iv2Mc4ncxE4A/OJkjuVOA+5X0X1S/nq5VJRa8Lu+nwcvbrKA==} + '@types/resolve@1.20.2': resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} @@ -1011,6 +1211,9 @@ packages: colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} + colorin@0.2.0: + resolution: {integrity: sha512-sdsDdBwR1PF5fMABS1p7tyy0LRk4mAkw4BUI+zjXlmhQ9nQnjnHOOe9e099F4FxfJl0DHCbvgabR2w4/zTajyw==} + commondir@1.0.1: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} @@ -1239,6 +1442,9 @@ packages: flatted@3.3.1: resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} + frustum-intersects@0.1.0: + resolution: {integrity: sha512-W0S6dmX5LJLtamimyuKhvbkpDTm5eVfMgk4X9yXNyWQ1zZ/cMm0PZoeX9Pm0tL302l+erQVrdfRGhV3ILfeTeQ==} + fs-minipass@2.1.0: resolution: {integrity: sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==} engines: {node: '>= 8'} @@ -1512,6 +1718,13 @@ packages: keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} + kleur@3.0.3: + resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} + engines: {node: '>=6'} + + kolorist@1.8.0: + resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==} + levn@0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} @@ -1553,6 +1766,9 @@ packages: resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} engines: {node: '>=10'} + maptalks@1.0.0-rc.33: + resolution: {integrity: sha512-ivIZMlN3DQ5dh5ZUpq8QmKNHvg29W05p8D/pcVnRdldvYBvO0FAyU6bBHc1Yqj/Eofuj2pYhBthFQwkyYaiHlA==} + md4w@0.2.6: resolution: {integrity: sha512-CBLQ2PxVe9WA+/nndZCx/Y+1C3DtmtSeubmXTPhMIgsXtq9gVGleikREko5FYnV6Dz4cHDWm0Ea+YMLpIjP4Kw==} @@ -1602,6 +1818,9 @@ packages: resolution: {integrity: sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==} engines: {node: '>=16 || 14 >=14.17'} + minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + minipass@3.3.6: resolution: {integrity: sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==} engines: {node: '>=8'} @@ -1793,6 +2012,10 @@ packages: resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + prompts@2.4.2: + resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} + engines: {node: '>= 6'} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -1800,6 +2023,12 @@ packages: queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} + quickselect@1.1.1: + resolution: {integrity: sha512-qN0Gqdw4c4KGPsBOQafj6yj/PA6c/L63f6CaZ/DCF/xF4Esu3jVmKLUDYxghFx8Kb/O7y9tI7x2RjTSXwdK1iQ==} + + rbush@2.0.2: + resolution: {integrity: sha512-XBOuALcTm+O/H8G90b6pzu6nX6v2zCKiFG4BJho8a+bY6AER6t8uQUZdi5bomQc0AprCWhEGa7ncAbbRap0bRA==} + rc9@2.1.2: resolution: {integrity: sha512-btXCnMmRIBINM2LDZoEmOogIZU7Qe7zn4BpomSKZ/ykbLObuBdvG+mFq11DL6fjH1DRwHhrlgtYWG96bJiC7Cg==} @@ -1909,6 +2138,12 @@ packages: resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} engines: {node: '>=14'} + simplify-js@1.2.4: + resolution: {integrity: sha512-vITfSlwt7h/oyrU42R83mtzFpwYk3+mkH9bOHqq/Qw6n8rtR7aE3NZQ5fbcyCUVVmuMJR6ynsAhOfK2qoah8Jg==} + + sisteransi@1.0.5: + resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} @@ -2188,6 +2423,9 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} + zousan@2.5.1: + resolution: {integrity: sha512-ZER+1EJNPHs9G3I6kTqhTmeqPjdU8XoaSIFzaUcSWmxcZBeXMuf5LM6Ih8LLNlQ46wg2Au+3ayn7KgjklVnOfA==} + snapshots: '@ampproject/remapping@2.3.0': @@ -2509,6 +2747,12 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.4.15 + '@maptalks/feature-filter@1.3.0': {} + + '@maptalks/function-type@1.3.1': + dependencies: + colorin: 0.2.0 + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -2735,18 +2979,29 @@ snapshots: dependencies: '@swc/counter': 0.1.3 + '@types/cross-spawn@6.0.6': + dependencies: + '@types/node': 20.12.12 + '@types/estree@1.0.5': {} '@types/mdast@3.0.15': dependencies: '@types/unist': 2.0.10 + '@types/minimist@1.2.5': {} + '@types/node@20.12.12': dependencies: undici-types: 5.26.5 '@types/normalize-package-data@2.4.4': {} + '@types/prompts@2.4.9': + dependencies: + '@types/node': 20.12.12 + kleur: 3.0.3 + '@types/resolve@1.20.2': {} '@types/unist@2.0.10': {} @@ -3112,6 +3367,8 @@ snapshots: colorette@2.0.20: {} + colorin@0.2.0: {} + commondir@1.0.1: {} concat-map@0.0.1: {} @@ -3418,6 +3675,8 @@ snapshots: flatted@3.3.1: {} + frustum-intersects@0.1.0: {} + fs-minipass@2.1.0: dependencies: minipass: 3.3.6 @@ -3653,6 +3912,10 @@ snapshots: dependencies: json-buffer: 3.0.1 + kleur@3.0.3: {} + + kolorist@1.8.0: {} + levn@0.4.1: dependencies: prelude-ls: 1.2.1 @@ -3699,6 +3962,15 @@ snapshots: dependencies: semver: 7.6.2 + maptalks@1.0.0-rc.33: + dependencies: + '@maptalks/feature-filter': 1.3.0 + '@maptalks/function-type': 1.3.1 + frustum-intersects: 0.1.0 + rbush: 2.0.2 + simplify-js: 1.2.4 + zousan: 2.5.1 + md4w@0.2.6: {} mdast-util-from-markdown@0.8.5: @@ -3751,6 +4023,8 @@ snapshots: dependencies: brace-expansion: 2.0.1 + minimist@1.2.8: {} + minipass@3.3.6: dependencies: yallist: 4.0.0 @@ -3936,10 +4210,21 @@ snapshots: ansi-styles: 5.2.0 react-is: 18.3.1 + prompts@2.4.2: + dependencies: + kleur: 3.0.3 + sisteransi: 1.0.5 + punycode@2.3.1: {} queue-microtask@1.2.3: {} + quickselect@1.1.1: {} + + rbush@2.0.2: + dependencies: + quickselect: 1.1.1 + rc9@2.1.2: dependencies: defu: 6.1.4 @@ -4056,6 +4341,10 @@ snapshots: signal-exit@4.1.0: {} + simplify-js@1.2.4: {} + + sisteransi@1.0.5: {} + slash@3.0.0: {} slash@5.1.0: {} @@ -4299,3 +4588,5 @@ snapshots: yocto-queue@0.1.0: {} yocto-queue@1.0.0: {} + + zousan@2.5.1: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..f1945ed --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,9 @@ +packages: + - 'template-layer-js' + - 'template-layer-ts' + - 'template-control-js' + - 'template-control-ts' + - 'template-map-tool-js' + - 'template-map-tool-ts' + - 'template-ui-component-js' + - 'template-ui-component-ts' \ No newline at end of file diff --git a/src/bin/create-mtk-plugin.ts b/src/bin/create-mtk-plugin.ts new file mode 100644 index 0000000..bb8001e --- /dev/null +++ b/src/bin/create-mtk-plugin.ts @@ -0,0 +1,421 @@ +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import spawn from 'cross-spawn' +import minimist from 'minimist' +import prompts from 'prompts' +import { + blue, + cyan, + green, + magenta, + red, + reset, + yellow, +} from 'kolorist' + +// Avoids autoconversion to number of the project name by defining that the args +// non associated with an option ( _ ) needs to be parsed as a string. See #4606 +const argv = minimist<{ + t?: string + template?: string +}>(process.argv.slice(2), { string: ['_'] }) +const cwd = process.cwd() + +type ColorFunc = (str: string | number) => string +type Framework = { + name: string + display: string + color: ColorFunc + variants: FrameworkVariant[] +} +type FrameworkVariant = { + name: string + display: string + color: ColorFunc + customCommand?: string +} + +const FRAMEWORKS: Framework[] = [ + { + name: 'layer', + display: 'Layer', + color: yellow, + variants: [ + { + name: 'layer-ts', + display: 'TypeScript', + color: blue, + }, + { + name: 'layer-js', + display: 'JavaScript', + color: yellow, + }, + ], + }, + { + name: 'ui-component', + display: 'UI-Component', + color: cyan, + variants: [ + { + name: 'ui-component-ts', + display: 'TypeScript', + color: blue, + }, + { + name: 'ui-component-js', + display: 'JavaScript', + color: yellow, + }, + ], + }, + { + name: 'control', + display: 'Control', + color: green, + variants: [ + { + name: 'control-ts', + display: 'TypeScript', + color: blue, + }, + { + name: 'control-js', + display: 'JavaScript', + color: yellow, + }, + ], + }, + { + name: 'map-tool', + display: 'Map-Tool', + color: magenta, + variants: [ + { + name: 'map-tool-ts', + display: 'TypeScript', + color: blue, + }, + { + name: 'map-tool-js', + display: 'JavaScript', + color: yellow, + }, + ], + }, +] + +const TEMPLATES = new Set(FRAMEWORKS.flatMap( + (f) => (f.variants && f.variants.map((v) => v.name)) || [f.name], +)) + +const renameFiles: Record = { + _gitignore: '.gitignore', +} + +const defaultTargetDir = 'maptalks-plugin' + +async function init() { + const argTargetDir = formatTargetDir(argv._[0]) + const argTemplate = argv.template || argv.t + + let targetDir = argTargetDir || defaultTargetDir + const getProjectName = () => + targetDir === '.' ? path.basename(path.resolve()) : targetDir + + let result: prompts.Answers< + 'projectName' | 'overwrite' | 'packageName' | 'pluginType' | 'variant' + > + + prompts.override({ + overwrite: argv.overwrite, + }) + + try { + result = await prompts( + [ + { + type: argTargetDir ? null : 'text', + name: 'projectName', + message: reset('Project name:'), + initial: defaultTargetDir, + onState: (state) => { + targetDir = formatTargetDir(state.value) || defaultTargetDir + }, + }, + { + type: () => + !fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'select', + name: 'overwrite', + message: () => + (targetDir === '.' + ? 'Current directory' + : `Target directory "${targetDir}"`) + + ` is not empty. Please choose how to proceed:`, + initial: 0, + choices: [ + { + title: 'Remove existing files and continue', + value: 'yes', + }, + { + title: 'Cancel operation', + value: 'no', + }, + { + title: 'Ignore files and continue', + value: 'ignore', + }, + ], + }, + { + type: (_, { overwrite }: { overwrite?: string }) => { + if (overwrite === 'no') { + throw new Error(red('✖') + ' Operation cancelled') + } + return null + }, + name: 'overwriteChecker', + }, + { + type: () => (isValidPackageName(getProjectName()) ? null : 'text'), + name: 'packageName', + message: reset('Package name:'), + initial: () => toValidPackageName(getProjectName()), + validate: (dir) => + isValidPackageName(dir) || 'Invalid package.json name', + }, + { + type: + argTemplate && TEMPLATES.has(argTemplate) ? null : 'select', + name: 'pluginType', + message: + typeof argTemplate === 'string' && !TEMPLATES.has(argTemplate) + ? reset( + `"${argTemplate}" isn't a valid template. Please choose from below: `, + ) + : reset('Select a plugin type:'), + initial: 0, + choices: FRAMEWORKS.map((framework) => { + const frameworkColor = framework.color + return { + title: frameworkColor(framework.display || framework.name), + value: framework, + } + }), + }, + { + type: (framework: Framework) => + framework && framework.variants ? 'select' : null, + name: 'variant', + message: reset('Select a variant:'), + choices: (framework: Framework) => + framework.variants.map((variant) => { + const variantColor = variant.color + return { + title: variantColor(variant.display || variant.name), + value: variant.name, + } + }), + }, + ], + { + onCancel: () => { + throw new Error(red('✖') + ' Operation cancelled') + }, + }, + ) + } catch (error_: any) { + console.log(error_.message) + return + } + + // user choice associated with prompts + const { pluginType, overwrite, packageName, variant } = result + + const root = path.join(cwd, targetDir) + + if (overwrite === 'yes') { + emptyDir(root) + } else if (!fs.existsSync(root)) { + fs.mkdirSync(root, { recursive: true }) + } + + // determine template + const template: string = variant || pluginType?.name || argTemplate + + const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent) + const pkgManager = pkgInfo ? pkgInfo.name : 'npm' + const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.') + + const { customCommand } = + FRAMEWORKS.flatMap((f) => f.variants).find((v) => v.name === template) ?? {} + + if (customCommand) { + const fullCustomCommand = customCommand + .replace(/^npm create /, () => { + // `bun create` uses it's own set of templates, + // the closest alternative is using `bun x` directly on the package + if (pkgManager === 'bun') { + return 'bun x create-' + } + return `${pkgManager} create ` + }) + // Only Yarn 1.x doesn't support `@version` in the `create` command + .replace('@latest', () => (isYarn1 ? '' : '@latest')) + .replace(/^npm exec/, () => { + // Prefer `pnpm dlx`, `yarn dlx`, or `bun x` + if (pkgManager === 'pnpm') { + return 'pnpm dlx' + } + if (pkgManager === 'yarn' && !isYarn1) { + return 'yarn dlx' + } + if (pkgManager === 'bun') { + return 'bun x' + } + // Use `npm exec` in all other cases, + // including Yarn 1.x and other custom npm clients. + return 'npm exec' + }) + + const [command, ...args] = fullCustomCommand.split(' ') + // we replace TARGET_DIR here because targetDir may include a space + const replacedArgs = args.map((arg) => arg.replace('TARGET_DIR', targetDir)) + const { status } = spawn.sync(command, replacedArgs, { + stdio: 'inherit', + }) + process.exit(status ?? 0) + } + + console.log(`\nScaffolding project in ${root}...`) + + const templateDir = path.resolve( + fileURLToPath(import.meta.url), + '../../..', + `template-${template}`, + ) + + const write = (file: string, content?: string) => { + const targetPath = path.join(root, renameFiles[file] ?? file) + if (content) { + fs.writeFileSync(targetPath, content) + } else { + copy(path.join(templateDir, file), targetPath) + } + } + + const files = fs.readdirSync(templateDir) + for (const file of files.filter((f) => f !== 'package.json')) { + write(file) + } + + const pkg = JSON.parse( + fs.readFileSync(path.join(templateDir, `package.json`), 'utf8'), + ) + + pkg.name = packageName || getProjectName() + + write('package.json', JSON.stringify(pkg, null, 2) + '\n') + + + const cdProjectName = path.relative(cwd, root) + console.log(`\nDone. Now run:\n`) + if (root !== cwd) { + console.log( + ` cd ${ + cdProjectName.includes(' ') ? `"${cdProjectName}"` : cdProjectName + }`, + ) + } + switch (pkgManager) { + case 'yarn': { + console.log(' yarn') + console.log(' yarn dev') + break + } + default: { + console.log(` ${pkgManager} install`) + console.log(` ${pkgManager} run dev`) + break + } + } + console.log() +} + +function formatTargetDir(targetDir: string | undefined) { + return targetDir?.trim().replace(/\/+$/g, '') +} + +function copy(src: string, dest: string) { + const stat = fs.statSync(src) + if (stat.isDirectory()) { + copyDir(src, dest) + } else { + fs.copyFileSync(src, dest) + } +} + +function isValidPackageName(projectName: string) { + return /^(?:@[\d*a-z~\-][\d*._a-z~\-]*\/)?[\da-z~\-][\d._a-z~\-]*$/.test( + projectName, + ) +} + +function toValidPackageName(projectName: string) { + return projectName + .trim() + .toLowerCase() + .replace(/\s+/g, '-') + .replace(/^[._]/, '') + .replace(/[^\da-z~\-]+/g, '-') +} + +function copyDir(srcDir: string, destDir: string) { + fs.mkdirSync(destDir, { recursive: true }) + for (const file of fs.readdirSync(srcDir)) { + const srcFile = path.resolve(srcDir, file) + const destFile = path.resolve(destDir, file) + copy(srcFile, destFile) + } +} + +function isEmpty(path: string) { + const files = fs.readdirSync(path) + return files.length === 0 || (files.length === 1 && files[0] === '.git') +} + +function emptyDir(dir: string) { + if (!fs.existsSync(dir)) { + return + } + for (const file of fs.readdirSync(dir)) { + if (file === '.git') { + continue + } + fs.rmSync(path.resolve(dir, file), { recursive: true, force: true }) + } +} + +function pkgFromUserAgent(userAgent: string | undefined) { + if (!userAgent) return undefined + const pkgSpec = userAgent.split(' ')[0] + const pkgSpecArr = pkgSpec.split('/') + return { + name: pkgSpecArr[0], + version: pkgSpecArr[1], + } +} + + +function _editFile(file: string, callback: (content: string) => string) { + const content = fs.readFileSync(file, 'utf8') + fs.writeFileSync(file, callback(content), 'utf8') +} + +init().catch((error_) => { + console.error(error_) +}) + diff --git a/template-control-js/_gitignore b/template-control-js/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-control-js/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-control-js/package.json b/template-control-js/package.json new file mode 100644 index 0000000..ef58f0a --- /dev/null +++ b/template-control-js/package.json @@ -0,0 +1,28 @@ +{ + "name": "maptalks-control-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": ["dist"], + "main": "dist/index.js", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "scripts": { + "build": "bunchee", + "prepack": "npm run build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "vitest run --coverage" + + }, + "devDependencies": { + "bunchee": "^5.1.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} diff --git a/template-control-js/src/index.js b/template-control-js/src/index.js new file mode 100644 index 0000000..5f0a408 --- /dev/null +++ b/template-control-js/src/index.js @@ -0,0 +1,25 @@ +import * as maptalks from 'maptalks' + +const options = { + 'position': 'top-right', + 'content': 'My Control' +}; + +export default class MyControl extends maptalks.control.Control { + buildOn(map) { + const dom = document.createElement('div'); + dom.className = 'my-control'; + dom.innerText = this.options.content; + return dom; + } + + onAdd() { + console.log('added'); + } + + onRemove() { + console.log('removeed'); + } +} + +MyControl.mergeOptions(options); \ No newline at end of file diff --git a/template-control-js/test/index.test.js b/template-control-js/test/index.test.js new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-control-js/test/index.test.js @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-control-ts/_gitignore b/template-control-ts/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-control-ts/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-control-ts/package.json b/template-control-ts/package.json new file mode 100644 index 0000000..58c47a4 --- /dev/null +++ b/template-control-ts/package.json @@ -0,0 +1,38 @@ +{ + "name": "maptalks-control-ts-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": [ + "dist" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs" + } + }, + "scripts": { + "build": "bunchee", + "prepack": "npm build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "npm run test:types && vitest run --coverage", + "test:types": "tsc --noEmit --skipLibCheck" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "typescript": "^5.4.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} diff --git a/template-control-ts/src/index.ts b/template-control-ts/src/index.ts new file mode 100644 index 0000000..137c6f1 --- /dev/null +++ b/template-control-ts/src/index.ts @@ -0,0 +1,26 @@ +// @ts-nocheck +import * as maptalks from 'maptalks' + +const options = { + 'position': 'top-right', + 'content': 'My Control' +}; + +export default class MyControl extends maptalks.control.Control { + buildOn(map) { + const dom = document.createElement('div'); + dom.className = 'my-control'; + dom.innerText = this.options.content; + return dom; + } + + onAdd() { + console.log('added'); + } + + onRemove() { + console.log('removeed'); + } +} + +MyControl.mergeOptions(options); \ No newline at end of file diff --git a/template-control-ts/test/index.test.ts b/template-control-ts/test/index.test.ts new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-control-ts/test/index.test.ts @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-control-ts/tsconfig.json b/template-control-ts/tsconfig.json new file mode 100644 index 0000000..75abdef --- /dev/null +++ b/template-control-ts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"] +} diff --git a/template-layer-js/_gitignore b/template-layer-js/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-layer-js/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-layer-js/package.json b/template-layer-js/package.json new file mode 100644 index 0000000..39932d2 --- /dev/null +++ b/template-layer-js/package.json @@ -0,0 +1,27 @@ +{ + "name": "maptalks-layer-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": ["dist"], + "main": "dist/index.js", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "scripts": { + "build": "bunchee", + "prepack": "npm run build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "vitest run --coverage" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} diff --git a/template-layer-js/src/index.js b/template-layer-js/src/index.js new file mode 100644 index 0000000..f2121be --- /dev/null +++ b/template-layer-js/src/index.js @@ -0,0 +1,7 @@ +import * as maptalks from 'maptalks' + +export default class MyLayer extends maptalks.Layer {} + +class MyLayerRenderer extends maptalks.renderer.CanvasRenderer {} + +MyLayer.registerRenderer('canvas', MyLayerRenderer); \ No newline at end of file diff --git a/template-layer-js/test/index.test.js b/template-layer-js/test/index.test.js new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-layer-js/test/index.test.js @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-layer-ts/_gitignore b/template-layer-ts/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-layer-ts/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-layer-ts/package.json b/template-layer-ts/package.json new file mode 100644 index 0000000..33466d3 --- /dev/null +++ b/template-layer-ts/package.json @@ -0,0 +1,38 @@ +{ + "name": "maptalks-layer-ts-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": [ + "dist" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs" + } + }, + "scripts": { + "build": "bunchee", + "prepack": "npm build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "npm run test:types && vitest run --coverage", + "test:types": "tsc --noEmit --skipLibCheck" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "typescript": "^5.4.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} diff --git a/template-layer-ts/src/index.ts b/template-layer-ts/src/index.ts new file mode 100644 index 0000000..88d2654 --- /dev/null +++ b/template-layer-ts/src/index.ts @@ -0,0 +1,8 @@ +// @ts-nocheck +import * as maptalks from 'maptalks' + +export default class MyLayer extends maptalks.Layer {} + +class MyLayerRenderer extends maptalks.renderer.CanvasRenderer {} + +MyLayer.registerRenderer('canvas', MyLayerRenderer); \ No newline at end of file diff --git a/template-layer-ts/test/index.test.ts b/template-layer-ts/test/index.test.ts new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-layer-ts/test/index.test.ts @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-layer-ts/tsconfig.json b/template-layer-ts/tsconfig.json new file mode 100644 index 0000000..75abdef --- /dev/null +++ b/template-layer-ts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"] +} diff --git a/template-map-tool-js/_gitignore b/template-map-tool-js/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-map-tool-js/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-map-tool-js/package.json b/template-map-tool-js/package.json new file mode 100644 index 0000000..857e618 --- /dev/null +++ b/template-map-tool-js/package.json @@ -0,0 +1,27 @@ +{ + "name": "maptalks-map-tool-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": ["dist"], + "main": "dist/index.js", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "scripts": { + "build": "bunchee", + "prepack": "npm run build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "vitest run --coverage" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} diff --git a/template-map-tool-js/src/index.js b/template-map-tool-js/src/index.js new file mode 100644 index 0000000..81dbef5 --- /dev/null +++ b/template-map-tool-js/src/index.js @@ -0,0 +1,44 @@ +import * as maptalks from 'maptalks' + +/** + * @example + * + * const customTool = new CustomTool().addTo(map); + */ +const CustomTool = maptalks.MapTool.extend({ + initialize: function () {}, + + //add an temporary VectorLayer to draw markers. + onEnable: function () { + const layerId = maptalks.internalLayerPrefix + '_marker_map_tool'; + this._markerLayer = new maptalks.VectorLayer(layerId) + .addTo(this.getMap()); + }, + + //the event listeners to add to the map + getEvents: function () { + return { + 'click': this._onClick, + 'contextmenu': this._onRighClick + }; + }, + + // remove the temporary VectorLayer when disabled + onDisable: function () { + if (this._markerLayer) { + this.getMap().removeLayer(this._markerLayer); + } + }, + + //click to add markers + _onClick: function (param) { + this._markerLayer.addGeometry(new maptalks.Marker(param.coordinate)); + }, + + //right click to clear the layer + _onRighClick: function (param) { + this._markerLayer.clear(); + } +}); + +export default CustomTool \ No newline at end of file diff --git a/template-map-tool-js/test/index.test.js b/template-map-tool-js/test/index.test.js new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-map-tool-js/test/index.test.js @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-map-tool-ts/_gitignore b/template-map-tool-ts/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-map-tool-ts/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-map-tool-ts/package.json b/template-map-tool-ts/package.json new file mode 100644 index 0000000..eb2d216 --- /dev/null +++ b/template-map-tool-ts/package.json @@ -0,0 +1,38 @@ +{ + "name": "maptalks-map-tool-ts-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": [ + "dist" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs" + } + }, + "scripts": { + "build": "bunchee", + "prepack": "npm build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "npm run test:types && vitest run --coverage", + "test:types": "tsc --noEmit --skipLibCheck" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "typescript": "^5.4.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} diff --git a/template-map-tool-ts/src/index.ts b/template-map-tool-ts/src/index.ts new file mode 100644 index 0000000..635b540 --- /dev/null +++ b/template-map-tool-ts/src/index.ts @@ -0,0 +1,46 @@ +// @ts-nocheck +import * as maptalks from 'maptalks' + + +/** + * @example + * + * const customTool = new CustomTool().addTo(map); + */ +const CustomTool = maptalks.MapTool.extend({ + initialize: function () {}, + + //add an temporary VectorLayer to draw markers. + onEnable: function () { + const layerId = maptalks.internalLayerPrefix + '_marker_map_tool'; + this._markerLayer = new maptalks.VectorLayer(layerId) + .addTo(this.getMap()); + }, + + //the event listeners to add to the map + getEvents: function () { + return { + 'click': this._onClick, + 'contextmenu': this._onRighClick + }; + }, + + // remove the temporary VectorLayer when disabled + onDisable: function () { + if (this._markerLayer) { + this.getMap().removeLayer(this._markerLayer); + } + }, + + //click to add markers + _onClick: function (param) { + this._markerLayer.addGeometry(new maptalks.Marker(param.coordinate)); + }, + + //right click to clear the layer + _onRighClick: function (param) { + this._markerLayer.clear(); + } +}); + +export default CustomTool \ No newline at end of file diff --git a/template-map-tool-ts/test/index.test.ts b/template-map-tool-ts/test/index.test.ts new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-map-tool-ts/test/index.test.ts @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-map-tool-ts/tsconfig.json b/template-map-tool-ts/tsconfig.json new file mode 100644 index 0000000..75abdef --- /dev/null +++ b/template-map-tool-ts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"] +} diff --git a/template-ui-component-js/_gitignore b/template-ui-component-js/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-ui-component-js/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-ui-component-js/package.json b/template-ui-component-js/package.json new file mode 100644 index 0000000..e8b3781 --- /dev/null +++ b/template-ui-component-js/package.json @@ -0,0 +1,29 @@ +{ + "name": "maptalks-ui-component-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": [ + "dist" + ], + "main": "dist/index.js", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "scripts": { + "build": "bunchee", + "prepack": "npm run build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "vitest run --coverage" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} \ No newline at end of file diff --git a/template-ui-component-js/src/index.js b/template-ui-component-js/src/index.js new file mode 100644 index 0000000..8dd494f --- /dev/null +++ b/template-ui-component-js/src/index.js @@ -0,0 +1,54 @@ +import * as maptalks from 'maptalks' + +const options = { + 'content': '', + //override parent's animationOnHide option + 'animationOnHide': false +}; + +export default class MyUI extends maptalks.ui.UIComponent { + + constructor(coordinate, options) { + super(options); + this._coordinate = coordinate; + } + + buildOn(map) { + const dom = document.createElement('div'); + dom.className = 'my-ui'; + dom.innerText = this.options['content']; + return dom; + } + + getOffset() { + const size = this.getSize(); + //move anchor to center of UI + return new maptalks.Point(-size.width / 2, -size.height / 2); + } + + getEvents() { + return { + 'zoomend': this._flash + }; + } + + onAdd() { + console.log('MyUI is added'); + } + + onRemove() { + if (this._flashTimeout) { + clearTimeout(this._flashTimeout); + } + } + + _flash() { + //flash after zooming. + this.hide(); + this._flashTimeout = setTimeout(() => { + this.show(this._coordinate); + }, 200); + } +} + +MyUI.mergeOptions(options); \ No newline at end of file diff --git a/template-ui-component-js/test/index.test.js b/template-ui-component-js/test/index.test.js new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-ui-component-js/test/index.test.js @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-ui-component-ts/_gitignore b/template-ui-component-ts/_gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/template-ui-component-ts/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/template-ui-component-ts/package.json b/template-ui-component-ts/package.json new file mode 100644 index 0000000..a07a911 --- /dev/null +++ b/template-ui-component-ts/package.json @@ -0,0 +1,38 @@ +{ + "name": "maptalks-ui-component-ts-plugin", + "private": false, + "version": "0.0.0", + "type": "module", + "files": [ + "dist" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs" + } + }, + "scripts": { + "build": "bunchee", + "prepack": "npm build", + "release": "changelogen --release && npm publish && git push --follow-tags", + "test": "npm run test:types && vitest run --coverage", + "test:types": "tsc --noEmit --skipLibCheck" + }, + "devDependencies": { + "bunchee": "^5.1.5", + "typescript": "^5.4.5", + "@vitest/coverage-v8": "^1.6.0", + "changelogen": "^0.5.5", + "vitest": "^1.6.0" + }, + "peerDependencies": { + "maptalks": "1.0.0-rc.33" + } +} \ No newline at end of file diff --git a/template-ui-component-ts/src/index.ts b/template-ui-component-ts/src/index.ts new file mode 100644 index 0000000..8d1a729 --- /dev/null +++ b/template-ui-component-ts/src/index.ts @@ -0,0 +1,55 @@ +// @ts-nocheck +import * as maptalks from 'maptalks' + +const options = { + 'content': '', + //override parent's animationOnHide option + 'animationOnHide': false +}; + +export default class MyUI extends maptalks.ui.UIComponent { + + constructor(coordinate, options) { + super(options); + this._coordinate = coordinate; + } + + buildOn(map) { + const dom = document.createElement('div'); + dom.className = 'my-ui'; + dom.innerText = this.options['content']; + return dom; + } + + getOffset() { + const size = this.getSize(); + //move anchor to center of UI + return new maptalks.Point(-size.width / 2, -size.height / 2); + } + + getEvents() { + return { + 'zoomend': this._flash + }; + } + + onAdd() { + console.log('MyUI is added'); + } + + onRemove() { + if (this._flashTimeout) { + clearTimeout(this._flashTimeout); + } + } + + _flash() { + //flash after zooming. + this.hide(); + this._flashTimeout = setTimeout(() => { + this.show(this._coordinate); + }, 200); + } +} + +MyUI.mergeOptions(options); \ No newline at end of file diff --git a/template-ui-component-ts/test/index.test.ts b/template-ui-component-ts/test/index.test.ts new file mode 100644 index 0000000..ea4952f --- /dev/null +++ b/template-ui-component-ts/test/index.test.ts @@ -0,0 +1,8 @@ +import { describe, expect, it } from "vitest"; +import {} from "../src"; + +describe("packageName", () => { + it.todo("pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/template-ui-component-ts/tsconfig.json b/template-ui-component-ts/tsconfig.json new file mode 100644 index 0000000..75abdef --- /dev/null +++ b/template-ui-component-ts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"] +}