47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
/**
|
|
* npm run shop create a short wizard: name and code
|
|
* npm run shop list show every shop
|
|
*/
|
|
import { createShopWizard, shopListLines } from '../src/cli/shopWizard';
|
|
import { loadConfig } from '../src/config';
|
|
import { openDb } from '../src/db';
|
|
import { runMigrations } from '../src/db/migrate';
|
|
import { makeIo } from './cliIo';
|
|
|
|
async function main(): Promise<number> {
|
|
const command = process.argv[2];
|
|
if (command !== 'create' && command !== 'list') {
|
|
console.log('usage:');
|
|
console.log(' npm run shop create add a shop (a short wizard)');
|
|
console.log(' npm run shop list show every shop');
|
|
return command ? 1 : 0;
|
|
}
|
|
|
|
const config = loadConfig();
|
|
const db = openDb(config.dbPath);
|
|
runMigrations(db);
|
|
|
|
try {
|
|
if (command === 'list') {
|
|
for (const line of shopListLines(db)) console.log(line);
|
|
return 0;
|
|
}
|
|
const { io, close } = makeIo();
|
|
try {
|
|
return await createShopWizard(db, io);
|
|
} finally {
|
|
close();
|
|
}
|
|
} finally {
|
|
db.close();
|
|
}
|
|
}
|
|
|
|
main().then(
|
|
(code) => process.exit(code),
|
|
(err) => {
|
|
console.error(String(err));
|
|
process.exit(1);
|
|
},
|
|
);
|