This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(database): switch to objectbox
- Loading branch information
Showing
50 changed files
with
826 additions
and
856 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -33,4 +33,5 @@ appimage-builder-cache/ | |
builder.g.yml | ||
assets/data/meta.json | ||
certs | ||
cli/.cache | ||
cli/.cache | ||
lib/**/*.g.dart |
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,133 @@ | ||
import { dirname, join, relative } from "path"; | ||
import chalk from "chalk"; | ||
import { | ||
pathExists, | ||
copyFile, | ||
rm, | ||
ensureDir, | ||
readFile, | ||
writeFile, | ||
} from "fs-extra"; | ||
import { SpawnError, spawn } from "../../../spawn"; | ||
import { config } from "../../../config"; | ||
import { Logger } from "../../../logger"; | ||
|
||
const logger = new Logger("build_runner:generate"); | ||
|
||
const generated = { | ||
from: join(config.base, "lib"), | ||
to: join(config.base, "lib/modules/database/objectbox"), | ||
pre: { | ||
files: ["objectbox-model.json"], | ||
async do() { | ||
logger.log( | ||
`Restoring files to ${chalk.cyanBright( | ||
relative(config.base, generated.from) | ||
)}` | ||
); | ||
|
||
for (const x of generated.pre.files) { | ||
const path = join(generated.to, x); | ||
if (await pathExists(path)) { | ||
await copyFile(path, join(generated.from, x)); | ||
} | ||
} | ||
}, | ||
}, | ||
post: { | ||
files: ["objectbox.g.dart", "objectbox-model.json"], | ||
async do(success: boolean) { | ||
logger.log( | ||
`Moving files to ${chalk.cyanBright( | ||
relative(config.base, generated.to) | ||
)}` | ||
); | ||
|
||
await ensureDir(generated.to); | ||
|
||
for (const x of generated.post.files) { | ||
const path = join(generated.from, x); | ||
|
||
if (success) { | ||
if (/\.g\.dart$/.test(x)) { | ||
await writeFile( | ||
path, | ||
await generated.modifyImports(path, generated.to) | ||
); | ||
} | ||
|
||
await copyFile(path, join(generated.to, x)); | ||
} | ||
|
||
await rm(path); | ||
} | ||
}, | ||
}, | ||
async modifyImports(path: string, to: string) { | ||
const from = dirname(path); | ||
const content = (await readFile(path)).toString(); | ||
|
||
const importRegex = /import ['"](?!dart|package:)(.*)['"];/; | ||
const modified = content.replace(RegExp(importRegex, "g"), (str) => { | ||
const match = str.match(importRegex)!; | ||
const importFromPath = join(from, match[1]); | ||
const importToPath = relative(to, importFromPath).replace( | ||
/\\/g, | ||
"/" | ||
); | ||
|
||
return `import '${importToPath}';`; | ||
}); | ||
|
||
return modified; | ||
}, | ||
}; | ||
|
||
const execute = async (force: boolean) => { | ||
try { | ||
await generated.pre.do(); | ||
|
||
const flags: string[] = []; | ||
|
||
if (force) { | ||
flags.push("--delete-conflicting-outputs"); | ||
} | ||
|
||
await spawn( | ||
"flutter", | ||
["packages", "pub", "run", "build_runner", "build", ...flags], | ||
config.base | ||
); | ||
|
||
await generated.post.do(true); | ||
} catch (err) { | ||
await generated.post.do(false); | ||
throw err; | ||
} | ||
}; | ||
|
||
export const generate = async () => { | ||
logger.log("Running build_runner command..."); | ||
|
||
try { | ||
await execute(process.argv.includes("-f")); | ||
} catch (err: any) { | ||
if ( | ||
err instanceof SpawnError && | ||
typeof err.result.code === "number" && | ||
err.result.code === 78 | ||
) { | ||
logger.warn( | ||
`Found conflicting outputs, retrying with ${chalk.redBright( | ||
"--delete-conflicting-outputs" | ||
)} flag` | ||
); | ||
|
||
await execute(true); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
|
||
logger.log("Finished running build_runner command"); | ||
}; |
File renamed without changes.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:path/path.dart' as path; | ||
import 'package:path_provider/path_provider.dart' as path_provider; | ||
import './app.dart'; | ||
|
||
abstract class PathDirs { | ||
static late String documents; | ||
static late String temp; | ||
|
||
static Future<void> initialize() async { | ||
documents = path.join( | ||
(await path_provider.getApplicationDocumentsDirectory()).path, | ||
Config.code, | ||
); | ||
|
||
temp = path.join( | ||
(await path_provider.getTemporaryDirectory()).path, | ||
Config.code, | ||
); | ||
} | ||
|
||
static String get data => path.join(documents, 'data'); | ||
} |
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
Oops, something went wrong.