import mustache from 'mustache'; import Shell from './shell.js'; import { MICROPYTHON, PYTHON } from './config.js'; export default class ShellAmpy extends Shell { static { this.TEMPLATE = { ls: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 ls "{{&folderPath}}"', get: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 get "{{&filePath}}"', mkdir: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 mkdir "{{&folderPath}}"', mkfile: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 mkfile "{{&filePath}}"', isdir: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 isdir "{{&folderPath}}"', isfile: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 isfile "{{&filePath}}"', put: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 put "{{&startPath}}" "{{&endPath}}"', rm: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rm "{{&filePath}}"', rmdir: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rmdir "{{&folderPath}}"', rename: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 rename "{{&oldPath}}" "{{&newPath}}"', run: '{{&y}} -p {{&port}} -b {{&baud}} -i 0 run "{{&filePath}}"' } this.AMPY_TEMPLATE = mustache.render('"{{&python3}}" "{{&y}}"', { python3: PYTHON.path.cli, ampy: MICROPYTHON.path.ampy }); } constructor() { super(); } async ls(port, baud, folderPath) { return this.exec(this.render('ls', { port, baud, folderPath }), { encoding: 'utf-8' }); } async get(port, baud, filePath) { return this.exec(this.render('get', { port, baud, filePath }), { encoding: 'utf-8' }); } async mkdir(port, baud, folderPath) { return this.exec(this.render('mkdir', { port, baud, folderPath }), { encoding: 'utf-8' }); } async mkfile(port, baud, filePath) { return this.exec(this.render('mkfile', { port, baud, filePath }), { encoding: 'utf-8' }); } async isdir(port, baud, folderPath) { return this.exec(this.render('isdir', { port, baud, folderPath }), { encoding: 'utf-8' }); } async isfile(port, baud, filePath) { return this.exec(this.render('isfile', { port, baud, filePath }), { encoding: 'utf-8' }); } async put(port, baud, startPath, endPath) { return this.exec(this.render('put', { port, baud, startPath, endPath }), { encoding: 'utf-8' }); } async rm(port, baud, filePath) { return this.exec(this.render('rm', { port, baud, filePath }), { encoding: 'utf-8' }); } async rmdir(port, baud, folderPath) { return this.exec(this.render('rmdir', { port, baud, folderPath }), { encoding: 'utf-8' }); } async rename(port, baud, oldPath, newPath) { return this.exec(this.render('rename', { port, baud, oldPath, newPath }), { encoding: 'utf-8' }); } async run(port, baud, filePath) { return this.exec(this.render('run', { port, baud, filePath }), { encoding: 'utf-8' }); } render(templateName, args) { return mustache.render(ShellAmpy.TEMPLATE[templateName], { ...args, ampy: ShellAmpy.AMPY_TEMPLATE }); } }