Skip to content

Commit

Permalink
Merge pull request #12789 from strapi/features/typescript
Browse files Browse the repository at this point in the history
[Features] Typescript
  • Loading branch information
Convly committed Jul 27, 2022
2 parents 2d11fe5 + 1a4ac39 commit 0ad69d7
Show file tree
Hide file tree
Showing 367 changed files with 8,816 additions and 1,530 deletions.
11 changes: 0 additions & 11 deletions examples/getstarted/global.d.ts

This file was deleted.

9 changes: 9 additions & 0 deletions examples/getstarted/src/admin/app.example.js
@@ -0,0 +1,9 @@
const config = {
locales: ['fr'],
};
const bootstrap = () => {};

export default {
config,
bootstrap,
};
6 changes: 0 additions & 6 deletions examples/getstarted/src/admin/app.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/kitchensink-ts/config/admin.ts
@@ -0,0 +1,8 @@
export default ({ env }) => ({
auth: {
secret: env('ADMIN_JWT_SECRET', 'example-token'),
},
apiToken: {
salt: env('API_TOKEN_SALT', 'example-salt'),
},
});
7 changes: 7 additions & 0 deletions examples/kitchensink-ts/config/api.ts
@@ -0,0 +1,7 @@
export default {
rest: {
defaultLimit: 25,
maxLimit: 100,
withCount: true,
},
};
11 changes: 11 additions & 0 deletions examples/kitchensink-ts/config/database.ts
@@ -0,0 +1,11 @@
import path from 'path';

export default ({ env }) => ({
connection: {
client: 'sqlite',
connection: {
filename: path.join(__dirname, '..', '..', env('DATABASE_FILENAME', '.tmp/data.db')),
},
useNullAsDefault: true,
},
});
12 changes: 12 additions & 0 deletions examples/kitchensink-ts/config/middlewares.ts
@@ -0,0 +1,12 @@
export default [
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
];
7 changes: 7 additions & 0 deletions examples/kitchensink-ts/config/server.ts
@@ -0,0 +1,7 @@
export default ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
});
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/kitchensink-ts/package.json
@@ -0,0 +1,30 @@
{
"name": "kitchensink-ts",
"private": true,
"version": "4.2.2",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"@strapi/strapi": "4.2.2",
"@strapi/plugin-users-permissions": "4.1.12",
"@strapi/plugin-i18n": "4.1.12",
"better-sqlite3": "7.4.6"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "getstarted"
},
"engines": {
"node": ">=14.19.1 <=16.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
File renamed without changes.
5 changes: 5 additions & 0 deletions examples/kitchensink-ts/src/admin/tsconfig.json
@@ -0,0 +1,5 @@
{
"extends": "@strapi/typescript-utils/tsconfigs/admin",
"include": ["../plugins/**/admin/src/**/*", "./"],
"exclude": ["node_modules/", "build/", "dist/", "**/*.test.ts"]
}
6 changes: 6 additions & 0 deletions examples/kitchensink-ts/src/admin/webpack.config.example.ts
@@ -0,0 +1,6 @@
export default (config, webpack) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
return config;
};
File renamed without changes.
20 changes: 20 additions & 0 deletions examples/kitchensink-ts/src/index.ts
@@ -0,0 +1,20 @@
import '@strapi/strapi';

export default {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register(/*{ strapi }*/) {},

/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
bootstrap(/*{ strapi }*/) {},
};
18 changes: 18 additions & 0 deletions examples/kitchensink-ts/tsconfig.json
@@ -0,0 +1,18 @@
{
"extends": "@strapi/typescript-utils/tsconfigs/server",
"compilerOptions": {
"outDir": "dist",
"rootDir": "."
},
"include": ["./", "src/**/*.json"],
"exclude": [
"node_modules/",
"build/",
"dist/",
".cache/",
".tmp/",
"src/admin/",
"**/*.test.ts",
"src/plugins/**"
]
}
4 changes: 4 additions & 0 deletions examples/kitchensink/config/plugins.js
@@ -0,0 +1,4 @@
module.exports = {
// ...
// ...
};
62 changes: 34 additions & 28 deletions examples/kitchensink/src/admin/app.example.js
@@ -1,33 +1,39 @@
import theme from './extensions/theme';

