Comparing version 2.0.1 to 2.0.2
102
index.js
@@ -7,10 +7,17 @@ #!/usr/bin/env node | ||
const chalk = require('chalk') | ||
const argv = require('minimist')(process.argv.slice(2)) | ||
const commander = require('commander') | ||
commander.option('-d, --dirName', 'package name').option('-n, --websiteName', 'website name') | ||
const argv = require('minimist')(process.argv.slice(2)) | ||
commander | ||
.option('-d, --dirName', 'package name') | ||
.option('-n, --websiteName', 'website name') | ||
.parse(process.argv) | ||
;(async () => { | ||
if (!argv.n) { | ||
console.log(chalk.red.bold.bgWhite('请自定义子域名')) | ||
return | ||
} | ||
let zipName | ||
function readDir(zip, dirPath) { | ||
const files = fs.readdirSync(dirPath) | ||
files.forEach(fileName => { | ||
files.forEach((fileName) => { | ||
const fillPath = dirPath + '/' + fileName | ||
@@ -41,5 +48,5 @@ const file = fs.statSync(fillPath) | ||
compression: 'DEFLATE', // 压缩算法 | ||
compressionOptions: { level: 9 } // 压缩级别 | ||
compressionOptions: { level: 9 }, // 压缩级别 | ||
}) | ||
.then(async content => { | ||
.then(async (content) => { | ||
const dest = path.join(process.cwd(), './') | ||
@@ -62,43 +69,58 @@ zipName = sourceDirName + '.zip' | ||
process.exit() | ||
browser.close() | ||
} | ||
try { | ||
await generateZip() | ||
const browser = await puppeteer.launch() | ||
const page = await browser.newPage() | ||
await page.goto('http://show.hsmob.com/') | ||
try { | ||
await page.waitForSelector('input[type=file]', { | ||
timeout: 2000 | ||
}) | ||
} catch (error) { | ||
console.log(chalk.red.bold.bgWhite('网络有误,查看内网是否正常连接')) | ||
end(zipName, browser) | ||
} | ||
console.log(chalk.green('上传中...')) | ||
const inputUploadHandle = await page.$('input[type=file]') | ||
await inputUploadHandle.uploadFile(zipName) | ||
const checkbox = '#add-password' | ||
await page.waitForSelector(checkbox) | ||
await page.click(checkbox) | ||
const input = '#password-input' | ||
await page.waitForSelector(input) | ||
await page.focus(input) | ||
const websiteName = argv.n | ||
await page.keyboard.type(websiteName) | ||
const submit = '#upload-btn' | ||
await page.waitForSelector(submit) | ||
await page.click(submit) | ||
await page.waitForTimeout(1000) | ||
try { | ||
const a = await page.waitForSelector(`input`, { | ||
timeout: 15000 | ||
}) | ||
console.log(document.querySelector('input')) | ||
} catch (error) { | ||
console.log(chalk.red.bold.bgWhite('上传失败,文件中未包含 index.html ,自定义域名错误,文件格式错误,其他。')) | ||
} catch (error) { | ||
return | ||
} | ||
const browser = await puppeteer.launch({ headless: true }) | ||
const page = await browser.newPage() | ||
await page.goto('http://show.hsmob.com/') | ||
try { | ||
await page.waitForSelector('input[type=file]', { | ||
timeout: 1000, | ||
}) | ||
} catch (error) { | ||
console.log(chalk.red.bold.bgWhite('网络有误,查看内网是否正常连接')) | ||
end(zipName) | ||
return | ||
} | ||
console.log(chalk.green('上传中...')) | ||
const inputUploadHandle = await page.$('input[type=file]') | ||
await inputUploadHandle.uploadFile(zipName) | ||
const checkbox = '#add-password' | ||
await page.waitForSelector(checkbox) | ||
await page.click(checkbox) | ||
const input = '#password-input' | ||
await page.waitForSelector(input) | ||
await page.focus(input) | ||
const websiteName = argv.n | ||
await page.keyboard.type(websiteName) | ||
const submit = '#upload-btn' | ||
await page.waitForSelector(submit) | ||
await page.click(submit) | ||
await page.waitForTimeout(1000) | ||
page.waitForSelector('h1').then(async () => { | ||
const element = await page.$eval('h1', (el) => el.textContent) | ||
const isError = ['错误', 'wrong'].some((e) => element.includes(e)) | ||
if (isError) { | ||
console.log( | ||
chalk.red.bold.bgWhite( | ||
'上传失败,文件中未包含 index.html ,自定义域名错误,文件格式错误,其他。' | ||
) | ||
) | ||
end(zipName) | ||
return | ||
} | ||
console.log(chalk.green(`上传成功:http://${websiteName}.show.hsmob.com`)) | ||
}) | ||
try { | ||
const input = await page.waitForSelector('input', { | ||
timeout: 15000, | ||
}) | ||
const inputValue = await page.$eval('input', (el) => el.value) | ||
console.log(33, inputValue) | ||
console.log(chalk.green(`上传成功:${inputValue}`)) | ||
end(zipName) | ||
browser.close() | ||
} catch (error) { | ||
@@ -105,0 +127,0 @@ end(zipName) |
{ | ||
"name": "hsmob", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "upload zip to show.hsmob.com", | ||
@@ -18,3 +18,3 @@ "main": "index.js", | ||
"author": "", | ||
"license": "ISC" | ||
} | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4291
124
1