Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
36 changes: 36 additions & 0 deletions playground/__tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,40 @@ describe('Test the config-sync CLI', () => {
}
expect(error).toHaveProperty('code', 1);
});

test('Import build project', async () => {
// First we make sure the dist folder is deleted.
await exec('rm -rf dist');

await exec('yarn cs import -y');

const { stdout: buildOutput } = await exec('ls dist');
expect(buildOutput).toContain('config');
expect(buildOutput).toContain('src');
expect(buildOutput).toContain('tsconfig.tsbuildinfo');

});
test('Import project already built', async () => {


// First we make sure the dist folder exists by doing an import.
await exec('yarn cs import -y');

const { stdout: lsDist } = await exec('ls dist');
expect(lsDist).toContain('config');
expect(lsDist).toContain('src');
expect(lsDist).toContain('tsconfig.tsbuildinfo');

// We remove on file from the dist folder
await exec('mv dist/tsconfig.tsbuildinfo .tmp');

// The new import should not rebuild the project.
await exec('yarn cs import -y');

const { stdout: buildOutput } = await exec('ls dist');
expect(buildOutput).toContain('config');
expect(buildOutput).toContain('src');
expect(buildOutput).not.toContain('tsconfig.tsbuildinfo');

});
});
10 changes: 5 additions & 5 deletions playground/__tests__/import-on-boostrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jest.setTimeout(20000);

afterEach(async () => {
// Disable importOnBootstrap
await exec('sed -i "s/importOnBootstrap: true/importOnBootstrap: false/g" config/plugins.js');
await exec('sed -i "s/importOnBootstrap: true/importOnBootstrap: false/g" config/plugins.ts');

await cleanupStrapi();
await exec('rm -rf config/sync');
Expand All @@ -19,8 +19,8 @@ describe('Test the importOnBootstrap feature', () => {
await exec('yarn cs export -y');
await exec('rm -rf .tmp');

// Manually change the plugins.js to enable importOnBoostrap.
await exec('sed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.js');
// Manually change the plugins.ts to enable importOnBoostrap.
await exec('sed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.ts');

// Start up Strapi to initiate the importOnBootstrap function.
await setupStrapi();
Expand All @@ -33,8 +33,8 @@ describe('Test the importOnBootstrap feature', () => {
await exec('rm -rf .tmp');
await exec('yarn cs export -y');

// Manually change the plugins.js to enable importOnBoostrap.
await exec('sed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.js');
// Manually change the plugins.ts to enable importOnBoostrap.
await exec('sed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.ts');

// Remove a config file to make sure the importOnBoostrap
// function actually attempts to import.
Expand Down
5 changes: 2 additions & 3 deletions playground/config/admin.js → playground/config/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = ({ env }) => ({
export default ({ env }) => ({
auth: {
secret: env('ADMIN_JWT_SECRET'),
},
Expand All @@ -19,6 +19,5 @@ module.exports = ({ env }) => ({
},
watchIgnoreFiles: [
'!**/.yalc/**/server/**',
'**/config/sync/**',
]
],
});
2 changes: 1 addition & 1 deletion playground/config/api.js → playground/config/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
rest: {
defaultLimit: 25,
maxLimit: 100,
Expand Down
11 changes: 0 additions & 11 deletions playground/config/database.js

This file was deleted.

15 changes: 15 additions & 0 deletions playground/config/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path from 'path';

export default ({ env }) => {

return {
connection: {
client: 'sqlite',
connection: {
filename: path.join(__dirname, '..', '..', env('DATABASE_FILENAME', '.tmp/data.db')),
},
useNullAsDefault: true,
},
};

};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
export default [
'strapi::logger',
'strapi::errors',
'strapi::security',
Expand Down
4 changes: 2 additions & 2 deletions playground/config/plugins.js → playground/config/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
export default () => ({
'config-sync': {
enabled: true,
config: {
importOnBootstrap: false,
minify: true,
},
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = ({ env }) => ({
export default ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
app: {
Expand Down
4 changes: 4 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"cs": "config-sync"
},
"devDependencies": {
"@types/node": "^24.0.7",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"supertest": "^6.3.3",
"typescript": "^5.8.3",
"yalc": "^1.0.0-pre.53"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { StrapiApp } from '@strapi/strapi/admin';

export default {
config: {
locales: [
Expand Down Expand Up @@ -29,7 +31,7 @@ export default {
// 'zh',
],
},
bootstrap(app) {
bootstrap(app: StrapiApp) {
console.log(app);
},
};
20 changes: 20 additions & 0 deletions playground/src/admin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["../plugins/**/admin/src/**/*", "./"],
"exclude": ["node_modules/", "build/", "dist/", "**/*.test.ts"]
}
9 changes: 0 additions & 9 deletions playground/src/admin/webpack.config.example.js

This file was deleted.

12 changes: 12 additions & 0 deletions playground/src/admin/webpack.config.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { mergeConfig, type UserConfig } from 'vite';

export default (config: UserConfig) => {
// Important: always return the modified config
return mergeConfig(config, {
resolve: {
alias: {
'@': '/src',
},
},
});
};
9 changes: 0 additions & 9 deletions playground/src/api/home/controllers/home.js

This file was deleted.

7 changes: 7 additions & 0 deletions playground/src/api/home/controllers/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* home controller
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreController('api::home.home');
9 changes: 0 additions & 9 deletions playground/src/api/home/routes/home.js

This file was deleted.

8 changes: 8 additions & 0 deletions playground/src/api/home/routes/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/**
* home router
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreRouter('api::home.home');
9 changes: 0 additions & 9 deletions playground/src/api/home/services/home.js

This file was deleted.

7 changes: 7 additions & 0 deletions playground/src/api/home/services/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* home service
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreService('api::home.home');
9 changes: 0 additions & 9 deletions playground/src/api/page/controllers/page.js

This file was deleted.

7 changes: 7 additions & 0 deletions playground/src/api/page/controllers/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* page controller
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreController('api::page.page');
9 changes: 0 additions & 9 deletions playground/src/api/page/routes/page.js

This file was deleted.

7 changes: 7 additions & 0 deletions playground/src/api/page/routes/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* page router
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreRouter('api::page.page');
9 changes: 0 additions & 9 deletions playground/src/api/page/services/page.js

This file was deleted.

7 changes: 7 additions & 0 deletions playground/src/api/page/services/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* page service
*/

import { factories } from '@strapi/strapi';

module.exports = factories.createCoreService('api::page.page');
8 changes: 4 additions & 4 deletions playground/src/index.js → playground/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
// import type { Core } from '@strapi/strapi';

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

/**
* An asynchronous bootstrap function that runs before
Expand All @@ -16,5 +16,5 @@ module.exports = {
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
bootstrap(/*{ strapi }*/) {},
bootstrap(/* { strapi }: { strapi: Core.Strapi } */) {},
};
43 changes: 43 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"lib": ["ES2020"],
"target": "ES2019",
"strict": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"noEmitOnError": true,
"noImplicitThis": true,
"outDir": "dist",
"rootDir": ".",
},
"include": [
// Include root files
"./",
// Include all ts files
"./**/*.ts",
// Include all js files
"./**/*.js",
// Force the JSON files in the src folder to be included
"src/**/*.json"
],

"exclude": [
"node_modules/",
"build/",
"dist/",
".cache/",
".tmp/",

// Do not include admin files in the server compilation
"src/admin/",
// Do not include test files
"**/*.test.*",
// Do not include plugins in the server compilation
"src/plugins/**"
]
}
Loading
Loading