mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat: allow TS to be used in challenges (#56159)
This commit is contained in:
committed by
GitHub
parent
349fca83de
commit
8b601d762e
@@ -191,6 +191,7 @@ const modeMap = {
|
|||||||
html: 'html',
|
html: 'html',
|
||||||
js: 'javascript',
|
js: 'javascript',
|
||||||
jsx: 'javascript',
|
jsx: 'javascript',
|
||||||
|
ts: 'typescript',
|
||||||
py: 'python',
|
py: 'python',
|
||||||
python: 'python'
|
python: 'python'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export type VisibleEditors = {
|
|||||||
indexjsx?: boolean;
|
indexjsx?: boolean;
|
||||||
stylescss?: boolean;
|
stylescss?: boolean;
|
||||||
scriptjs?: boolean;
|
scriptjs?: boolean;
|
||||||
|
indexts?: boolean;
|
||||||
mainpy?: boolean;
|
mainpy?: boolean;
|
||||||
};
|
};
|
||||||
type MultifileEditorProps = Pick<
|
type MultifileEditorProps = Pick<
|
||||||
@@ -78,7 +79,14 @@ const MultifileEditor = (props: MultifileEditorProps) => {
|
|||||||
isUsingKeyboardInTablist,
|
isUsingKeyboardInTablist,
|
||||||
resizeProps,
|
resizeProps,
|
||||||
title,
|
title,
|
||||||
visibleEditors: { stylescss, indexhtml, scriptjs, indexjsx, mainpy },
|
visibleEditors: {
|
||||||
|
stylescss,
|
||||||
|
indexhtml,
|
||||||
|
scriptjs,
|
||||||
|
indexts,
|
||||||
|
indexjsx,
|
||||||
|
mainpy
|
||||||
|
},
|
||||||
usesMultifileEditor,
|
usesMultifileEditor,
|
||||||
showProjectPreview
|
showProjectPreview
|
||||||
} = props;
|
} = props;
|
||||||
@@ -103,6 +111,7 @@ const MultifileEditor = (props: MultifileEditorProps) => {
|
|||||||
if (stylescss) editorKeys.push('stylescss');
|
if (stylescss) editorKeys.push('stylescss');
|
||||||
if (scriptjs) editorKeys.push('scriptjs');
|
if (scriptjs) editorKeys.push('scriptjs');
|
||||||
if (mainpy) editorKeys.push('mainpy');
|
if (mainpy) editorKeys.push('mainpy');
|
||||||
|
if (indexts) editorKeys.push('indexts');
|
||||||
|
|
||||||
const editorAndSplitterKeys = editorKeys.reduce((acc: string[] | [], key) => {
|
const editorAndSplitterKeys = editorKeys.reduce((acc: string[] | [], key) => {
|
||||||
if (acc.length === 0) {
|
if (acc.length === 0) {
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
import { ChallengeFile } from "../../src/redux/prop-types";
|
import { ChallengeFile } from "../../src/redux/prop-types";
|
||||||
|
|
||||||
export const challengeFiles: ChallengeFile[] = [
|
export const challengeFiles: ChallengeFile[] = [
|
||||||
|
{
|
||||||
|
id: '0',
|
||||||
|
contents: 'some ts',
|
||||||
|
error: null,
|
||||||
|
ext: 'ts',
|
||||||
|
head: '',
|
||||||
|
history: ['index.ts'],
|
||||||
|
fileKey: 'indexts',
|
||||||
|
name: 'index',
|
||||||
|
seed: 'some ts',
|
||||||
|
tail: '',
|
||||||
|
editableRegionBoundaries: [],
|
||||||
|
usesMultifileEditor: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
contents: 'some css',
|
contents: 'some css',
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ exports.sortChallengeFiles = function sortChallengeFiles(challengeFiles) {
|
|||||||
if (b.history[0] === 'index.jsx') return 1;
|
if (b.history[0] === 'index.jsx') return 1;
|
||||||
if (a.history[0] === 'script.js') return -1;
|
if (a.history[0] === 'script.js') return -1;
|
||||||
if (b.history[0] === 'script.js') return 1;
|
if (b.history[0] === 'script.js') return 1;
|
||||||
|
if (a.history[0] === 'index.ts') return -1;
|
||||||
|
if (b.history[0] === 'index.ts') return 1;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
return xs;
|
return xs;
|
||||||
|
|||||||
@@ -14,10 +14,16 @@ describe('sort-files', () => {
|
|||||||
expect(sorted.length).toEqual(expected.length);
|
expect(sorted.length).toEqual(expected.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should sort the objects into html, css, jsx, js order', () => {
|
it('should sort the objects into html, css, jsx, js, ts order', () => {
|
||||||
const sorted = sortChallengeFiles(challengeFiles);
|
const sorted = sortChallengeFiles(challengeFiles);
|
||||||
const sortedKeys = sorted.map(({ fileKey }) => fileKey);
|
const sortedKeys = sorted.map(({ fileKey }) => fileKey);
|
||||||
const expected = ['indexhtml', 'stylescss', 'indexjsx', 'scriptjs'];
|
const expected = [
|
||||||
|
'indexhtml',
|
||||||
|
'stylescss',
|
||||||
|
'indexjsx',
|
||||||
|
'scriptjs',
|
||||||
|
'indexts'
|
||||||
|
];
|
||||||
expect(sortedKeys).toStrictEqual(expected);
|
expect(sortedKeys).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ const keyToSection = {
|
|||||||
head: 'before-user-code',
|
head: 'before-user-code',
|
||||||
tail: 'after-user-code'
|
tail: 'after-user-code'
|
||||||
};
|
};
|
||||||
const supportedLanguages = ['js', 'css', 'html', 'jsx', 'py'];
|
const supportedLanguages = ['js', 'css', 'html', 'jsx', 'py', 'ts'];
|
||||||
const longToShortLanguages = {
|
const longToShortLanguages = {
|
||||||
javascript: 'js',
|
javascript: 'js',
|
||||||
|
typescript: 'ts',
|
||||||
python: 'py'
|
python: 'py'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user