UNPKG

as-package

Version:

Publish AssemblyScript Packages To The AssemblyScript Package List

131 lines (77 loc) 2.92 kB
const fs = require('fs') const package = require(process.cwd() + '/package.json') const needle = require('needle') const getPackage = require('package-json') const user = { username: null, password: null } const readline = require('readline') const args = [] const input = process.argv.slice(2, process.argv.length) for (let i = 0; i < input.length; i++) { args.push(input[i].toLowerCase().trim()) } if (args.includes('publish') || args.includes('update')) { let usernamePrompt = readline.createInterface({ input: process.stdin, output: process.stdout }) usernamePrompt.question('Enter Username: ', (answer) => { user.username = answer.trim() usernamePrompt.close() let passwordPrompt = readline.createInterface({ input: process.stdin, output: process.stdout }) passwordPrompt.question('Enter Password: ', async (answer) => { user.password = answer.trim() passwordPrompt.close() let npm = null let github = null const name = package['name'] if (await isNPM(package)) { npm = `https://www.npmjs.com/package/${name}` } if (isGitHub(package)) { github = package.repository.url.replace('git+', 'git').replace('.git', '').replace('githttp', 'http') } if (!npm && !github) { throw new Error('Could Not Find Repository. Must Be NPM Or GitHub.') } const response = await needle('get', `https://assemblyscript-packages.jairussw.repl.co/publish?data=${JSON.stringify({ npm: npm, github: github, name: package.name, username: user.username, password: user.password, version: package.version, readme: fs.readFileSync(process.cwd() + '/README.md').toString('hex'), keywords: package.keywords, license: package.license, description: package.description })}`) console.log(response.body) }) }) } async function isNPM (package) { try { await getPackage(package.name) return true } catch { return false } } async function isGitHub (package) { try { if (!package.repository) return false if (package.repository.type === 'git') { const res = await needle('get', `${package.repository.url.replace('+git', '').replace('.git', '')}`) if (res.statusCode >= 400) return false } return true } catch { return false } }