| #!/usr/bin/env node |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| const fs = require('fs'); |
| const path = require('path'); |
| const os = require('os'); |
|
|
| const token = process.argv[2]; |
| const npmrcPath = path.join(os.homedir(), '.npmrc'); |
|
|
| if (!token) { |
| console.error(' Error: NPM token not provided'); |
| console.error('\nUsage:'); |
| console.error(' npm run npm:setup-token <token>'); |
| console.error('\nExample:'); |
| console.error(' npm run npm:setup-token npm_xxxxxxxxxxxxxxxx'); |
| process.exit(1); |
| } |
|
|
| try { |
| console.log(' Setting up NPM authentication token...\n'); |
| |
| |
| let npmrcContent = ''; |
| if (fs.existsSync(npmrcPath)) { |
| npmrcContent = fs.readFileSync(npmrcPath, 'utf-8'); |
| } |
|
|
| |
| const lines = npmrcContent.split('\n').filter(line => !line.includes('_authToken')); |
| |
| |
| lines.push(`//registry.npmjs.org/:_authToken=${token}`); |
| |
| |
| fs.writeFileSync(npmrcPath, lines.join('\n').trim() + '\n'); |
| |
| console.log(' NPM token configured successfully!\n'); |
| console.log(' Location:', npmrcPath); |
| console.log('\n You can now publish packages:'); |
| console.log(' npm run npm:publish-test (dry run)'); |
| console.log(' npm run npm:publish (actual publish)\n'); |
|
|
| } catch (error) { |
| console.error(' Error setting up NPM token:', error.message); |
| process.exit(1); |
| } |
|
|