-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch to basic-ftp (#148)
* chore(ci): switch to GitHub Actions * test: use ftp-srv * chore: update dependencies
- Loading branch information
1 parent
f9580f1
commit 308b185
Showing
7 changed files
with
148 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Tester | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
linter: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
- name: Install Dependencies | ||
run: npm install | ||
- run: npm run eslint | ||
- name: Coverage | ||
run: npx nyc --reporter=lcovonly npm run test | ||
env: | ||
CI: true | ||
- name: Coveralls | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const ftp = require('basic-ftp'); | ||
|
||
module.exports = async function(args, callback) { | ||
const log = this.log; | ||
if (!args.host || !args.user || args.pass == null) { | ||
const help = [ | ||
'You should ensure deployment settings in _config.yml first!', | ||
'', | ||
'Example:', | ||
' deploy:', | ||
' type: ftpsync', | ||
' host: <host>', | ||
' user: <user>', | ||
' pass: <pass>', | ||
' remote: [remote] # Default is `/`', | ||
' port: [port] # Default is 21', | ||
' clear: [true|false] # Default is false', | ||
' verbose: [true|false]', | ||
'', | ||
'For more help, you can check the docs: http://hexo.io/docs/deployment.html' | ||
]; | ||
|
||
log.warn(help.join('\n')); | ||
return callback(); | ||
} | ||
|
||
const client = new ftp.Client(); | ||
client.ftp.verbose = args.verbose || false; | ||
|
||
try { | ||
await client.access({ | ||
host: args.host, | ||
port: args.port || 21, | ||
user: args.user, | ||
password: args.pass, | ||
secure: false | ||
}); | ||
|
||
await client.ensureDir(args.remote || '/'); | ||
if (args.clear) await client.clearWorkingDir(); | ||
await client.uploadFromDir(this.public_dir); | ||
|
||
log.info('Deployment complete'); | ||
} catch (err) { | ||
log.error('FTP Deployment Error:', err); | ||
} finally { | ||
client.close(); | ||
callback(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,66 @@ | ||
'use strict'; | ||
|
||
const should = require('chai').should(); // eslint-disable-line | ||
const pathFn = require('path'); | ||
const fs = require('hexo-fs'); | ||
const FtpSrv = require('ftp-srv'); | ||
|
||
describe('hexo-deployer-ftpsync', () => { | ||
// Tests. | ||
it('should deploy through ftp.', () => { | ||
return true; | ||
describe('deployer', () => { | ||
const baseDir = pathFn.join(__dirname, 'deployer_test'); | ||
const publicDir = pathFn.join(baseDir, 'public'); | ||
const fakeRemote = pathFn.join(baseDir, 'remote'); | ||
|
||
const hostname = '127.0.0.1'; | ||
const port = 8021; | ||
const ftpServer = new FtpSrv({ | ||
url: `ftp://${hostname}:${port}` | ||
}); | ||
|
||
ftpServer.on('login', ({ connection, username, password }, resolve, reject) => { | ||
resolve({ root: fakeRemote }); | ||
}); | ||
|
||
ftpServer.listen(); | ||
|
||
const ctx = { | ||
base_dir: baseDir, | ||
public_dir: publicDir, | ||
log: { | ||
info: () => {}, | ||
error: () => {} | ||
} | ||
}; | ||
|
||
const deployer = require('../lib/deployer').bind(ctx); | ||
|
||
before(() => { | ||
fs.mkdir(baseDir); | ||
return fs.writeFile(pathFn.join(publicDir, 'foo.txt'), 'foo'); | ||
}); | ||
|
||
beforeEach(() => { | ||
}); | ||
|
||
after(() => { | ||
ftpServer.close(); | ||
return fs.rmdir(baseDir); | ||
}); | ||
|
||
afterEach(() => { | ||
}); | ||
|
||
function validate() { | ||
return fs.existsSync(pathFn.join(publicDir, 'foo.txt')); | ||
} | ||
|
||
it('default', () => { | ||
return deployer({ | ||
host: '127.0.0.1', | ||
user: 'anonymous', | ||
pass: 'nopassword', | ||
port | ||
}, () => {}).then(() => { | ||
return validate(); | ||
}); | ||
}); | ||
}); |