feat(cli): make --raw the default for cli sync

This commit is contained in:
Ruben Fiszel
2024-01-27 14:49:16 +01:00
parent 91f2b35c73
commit 23c2fa1de3
3 changed files with 47 additions and 34 deletions

View File

@@ -26,6 +26,9 @@ import {
ScriptLanguage,
inferContentTypeFromFilePath,
} from "./script_common.ts";
import { elementsToMap } from "./sync.ts";
import { ignoreF } from "./sync.ts";
import { FSFSElement } from "./sync.ts";
export interface ScriptFile {
parent_hash?: string;
@@ -561,17 +564,35 @@ async function bootstrap(
async function generateMetadata(
opts: GlobalOptions & { lockOnly?: boolean; schemaOnly?: boolean },
scriptPath: string
scriptPath?: string
) {
if (!validatePath(scriptPath)) {
if (scriptPath == "") {
scriptPath = undefined;
}
if (scriptPath && !validatePath(scriptPath)) {
return;
}
const workspace = await resolveWorkspace(opts);
await requireLogin(opts);
// read script metadata file
await generateMetadataInternal(scriptPath, workspace, opts);
if (scriptPath) {
// read script metadata file
await generateMetadataInternal(scriptPath, workspace, opts);
} else {
log.error("Not implemented");
// const elems = await elementsToMap(
// await FSFSElement(Deno.cwd()),
// await ignoreF(),
// false,
// {}
// );
// log.info("Generating metadata for all stale scripts");
// for (const e of Object.keys(elems)) {
// log.info(`Processing ${e}`);
// await generateMetadataInternal(e, workspace, opts);
// }
}
}
const command = new Command()
@@ -607,15 +628,7 @@ const command = new Command()
"generate-metadata",
"re-generate the metadata file updating the lock and the script schema"
)
.arguments("<path_to_script_file:string>")
.option("--lock-only", "re-generate only the lock")
.option("--schema-only", "re-generate only script schema")
.action(generateMetadata as any)
.command(
"update-all-locks",
"re-generate the metadata file updating the lock and the script schema"
)
.arguments("<path_to_script_file:string>")
.arguments("[script:string]")
.option("--lock-only", "re-generate only the lock")
.option("--schema-only", "re-generate only script schema")
.action(generateMetadata as any);

View File

@@ -48,7 +48,7 @@ type DynFSElement = {
getChildren(): AsyncIterable<DynFSElement>;
};
async function FSFSElement(p: string): Promise<DynFSElement> {
export async function FSFSElement(p: string): Promise<DynFSElement> {
function _internal_element(localP: string, isDir: boolean): DynFSElement {
return {
isDirectory: isDir,
@@ -303,7 +303,7 @@ type Edit = { name: "edited"; path: string; before: string; after: string };
type Change = Added | Deleted | Edit;
async function elementsToMap(
export async function elementsToMap(
els: DynFSElement,
ignore: (path: string, isDirectory: boolean) => boolean,
json: boolean,
@@ -504,7 +504,7 @@ export async function ignoreF(): Promise<
async function pull(
opts: GlobalOptions & {
raw: boolean;
stateful: boolean;
yes: boolean;
failConflicts: boolean;
plainSecrets?: boolean;
@@ -515,7 +515,7 @@ async function pull(
includeSchedules?: boolean;
}
) {
if (!opts.raw) {
if (opts.stateful) {
await ensureDir(path.join(Deno.cwd(), ".wmill"));
}
@@ -538,7 +538,7 @@ async function pull(
))!,
!opts.json
);
const local = opts.raw
const local = !opts.stateful
? await FSFSElement(Deno.cwd())
: await FSFSElement(path.join(Deno.cwd(), ".wmill"));
const changes = await compareDynFSElement(
@@ -613,19 +613,19 @@ async function pull(
}
await Deno.writeTextFile(target, change.after);
if (!opts.raw) {
if (opts.stateful) {
await ensureDir(path.dirname(stateTarget));
await Deno.copyFile(target, stateTarget);
}
} else if (change.name === "added") {
await ensureDir(path.dirname(target));
if (!opts.raw) {
if (opts.stateful) {
await ensureDir(path.dirname(stateTarget));
log.info(`Adding ${getTypeStrFromPath(change.path)} ${change.path}`);
}
await Deno.writeTextFile(target, change.content);
log.info(`Writing ${getTypeStrFromPath(change.path)} ${change.path}`);
if (!opts.raw) {
if (opts.stateful) {
await Deno.copyFile(target, stateTarget);
}
} else if (change.name === "deleted") {
@@ -634,11 +634,11 @@ async function pull(
`Deleting ${getTypeStrFromPath(change.path)} ${change.path}`
);
await Deno.remove(target);
if (!opts.raw) {
if (opts.stateful) {
await Deno.remove(stateTarget);
}
} catch {
if (!opts.raw) {
if (opts.stateful) {
await Deno.remove(stateTarget);
}
}
@@ -715,6 +715,7 @@ function removeSuffix(str: string, suffix: string) {
async function push(
opts: GlobalOptions & {
stateful: boolean;
raw: boolean;
yes: boolean;
skipPull: boolean;
@@ -728,7 +729,10 @@ async function push(
message?: string;
}
) {
if (!opts.raw) {
if (opts.raw) {
log.info("--raw is now the default, you can remove it as a flag");
}
if (opts.stateful) {
if (!opts.skipPull) {
log.info(
colors.gray("You need to be up-to-date before pushing, pulling first.")
@@ -819,7 +823,7 @@ async function push(
lockfileUseArray
)
) {
if (!opts.raw && stateExists) {
if (opts.stateful && stateExists) {
await Deno.writeTextFile(stateTarget, change.after);
}
continue;
@@ -833,12 +837,12 @@ async function push(
opts
)
) {
if (!opts.raw && stateExists) {
if (opts.stateful && stateExists) {
await Deno.writeTextFile(stateTarget, change.after);
}
continue;
}
if (!opts.raw) {
if (opts.stateful) {
await ensureDir(path.dirname(stateTarget));
log.info(`Editing ${getTypeStrFromPath(change.path)} ${change.path}`);
}
@@ -854,7 +858,7 @@ async function push(
opts.message
);
if (!opts.raw && stateExists) {
if (opts.stateful && stateExists) {
await Deno.writeTextFile(stateTarget, change.after);
}
} else if (change.name === "added") {
@@ -875,7 +879,7 @@ async function push(
) {
continue;
}
if (!opts.raw && stateExists) {
if (opts.stateful && stateExists) {
await ensureDir(path.dirname(stateTarget));
log.info(`Adding ${getTypeStrFromPath(change.path)} ${change.path}`);
}
@@ -889,7 +893,7 @@ async function push(
opts.message
);
if (!opts.raw && stateExists) {
if (opts.stateful && stateExists) {
await Deno.writeTextFile(stateTarget, change.content);
}
} else if (change.name === "deleted") {

View File

@@ -679,10 +679,6 @@ export function roughSizeOfObject(object: object | string) {
return object.length * 2
}
if (typeof object != 'object') {
return 0
}
var objectList: any[] = []
var stack = [object]
var bytes = 0