mirror of
https://github.com/bcomnes/deploy-to-neocities.git
synced 2026-01-21 08:51:54 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f13458cc2d | ||
|
|
5e6f9848c7 | ||
|
|
fad2c4a165 | ||
|
|
1638c39428 | ||
|
|
c50fdeb3e6 | ||
|
|
48d2e5e4e0 | ||
|
|
aaf8a90973 | ||
|
|
34601c4927 | ||
|
|
ce8f0e70b0 | ||
|
|
22ef26e851 | ||
|
|
b96571b8ad | ||
|
|
bc86874ede | ||
|
|
4a9e7f6a6d | ||
|
|
2c52eeaa2b | ||
|
|
19246fac79 |
43
CHANGELOG.md
43
CHANGELOG.md
@@ -7,6 +7,49 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
## [v0.0.9](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.8...v0.0.9) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- chore: update deps [`5e6f984`](https://github.com/bcomnes/deploy-to-neocities/commit/5e6f9848c78a5f3a668b47a27dc14835005bf98c)
|
||||
|
||||
## [v0.0.8](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.7...v0.0.8) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- chore: update async-neocities to 1.1.3 [`1638c39`](https://github.com/bcomnes/deploy-to-neocities/commit/1638c394287dcf61bcf439a387dbefc2e68b2128)
|
||||
|
||||
## [v0.0.7](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.6...v0.0.7) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- refactor: Remove core calls [`48d2e5e`](https://github.com/bcomnes/deploy-to-neocities/commit/48d2e5e4e064176c8c4d27eddea40d0009446dba)
|
||||
|
||||
## [v0.0.6](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.5...v0.0.6) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: update async-neocities to 1.1.2 [`34601c4`](https://github.com/bcomnes/deploy-to-neocities/commit/34601c49277891d15395a79b28eeb21781a019da)
|
||||
|
||||
## [v0.0.5](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.4...v0.0.5) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Use correct version of async-neocities [`22ef26e`](https://github.com/bcomnes/deploy-to-neocities/commit/22ef26e851efa57357d731a73a1f606dc212608a)
|
||||
|
||||
## [v0.0.4](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.3...v0.0.4) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- refactor: Dramatically simplify logging [`bc86874`](https://github.com/bcomnes/deploy-to-neocities/commit/bc86874ede188f9c33f0b6dfd2e54b25328b1285)
|
||||
|
||||
## [v0.0.3](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.2...v0.0.3) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- Fix boolean parsing [`19246fa`](https://github.com/bcomnes/deploy-to-neocities/commit/19246fac798151a3ab80666412f72394c0615c32)
|
||||
- bug: Fix reference bug in logging [`2c52eea`](https://github.com/bcomnes/deploy-to-neocities/commit/2c52eeaa2badbb1bcb3c2520e358fcc088bc3879)
|
||||
|
||||
## [v0.0.2](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.1...v0.0.2) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
@@ -4,10 +4,10 @@ branding:
|
||||
icon: cat
|
||||
color: yellow
|
||||
inputs:
|
||||
api-token: # api token for site to deploy to
|
||||
apiToken: # api token for site to deploy to
|
||||
description: 'Neocities API token for site to deploy to'
|
||||
required: true
|
||||
dist-dir:
|
||||
distDir:
|
||||
description: 'Local folder to deploy to neocities'
|
||||
default: 'public'
|
||||
required: true
|
||||
|
||||
98
index.js
98
index.js
@@ -3,101 +3,29 @@ const core = require('@actions/core')
|
||||
const Neocities = require('async-neocities')
|
||||
const path = require('path')
|
||||
const prettyTime = require('pretty-time')
|
||||
const prettyBytes = require('pretty-bytes')
|
||||
const assert = require('nanoassert')
|
||||
|
||||
async function doDeploy () {
|
||||
const token = core.getInput('api-token')
|
||||
const distDir = path.join(process.cwd(), core.getInput('dist-dir'))
|
||||
const cleanup = core.getInput('cleanup')
|
||||
const token = core.getInput('apiToken')
|
||||
const distDir = path.join(process.cwd(), core.getInput('distDir'))
|
||||
const cleanup = JSON.parse(core.getInput('cleanup'))
|
||||
assert(typeof cleanup === 'boolean', 'Cleanup input must be a boolean "true" or "false"')
|
||||
console.log(typeof cleanup)
|
||||
|
||||
const client = new Neocities(token)
|
||||
|
||||
const finalStats = await client.deploy(distDir, {
|
||||
const stats = await client.deploy(distDir, {
|
||||
cleanup,
|
||||
statsCb: statsHandler({ cleanup, distDir })
|
||||
statsCb: Neocities.statsHandler()
|
||||
})
|
||||
|
||||
return finalStats
|
||||
console.log(`Deployed to Neocities in ${prettyTime([0, stats.time])}:`)
|
||||
console.log(` Uploaded ${stats.filesToUpload.length} files`)
|
||||
console.log(` ${cleanup ? 'Deleted' : 'Orphaned'} ${stats.filesToDelete.length} files`)
|
||||
console.log(` Skipped ${stats.filesSkipped.length} files`)
|
||||
}
|
||||
|
||||
doDeploy().then((finalStats) => {}).catch(err => {
|
||||
doDeploy().catch(err => {
|
||||
console.error(err)
|
||||
core.setFailed(err.message)
|
||||
})
|
||||
|
||||
function statsHandler (opts = {}) {
|
||||
return (stats) => {
|
||||
switch (stats.stage) {
|
||||
case 'inspecting': {
|
||||
switch (stats.status) {
|
||||
case 'start': {
|
||||
core.startGroup('Inspecting files')
|
||||
console.log('Inspecting local and remote files...')
|
||||
console.log(`Dist directory: ${opts.distDir})`)
|
||||
break
|
||||
}
|
||||
case 'progress': {
|
||||
break
|
||||
}
|
||||
case 'stop': {
|
||||
console.log(`Done inspecting local and remote files in ${prettyTime([0, stats.timer.elapsed])}`)
|
||||
const { tasks: { localScan, remoteScan } } = stats
|
||||
console.log(`Scanned ${localScan.numberOfFiles} local files (${prettyBytes(localScan.totalSize)}) in ${prettyTime([0, localScan.timer.elapsed])}`)
|
||||
console.log(`Scanned ${remoteScan.numberOfFiles} remote files (${prettyBytes(remoteScan.totalSize)}) in ${prettyTime([0, remoteScan.timer.elapsed])}`)
|
||||
core.endGroup()
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'diffing': {
|
||||
switch (stats.status) {
|
||||
case 'start': {
|
||||
core.startGroup('Diffing files')
|
||||
console.log('Diffing local and remote files...')
|
||||
break
|
||||
}
|
||||
case 'progress': {
|
||||
// No progress on diffing
|
||||
break
|
||||
}
|
||||
case 'stop': {
|
||||
const { tasks: { diffing } } = stats
|
||||
console.log(`Done diffing local and remote files in ${prettyTime([0, stats.timer.elapsed])}`)
|
||||
console.log(`${diffing.uploadCount} files to upload`)
|
||||
console.log(`${diffing.deleteCount} ` + (opts.cleanup ? 'files to delete' : 'orphaned files'))
|
||||
console.log(`${diffing.skipCoount} files to skip`)
|
||||
core.endGroup()
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'applying': {
|
||||
switch (stats.status) {
|
||||
case 'start': {
|
||||
core.startGroup('Applying diff')
|
||||
console.log('Uploading changes' + (opts.cleanup ? ' and deleting orphaned files...' : '...'))
|
||||
break
|
||||
}
|
||||
case 'progress': {
|
||||
break
|
||||
}
|
||||
case 'stop': {
|
||||
const { tasks: { uploadFiles, deleteFiles, skippedFiles } } = stats
|
||||
console.log('Done uploading changes' + (opts.cleanup ? ' and deleting orphaned files' : '') + ` in ${prettyTime([0, stats.timer.elapsed])}`)
|
||||
console.log(`Average upload speed: ${prettyBytes(uploadFiles.speed)}/s`)
|
||||
if (opts.cleanup) console.log(`Average delete speed: ${prettyBytes(deleteFiles.speed)}/s`)
|
||||
console.log(`Skipped ${skippedFiles.count} files (${prettyBytes(skippedFiles.size)})`)
|
||||
core.endGroup()
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
default: {
|
||||
console.log(stats)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
node_modules/async-neocities/CHANGELOG.md
generated
vendored
36
node_modules/async-neocities/CHANGELOG.md
generated
vendored
@@ -7,6 +7,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
## [v1.1.4](https://github.com/bcomnes/async-neocities/compare/v1.1.3...v1.1.4) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: fix logging handler logic [`f6c5921`](https://github.com/bcomnes/async-neocities/commit/f6c5921d6fd0a420c5895ed6ba2fe2f766e726fd)
|
||||
|
||||
## [v1.1.3](https://github.com/bcomnes/async-neocities/compare/v1.1.2...v1.1.3) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- refactor: Stop logging progress when the stream has been read. [`3ce0fc4`](https://github.com/bcomnes/async-neocities/commit/3ce0fc452acbbbd28c39b53a3a9a4318a8019c09)
|
||||
|
||||
## [v1.1.2](https://github.com/bcomnes/async-neocities/compare/v1.1.1...v1.1.2) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Fix export name of statsHandler [`8958e5e`](https://github.com/bcomnes/async-neocities/commit/8958e5eeb947376690a1ce0cefe7cce3d59be5b8)
|
||||
|
||||
## [v1.1.1](https://github.com/bcomnes/async-neocities/compare/v1.1.0...v1.1.1) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Fix busted export of stats handler. [`510ae29`](https://github.com/bcomnes/async-neocities/commit/510ae293263955e0e34d3ab48df253fb6e093053)
|
||||
|
||||
## [v1.1.0](https://github.com/bcomnes/async-neocities/compare/v1.0.2...v1.1.0) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- feat: Finish statsCb API and add a stats-handler.js function. [`c8e6483`](https://github.com/bcomnes/async-neocities/commit/c8e64835e594e68715ef71590b08baac374052bd)
|
||||
|
||||
## [v1.0.2](https://github.com/bcomnes/async-neocities/compare/v1.0.1...v1.0.2) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- chore: remove total time from stats [`3c375ec`](https://github.com/bcomnes/async-neocities/commit/3c375ecf64ae8536a8e3ccce0a69cd93c8c6a306)
|
||||
|
||||
## [v1.0.1](https://github.com/bcomnes/async-neocities/compare/v1.0.0...v1.0.1) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
4
node_modules/async-neocities/README.md
generated
vendored
4
node_modules/async-neocities/README.md
generated
vendored
@@ -185,11 +185,11 @@ Deploy a path to a `directory`, efficiently only uploading missing and changed f
|
||||
```js
|
||||
{
|
||||
cleanup: false // delete orphaned files on neocities that are not in the `directory`
|
||||
statsCb: () => {} // WIP progress API
|
||||
statsCb: (stats) => {}
|
||||
}
|
||||
```
|
||||
|
||||
The return value of this method is subject to change.
|
||||
For an example of a stats handler, see [lib/stats-handler.js]('./lib/stats-handler.js').
|
||||
|
||||
### `client.get(endpoint, [quieries], [opts])`
|
||||
|
||||
|
||||
210
node_modules/async-neocities/index.js
generated
vendored
210
node_modules/async-neocities/index.js
generated
vendored
@@ -12,6 +12,7 @@ const { neocitiesLocalDiff } = require('./lib/folder-diff')
|
||||
const pkg = require('./package.json')
|
||||
const SimpleTimer = require('./lib/timer')
|
||||
const { getStreamLength, meterStream } = require('./lib/stream-meter')
|
||||
const statsHandler = require('./lib/stats-handler')
|
||||
|
||||
const defaultURL = 'https://neocities.org'
|
||||
|
||||
@@ -19,6 +20,7 @@ const defaultURL = 'https://neocities.org'
|
||||
const START = 'start'
|
||||
const PROGRESS = 'progress' // progress updates
|
||||
const STOP = 'stop'
|
||||
const SKIP = 'skip'
|
||||
// Progress stages
|
||||
const INSPECTING = 'inspecting'
|
||||
const DIFFING = 'diffing'
|
||||
@@ -55,6 +57,8 @@ class NeocitiesAPIClient {
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
static statsHandler (...args) { return statsHandler(...args) }
|
||||
|
||||
/**
|
||||
* Create an async-neocities api client.
|
||||
* @param {string} apiKey An apiKey to make requests with.
|
||||
@@ -226,195 +230,73 @@ class NeocitiesAPIClient {
|
||||
}
|
||||
|
||||
const statsCb = opts.statsCb
|
||||
const startDeployTime = Date.now()
|
||||
const totalTime = new SimpleTimer(startDeployTime)
|
||||
const totalTime = new SimpleTimer(Date.now())
|
||||
|
||||
// Inspection stage stats initializer
|
||||
const inspectionStats = {
|
||||
stage: INSPECTING,
|
||||
status: START,
|
||||
timer: new SimpleTimer(startDeployTime),
|
||||
totalTime,
|
||||
tasks: {
|
||||
localScan: {
|
||||
numberOfFiles: 0,
|
||||
totalSize: 0,
|
||||
timer: new SimpleTimer(startDeployTime)
|
||||
},
|
||||
remoteScan: {
|
||||
numberOfFiles: 0,
|
||||
totalSize: 0,
|
||||
timer: new SimpleTimer(startDeployTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
const sendInspectionUpdate = (status) => {
|
||||
if (status) inspectionStats.status = status
|
||||
statsCb(inspectionStats)
|
||||
}
|
||||
sendInspectionUpdate(START)
|
||||
|
||||
// Remote scan timers
|
||||
const remoteScanJob = this.list()
|
||||
remoteScanJob.then(({ files }) => { // Comes in the form of a response object
|
||||
const { tasks: { remoteScan } } = inspectionStats
|
||||
remoteScan.numberOfFiles = files.length
|
||||
remoteScan.totalSize = files.reduce((accum, cur) => {
|
||||
return accum + cur.size || 0
|
||||
}, 0)
|
||||
remoteScan.timer.stop()
|
||||
sendInspectionUpdate(PROGRESS)
|
||||
})
|
||||
|
||||
// Local scan timers and progress accumulator
|
||||
const localScanJob = progressAccum(
|
||||
afw.asyncFolderWalker(directory, { shaper: f => f })
|
||||
)
|
||||
async function progressAccum (iterator) {
|
||||
const localFiles = []
|
||||
const { tasks: { localScan } } = inspectionStats
|
||||
|
||||
for await (const file of iterator) {
|
||||
localFiles.push(file)
|
||||
localScan.numberOfFiles += 1
|
||||
localScan.totalSize += file.stat.size
|
||||
sendInspectionUpdate(PROGRESS)
|
||||
}
|
||||
return localFiles
|
||||
}
|
||||
localScanJob.then(files => {
|
||||
const { tasks: { localScan } } = inspectionStats
|
||||
localScan.timer.stop()
|
||||
sendInspectionUpdate(PROGRESS)
|
||||
})
|
||||
|
||||
// Inspection stage finalizer
|
||||
// INSPECTION STAGE
|
||||
statsCb({ stage: INSPECTING, status: START })
|
||||
const [localFiles, remoteFiles] = await Promise.all([
|
||||
localScanJob,
|
||||
remoteScanJob.then(res => res.files)
|
||||
afw.allFiles(directory, { shaper: f => f }),
|
||||
this.list().then(res => res.files)
|
||||
])
|
||||
inspectionStats.timer.stop()
|
||||
sendInspectionUpdate(STOP)
|
||||
statsCb({ stage: INSPECTING, status: STOP })
|
||||
|
||||
// DIFFING STAGE
|
||||
|
||||
const diffingStats = {
|
||||
stage: DIFFING,
|
||||
status: START,
|
||||
timer: new SimpleTimer(Date.now()),
|
||||
totalTime,
|
||||
tasks: {
|
||||
diffing: {
|
||||
uploadCount: 0,
|
||||
deleteCount: 0,
|
||||
skipCount: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
statsCb(diffingStats)
|
||||
|
||||
const { tasks: { diffing } } = diffingStats
|
||||
statsCb({ stage: DIFFING, status: START })
|
||||
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
||||
statsCb({ stage: DIFFING, status: STOP })
|
||||
|
||||
diffingStats.timer.stop()
|
||||
diffingStats.status = STOP
|
||||
diffing.uploadCount = filesToUpload.length
|
||||
diffing.deleteCount = filesToDelete.length
|
||||
diffing.skipCount = filesSkipped.length
|
||||
statsCb(diffingStats)
|
||||
|
||||
const applyingStartTime = Date.now()
|
||||
const applyingStats = {
|
||||
stage: APPLYING,
|
||||
status: START,
|
||||
timer: new SimpleTimer(applyingStartTime),
|
||||
totalTime,
|
||||
tasks: {
|
||||
uploadFiles: {
|
||||
timer: new SimpleTimer(applyingStartTime),
|
||||
bytesWritten: 0,
|
||||
totalBytes: 0,
|
||||
get percent () {
|
||||
return this.totalBytes === 0 ? 0 : this.bytesWritten / this.totalBytes
|
||||
},
|
||||
get speed () {
|
||||
return this.bytesWritten / this.timer.elapsed
|
||||
}
|
||||
},
|
||||
deleteFiles: {
|
||||
timer: new SimpleTimer(applyingStartTime),
|
||||
bytesWritten: 0,
|
||||
totalBytes: 0,
|
||||
get percent () {
|
||||
return this.totalBytes === 0 ? 0 : this.bytesWritten / this.totalBytes
|
||||
},
|
||||
get speed () {
|
||||
return this.bytesWritten / this.timer.elapsed
|
||||
}
|
||||
},
|
||||
skippedFiles: {
|
||||
count: filesSkipped.length,
|
||||
size: filesSkipped.reduce((accum, file) => accum + file.stat.size, 0)
|
||||
}
|
||||
}
|
||||
// APPLYING STAGE
|
||||
if (filesToUpload.length === 0 && (!opts.cleanup || filesToDelete.length === 0)) {
|
||||
statsCb({ stage: APPLYING, status: SKIP })
|
||||
return stats()
|
||||
}
|
||||
const sendApplyingUpdate = (status) => {
|
||||
if (status) applyingStats.status = status
|
||||
statsCb(applyingStats)
|
||||
}
|
||||
sendApplyingUpdate(START)
|
||||
|
||||
statsCb({ stage: APPLYING, status: START })
|
||||
const work = []
|
||||
const { tasks: { uploadFiles, deleteFiles } } = applyingStats
|
||||
|
||||
if (filesToUpload.length > 0) {
|
||||
const uploadJob = this.upload(filesToUpload, {
|
||||
statsCb: ({ bytesWritten, totalBytes }) => {
|
||||
uploadFiles.bytesWritten = bytesWritten
|
||||
uploadFiles.totalBytes = totalBytes
|
||||
sendApplyingUpdate(PROGRESS)
|
||||
statsCb ({ totalBytes, bytesWritten }) {
|
||||
statsCb({
|
||||
stage: APPLYING,
|
||||
status: PROGRESS,
|
||||
complete: false,
|
||||
totalBytes,
|
||||
bytesWritten,
|
||||
get progress () {
|
||||
return (this.bytesWritten / this.totalBytes) || 0
|
||||
}
|
||||
})
|
||||
}
|
||||
}).then((_) => {
|
||||
statsCb({
|
||||
stage: APPLYING,
|
||||
status: PROGRESS,
|
||||
complete: true,
|
||||
progress: 1.0
|
||||
})
|
||||
})
|
||||
work.push(uploadJob)
|
||||
uploadJob.then(res => {
|
||||
uploadFiles.timer.stop()
|
||||
sendApplyingUpdate(PROGRESS)
|
||||
})
|
||||
} else {
|
||||
uploadFiles.timer.stop()
|
||||
}
|
||||
|
||||
if (opts.cleanup && filesToDelete.length > 0) {
|
||||
const deleteJob = this.delete(filesToDelete, {
|
||||
statsCb: ({ bytesWritten, totalBytes }) => {
|
||||
deleteFiles.bytesWritten = bytesWritten
|
||||
deleteFiles.totalBytes = totalBytes
|
||||
sendApplyingUpdate(PROGRESS)
|
||||
}
|
||||
})
|
||||
work.push(deleteJob)
|
||||
deleteJob.then(res => {
|
||||
deleteFiles.timer.stop()
|
||||
sendApplyingUpdate(PROGRESS)
|
||||
})
|
||||
} else {
|
||||
deleteFiles.timer.stop()
|
||||
work.push(this.delete(filesToDelete))
|
||||
}
|
||||
|
||||
await Promise.all(work)
|
||||
applyingStats.timer.stop()
|
||||
sendApplyingUpdate(STOP)
|
||||
statsCb({ stage: APPLYING, status: STOP })
|
||||
|
||||
totalTime.stop()
|
||||
return stats()
|
||||
|
||||
const statsSummary = {
|
||||
time: totalTime,
|
||||
inspectionStats,
|
||||
diffingStats,
|
||||
applyingStats
|
||||
function stats () {
|
||||
totalTime.stop()
|
||||
return {
|
||||
time: totalTime.elapsed,
|
||||
filesToUpload,
|
||||
filesToDelete,
|
||||
filesSkipped
|
||||
}
|
||||
}
|
||||
|
||||
return statsSummary
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
57
node_modules/async-neocities/lib/stats-handler.js
generated
vendored
Normal file
57
node_modules/async-neocities/lib/stats-handler.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
const prettyBytes = require('pretty-bytes')
|
||||
|
||||
// Progress API constants
|
||||
const START = 'start'
|
||||
const PROGRESS = 'progress' // progress updates
|
||||
const STOP = 'stop'
|
||||
const SKIP = 'skip'
|
||||
|
||||
function statsHandler (opts = {}) {
|
||||
let progressInterval
|
||||
const lastStats = {}
|
||||
|
||||
return (stats) => {
|
||||
switch (stats.status) {
|
||||
case START: {
|
||||
console.log(`Starting ${stats.stage} stage...`)
|
||||
break
|
||||
}
|
||||
case STOP: {
|
||||
console.log(`Finished ${stats.stage} stage.`)
|
||||
break
|
||||
}
|
||||
case SKIP: {
|
||||
console.log(`Skipping ${stats.stage} stage.`)
|
||||
break
|
||||
}
|
||||
case PROGRESS: {
|
||||
progressHandler(stats)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function progressHandler (stats) {
|
||||
Object.assign(lastStats, stats)
|
||||
if (!stats.complete && stats.progress < 1) {
|
||||
if (!progressInterval) {
|
||||
progressInterval = setInterval(logProgress, 500, lastStats)
|
||||
logProgress(lastStats)
|
||||
}
|
||||
} else {
|
||||
if (progressInterval) clearInterval(progressInterval)
|
||||
}
|
||||
}
|
||||
|
||||
function logProgress (stats) {
|
||||
let logLine = `Stage ${stats.stage}: ${stats.progress * 100}%`
|
||||
if (stats.bytesWritten != null && stats.totalBytes != null) {
|
||||
logLine = logLine + ` (${prettyBytes(stats.bytesWritten)} / ${prettyBytes(stats.totalBytes)})`
|
||||
}
|
||||
console.log(logLine)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = statsHandler
|
||||
21
node_modules/async-neocities/package.json
generated
vendored
21
node_modules/async-neocities/package.json
generated
vendored
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"_from": "async-neocities@1.0.1",
|
||||
"_id": "async-neocities@1.0.1",
|
||||
"_from": "async-neocities@1.1.4",
|
||||
"_id": "async-neocities@1.1.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-5TVaKLYKnaHoSiluCP0i78e0CBZbeqBL6bgK8/QsM8YOAtrhd5JO9c5DEaW4SFpmf4wV0qcamQXh0A3C7CANLw==",
|
||||
"_integrity": "sha512-EpVYipQlIkBGSbZYfnrJYpAhgoYbC2MyWypcMZ+YnPUM1c38WsKGA5QGujX6Rg6gQQKwUUTt/tuYSg8gPQGsSA==",
|
||||
"_location": "/async-neocities",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "async-neocities@1.0.1",
|
||||
"raw": "async-neocities@1.1.4",
|
||||
"name": "async-neocities",
|
||||
"escapedName": "async-neocities",
|
||||
"rawSpec": "1.0.1",
|
||||
"rawSpec": "1.1.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.1"
|
||||
"fetchSpec": "1.1.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async-neocities/-/async-neocities-1.0.1.tgz",
|
||||
"_shasum": "3428ae48f48104b205a3537212090b00d9bbce45",
|
||||
"_spec": "async-neocities@1.0.1",
|
||||
"_resolved": "https://registry.npmjs.org/async-neocities/-/async-neocities-1.1.4.tgz",
|
||||
"_shasum": "7edb6d8a9ceee4fdc410b562430119619dd31aca",
|
||||
"_spec": "async-neocities@1.1.4",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||
"author": {
|
||||
"name": "Bret Comnes",
|
||||
@@ -37,6 +37,7 @@
|
||||
"form-data": "^3.0.0",
|
||||
"nanoassert": "^2.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"pretty-bytes": "^5.3.0",
|
||||
"pump": "^3.0.0",
|
||||
"pumpify": "^2.0.1",
|
||||
"qs": "^6.9.1",
|
||||
@@ -79,5 +80,5 @@
|
||||
"dist"
|
||||
]
|
||||
},
|
||||
"version": "1.0.1"
|
||||
"version": "1.1.4"
|
||||
}
|
||||
|
||||
15
node_modules/async-neocities/test.js
generated
vendored
15
node_modules/async-neocities/test.js
generated
vendored
@@ -3,6 +3,7 @@ const tap = require('tap')
|
||||
const { readFileSync } = require('fs')
|
||||
const { resolve } = require('path')
|
||||
const NeocitiesAPIClient = require('.')
|
||||
const statsHanlder = require('./lib/stats-handler')
|
||||
|
||||
let token = process.env.NEOCITIES_API_TOKEN
|
||||
let fakeToken = false
|
||||
@@ -87,18 +88,10 @@ if (!fakeToken) {
|
||||
tap.test('can deploy folders', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
const statsCb = (stats) => {
|
||||
let logLine = `${stats.stage} ${stats.status} ${stats.timer.elapsed}`
|
||||
Object.entries(stats.tasks).forEach(([key, val]) => {
|
||||
logLine += ` ${key}: ${JSON.stringify(val)}`
|
||||
})
|
||||
console.log(logLine)
|
||||
}
|
||||
|
||||
const deployStats = await client.deploy(
|
||||
resolve(__dirname, 'fixtures'),
|
||||
{
|
||||
statsCb,
|
||||
statsCb: statsHanlder(),
|
||||
cleanup: false
|
||||
}
|
||||
)
|
||||
@@ -110,7 +103,7 @@ if (!fakeToken) {
|
||||
const redeployStats = await client.deploy(
|
||||
resolve(__dirname, 'fixtures'),
|
||||
{
|
||||
statsCb,
|
||||
statsCb: statsHanlder(),
|
||||
cleanup: false
|
||||
}
|
||||
)
|
||||
@@ -122,7 +115,7 @@ if (!fakeToken) {
|
||||
const cleanupStats = await client.deploy(
|
||||
resolve(__dirname, 'fixtures/empty'),
|
||||
{
|
||||
statsCb,
|
||||
statsCb: statsHanlder(),
|
||||
cleanup: true
|
||||
}
|
||||
)
|
||||
|
||||
4
node_modules/pretty-bytes/package.json
generated
vendored
4
node_modules/pretty-bytes/package.json
generated
vendored
@@ -16,12 +16,12 @@
|
||||
"fetchSpec": "^5.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
"/async-neocities"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.3.0.tgz",
|
||||
"_shasum": "f2849e27db79fb4d6cfe24764fc4134f165989f2",
|
||||
"_spec": "pretty-bytes@^5.3.0",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/async-neocities",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
|
||||
12
node_modules/pretty-time/package.json
generated
vendored
12
node_modules/pretty-time/package.json
generated
vendored
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"_from": "pretty-time@^1.1.0",
|
||||
"_from": "pretty-time@1.1.0",
|
||||
"_id": "pretty-time@1.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==",
|
||||
"_location": "/pretty-time",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "pretty-time@^1.1.0",
|
||||
"raw": "pretty-time@1.1.0",
|
||||
"name": "pretty-time",
|
||||
"escapedName": "pretty-time",
|
||||
"rawSpec": "^1.1.0",
|
||||
"rawSpec": "1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.0"
|
||||
"fetchSpec": "1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pretty-time/-/pretty-time-1.1.0.tgz",
|
||||
"_shasum": "ffb7429afabb8535c346a34e41873adf3d74dd0e",
|
||||
"_spec": "pretty-time@^1.1.0",
|
||||
"_spec": "pretty-time@1.1.0",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||
"author": {
|
||||
"name": "Jon Schlinkert",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "deploy-to-neocities",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.9",
|
||||
"description": "Github Action to deplpoy a folder to Neocities.org",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
@@ -39,9 +39,8 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "1.2.2",
|
||||
"@actions/github": "2.1.0",
|
||||
"async-neocities": "1.0.1",
|
||||
"pretty-bytes": "^5.3.0",
|
||||
"pretty-time": "^1.1.0"
|
||||
"async-neocities": "1.1.4",
|
||||
"pretty-time": "1.1.0"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
|
||||
Reference in New Issue
Block a user