diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 67fc288..0000000 --- a/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env" - ] - ] -} diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index beffa30..0000000 --- a/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index e098aa1..6a3e3b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,6 @@ node_modules bower_components coverage -npm-debug.log -yarn.lock -package-lock.json .DS_Store .idea .vscode @@ -11,3 +8,9 @@ package-lock.json # vscode localhistory .history dist + +# package manager +npm-debug.log +yarn.lock +package-lock.json +pnpm-lock.yaml diff --git a/.ncurc.json b/.ncurc.json new file mode 100644 index 0000000..1a2139d --- /dev/null +++ b/.ncurc.json @@ -0,0 +1,5 @@ +{ + "upgrade": true, + "filter": "/^@jswork|@afeiship/", + "registry": "https://registry.npmjs.org" +} diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 407d4d9..0000000 --- a/.npmignore +++ /dev/null @@ -1,27 +0,0 @@ -.idea -.DS_Store -**/npm-debug.log -**/node_modules -test -__tests__ -src -build -docs -gulpfile.js - -.editorconfig -.prettierrc -Gemfile -jest.config.js -jest.setup.js -LICENSE.txt -Rakefile -express.js -.babelrc -.vscode -.release-it.json - - -# vscode localhistory -.history -.release-it.json diff --git a/.npmrc b/.npmrc index 3475c59..43c97e7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,11 +1 @@ -registry=https://registry.npm.taobao.org -disturl=https://npm.taobao.org/dist -sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ -phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/ -electron_mirror=https://npm.taobao.org/mirrors/electron/ -chromedriver_cdnurl=https://npm.taobao.org/mirrors/chromedriver -operadriver_cdnurl=https://npm.taobao.org/mirrors/operadriver -selenium_cdnurl=https://npm.taobao.org/mirrors/selenium -node_inspector_cdnurl=https://npm.taobao.org/mirrors/node-inspector -fsevents_binary_host_mirror=http://npm.taobao.org/mirrors/fsevents/ package-lock=false diff --git a/.prettierrc b/.prettierrc index bfc51ad..cf847e6 100644 --- a/.prettierrc +++ b/.prettierrc @@ -6,31 +6,5 @@ "jsxBracketSameLine": true, "tabWidth": 2, "semi": true, - "singleQuote": true, - "overrides": [ - { - "files": "*.scss", - "options": { - "trailingComma": "none", - "tabWidth": 2, - "parser": "scss" - } - }, - { - "files": "*.json", - "options": { - "trailingComma": "none", - "tabWidth": 2, - "parser": "json" - } - }, - { - "files": "*.md", - "options": { - "trailingComma": "none", - "tabWidth": 2, - "parser": "json" - } - } - ] + "singleQuote": true } diff --git a/.release-it.json b/.release-it.json index d7341a3..f7f3e83 100644 --- a/.release-it.json +++ b/.release-it.json @@ -3,15 +3,12 @@ "requireCleanWorkingDir": false }, "hooks": { - "after:init": [ - "npm run test", - "t2k" - ], - "after:bump": [ - "npm run build" - ] + "after:init": ["npm run test", "t2k"], + "after:bump": ["npm run build"], + "after:release": ["npm pkg get name | cnpm sync"] }, "github": { - "release": true + "release": true, + "proxy": "http://127.0.0.1:9090" } } diff --git a/README.md b/README.md index 9c506fc..b2fd266 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## installation ```bash -npm install -S @jswork/next-gpid +yarn add @jswork/next-gpid ``` ## usage diff --git a/__tests__/index.spec.js b/__tests__/index.spec.js index a160178..236da7e 100644 --- a/__tests__/index.spec.js +++ b/__tests__/index.spec.js @@ -2,8 +2,8 @@ require('../src'); describe('api.basic test', () => { test('nx.gpid basic case', function () { - var url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'; - var res = nx.gpid(url); - expect(res).toBe('googlelogo_color_272x92dp'); - }); + var url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'; + var res = nx.gpid(url); + expect(res).toBe('googlelogo_color_272x92dp'); + }); }); diff --git a/build/clean.js b/build/clean.js deleted file mode 100644 index 2b0766a..0000000 --- a/build/clean.js +++ /dev/null @@ -1,13 +0,0 @@ -(function() { - 'use strict'; - - const gulp = require('gulp'); - const $ = require('gulp-load-plugins')({ - pattern: ['gulp-*', 'gulp.*', 'del'] - }); - - //clean - gulp.task('clean', function() { - return $.del('dist'); - }); -})(); diff --git a/build/scripts.js b/build/scripts.js deleted file mode 100644 index 043d64f..0000000 --- a/build/scripts.js +++ /dev/null @@ -1,22 +0,0 @@ -(function() { - 'use strict'; - - const gulp = require('gulp'); - const saveLicense = require('uglify-save-license'); - const $ = require('gulp-load-plugins')({ - pattern: ['gulp-*', 'gulp.*', 'del', '@jswork/gulp-*'] - }); - - gulp.task('scripts', function() { - return gulp - .src('src/*.js') - // .pipe($.babel()) - .pipe($.jswork.pkgHeader()) - .pipe(gulp.dest('dist')) - .pipe($.size({ title: '[ default size ]:' })) - .pipe($.uglify({ output: { comments: saveLicense } })) - .pipe($.rename({ extname: '.min.js' })) - .pipe(gulp.dest('dist')) - .pipe($.size({ title: '[ minimize size ]:' })); - }); -})(); diff --git a/gulpfile.js b/gulpfile.js index 0513561..c318497 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,9 @@ -(function() { - 'use strict'; +const gulp = require('gulp'); +const { NxScripts, CleanRegistry } = require('@jswork/gulp-registry'); - const gulp = require('gulp'); - const fs = require('fs'); +const task1 = new CleanRegistry(); +const task2 = new NxScripts({ name: 'qs', classify: false }); - //import - fs.readdirSync('./build').map(function(file) { - require('./build/' + file); - }); +[task1, task2].forEach(gulp.registry); - gulp.task('default', gulp.series(['clean', 'scripts'])); -})(); +gulp.task('default', gulp.series(['clean', 'nx:scripts'])); diff --git a/index.d.ts b/index.d.ts index fc0a7ea..e3302c3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,3 @@ interface NxStatic { - gpid(inUrl: string): string; + gpid: any; } diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index a0ca96e..0000000 --- a/jest.config.js +++ /dev/null @@ -1,11 +0,0 @@ -// https://jestjs.io/docs/en/configuration -module.exports = { - verbose: true, - testRegex: [/\.spec.js/], - //preset: "jest-puppeteer", - automock: false, - setupFiles: ['./jest.setup.js'], - moduleNameMapper: { - '^@/(.*)$': '/src/$1' - } -}; diff --git a/jest.setup.js b/jest.setup.js deleted file mode 100644 index ec28f0a..0000000 --- a/jest.setup.js +++ /dev/null @@ -1 +0,0 @@ -jest.setTimeout(60 * 1000); diff --git a/package.json b/package.json index e458fcf..9d637f0 100644 --- a/package.json +++ b/package.json @@ -3,54 +3,55 @@ "version": "1.0.2", "description": "Get picture uid from url.", "homepage": "https://js.work", + "files": [ + "dist", + "index.d.ts" + ], "author": { "name": "afei", "email": "1290657123@qq.com" }, "scripts": { "build": "gulp", - "test": "jest", - "start": "node ./express.js", + "test": "bun test", "release": "release-it" }, "main": "dist/index.js", + "module": "dist/index.esm.js", "license": "MIT", "devDependencies": { - "@babel/core": "^7.13.14", - "@babel/preset-env": "^7.13.12", - "@jswork/gulp-pkg-header": "^1.0.4", - "@jswork/next": "^1.0.9", + "@babel/core": "^7.21.3", + "@babel/preset-env": "^7.20.2", + "@jswork/gulp-pkg-header": "^1.0.8", + "@jswork/gulp-registry": "^1.0.45", + "@jswork/next": "^1.2.2", + "@types/jest": "^29.5.12", "del": "^6.0.0", "gulp": "^4.0.2", "gulp-babel": "^8.0.0", - "gulp-debug": "^4.0.0", - "gulp-header": "^2.0.9", - "gulp-ignore": "^3.0.0", - "gulp-load-plugins": "^2.0.6", + "gulp-prettier": "^4.0.0", "gulp-rename": "^2.0.0", - "gulp-size": "^3.0.0", + "gulp-replace": "^1.1.4", "gulp-uglify": "^3.0.2", - "jest": "^26.6.3", - "prettier": "^2.2.1", - "release-it": "^14.2.2", - "uglify-js": "3.12.4", + "husky": "^9.0.11", + "lint-staged": "^15.2.2", + "prettier": "^3.2.5", "uglify-save-license": "^0.4.1" }, + "babel": { + "presets": [ + [ + "@babel/preset-env" + ] + ] + }, "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" }, - "boilerplate": "boilerplate-next-package", - "repository": { - "type": "git", - "url": "https://github.com/afeiship/boilerplate-next-package.git" - }, - "keywords": [ - "next", - "id", - "image", - "picture", - "pid", - "uid" - ] + "lint-staged": { + "src/**/*.{js,jsx}": [ + "npm run pretty" + ] + } } diff --git a/src/index.js b/src/index.js index 3d037c5..8b0914c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,13 @@ -(function () { - var global = typeof window !== 'undefined' ? window : this || Function('return this')(); - var nx = global.nx || require('@jswork/next'); +import nx from '@jswork/next'; - nx.gpid = function (inUrl) { - var url = inUrl || location.href || ''; - var filename = url.substring(url.lastIndexOf('/') + 1); - return filename.split('.')[0]; - }; +nx.gpid = function (inUrl) { + var url = inUrl || location.href || ''; + var filename = url.substring(url.lastIndexOf('/') + 1); + return filename.split('.')[0]; +}; - if (typeof module !== 'undefined' && module.exports) { - module.exports = nx.gpid; - } -})(); +if (typeof module !== 'undefined' && module.exports && typeof wx === 'undefined') { + module.exports = nx.gpid; +} + +export default nx.gpid;