Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(icons-scripts): glob on windows #922

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/icons-scripts/scripts/icons-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getReplacementIconComponentName(name) {
* @return {Icon[]}
*/
function dirMap(src, pattern, prefix = '', deprecatedIcons) {
const files = sortArrayAlphabetically(glob.sync(path.join(src, `./svg/${pattern}/*.svg`)));
const files = sortArrayAlphabetically(glob.sync(path.posix.join(src, `./svg/${pattern}/*.svg`)));

const { common, parts } = files
.map((filepath) => {
Expand Down
11 changes: 8 additions & 3 deletions packages/icons-scripts/scripts/icons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const { performance } = require('perf_hooks');
const { execSync } = require('child_process');
const { debugInfo, debugError, sortArrayAlphabetically } = require('./utils');
Expand All @@ -8,6 +9,7 @@ const { prepareOptions } = require('./options');
const { optimize } = require('./optimize');
const { createReactIcon } = require('./output');
const { generateRasterIcons } = require('./raster/icons');
const tsc = require('./tsc');

/**
* @typedef {import('./options').GenerateOptions} GenerateOptions
Expand Down Expand Up @@ -168,9 +170,12 @@ function generateIcons(options) {
);

debugInfo('Running tsc...');
execSync(
`tsc ${tsFilesDirectory}/**/*.ts ${tsFilesDirectory}/*.ts --emitDeclarationOnly --declaration --outDir ${distDirectory}/typings --jsx react --esModuleInterop --lib "dom,es2015" --skipLibCheck`,
);
const tsFiles = [
...glob.sync(path.posix.join(tsFilesDirectory, '**', '*.ts')),
...glob.sync(path.posix.join(tsFilesDirectory, '*.ts')),
];

tsc.compile(tsFiles, path.join(distDirectory, 'typings'));
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/icons-scripts/scripts/raster/icons-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { dashToCamel, sortArrayAlphabetically } = require('../utils');
* @param {string} src
*/
function createIconsMap(src) {
const files = sortArrayAlphabetically(glob.sync(path.join(src, `./png/**/*.png`)));
const files = sortArrayAlphabetically(glob.sync(path.posix.join(src, `./png/**/*.png`)));

/**
* @type {Map<string, IconEntity>}
Expand Down
48 changes: 48 additions & 0 deletions packages/icons-scripts/scripts/tsc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const ts = require('typescript');

/**
* @type {ts.FormatDiagnosticsHost}
*/
const formatHost = {
getCanonicalFileName: (path) => path,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine,
};

/**
* Компиляция ts файлов в js файлы
*
* @param {string[]} rootNames
* @param {string} outDir
*/
function compile(rootNames, outDir) {
/**
* @type {ts.CompilerOptions}
*/
const options = {
outDir,
emitDeclarationOnly: true,
declaration: true,
jsx: 'react',
esModuleInterop: true,
skipLibCheck: true,
};

const program = ts.createProgram(rootNames, options);

const preEmitDiagnostics = ts.getPreEmitDiagnostics(program);
if (preEmitDiagnostics.length) {
console.log(ts.formatDiagnosticsWithColorAndContext(preEmitDiagnostics, formatHost));
throw new Error('Pre-Emit diagnostics failed');
}

const emitResult = program.emit();
if (emitResult.diagnostics.length) {
console.log(ts.formatDiagnosticsWithColorAndContext(emitResult.diagnostics, formatHost));
throw new Error('Compilation failed');
}

return emitResult;
}

module.exports = { compile };