add uuid to ffc files (used for sync)

This commit is contained in:
Niko Lockenvitz 2020-07-20 22:33:38 +02:00
parent e0b3782923
commit 38f4aeef7b
No known key found for this signature in database
GPG key ID: 9403BD1956FFF190
5 changed files with 33 additions and 2 deletions

View file

@ -1,4 +1,5 @@
const fs = require("fs");
const { v4: uuidv4 } = require('uuid');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
@ -72,6 +73,7 @@ async function cliEditFile (filename) {
if (!curFilename.endsWith(".json")) curFilename += ".json";
curFileContent = await readJSONFromFile(curFilename);
console.log(`now editing ${curFilename}`);
addUUIDToFileIfItExistsNotYet();
while (true) {
const cmd = await readCommand(`Commands: new deck <name>, list decks, edit deck <name>, delete deck <name>, show meta, meta <attr> <value>, whereami, back`);
if (cmd.startsWith("new deck ")) {
@ -123,6 +125,12 @@ async function cliEditFile (filename) {
}
}
function addUUIDToFileIfItExistsNotYet () {
if (!("uuid" in curFileContent.meta)) {
curFileContent.meta.uuid = uuidv4();
}
}
async function cliEditDeck (deckName) {
console.log(`now editing ${deckName} in ${curFilename}`);
while (true) {

13
cli/package-lock.json generated Normal file
View file

@ -0,0 +1,13 @@
{
"name": "cli",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"uuid": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.2.0.tgz",
"integrity": "sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q=="
}
}
}

View file

@ -9,5 +9,8 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Niko Lockenvitz",
"license": "MIT"
}
"license": "MIT",
"dependencies": {
"uuid": "^8.2.0"
}
}

View file

@ -182,6 +182,8 @@ Our first proposal is as follows:
{
"meta": {
"author": "Name of the Author",
"uuid": "Optional UUID to allow updates (especially for local files)",
"url": "This keyword is reserved for internal use and will be overridden. Do not use it.",
"...": "..."
},
"decks": {
@ -190,6 +192,7 @@ Our first proposal is as follows:
"deck_name": "Full Name of the Deck",
"description": "Description",
"next_card_id": 3,
"short_name": "This keyword is reserved for internal use and will be overridden. Do not use it.",
"...": "..."
},
"cards": {

View file

@ -1,6 +1,7 @@
export interface FFCFile {
meta: {
author: string;
uuid?: string;
[x: string]: any;
};
decks: {
@ -27,9 +28,12 @@ export interface Deck {
name: string;
meta: {
file: {
uuid?: string;
url?: string;
[x: string]: any;
};
deck: {
short_name: string;
[x: string]: any;
};
};