-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
128c70a
commit 3f5d298
Showing
85 changed files
with
1,080 additions
and
265 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
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
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
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,45 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { CliOptions, getTestFolder } from './utils'; | ||
import { TemplateOptions, DataImportOptions, relativeImport } from '../utils'; | ||
import { createDataTemplate } from '../data-templates/data-template'; | ||
|
||
/** | ||
* save a data template file based on options | ||
* @param options - the rendering and file options | ||
*/ | ||
export const saveDataTemplate = async <P extends TemplateOptions>( | ||
options: CliOptions<P>, | ||
): Promise<DataImportOptions | undefined> => { | ||
const testFolder = getTestFolder(options); | ||
if (!testFolder) { | ||
return undefined; | ||
} | ||
const { test, overwrite } = options; | ||
const dataName = test | ||
.split('.') | ||
.map((e, i) => (i === 1 ? 'data' : e)) | ||
.join('.'); | ||
const filePath = path.resolve(testFolder, dataName); | ||
let existing: Record<string, any> | undefined = undefined; | ||
if (fs.existsSync(filePath)) { | ||
if (overwrite) { | ||
//load existing data file | ||
existing = require(filePath); | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
const dataTemplate = await createDataTemplate(options, existing); | ||
if (dataTemplate) { | ||
if (!fs.existsSync(testFolder)) { | ||
fs.mkdirSync(testFolder); | ||
} | ||
fs.writeFileSync(filePath, dataTemplate.content, 'utf8'); | ||
return { | ||
data: dataTemplate.data, | ||
filePath: relativeImport(testFolder, filePath), | ||
}; | ||
} | ||
return undefined; | ||
}; |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import path from 'path'; | ||
import { TemplateOptions } from '../utils'; | ||
|
||
export type CliOptions<P extends TemplateOptions = TemplateOptions> = { | ||
overwrite: boolean; | ||
test: string; | ||
/** | ||
* components to include | ||
*/ | ||
include?: string[]; | ||
/** | ||
* components to exclude | ||
*/ | ||
exclude?: string[]; | ||
} & P; | ||
|
||
export const getTestFolder = (options: CliOptions): string | undefined => { | ||
const { test, output, include, exclude } = options; | ||
//check if the test file name is to be included. | ||
const testName = test.split('.')[0]; | ||
if (include && !include.includes(testName)) { | ||
return undefined; | ||
} | ||
if (exclude && exclude.includes(testName)) { | ||
return undefined; | ||
} | ||
let testFolder = output as string; | ||
|
||
if (!path.isAbsolute(testFolder)) { | ||
testFolder = path.resolve(process.cwd(), testFolder); | ||
} | ||
return testFolder; | ||
}; |
Oops, something went wrong.