├── .gitignore ├── LICENSE ├── README.md ├── bin └── index.js ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | bower_components 10 | 11 | # Dependency directories 12 | node_modules/ 13 | jspm_packages/ 14 | 15 | # TypeScript v1 declaration files 16 | typings/ 17 | 18 | # dotenv environment variables file 19 | .env 20 | .env.test 21 | 22 | # parcel-bundler cache (https://parceljs.org/) 23 | .cache -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Lazy Engineer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # npm-sync-taobao 2 | 3 | Sync npm package to npmmirror (taobao) 4 | 5 | 同步npm仓库的包 到 npmmirror(淘宝镜像站) 6 | 7 | ```bash 8 | npm i -g npm-sync-taobao 9 | 10 | # package 为具体的包名称 11 | npm-sync-taobao package 12 | 13 | ``` 14 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const axios = require('axios').default; 4 | 5 | const packageName = require('../package.json').name; 6 | 7 | const syncPackageName = process.argv.slice(process.argv.length - 1); 8 | 9 | let logId = null; 10 | 11 | function wait(ms) { 12 | return new Promise(resolve => setTimeout(() => resolve(), ms)); 13 | } 14 | 15 | async function syncPackage() { 16 | const url = `https://registry-direct.npmmirror.com/${syncPackageName}/sync?sync_upstream=true`; 17 | 18 | const res = await axios.put(url); 19 | if (res.data.ok) { 20 | 21 | logId = res.data.logId; 22 | getSyncResult(); 23 | 24 | } else { 25 | console.error(`[${packageName}]==== Failed sync npm package to npmmirror (taobao) ====`); 26 | } 27 | 28 | } 29 | 30 | async function getSyncResult() { 31 | const url = `https://registry-direct.npmmirror.com/${syncPackageName}/sync/log/${logId}`; 32 | 33 | const res = await axios.get(url); 34 | if (!res.data) { 35 | console.error(`[${packageName}]==== Unexpected result ====`); 36 | return; 37 | } 38 | if (!res.data.syncDone) { 39 | await wait(2000); 40 | await getSyncResult(); 41 | } 42 | if (res.data.syncDone) { 43 | console.log(`[${packageName}]==== Sync npm package to npmmirror (taobao) successfully ====`); 44 | } 45 | } 46 | 47 | 48 | syncPackage(); -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-sync-taobao", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "asynckit": { 8 | "version": "0.4.0", 9 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", 10 | "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", 11 | "dev": true 12 | }, 13 | "axios": { 14 | "version": "0.27.2", 15 | "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", 16 | "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", 17 | "dev": true, 18 | "requires": { 19 | "follow-redirects": "^1.14.9", 20 | "form-data": "^4.0.0" 21 | } 22 | }, 23 | "combined-stream": { 24 | "version": "1.0.8", 25 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", 26 | "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", 27 | "dev": true, 28 | "requires": { 29 | "delayed-stream": "~1.0.0" 30 | } 31 | }, 32 | "delayed-stream": { 33 | "version": "1.0.0", 34 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 35 | "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", 36 | "dev": true 37 | }, 38 | "follow-redirects": { 39 | "version": "1.14.9", 40 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", 41 | "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", 42 | "dev": true 43 | }, 44 | "form-data": { 45 | "version": "4.0.0", 46 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", 47 | "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", 48 | "dev": true, 49 | "requires": { 50 | "asynckit": "^0.4.0", 51 | "combined-stream": "^1.0.8", 52 | "mime-types": "^2.1.12" 53 | } 54 | }, 55 | "mime-db": { 56 | "version": "1.52.0", 57 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", 58 | "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", 59 | "dev": true 60 | }, 61 | "mime-types": { 62 | "version": "2.1.35", 63 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", 64 | "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", 65 | "dev": true, 66 | "requires": { 67 | "mime-db": "1.52.0" 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-sync-taobao", 3 | "version": "1.0.3", 4 | "description": "Sync npm package to npmmirror (taobao) ", 5 | "main": "./bin/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "bin": { 10 | "npm-sync-taobao": "./bin/index.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/lazyperson/npm-sync-taobao.git" 15 | }, 16 | "keywords": [ 17 | "npm-package" 18 | ], 19 | "author": "lazyperson", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/lazyperson/npm-sync-taobao/issues" 23 | }, 24 | "homepage": "https://github.com/lazyperson/npm-sync-taobao#readme", 25 | "dependencies": { 26 | "axios": "^0.27.2" 27 | } 28 | } 29 | --------------------------------------------------------------------------------