|
@@ -19,11 +19,19 @@ const HEADER_TEMPLATE = `
|
|
|
/* This file was auto-generated by {{funcName}}() in @jupyterlab/buildutils */
|
|
|
`;
|
|
|
|
|
|
-function generatedHeader(funcName: string): string {
|
|
|
- return HEADER_TEMPLATE.split('{{funcName}}')
|
|
|
- .join(funcName)
|
|
|
- .trim();
|
|
|
+const ICON_IMPORTS_TEMPLATE = `
|
|
|
+import { Icon } from './interfaces';
|
|
|
+
|
|
|
+// icon svg import statements
|
|
|
+{{iconImportStatements}}
|
|
|
+
|
|
|
+// defaultIcons definition
|
|
|
+export namespace IconImports {
|
|
|
+ export const defaultIcons: ReadonlyArray<Icon.IModel> = [
|
|
|
+ {{iconModelDeclarations}}
|
|
|
+ ];
|
|
|
}
|
|
|
+`;
|
|
|
|
|
|
/**
|
|
|
* Ensure the integrity of a package.
|
|
@@ -144,7 +152,12 @@ export async function ensurePackage(
|
|
|
|
|
|
// Template the CSS index file.
|
|
|
if (cssImports && fs.existsSync(path.join(pkgPath, 'style/base.css'))) {
|
|
|
- let cssIndex = generatedHeader('ensurePackage');
|
|
|
+ const funcName = 'ensurePackage';
|
|
|
+ let cssIndex = utils.fromTemplate(
|
|
|
+ HEADER_TEMPLATE,
|
|
|
+ { funcName },
|
|
|
+ { end: '' }
|
|
|
+ );
|
|
|
cssImports.forEach(cssImport => {
|
|
|
cssIndex += `\n@import url('~${cssImport}');`;
|
|
|
});
|
|
@@ -307,7 +320,7 @@ export async function ensurePackage(
|
|
|
*/
|
|
|
export async function ensureUiComponents(pkgPath: string): Promise<string[]> {
|
|
|
let messages: string[] = [];
|
|
|
- const tab = ' ';
|
|
|
+ // const tab = ' ';
|
|
|
|
|
|
const iconSrcDir = path.join(pkgPath, 'src/icon');
|
|
|
const svgs = glob.sync(path.join(pkgPath, 'style/icons', '**/*.svg'));
|
|
@@ -321,25 +334,26 @@ export async function ensureUiComponents(pkgPath: string): Promise<string[]> {
|
|
|
iconImportStatements.push(
|
|
|
`import ${nameCamel} from '${path.relative(iconSrcDir, svg)}';`
|
|
|
);
|
|
|
- iconModelDeclarations.push(
|
|
|
- tab + tab + `{ name: '${name}', svg: ${nameCamel} }`
|
|
|
- );
|
|
|
+ iconModelDeclarations.push(`{ name: '${name}', svg: ${nameCamel} }`);
|
|
|
});
|
|
|
|
|
|
// generate the actual iconImports file
|
|
|
- let iconImports = generatedHeader('ensureUiComponents') + '\n\n';
|
|
|
- iconImports += "import { Icon } from './interfaces';\n\n";
|
|
|
-
|
|
|
- iconImports += '// icon svg import statements\n';
|
|
|
- iconImports += iconImportStatements.join('\n') + '\n\n';
|
|
|
-
|
|
|
- iconImports += '// defaultIcons definition\n';
|
|
|
- iconImports += 'export namespace IconImports {\n';
|
|
|
- iconImports +=
|
|
|
- tab + 'export const defaultIcons: ReadonlyArray<Icon.IModel> = [\n';
|
|
|
- iconImports += iconModelDeclarations.join(',\n') + '\n';
|
|
|
- iconImports += tab + '];\n';
|
|
|
- iconImports += '}\n';
|
|
|
+ /* tslint:disable */
|
|
|
+ const funcName = 'ensureUiComponents';
|
|
|
+ let iconImports = utils.fromTemplate(
|
|
|
+ HEADER_TEMPLATE,
|
|
|
+ { funcName },
|
|
|
+ { end: '\n\n' }
|
|
|
+ );
|
|
|
+ iconImports += utils.fromTemplate(ICON_IMPORTS_TEMPLATE, {
|
|
|
+ iconImportStatements
|
|
|
+ });
|
|
|
+ iconImports = utils.fromTemplate(
|
|
|
+ iconImports,
|
|
|
+ { iconModelDeclarations },
|
|
|
+ { join: ',\n' }
|
|
|
+ );
|
|
|
+ /* tslint:enable */
|
|
|
|
|
|
// write the iconImports file
|
|
|
const iconImportsPath = path.join(iconSrcDir, 'iconImports.ts');
|