export default {
config: {
auth: {
logo:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
},
head: {
favicon:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
title: 'Strapi test',
},
locales: ['fr', 'de'],
menu: {
logo:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
},
theme,
translations: {
fr: {
'Auth.form.email.label': 'test',
Users: 'Utilisateurs',
City: 'CITY FRENCH',
// Customize the label of the CM table..
Id: 'ID french',
},
const config = {
auth: {
logo:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
},
head: {
favicon:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
title: 'Strapi test',
},
locales: ['fr', 'de'],
menu: {
logo:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
},
theme,
translations: {
fr: {
'Auth.form.email.label': 'test',
Users: 'Utilisateurs',
City: 'CITY FRENCH',
// Customize the label of the CM table..
Id: 'ID french',
},
tutorials: false,
notifications: { release: false },
},
bootstrap() {},
tutorials: false,
notifications: { release: false },
};

const bootstrap = app => {
console.log(app);
};

export default {
config,
bootstrap,
};
39 changes: 39 additions & 0 deletions examples/kitchensink/src/admin/app.js
@@ -0,0 +1,39 @@
import theme from './extensions/theme';

const config = {
auth: {
logo:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
},
head: {
favicon:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
title: 'Strapi tesrrt',
},
locales: ['fr', 'de'],
menu: {
logo:
'https://images.unsplash.com/photo-1593642634367-d91a135587b5?ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80',
},
theme,
translations: {
fr: {
'Auth.form.email.label': 'test',
Users: 'Utilisateurs',
City: 'CITY FRENCH',
// Customize the label of the CM table..
Id: 'ID french',
},
},
tutorials: false,
notifications: { release: false },
};

const bootstrap = app => {
console.log(app);
};

export default {
config,
bootstrap,
};
1 change: 1 addition & 0 deletions packages/admin-test-utils/lib/fixtures/store/index.js
Expand Up @@ -4,6 +4,7 @@
const { combineReducers, createStore } = require('redux');

const reducers = {
admin_app: jest.fn(() => ({ status: 'init' })),
'content-manager_app': jest.fn(() => ({
components: [],
status: 'loading',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/create-strapi-app/create-strapi-app.js
Expand Up @@ -37,6 +37,7 @@ program
.option('--dbfile <dbfile>', 'Database file path for sqlite')
.option('--dbforce', 'Overwrite database content if any')
.option('--template <templateurl>', 'Specify a Strapi template')
.option('--ts, --typescript', 'Use TypeScript to generate the project')
.description('create a new application')
.action(directory => {
initProject(directory, program);
Expand Down
11 changes: 7 additions & 4 deletions packages/core/admin/admin/src/app.js
@@ -1,6 +1,9 @@
const config = {
locales: ['fr'],
};
const bootstrap = () => {};

export default {
config: {
locales: ['fr'],
},
bootstrap() {},
config,
bootstrap,
};
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { IntlProvider } from 'react-intl';
import { useGuidedTour } from '@strapi/helper-plugin';
import { useGuidedTour, TrackingContext } from '@strapi/helper-plugin';
import { ThemeProvider, lightTheme } from '@strapi/design-system';
import GuidedTourHomepage from '../index';

Expand Down Expand Up @@ -31,13 +31,15 @@ jest.mock('@strapi/helper-plugin', () => ({
const history = createMemoryHistory();

const App = (
<ThemeProvider theme={lightTheme}>
<IntlProvider locale="en" messages={{}} textComponent="span">
<Router history={history}>
<GuidedTourHomepage />
</Router>
</IntlProvider>
</ThemeProvider>
<TrackingContext.Provider value={{ uuid: null, telemetryProperties: undefined }}>
<ThemeProvider theme={lightTheme}>
<IntlProvider locale="en" messages={{}} textComponent="span">
<Router history={history}>
<GuidedTourHomepage />
</Router>
</IntlProvider>
</ThemeProvider>
</TrackingContext.Provider>
);

describe('GuidedTour Homepage', () => {
Expand Down
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import { useGuidedTour } from '@strapi/helper-plugin';
import { useGuidedTour, TrackingContext } from '@strapi/helper-plugin';
import { lightTheme, darkTheme } from '@strapi/design-system';
import Theme from '../../../Theme';
import ThemeToggleProvider from '../../../ThemeToggleProvider';
Expand Down Expand Up @@ -30,13 +30,15 @@ jest.mock('@strapi/helper-plugin', () => ({
}));

const App = (
<ThemeToggleProvider themes={{ light: lightTheme, dark: darkTheme }}>
<Theme>
<IntlProvider locale="en" messages={{}} defaultLocale="en" textComponent="span">
<GuidedTourModal />
</IntlProvider>
</Theme>
</ThemeToggleProvider>
<TrackingContext.Provider value={{ uuid: null, telemetryProperties: undefined }}>
<ThemeToggleProvider themes={{ light: lightTheme, dark: darkTheme }}>
<Theme>
<IntlProvider locale="en" messages={{}} defaultLocale="en" textComponent="span">
<GuidedTourModal />
</IntlProvider>
</Theme>
</ThemeToggleProvider>
</TrackingContext.Provider>
);

describe('<GuidedTourModal />', () => {
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { useQuery } from 'react-query';
import { useNotification } from '@strapi/helper-plugin';
import { fetchMarketplacePlugins } from './utils/api';

const useFetchMarketplaceProviders = (notifyLoad) => {
const useFetchMarketplaceProviders = notifyLoad => {
const toggleNotification = useNotification();

return useQuery('list-marketplace-providers', () => fetchMarketplacePlugins(), {
Expand Down

0 comments on commit 0ad69d7

Please sign in to comment.