mirror of
https://github.com/bcomnes/deploy-to-neocities.git
synced 2026-01-22 17:24:28 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0dd3a06ef7 | ||
|
|
bf2d333152 | ||
|
|
f13458cc2d | ||
|
|
5e6f9848c7 | ||
|
|
fad2c4a165 | ||
|
|
1638c39428 | ||
|
|
c50fdeb3e6 | ||
|
|
48d2e5e4e0 | ||
|
|
aaf8a90973 | ||
|
|
34601c4927 | ||
|
|
ce8f0e70b0 | ||
|
|
22ef26e851 | ||
|
|
b96571b8ad | ||
|
|
bc86874ede | ||
|
|
4a9e7f6a6d | ||
|
|
2c52eeaa2b | ||
|
|
19246fac79 |
49
CHANGELOG.md
49
CHANGELOG.md
@@ -7,6 +7,55 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||||
|
|
||||||
|
## [v0.0.10](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.9...v0.0.10) - 2020-02-13
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- chore: deps [`bf2d333`](https://github.com/bcomnes/deploy-to-neocities/commit/bf2d333152be116ec87d35592c8cb9ee4ef6821b)
|
||||||
|
|
||||||
|
## [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
|
## [v0.0.2](https://github.com/bcomnes/deploy-to-neocities/compare/v0.0.1...v0.0.2) - 2020-02-13
|
||||||
|
|
||||||
### Commits
|
### Commits
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ branding:
|
|||||||
icon: cat
|
icon: cat
|
||||||
color: yellow
|
color: yellow
|
||||||
inputs:
|
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'
|
description: 'Neocities API token for site to deploy to'
|
||||||
required: true
|
required: true
|
||||||
dist-dir:
|
distDir:
|
||||||
description: 'Local folder to deploy to neocities'
|
description: 'Local folder to deploy to neocities'
|
||||||
default: 'public'
|
default: 'public'
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
98
index.js
98
index.js
@@ -3,101 +3,29 @@ const core = require('@actions/core')
|
|||||||
const Neocities = require('async-neocities')
|
const Neocities = require('async-neocities')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const prettyTime = require('pretty-time')
|
const prettyTime = require('pretty-time')
|
||||||
const prettyBytes = require('pretty-bytes')
|
const assert = require('nanoassert')
|
||||||
|
|
||||||
async function doDeploy () {
|
async function doDeploy () {
|
||||||
const token = core.getInput('api-token')
|
const token = core.getInput('apiToken')
|
||||||
const distDir = path.join(process.cwd(), core.getInput('dist-dir'))
|
const distDir = path.join(process.cwd(), core.getInput('distDir'))
|
||||||
const cleanup = core.getInput('cleanup')
|
const cleanup = JSON.parse(core.getInput('cleanup'))
|
||||||
|
assert(typeof cleanup === 'boolean', 'Cleanup input must be a boolean "true" or "false"')
|
||||||
console.log(typeof cleanup)
|
console.log(typeof cleanup)
|
||||||
|
|
||||||
const client = new Neocities(token)
|
const client = new Neocities(token)
|
||||||
|
|
||||||
const finalStats = await client.deploy(distDir, {
|
const stats = await client.deploy(distDir, {
|
||||||
cleanup,
|
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)
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
42
node_modules/async-neocities/CHANGELOG.md
generated
vendored
42
node_modules/async-neocities/CHANGELOG.md
generated
vendored
@@ -7,6 +7,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||||
|
|
||||||
|
## [v1.1.5](https://github.com/bcomnes/async-neocities/compare/v1.1.4...v1.1.5) - 2020-02-13
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- bug: Log last stats before clear [`c4c83f8`](https://github.com/bcomnes/async-neocities/commit/c4c83f8e329303404dfec6a2943d8b01783040ad)
|
||||||
|
|
||||||
|
## [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
|
## [v1.0.1](https://github.com/bcomnes/async-neocities/compare/v1.0.0...v1.0.1) - 2020-02-13
|
||||||
|
|
||||||
### Commits
|
### 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
|
```js
|
||||||
{
|
{
|
||||||
cleanup: false // delete orphaned files on neocities that are not in the `directory`
|
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])`
|
### `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 pkg = require('./package.json')
|
||||||
const SimpleTimer = require('./lib/timer')
|
const SimpleTimer = require('./lib/timer')
|
||||||
const { getStreamLength, meterStream } = require('./lib/stream-meter')
|
const { getStreamLength, meterStream } = require('./lib/stream-meter')
|
||||||
|
const statsHandler = require('./lib/stats-handler')
|
||||||
|
|
||||||
const defaultURL = 'https://neocities.org'
|
const defaultURL = 'https://neocities.org'
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ const defaultURL = 'https://neocities.org'
|
|||||||
const START = 'start'
|
const START = 'start'
|
||||||
const PROGRESS = 'progress' // progress updates
|
const PROGRESS = 'progress' // progress updates
|
||||||
const STOP = 'stop'
|
const STOP = 'stop'
|
||||||
|
const SKIP = 'skip'
|
||||||
// Progress stages
|
// Progress stages
|
||||||
const INSPECTING = 'inspecting'
|
const INSPECTING = 'inspecting'
|
||||||
const DIFFING = 'diffing'
|
const DIFFING = 'diffing'
|
||||||
@@ -55,6 +57,8 @@ class NeocitiesAPIClient {
|
|||||||
return fetch(url, opts)
|
return fetch(url, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static statsHandler (...args) { return statsHandler(...args) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an async-neocities api client.
|
* Create an async-neocities api client.
|
||||||
* @param {string} apiKey An apiKey to make requests with.
|
* @param {string} apiKey An apiKey to make requests with.
|
||||||
@@ -226,195 +230,73 @@ class NeocitiesAPIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const statsCb = opts.statsCb
|
const statsCb = opts.statsCb
|
||||||
const startDeployTime = Date.now()
|
const totalTime = new SimpleTimer(Date.now())
|
||||||
const totalTime = new SimpleTimer(startDeployTime)
|
|
||||||
|
|
||||||
// Inspection stage stats initializer
|
// INSPECTION STAGE
|
||||||
const inspectionStats = {
|
statsCb({ stage: INSPECTING, status: START })
|
||||||
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
|
|
||||||
const [localFiles, remoteFiles] = await Promise.all([
|
const [localFiles, remoteFiles] = await Promise.all([
|
||||||
localScanJob,
|
afw.allFiles(directory, { shaper: f => f }),
|
||||||
remoteScanJob.then(res => res.files)
|
this.list().then(res => res.files)
|
||||||
])
|
])
|
||||||
inspectionStats.timer.stop()
|
statsCb({ stage: INSPECTING, status: STOP })
|
||||||
sendInspectionUpdate(STOP)
|
|
||||||
|
|
||||||
// DIFFING STAGE
|
// DIFFING STAGE
|
||||||
|
statsCb({ stage: DIFFING, status: START })
|
||||||
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
|
|
||||||
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
||||||
|
statsCb({ stage: DIFFING, status: STOP })
|
||||||
|
|
||||||
diffingStats.timer.stop()
|
// APPLYING STAGE
|
||||||
diffingStats.status = STOP
|
if (filesToUpload.length === 0 && (!opts.cleanup || filesToDelete.length === 0)) {
|
||||||
diffing.uploadCount = filesToUpload.length
|
statsCb({ stage: APPLYING, status: SKIP })
|
||||||
diffing.deleteCount = filesToDelete.length
|
return stats()
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const sendApplyingUpdate = (status) => {
|
|
||||||
if (status) applyingStats.status = status
|
|
||||||
statsCb(applyingStats)
|
|
||||||
}
|
|
||||||
sendApplyingUpdate(START)
|
|
||||||
|
|
||||||
|
statsCb({ stage: APPLYING, status: START })
|
||||||
const work = []
|
const work = []
|
||||||
const { tasks: { uploadFiles, deleteFiles } } = applyingStats
|
|
||||||
|
|
||||||
if (filesToUpload.length > 0) {
|
if (filesToUpload.length > 0) {
|
||||||
const uploadJob = this.upload(filesToUpload, {
|
const uploadJob = this.upload(filesToUpload, {
|
||||||
statsCb: ({ bytesWritten, totalBytes }) => {
|
statsCb ({ totalBytes, bytesWritten }) {
|
||||||
uploadFiles.bytesWritten = bytesWritten
|
statsCb({
|
||||||
uploadFiles.totalBytes = totalBytes
|
stage: APPLYING,
|
||||||
sendApplyingUpdate(PROGRESS)
|
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)
|
work.push(uploadJob)
|
||||||
uploadJob.then(res => {
|
|
||||||
uploadFiles.timer.stop()
|
|
||||||
sendApplyingUpdate(PROGRESS)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
uploadFiles.timer.stop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.cleanup && filesToDelete.length > 0) {
|
if (opts.cleanup && filesToDelete.length > 0) {
|
||||||
const deleteJob = this.delete(filesToDelete, {
|
work.push(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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(work)
|
await Promise.all(work)
|
||||||
applyingStats.timer.stop()
|
statsCb({ stage: APPLYING, status: STOP })
|
||||||
sendApplyingUpdate(STOP)
|
|
||||||
|
|
||||||
totalTime.stop()
|
return stats()
|
||||||
|
|
||||||
const statsSummary = {
|
function stats () {
|
||||||
time: totalTime,
|
totalTime.stop()
|
||||||
inspectionStats,
|
return {
|
||||||
diffingStats,
|
time: totalTime.elapsed,
|
||||||
applyingStats
|
filesToUpload,
|
||||||
|
filesToDelete,
|
||||||
|
filesSkipped
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return statsSummary
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
60
node_modules/async-neocities/lib/stats-handler.js
generated
vendored
Normal file
60
node_modules/async-neocities/lib/stats-handler.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
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)
|
||||||
|
logProgress(lastStats)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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",
|
"_from": "async-neocities@1.1.5",
|
||||||
"_id": "async-neocities@1.0.1",
|
"_id": "async-neocities@1.1.5",
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-5TVaKLYKnaHoSiluCP0i78e0CBZbeqBL6bgK8/QsM8YOAtrhd5JO9c5DEaW4SFpmf4wV0qcamQXh0A3C7CANLw==",
|
"_integrity": "sha512-7EHFjdmPACBQ2prEr7wUQsIi9bVXrD5tpR9PTmDndmZn5U+0uPe6dQxuk+xKI6BLizQVQVKjjODPTI+De5rlTA==",
|
||||||
"_location": "/async-neocities",
|
"_location": "/async-neocities",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "version",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "async-neocities@1.0.1",
|
"raw": "async-neocities@1.1.5",
|
||||||
"name": "async-neocities",
|
"name": "async-neocities",
|
||||||
"escapedName": "async-neocities",
|
"escapedName": "async-neocities",
|
||||||
"rawSpec": "1.0.1",
|
"rawSpec": "1.1.5",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "1.0.1"
|
"fetchSpec": "1.1.5"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/"
|
"/"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/async-neocities/-/async-neocities-1.0.1.tgz",
|
"_resolved": "https://registry.npmjs.org/async-neocities/-/async-neocities-1.1.5.tgz",
|
||||||
"_shasum": "3428ae48f48104b205a3537212090b00d9bbce45",
|
"_shasum": "b9d31cf903ff6253beaf9012201bfae97908436f",
|
||||||
"_spec": "async-neocities@1.0.1",
|
"_spec": "async-neocities@1.1.5",
|
||||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Bret Comnes",
|
"name": "Bret Comnes",
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
"form-data": "^3.0.0",
|
"form-data": "^3.0.0",
|
||||||
"nanoassert": "^2.0.0",
|
"nanoassert": "^2.0.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
|
"pretty-bytes": "^5.3.0",
|
||||||
"pump": "^3.0.0",
|
"pump": "^3.0.0",
|
||||||
"pumpify": "^2.0.1",
|
"pumpify": "^2.0.1",
|
||||||
"qs": "^6.9.1",
|
"qs": "^6.9.1",
|
||||||
@@ -79,5 +80,5 @@
|
|||||||
"dist"
|
"dist"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"version": "1.0.1"
|
"version": "1.1.5"
|
||||||
}
|
}
|
||||||
|
|||||||
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 { readFileSync } = require('fs')
|
||||||
const { resolve } = require('path')
|
const { resolve } = require('path')
|
||||||
const NeocitiesAPIClient = require('.')
|
const NeocitiesAPIClient = require('.')
|
||||||
|
const statsHanlder = require('./lib/stats-handler')
|
||||||
|
|
||||||
let token = process.env.NEOCITIES_API_TOKEN
|
let token = process.env.NEOCITIES_API_TOKEN
|
||||||
let fakeToken = false
|
let fakeToken = false
|
||||||
@@ -87,18 +88,10 @@ if (!fakeToken) {
|
|||||||
tap.test('can deploy folders', async t => {
|
tap.test('can deploy folders', async t => {
|
||||||
const client = new NeocitiesAPIClient(token)
|
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(
|
const deployStats = await client.deploy(
|
||||||
resolve(__dirname, 'fixtures'),
|
resolve(__dirname, 'fixtures'),
|
||||||
{
|
{
|
||||||
statsCb,
|
statsCb: statsHanlder(),
|
||||||
cleanup: false
|
cleanup: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -110,7 +103,7 @@ if (!fakeToken) {
|
|||||||
const redeployStats = await client.deploy(
|
const redeployStats = await client.deploy(
|
||||||
resolve(__dirname, 'fixtures'),
|
resolve(__dirname, 'fixtures'),
|
||||||
{
|
{
|
||||||
statsCb,
|
statsCb: statsHanlder(),
|
||||||
cleanup: false
|
cleanup: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -122,7 +115,7 @@ if (!fakeToken) {
|
|||||||
const cleanupStats = await client.deploy(
|
const cleanupStats = await client.deploy(
|
||||||
resolve(__dirname, 'fixtures/empty'),
|
resolve(__dirname, 'fixtures/empty'),
|
||||||
{
|
{
|
||||||
statsCb,
|
statsCb: statsHanlder(),
|
||||||
cleanup: true
|
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"
|
"fetchSpec": "^5.3.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/"
|
"/async-neocities"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.3.0.tgz",
|
"_resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.3.0.tgz",
|
||||||
"_shasum": "f2849e27db79fb4d6cfe24764fc4134f165989f2",
|
"_shasum": "f2849e27db79fb4d6cfe24764fc4134f165989f2",
|
||||||
"_spec": "pretty-bytes@^5.3.0",
|
"_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": {
|
"author": {
|
||||||
"name": "Sindre Sorhus",
|
"name": "Sindre Sorhus",
|
||||||
"email": "sindresorhus@gmail.com",
|
"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",
|
"_id": "pretty-time@1.1.0",
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==",
|
"_integrity": "sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==",
|
||||||
"_location": "/pretty-time",
|
"_location": "/pretty-time",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "range",
|
"type": "version",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "pretty-time@^1.1.0",
|
"raw": "pretty-time@1.1.0",
|
||||||
"name": "pretty-time",
|
"name": "pretty-time",
|
||||||
"escapedName": "pretty-time",
|
"escapedName": "pretty-time",
|
||||||
"rawSpec": "^1.1.0",
|
"rawSpec": "1.1.0",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
"fetchSpec": "^1.1.0"
|
"fetchSpec": "1.1.0"
|
||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"/"
|
"/"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/pretty-time/-/pretty-time-1.1.0.tgz",
|
"_resolved": "https://registry.npmjs.org/pretty-time/-/pretty-time-1.1.0.tgz",
|
||||||
"_shasum": "ffb7429afabb8535c346a34e41873adf3d74dd0e",
|
"_shasum": "ffb7429afabb8535c346a34e41873adf3d74dd0e",
|
||||||
"_spec": "pretty-time@^1.1.0",
|
"_spec": "pretty-time@1.1.0",
|
||||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Jon Schlinkert",
|
"name": "Jon Schlinkert",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "deploy-to-neocities",
|
"name": "deploy-to-neocities",
|
||||||
"version": "0.0.2",
|
"version": "0.0.10",
|
||||||
"description": "Github Action to deplpoy a folder to Neocities.org",
|
"description": "Github Action to deplpoy a folder to Neocities.org",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
@@ -39,9 +39,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "1.2.2",
|
"@actions/core": "1.2.2",
|
||||||
"@actions/github": "2.1.0",
|
"@actions/github": "2.1.0",
|
||||||
"async-neocities": "1.0.1",
|
"async-neocities": "1.1.5",
|
||||||
"pretty-bytes": "^5.3.0",
|
"pretty-time": "1.1.0"
|
||||||
"pretty-time": "^1.1.0"
|
|
||||||
},
|
},
|
||||||
"standard": {
|
"standard": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
|||||||
Reference in New Issue
Block a user