[ATL-1454] Refactor pull/push to edit files in place (#464)

* improve push/pull process

* improved diff tree performance generation

* skip some files to be synced

Co-authored-by: Francesco Stasi <f.stasi@me.com>
This commit is contained in:
Alberto Iannaccone
2021-07-28 14:00:54 +02:00
committed by GitHub
parent 57b9eb95bb
commit 65152731f9
5 changed files with 162 additions and 66 deletions

View File

@@ -93,7 +93,11 @@ export class CreateApi {
async readDirectory(
posixPath: string,
options: { recursive?: boolean; match?: string } = {}
options: {
recursive?: boolean;
match?: string;
skipSketchCache?: boolean;
} = {}
): Promise<Create.Resource[]> {
const url = new URL(
`${this.domain()}/files/d/$HOME/sketches_v2${posixPath}`
@@ -106,21 +110,29 @@ export class CreateApi {
}
const headers = await this.headers();
return this.run<Create.RawResource[]>(url, {
method: 'GET',
headers,
})
.then(async (result) => {
// add arduino_secrets.h to the results, when reading a sketch main folder
if (posixPath.length && posixPath !== posix.sep) {
const sketch = this.sketchCache.getSketch(posixPath);
const cachedSketch = this.sketchCache.getSketch(posixPath);
const sketchPromise = options.skipSketchCache
? (cachedSketch && this.sketch(cachedSketch.id)) || Promise.resolve(null)
: Promise.resolve(this.sketchCache.getSketch(posixPath));
return Promise.all([
sketchPromise,
this.run<Create.RawResource[]>(url, {
method: 'GET',
headers,
}),
])
.then(async ([sketch, result]) => {
if (posixPath.length && posixPath !== posix.sep) {
if (sketch && sketch.secrets && sketch.secrets.length > 0) {
result.push(this.getSketchSecretStat(sketch));
}
}
return result;
return result.filter(
(res) => !Create.do_not_sync_files.includes(res.name)
);
})
.catch((reason) => {
if (reason?.status === 404) return [] as Create.Resource[];