diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..f3b1a9f --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} diff --git a/package-lock.json b/package-lock.json index c26f181..1cdf614 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@web/state", + "name": "@apigo.cc/state", "version": "1.0.12", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@web/state", + "name": "@apigo.cc/state", "version": "1.0.12", "devDependencies": { "@playwright/test": "^1.40.0", diff --git a/package.json b/package.json index 9b28b45..c645068 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,22 @@ { - "name": "@web/state", - "version": "1.0.13", - "type": "module", - "main": "dist/state.js", - "module": "dist/state.js", - "files": [ - "dist" - ], - "scripts": { - "dev": "vite", - "build": "vite build", - "test": "playwright test" - }, - "devDependencies": { - "@playwright/test": "^1.40.0", - "@rollup/plugin-terser": "^1.0.0", - "terser": "^5.47.1", - "vite": "^5.0.0" - } + "name": "@apigo.cc/state", + "version": "1.0.12", + "type": "module", + "main": "dist/state.js", + "module": "dist/state.js", + "files": [ + "dist" + ], + "scripts": { + "dev": "vite", + "build": "vite build", + "test": "playwright test", + "pub": "node scripts/publish.js" + }, + "devDependencies": { + "@playwright/test": "^1.40.0", + "@rollup/plugin-terser": "^1.0.0", + "terser": "^5.47.1", + "vite": "^5.0.0" + } } diff --git a/scripts/publish.js b/scripts/publish.js new file mode 100644 index 0000000..b562aa9 --- /dev/null +++ b/scripts/publish.js @@ -0,0 +1,48 @@ +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +try { + // 1. 获取最新 tag + let tag; + try { + tag = execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim(); + } catch (err) { + throw new Error('Failed to find git tags. Please make sure the repository has tags (e.g., v1.0.0) before publishing.'); + } + // 去掉 v 前缀 + const version = tag.startsWith('v') ? tag.slice(1) : tag; + + console.log(`Latest git tag: ${tag}, Version to publish: ${version}`); + + // 2. 读取并更新 package.json + const pkgPath = path.join(__dirname, '../package.json'); + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); + + // 保持原有名称(如果已经带有 @apigo.cc/ 前缀)或替换前缀 + if (!pkg.name.startsWith('@apigo.cc/')) { + const baseName = pkg.name.includes('/') ? pkg.name.split('/')[1] : pkg.name; + pkg.name = `@apigo.cc/${baseName}`; + } + pkg.version = version; + + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); + console.log(`Updated package.json: name=${pkg.name}, version=${pkg.version}`); + + // 3. 构建 + console.log('Running build...'); + execSync('npm run build', { stdio: 'inherit', cwd: path.join(__dirname, '..') }); + + // 4. 发布 + console.log('Publishing to npm...'); + const args = process.argv.slice(2).join(' '); + execSync(`npm publish --access public ${args}`, { stdio: 'inherit', cwd: path.join(__dirname, '..') }); + + console.log('Publish successful!'); +} catch (error) { + console.error('Publish failed:', error.message); + process.exit(1); +} diff --git a/test/all.spec.js b/test/all.spec.js index eb9e31f..4681a8e 100644 --- a/test/all.spec.js +++ b/test/all.spec.js @@ -32,7 +32,7 @@ test('modular unit tests and benchmark', async ({ page }) => { const items = []; for(let i=0; i<1000; i++) items.push({val: 'item ' + i}); window.state.benchItems = items; - const { RefreshState } = await import('@web/state'); + const { RefreshState } = await import('@apigo.cc/state'); RefreshState(document.documentElement); return performance.now() - start; }); @@ -51,7 +51,7 @@ test('modular unit tests and benchmark', async ({ page }) => { // Extreme Data Test await page.evaluate(async () => { - const { RefreshState } = await import('@web/state'); + const { RefreshState } = await import('@apigo.cc/state'); document.body.innerHTML = '
'; window.state.extreme = null; RefreshState(document.getElementById('extreme')); diff --git a/test/index.html b/test/index.html index 09aaee9..d02bfb8 100644 --- a/test/index.html +++ b/test/index.html @@ -5,7 +5,7 @@