Skip to content

Commit

Permalink
feat: copy yaml assets
Browse files Browse the repository at this point in the history
  • Loading branch information
martyanovandrey committed Mar 27, 2024
1 parent 8977307 commit e79a9ac
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/cmd/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import glob from 'glob';
import walkSync from "walk-sync";

Check failure on line 2 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `"walk-sync"` with `'walk-sync'`
import {load} from "js-yaml";

Check failure on line 3 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `"js-yaml"` with `'js-yaml'`
import {readFileSync} from "fs";

Check failure on line 4 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `"fs"` with `'fs'`
import {Arguments, Argv} from 'yargs';
import {join, resolve} from 'path';
import shell from 'shelljs';

import {LINK_KEYS} from "@diplodoc/client/ssr";

Check failure on line 9 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `"@diplodoc/client/ssr"` with `'@diplodoc/client/ssr'`
import {isLocalUrl} from "@diplodoc/transform/lib/utils";

Check failure on line 10 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `"@diplodoc/transform/lib/utils"` with `'@diplodoc/transform/lib/utils'`
import OpenapiIncluder from '@diplodoc/openapi-extension/includer';

import {
BUNDLE_FOLDER,
LINT_CONFIG_FILENAME,
Expand All @@ -9,9 +20,7 @@ import {
YFM_CONFIG_FILENAME,
} from '../../constants';
import {argvValidator} from '../../validator';
import {join, resolve} from 'path';
import {ArgvService, Includers} from '../../services';
import OpenapiIncluder from '@diplodoc/openapi-extension/includer';
import {
initLinterWorkers,
processAssets,
Expand All @@ -22,11 +31,9 @@ import {
processServiceFiles,
} from '../../steps';
import {prepareMapFile} from '../../steps/processMapFile';
import shell from 'shelljs';
import {Resources} from '../../models';
import {copyFiles, logger} from '../../utils';
import {checkPathExists, copyFiles, findAllValuesByKeys, logger} from '../../utils';
import {upload as publishFilesToS3} from '../publish/upload';
import glob from 'glob';

export const build = {
command: ['build', '$0'],
Expand Down Expand Up @@ -257,6 +264,27 @@ async function handler(args: Arguments<any>) {
copyFiles(args.input, tmpOutputFolder, resourcePaths);
}

const yamlFiles: string[] = walkSync(args.input, {
globs: ['**/*.yaml'],
directories: false,
includeBasePath: true,
ignore: ['**/toc.yaml', resolve(pathToRedirects)],
});

yamlFiles.forEach(yamlFile => {

Check failure on line 274 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `yamlFile` with `(yamlFile)`
const content = load(readFileSync(yamlFile, 'utf8'));

if(!Object.prototype.hasOwnProperty.call(content, 'blocks')){

Check failure on line 277 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `(!Object.prototype.hasOwnProperty.call(content,·'blocks'))` with `·(!Object.prototype.hasOwnProperty.call(content,·'blocks'))·`
return

Check failure on line 278 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Insert `;`
}
const contentLinks = findAllValuesByKeys(content, LINK_KEYS);
const localMediaLinks = contentLinks.filter(
(link) => new RegExp(/^\S.*\.(svg|png|gif|jpg|jpeg|bmp|webp|ico)$/gm).test(link) && isLocalUrl(link),

Check failure on line 282 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `·new·RegExp(/^\S.*\.(svg|png|gif|jpg|jpeg|bmp|webp|ico)$/gm).test(link` with `⏎································new·RegExp(/^\S.*\.(svg|png|gif|jpg|jpeg|bmp|webp|ico)$/gm).test(⏎····································link,⏎································`
);

copyFiles(args.input, tmpOutputFolder, localMediaLinks.filter(link => checkPathExists(link, yamlFile)));

Check failure on line 285 in src/cmd/build/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `args.input,·tmpOutputFolder,·localMediaLinks.filter(link·=>·checkPathExists(link,·yamlFile))` with `⏎····························args.input,⏎····························tmpOutputFolder,⏎····························localMediaLinks.filter((link)·=>·checkPathExists(link,·yamlFile)),⏎························`
})

break;
}
}
Expand Down

0 comments on commit e79a9ac

Please sign in to comment.