Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix versions.json lookup and verification #12

Merged
merged 2 commits into from
Feb 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/auto-plugin-obsidian/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class ObsidianPlugin implements IPlugin {
private readonly main: string;
/** Path to the manifest.json for the plugin */
private readonly manifest: string;
/** Path to the versions.json for the plugin */
private readonly versions: string;
/** Path to the plugin-name.zip for manual installs of the plugin */
private readonly zip?: string;
/** Directory with distribution files */
Expand All @@ -42,6 +44,7 @@ export default class ObsidianPlugin implements IPlugin {
this.styles = path.join(dir, "style.css");
this.main = path.join(dir, "main.js");
this.manifest = path.join(process.cwd(), "manifest.json");
this.versions = path.join(process.cwd(), "versions.json");
this.zip = glob.sync(path.join(dir, "*.zip"))[0];
}

Expand Down Expand Up @@ -74,6 +77,11 @@ export default class ObsidianPlugin implements IPlugin {
auto.logger.log.error(`Could not find file "${this.manifest}"`);
process.exit(1);
}

if (!fs.existsSync(this.versions)) {
auto.logger.log.error(`Could not find file "${this.versions}"`);
process.exit(1);
}
});

auto.hooks.version.tapPromise(
Expand Down Expand Up @@ -114,17 +122,16 @@ export default class ObsidianPlugin implements IPlugin {
}

// Update the versions.json
const versionsPath = path.join(__dirname, "../versions.json");
const versions = JSON.parse(fs.readFileSync(versionsPath, "utf-8"));
const versions = JSON.parse(fs.readFileSync(this.versions, "utf-8"));

if (versions[lastVersion] !== manifest.minAppVersion) {
versions[manifest.version] = manifest.minAppVersion;

const newVersions = JSON.stringify(versions, null, 2);
auto.logger.log.info("Updated versions.json: ", newVersions);

fs.writeFileSync(versionsPath, newVersions);
await execPromise("git", ["add", versionsPath]);
fs.writeFileSync(this.versions, newVersions);
await execPromise("git", ["add", this.versions]);
}

await execPromise("git", [
Expand Down