-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimporter.ts
More file actions
34 lines (28 loc) · 1.05 KB
/
importer.ts
File metadata and controls
34 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as fs from 'fs';
import * as process from 'process';
import * as path from 'path';
import ImportCommand from '@contentstack/cli-cm-import';
import { pathValidator, sanitizePath } from '@contentstack/cli-utilities';
const STACK_FOLDER = 'stack';
export interface ImporterOptions {
master_locale: string;
api_key: string;
tmpPath: string;
cmaHost: string;
cdaHost: string;
isAuthenticated: boolean;
alias?: string;
}
export async function run(options: ImporterOptions) {
const tmpPathResolved = path.resolve(sanitizePath(options.tmpPath));
const stackPath = path.join(tmpPathResolved, STACK_FOLDER);
// Support both structures: repo with stack/ folder (per docs) or content at root
const importPath = fs.existsSync(stackPath)
? pathValidator(stackPath)
: pathValidator(tmpPathResolved);
const args = options.alias
? ['-k', options.api_key, '-d', importPath, '--alias', options.alias!]
: ['-k', options.api_key, '-d', importPath];
process.chdir(options.tmpPath);
await ImportCommand.run(args.concat('--skip-audit'));
}