mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
add test/upgradeDocument utility
This commit is contained in:
parent
1b6b56bea1
commit
95351fb187
7
test/setupPaths.js
Normal file
7
test/setupPaths.js
Normal file
@ -0,0 +1,7 @@
|
||||
// enhance require() to support project paths and typescript.
|
||||
const path = require('path');
|
||||
const appModulePath = require('app-module-path');
|
||||
const root = path.dirname(__dirname);
|
||||
appModulePath.addPath(path.join(root, "_build"));
|
||||
appModulePath.addPath(path.join(root, "_build/core"));
|
||||
appModulePath.addPath(path.join(root, "_build/ext"));
|
4
test/upgradeDocument
Executable file
4
test/upgradeDocument
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('./setupPaths');
|
||||
require('test/upgradeDocumentImpl').main().catch(e => console.error(String(e)));
|
43
test/upgradeDocumentImpl.ts
Normal file
43
test/upgradeDocumentImpl.ts
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Upgrade one or more documents (both the DocStorage and schema migrations).
|
||||
*
|
||||
* Usage:
|
||||
* test/upgradeDocument <docPaths...>
|
||||
*/
|
||||
import {copyFile} from 'app/server/lib/docUtils';
|
||||
import {createDocTools} from 'test/server/docTools';
|
||||
import log from 'app/server/lib/log';
|
||||
import * as fs from "fs";
|
||||
|
||||
export async function main() {
|
||||
const docPaths = process.argv.slice(2);
|
||||
if (docPaths.length === 0) {
|
||||
console.log(`Usage:\n test/upgradeDocument path/to/doc.grist ...\n`);
|
||||
throw new Error("Document argument required");
|
||||
}
|
||||
for (const docPath of docPaths) {
|
||||
if (!docPath.endsWith('.grist')) {
|
||||
throw new Error(`Document path should have .grist extension: ${docPath}`);
|
||||
}
|
||||
if (!fs.existsSync(docPath)) {
|
||||
throw new Error(`Document path doesn't exist: ${docPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
const prevLogLevel = log.transports.file.level;
|
||||
log.transports.file.level = 'warn';
|
||||
const docTools = createDocTools();
|
||||
await docTools.before();
|
||||
try {
|
||||
for (const docPath of docPaths) {
|
||||
console.log(`Upgrading ${docPath}`);
|
||||
const activeDoc = await docTools.loadLocalDoc(docPath);
|
||||
await activeDoc.waitForInitialization();
|
||||
await activeDoc.shutdown();
|
||||
await copyFile(docTools.getStorageManager().getPath(activeDoc.docName), docPath);
|
||||
}
|
||||
} finally {
|
||||
await docTools.after();
|
||||
log.transports.file.level = prevLogLevel;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user