mirror of
https://github.com/bcomnes/deploy-to-neocities.git
synced 2026-01-16 22:56:28 +00:00
0.0.5
This commit is contained in:
parent
22ef26e851
commit
ce8f0e70b0
@ -7,6 +7,12 @@ 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.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
|
||||
|
||||
18
node_modules/async-neocities/CHANGELOG.md
generated
vendored
18
node_modules/async-neocities/CHANGELOG.md
generated
vendored
@ -7,6 +7,24 @@ 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.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 statsHanler (...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) {
|
||||
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.1",
|
||||
"_id": "async-neocities@1.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-5TVaKLYKnaHoSiluCP0i78e0CBZbeqBL6bgK8/QsM8YOAtrhd5JO9c5DEaW4SFpmf4wV0qcamQXh0A3C7CANLw==",
|
||||
"_integrity": "sha512-iYSEfp6567pmuMXcHkm09zG/+jNBH1Bg0ThbvrJDX/PhxbttK5S66VX4M5BJbiEWEBDjrjcP+Km1eBM5DSeURQ==",
|
||||
"_location": "/async-neocities",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "async-neocities@1.0.1",
|
||||
"raw": "async-neocities@1.1.1",
|
||||
"name": "async-neocities",
|
||||
"escapedName": "async-neocities",
|
||||
"rawSpec": "1.0.1",
|
||||
"rawSpec": "1.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.1"
|
||||
"fetchSpec": "1.1.1"
|
||||
},
|
||||
"_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.1.tgz",
|
||||
"_shasum": "cca697ff75ff70225fa7e10bd1b3bada555ef8bf",
|
||||
"_spec": "async-neocities@1.1.1",
|
||||
"_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.1"
|
||||
}
|
||||
|
||||
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.4",
|
||||
"version": "0.0.5",
|
||||
"description": "Github Action to deplpoy a folder to Neocities.org",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user