-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
109 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,6 +1,38 @@ | ||
export async function action(options, { cwd, path }) { | ||
const { SSH } = await import('./ssh.mjs'); | ||
const { upload } = await import('./upload.mjs'); | ||
import { resolve } from 'node:path'; | ||
import { pathToFileURL } from 'node:url'; | ||
|
||
return SSH(options, (ssh) => upload(ssh, cwd, path)); | ||
import { preset } from './lib.mjs'; | ||
import { logger } from './logger.mjs'; | ||
import { checkSource } from './prepare.mjs'; | ||
import { checkServer } from './read-config.mjs'; | ||
|
||
function parsePath(cwd = preset.cwd) { | ||
return resolve( | ||
process.cwd(), | ||
cwd.replaceAll(/[/\\]+/g, '/').replaceAll(/^\/|\/$/g, ''), | ||
); | ||
} | ||
|
||
export async function action({ key, cwd, server, path: forcePath }) { | ||
const { user, hostname, port, path: filePath } = checkServer(server); | ||
|
||
const path = forcePath ?? filePath; | ||
|
||
const CWD = parsePath(cwd); | ||
|
||
if (checkSource(CWD)) { | ||
logger.info('From:', pathToFileURL(CWD).toString()); | ||
logger.info('To:', `sftp://${user}@${hostname}:${port}${path}`); | ||
|
||
const options = { hostname, port, user, key }; | ||
|
||
const { SSH } = await import('./ssh.mjs'); | ||
const { upload } = await import('./upload.mjs'); | ||
|
||
return SSH(options, (ssh) => upload(ssh, CWD, path)); | ||
} | ||
} | ||
|
||
process.on('SIGINT', () => { | ||
process.exit(1); | ||
}); |
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,4 @@ | ||
export const preset = { | ||
cwd: '.bring-it', | ||
conf: '.ssh/config', | ||
}; |
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,49 @@ | ||
import { execFile } from 'node:child_process'; | ||
|
||
import { ignore } from '@bring-it/utils'; | ||
import { globbySync } from 'globby'; | ||
|
||
function checkTarget(pattern) { | ||
if (pattern.length === 0) { | ||
throw new Error('Error: no pattern input'); | ||
} | ||
|
||
const list = globbySync(pattern, { | ||
dot: true, | ||
ignore, | ||
}); | ||
|
||
if (list.length > 0) { | ||
return pattern; | ||
} | ||
|
||
throw new Error('Error: no files targeting'); | ||
} | ||
|
||
export async function action({ pattern, name }) { | ||
const target = checkTarget(pattern); | ||
|
||
let io; | ||
|
||
execFile('tar', ['-c', '-f', `${name}.tar`, ...target], (error) => { | ||
if (error) { | ||
io = error; | ||
} | ||
}); | ||
|
||
execFile('tar', ['-c', '-f', `${name}.tar.gz`, '-z', ...target], (error) => { | ||
if (error) { | ||
io = error; | ||
} | ||
}); | ||
|
||
execFile('zip', ['-r', '-q', `${name}.zip`, ...target], (error) => { | ||
if (error) { | ||
io = error; | ||
} | ||
}); | ||
|
||
if (io) { | ||
throw new Error(`Error: ${io.message}`); | ||
} | ||
} |
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