mirror of
https://github.com/bcomnes/deploy-to-neocities.git
synced 2026-03-27 00:51:35 +00:00
commit node_modules
This commit is contained in:
25
node_modules/async-neocities-tmp/.github/workflows/tests.yml
generated
vendored
Normal file
25
node_modules/async-neocities-tmp/.github/workflows/tests.yml
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: tests
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
node: [12]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- name: npm install && npm test
|
||||
run: |
|
||||
npm i
|
||||
npm test
|
||||
env:
|
||||
CI: true
|
||||
8
node_modules/async-neocities-tmp/CHANGELOG.md
generated
vendored
Normal file
8
node_modules/async-neocities-tmp/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# async-neocities Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.0.1 - 2020-02-10
|
||||
* wip release
|
||||
4
node_modules/async-neocities-tmp/CODE_OF_CONDUCT.md
generated
vendored
Normal file
4
node_modules/async-neocities-tmp/CODE_OF_CONDUCT.md
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# Code of conduct
|
||||
|
||||
- This repo is governed as a dictatorship starting with the originator of the project.
|
||||
- No malevolence tolerated whatsoever.
|
||||
14
node_modules/async-neocities-tmp/CONTRIBUTING.md
generated
vendored
Normal file
14
node_modules/async-neocities-tmp/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Contributing
|
||||
|
||||
- Patches, ideas and changes welcome.
|
||||
- Fixes almost always welcome.
|
||||
- Features sometimes welcome.
|
||||
- Please open an issue to discuss the issue prior to spending lots of time on the problem.
|
||||
- It may be rejected.
|
||||
- If you don't want to wait around for the discussion to commence, and you really want to jump into the implementation work, be prepared for fork if the idea is respectfully declined.
|
||||
- Try to stay within the style of the existing code.
|
||||
- All tests must pass.
|
||||
- Additional features or code paths must be tested.
|
||||
- Aim for 100% coverage.
|
||||
- Questions are welcome, however unless there is a official support contract established between the maintainers and the requester, support is not guaranteed.
|
||||
- Contributors reserve the right to walk away from this project at any moment with or without notice.
|
||||
21
node_modules/async-neocities-tmp/LICENSE
generated
vendored
Normal file
21
node_modules/async-neocities-tmp/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Bret Comnes
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
33
node_modules/async-neocities-tmp/README.md
generated
vendored
Normal file
33
node_modules/async-neocities-tmp/README.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# async-neocities
|
||||
[](https://github.com/bcomnes/async-neocities/actions)
|
||||
|
||||
WIP - nothing to see here
|
||||
|
||||
```
|
||||
npm install async-neocities
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const path = require('path')
|
||||
const Neocities = require('async-neocities')
|
||||
|
||||
async function deploySite () {
|
||||
const token = await Neocities.getKey('sitename', 'password')
|
||||
|
||||
const client = new Neocities(token)
|
||||
|
||||
console.log(await client.list()) // site files
|
||||
console.log(await client.info()) // site info
|
||||
|
||||
return client.deploy(path.join(__dirname, './site-contents'))
|
||||
}
|
||||
|
||||
deploySite.then(info => { console.log('done deploying site!') })
|
||||
.catch(e => { throw e })
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
BIN
node_modules/async-neocities-tmp/fixtures/cat.png
generated
vendored
Normal file
BIN
node_modules/async-neocities-tmp/fixtures/cat.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
node_modules/async-neocities-tmp/fixtures/neocities.png
generated
vendored
Normal file
BIN
node_modules/async-neocities-tmp/fixtures/neocities.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
BIN
node_modules/async-neocities-tmp/fixtures/toot.gif
generated
vendored
Executable file
BIN
node_modules/async-neocities-tmp/fixtures/toot.gif
generated
vendored
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 461 B |
BIN
node_modules/async-neocities-tmp/fixtures/tootzzz.png
generated
vendored
Executable file
BIN
node_modules/async-neocities-tmp/fixtures/tootzzz.png
generated
vendored
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
172
node_modules/async-neocities-tmp/index.js
generated
vendored
Normal file
172
node_modules/async-neocities-tmp/index.js
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
const assert = require('nanoassert')
|
||||
const fetch = require('node-fetch')
|
||||
const { URL } = require('url')
|
||||
const qs = require('qs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const { createReadStream } = require('fs')
|
||||
const FormData = require('form-data')
|
||||
const { handleResponse } = require('fetch-errors')
|
||||
const afw = require('async-folder-walker')
|
||||
const pkg = require('./package.json')
|
||||
const { neocitiesLocalDiff } = require('./lib/folder-diff')
|
||||
|
||||
const defaultURL = 'https://neocities.org'
|
||||
|
||||
class NeocitiesAPIClient {
|
||||
static getKey (sitename, password, opts) {
|
||||
assert(sitename, 'must pass sitename as first arg')
|
||||
assert(typeof sitename === 'string', 'user arg must be a string')
|
||||
assert(password, 'must pass a password as the second arg')
|
||||
assert(typeof password, 'password arg must be a string')
|
||||
|
||||
opts = Object.assign({
|
||||
baseURL: defaultURL
|
||||
}, opts)
|
||||
|
||||
const baseURL = opts.baseURL
|
||||
delete opts.baseURL
|
||||
|
||||
const url = new URL('/api/key', baseURL)
|
||||
url.username = sitename
|
||||
url.password = password
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
constructor (apiKey, opts) {
|
||||
assert(apiKey, 'must pass apiKey as first argument')
|
||||
assert(typeof apiKey === 'string', 'apiKey must be a string')
|
||||
opts = Object.assign({
|
||||
url: defaultURL
|
||||
})
|
||||
|
||||
this.opts = opts
|
||||
this.url = opts.url
|
||||
this.apiKey = apiKey
|
||||
}
|
||||
|
||||
get defaultHeaders () {
|
||||
return {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'User-Agent': `deploy-to-neocities/${pkg.version} (${os.type()})`
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic get request to neocities
|
||||
*/
|
||||
get (endpoint, quieries, opts) {
|
||||
assert(endpoint, 'must pass endpoint as first argument')
|
||||
opts = Object.assign({
|
||||
method: 'GET'
|
||||
}, opts)
|
||||
opts.headers = Object.assign({}, this.defaultHeaders, opts.headers)
|
||||
|
||||
let path = `/api/${endpoint}`
|
||||
if (quieries) path += `?${qs.stringify(quieries)}`
|
||||
|
||||
const url = new URL(path, this.url)
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic post request to neocities
|
||||
*/
|
||||
post (endpoint, formEntries, opts) {
|
||||
assert(endpoint, 'must pass endpoint as first argument')
|
||||
const form = new FormData()
|
||||
opts = Object.assign({
|
||||
method: 'POST',
|
||||
body: form
|
||||
}, opts)
|
||||
|
||||
for (const { name, value } of formEntries) {
|
||||
form.append(name, value)
|
||||
}
|
||||
|
||||
opts.headers = Object.assign(
|
||||
{},
|
||||
this.defaultHeaders,
|
||||
form.getHeaders(),
|
||||
opts.headers)
|
||||
|
||||
const url = new URL(`/api/${endpoint}`, this.url)
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload files to neocities
|
||||
*/
|
||||
upload (files) {
|
||||
const formEntries = files.map(({ name, path }) => {
|
||||
return {
|
||||
name,
|
||||
value: createReadStream(path)
|
||||
}
|
||||
})
|
||||
|
||||
return this.post('upload', formEntries).then(handleResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* delete files from your website
|
||||
*/
|
||||
delete (filenames) {
|
||||
assert(filenames, 'filenames is a required first argument')
|
||||
assert(Array.isArray(filenames), 'filenames argument must be an array of file paths in your website')
|
||||
|
||||
const formEntries = filenames.map(file => ({
|
||||
name: 'filenames[]',
|
||||
value: file
|
||||
}))
|
||||
|
||||
return this.post('delete', formEntries).then(handleResponse)
|
||||
}
|
||||
|
||||
list (queries) {
|
||||
// args.path: Path to list
|
||||
return this.get('list', queries).then(handleResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* info returns info on your site, or optionally on a sitename querystrign
|
||||
* @param {Object} args Querystring arguments to include (e.g. sitename)
|
||||
* @return {Promise} Fetch request promise
|
||||
*/
|
||||
info (queries) {
|
||||
// args.sitename: sitename to get info on
|
||||
return this.get('info', queries).then(handleResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy a folder to neocities, skipping already uploaded files and optionally cleaning orphaned files.
|
||||
* @param {String} folder The path of the folder to deploy.
|
||||
* @param {Object} opts Options object.
|
||||
* @param {Boolean} opts.cleanup Boolean to delete orphaned files nor not. Defaults to false.
|
||||
* @param {Boolean} opts.statsCb Get access to stat info before uploading is complete.
|
||||
* @return {Promise} Promise containing stats about the deploy
|
||||
*/
|
||||
async deploy (folder, opts) {
|
||||
opts = {
|
||||
cleanup: false, // delete remote orphaned files
|
||||
statsCb: () => {},
|
||||
...opts
|
||||
}
|
||||
|
||||
const [localFiles, remoteFiles] = Promise.all([
|
||||
afw.allFiles(path.join(folder), { shaper: f => f }),
|
||||
this.list()
|
||||
])
|
||||
|
||||
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
||||
opts.statsCb({ filesToUpload, filesToDelete, filesSkipped })
|
||||
const work = [this.upload(filesToUpload)]
|
||||
if (opts.cleanup) work.push(this.delete(filesToDelete))
|
||||
|
||||
await work
|
||||
|
||||
return { filesToUpload, filesToDelete, filesSkipped }
|
||||
}
|
||||
}
|
||||
module.exports = NeocitiesAPIClient
|
||||
159
node_modules/async-neocities-tmp/lib/folder-diff.js
generated
vendored
Normal file
159
node_modules/async-neocities-tmp/lib/folder-diff.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
const crypto = require('crypto')
|
||||
const util = require('util')
|
||||
const fs = require('fs')
|
||||
const ppump = util.promisify(require('pump'))
|
||||
|
||||
/**
|
||||
* neocitiesLocalDiff returns an array of files to delete and update and some useful stats.
|
||||
*/
|
||||
async function neocitiesLocalDiff (neocitiesFiles, localListing, opts = {}) {
|
||||
opts = {
|
||||
...opts
|
||||
}
|
||||
|
||||
const localIndex = {}
|
||||
const ncIndex = {}
|
||||
|
||||
const neoCitiesFiltered = neocitiesFiles.filter(f => !f.is_directory)
|
||||
neoCitiesFiltered.forEach(f => { ncIndex[f.path] = f }) // index
|
||||
const ncFiles = new Set(neoCitiesFiltered.map(f => f.path)) // shape
|
||||
|
||||
const localListingFiltered = localListing.filter(f => !f.stat.isDirectory()) // files only
|
||||
localListingFiltered.forEach(f => { localIndex[f.relname] = f }) // index
|
||||
// TODO: convert windows to unix paths
|
||||
const localFiles = new Set(localListingFiltered.map(f => f.relname)) // shape
|
||||
|
||||
const filesToAdd = difference(localFiles, ncFiles)
|
||||
const filesToDelete = difference(ncFiles, localFiles)
|
||||
|
||||
const maybeUpdate = intersection(localFiles, ncFiles)
|
||||
const skipped = new Set()
|
||||
|
||||
for (const p of maybeUpdate) {
|
||||
const local = localIndex[p]
|
||||
const remote = ncIndex[p]
|
||||
|
||||
if (local.stat.size !== remote.size) { filesToAdd.add(p); continue }
|
||||
|
||||
const localSha1 = await sha1FromPath(local.filepath)
|
||||
if (localSha1 !== remote.sha1_hash) { filesToAdd.add(p); continue }
|
||||
|
||||
skipped.add(p)
|
||||
}
|
||||
|
||||
return {
|
||||
filesToUpload: Array.from(filesToAdd).map(p => ({
|
||||
name: localIndex[p].relname,
|
||||
path: localIndex[p].filepath
|
||||
})),
|
||||
filesToDelete: Array.from(filesToDelete).map(p => ncIndex[p].path),
|
||||
filesSkipped: Array.from(skipped).map(p => localIndex[p])
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
neocitiesLocalDiff
|
||||
}
|
||||
|
||||
/**
|
||||
* sha1FromPath returns a sha1 hex from a path
|
||||
* @param {String} p string of the path of the file to hash
|
||||
* @return {Promise<String>} the hex representation of the sha1
|
||||
*/
|
||||
async function sha1FromPath (p) {
|
||||
const rs = fs.createReadStream(p)
|
||||
const hash = crypto.createHash('sha1')
|
||||
|
||||
await ppump(rs, hash)
|
||||
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Implementing_basic_set_operations
|
||||
|
||||
/**
|
||||
* difference betwen setA and setB
|
||||
* @param {Set} setA LHS set
|
||||
* @param {Set} setB RHS set
|
||||
* @return {Set} The difference Set
|
||||
*/
|
||||
function difference (setA, setB) {
|
||||
const _difference = new Set(setA)
|
||||
for (const elem of setB) {
|
||||
_difference.delete(elem)
|
||||
}
|
||||
return _difference
|
||||
}
|
||||
|
||||
function intersection (setA, setB) {
|
||||
const _intersection = new Set()
|
||||
for (const elem of setB) {
|
||||
if (setA.has(elem)) {
|
||||
_intersection.add(elem)
|
||||
}
|
||||
}
|
||||
return _intersection
|
||||
}
|
||||
|
||||
// [
|
||||
// {
|
||||
// path: 'img',
|
||||
// is_directory: true,
|
||||
// updated_at: 'Thu, 21 Nov 2019 04:06:17 -0000'
|
||||
// },
|
||||
// {
|
||||
// path: 'index.html',
|
||||
// is_directory: false,
|
||||
// size: 1094,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: '7f15617e87d83218223662340f4052d9bb9d096d'
|
||||
// },
|
||||
// {
|
||||
// path: 'neocities.png',
|
||||
// is_directory: false,
|
||||
// size: 13232,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: 'fd2ee41b1922a39a716cacb88c323d613b0955e4'
|
||||
// },
|
||||
// {
|
||||
// path: 'not_found.html',
|
||||
// is_directory: false,
|
||||
// size: 347,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: 'd7f004e9d3b2eaaa8827f741356f1122dc9eb030'
|
||||
// },
|
||||
// {
|
||||
// path: 'style.css',
|
||||
// is_directory: false,
|
||||
// size: 298,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: 'e516457acdb0d00710ab62cc257109ef67209ce8'
|
||||
// }
|
||||
// ]
|
||||
|
||||
// [{
|
||||
// root: '/Users/bret/repos/async-folder-walker/fixtures',
|
||||
// filepath: '/Users/bret/repos/async-folder-walker/fixtures/sub-folder/sub-sub-folder',
|
||||
// stat: Stats {
|
||||
// dev: 16777220,
|
||||
// mode: 16877,
|
||||
// nlink: 3,
|
||||
// uid: 501,
|
||||
// gid: 20,
|
||||
// rdev: 0,
|
||||
// blksize: 4096,
|
||||
// ino: 30244023,
|
||||
// size: 96,
|
||||
// blocks: 0,
|
||||
// atimeMs: 1574381262779.8396,
|
||||
// mtimeMs: 1574380914743.5474,
|
||||
// ctimeMs: 1574380914743.5474,
|
||||
// birthtimeMs: 1574380905232.5996,
|
||||
// atime: 2019-11-22T00:07:42.780Z,
|
||||
// mtime: 2019-11-22T00:01:54.744Z,
|
||||
// ctime: 2019-11-22T00:01:54.744Z,
|
||||
// birthtime: 2019-11-22T00:01:45.233Z
|
||||
// },
|
||||
// relname: 'sub-folder/sub-sub-folder',
|
||||
// basename: 'sub-sub-folder'
|
||||
// }]
|
||||
65
node_modules/async-neocities-tmp/lib/folder-diff.test.js
generated
vendored
Normal file
65
node_modules/async-neocities-tmp/lib/folder-diff.test.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
const tap = require('tap')
|
||||
const afw = require('async-folder-walker')
|
||||
const path = require('path')
|
||||
const { neocitiesLocalDiff } = require('./folder-diff')
|
||||
|
||||
const remoteFiles = [
|
||||
{
|
||||
path: 'img',
|
||||
is_directory: true,
|
||||
updated_at: 'Thu, 21 Nov 2019 04:06:17 -0000'
|
||||
},
|
||||
{
|
||||
path: 'index.html',
|
||||
is_directory: false,
|
||||
size: 1094,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: '7f15617e87d83218223662340f4052d9bb9d096d'
|
||||
},
|
||||
{
|
||||
path: 'neocities.png',
|
||||
is_directory: false,
|
||||
size: 13232,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: 'fd2ee41b1922a39a716cacb88c323d613b0955e4'
|
||||
},
|
||||
{
|
||||
path: 'not_found.html',
|
||||
is_directory: false,
|
||||
size: 347,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: 'd7f004e9d3b2eaaa8827f741356f1122dc9eb030'
|
||||
},
|
||||
{
|
||||
path: 'style.css',
|
||||
is_directory: false,
|
||||
size: 298,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: 'e516457acdb0d00710ab62cc257109ef67209ce8'
|
||||
}
|
||||
]
|
||||
|
||||
tap.test('test differ', async t => {
|
||||
const localFiles = await afw.allFiles(path.join(__dirname, '../fixtures'), {
|
||||
shaper: f => f
|
||||
})
|
||||
|
||||
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
||||
|
||||
t.true(['tootzzz.png', 'toot.gif', 'cat.png'].every(path => {
|
||||
const found = filesToUpload.find(ftu => ftu.name === path)
|
||||
t.ok(found.path && found.name, 'each file to upload has a name and path')
|
||||
return found
|
||||
}), 'every file to upload is included')
|
||||
|
||||
t.deepEqual(filesToDelete, [
|
||||
'index.html',
|
||||
'not_found.html',
|
||||
'style.css'
|
||||
], 'filesToDelete returned correctly')
|
||||
|
||||
t.true(['neocities.png'].every(path => {
|
||||
const found = filesSkipped.find(fs => fs.relname === path)
|
||||
return found
|
||||
}), 'every file skipped is included')
|
||||
})
|
||||
72
node_modules/async-neocities-tmp/package.json
generated
vendored
Normal file
72
node_modules/async-neocities-tmp/package.json
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"_from": "async-neocities-tmp@0.0.2",
|
||||
"_id": "async-neocities-tmp@0.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-MP8zp6gdM92e9cODhDtBHu9n6XwiwlIG1/rgqalTu3wYdfTNwJtzXKNUWvdy934R+oeLk6mfGywQGM4YdnHHnw==",
|
||||
"_location": "/async-neocities-tmp",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "async-neocities-tmp@0.0.2",
|
||||
"name": "async-neocities-tmp",
|
||||
"escapedName": "async-neocities-tmp",
|
||||
"rawSpec": "0.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async-neocities-tmp/-/async-neocities-tmp-0.0.2.tgz",
|
||||
"_shasum": "b7cf75f9c61700e512d670143f4ab9c1b0b34f0d",
|
||||
"_spec": "async-neocities-tmp@0.0.2",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||
"author": {
|
||||
"name": "Bret Comnes",
|
||||
"email": "bcomnes@gmail.com",
|
||||
"url": "https://bret.io"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bcomnes/async-neocities/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"async-folder-walker": "^2.0.1",
|
||||
"fetch-errors": "^1.0.1",
|
||||
"form-data": "^3.0.0",
|
||||
"nanoassert": "^2.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"pump": "^3.0.0",
|
||||
"qs": "^6.9.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "WIP - nothing to see here",
|
||||
"devDependencies": {
|
||||
"dependency-check": "^4.1.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"standard": "^13.1.0",
|
||||
"tap": "^14.10.2"
|
||||
},
|
||||
"homepage": "https://github.com/bcomnes/async-neocities",
|
||||
"keywords": [],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "async-neocities-tmp",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bcomnes/async-neocities.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "run-s test:*",
|
||||
"test:deps": "dependency-check . --no-dev --no-peer",
|
||||
"test:standard": "standard",
|
||||
"test:tape": "tap"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
},
|
||||
"version": "0.0.2"
|
||||
}
|
||||
86
node_modules/async-neocities-tmp/test.js
generated
vendored
Normal file
86
node_modules/async-neocities-tmp/test.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
const tap = require('tap')
|
||||
|
||||
const { readFileSync } = require('fs')
|
||||
const { resolve } = require('path')
|
||||
const NeocitiesAPIClient = require('.')
|
||||
|
||||
let token = process.env.NEOCITIES_API_TOKEN
|
||||
let fakeToken = false
|
||||
|
||||
if (!token) {
|
||||
try {
|
||||
const config = JSON.parse(readFileSync(resolve(__dirname, 'config.json')))
|
||||
token = config.token
|
||||
tap.test('token loaded', async t => {
|
||||
t.ok(token)
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn('error loading config.json')
|
||||
console.warn('using fake token, live tests disabled')
|
||||
fakeToken = true
|
||||
token = '123456'
|
||||
}
|
||||
}
|
||||
|
||||
tap.test('basic client api', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
t.ok(client.info, 'info method available')
|
||||
t.ok(client.list, 'list method available')
|
||||
t.ok(client.get, 'get method available')
|
||||
t.ok(client.post, 'post method available')
|
||||
})
|
||||
|
||||
if (!fakeToken) {
|
||||
tap.test('can get info about site', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
const info = await client.info()
|
||||
// console.log(info)
|
||||
t.equal(info.result, 'success', 'info requesst successfull')
|
||||
const list = await client.list()
|
||||
// console.log(list)
|
||||
t.equal(list.result, 'success', 'list result successfull')
|
||||
})
|
||||
|
||||
// test('form data works the way I think', t => {
|
||||
// const form = new FormData();
|
||||
// const p = resolve(__dirname, 'package.json');
|
||||
// form.append('package.json', next => next(createReadStream(p)));
|
||||
//
|
||||
// const concatStream = concat((data) => {
|
||||
// console.log(data);
|
||||
// t.end();
|
||||
// });
|
||||
//
|
||||
// form.on('error', (err) => {
|
||||
// t.error(err);
|
||||
// });
|
||||
// form.pipe(concatStream);
|
||||
// });
|
||||
|
||||
tap.test('can upload and delete files', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
const uploadResults = await client.upload([
|
||||
{
|
||||
name: 'toot.gif',
|
||||
path: resolve(__dirname, 'fixtures/toot.gif')
|
||||
},
|
||||
{
|
||||
name: 'img/tootzzz.png',
|
||||
path: resolve(__dirname, 'fixtures/tootzzz.png')
|
||||
}
|
||||
])
|
||||
|
||||
// console.log(uploadResults)
|
||||
t.equal(uploadResults.result, 'success', 'list result successfull')
|
||||
|
||||
const deleteResults = await client.delete([
|
||||
'toot.gif',
|
||||
'img/tootzzz.png'
|
||||
])
|
||||
// console.log(deleteResults)
|
||||
t.equal(deleteResults.result, 'success', 'list result successfull')
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user