Skip to content

Commit

Permalink
fix: build templates for Strapi 5 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
innerdvations authored May 8, 2024
1 parent 8b8b5aa commit 8891da5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
coverage
dist
*.yaml
*.yaml
.changeset
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
dist
pnpm-lock.yaml
pnpm-lock.yaml
.changeset
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ npx @strapi/sdk-plugin@latest init my-plugin

That will create a directory with all your plugin project files.

Once your project has been installed, you will have access to the `strapi-plugin` command.

Run `strapi-plugin -h` for more information on CLI usage.

## Commands
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"./package.json": "./package.json"
},
"bin": "./bin/sdk-plugin.js",
"bin": "./bin/strapi-plugin.js",
"files": [
"bin",
"dist"
Expand Down
18 changes: 13 additions & 5 deletions src/cli/commands/plugin/init/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import type { InitOptions, TemplateFile } from '@strapi/pack-up';

type ActionOptions = Pick<InitOptions, 'silent' | 'debug'>;

// TODO: remove these when release versions are available
const USE_BETA_VERSIONS: string[] = [
'@strapi/design-system',
'@strapi/icons',
'@strapi/strapi',
] as const;

export default async (
packagePath: string,
{ silent, debug }: ActionOptions,
Expand Down Expand Up @@ -246,7 +253,8 @@ const PLUGIN_TEMPLATE = defineTemplate(async ({ logger, gitConfig, packagePath }
prettier: '*',
},
peerDependencies: {
'@strapi/strapi': '^4.0.0',
// TODO: set this to 5.0.0 when Strapi 5 is released
'@strapi/strapi': '^5.0.0-beta',
},
strapi: {
kind: 'plugin',
Expand Down Expand Up @@ -306,15 +314,15 @@ const PLUGIN_TEMPLATE = defineTemplate(async ({ logger, gitConfig, packagePath }
react: '*',
'react-dom': '*',
'react-router-dom': '*',
'styled-components': '5.3.3',
'styled-components': '*',
};

pkgJson.peerDependencies = {
...pkgJson.peerDependencies,
react: '^17.0.0 || ^18.0.0',
'react-dom': '^17.0.0 || ^18.0.0',
'react-router-dom': '^6.0.0',
'styled-components': '^5.2.1',
'styled-components': '^6.0.0',
};
}

Expand Down Expand Up @@ -364,7 +372,6 @@ const PLUGIN_TEMPLATE = defineTemplate(async ({ logger, gitConfig, packagePath }
...pkgJson.devDependencies,
'@types/react': '*',
'@types/react-dom': '*',
'@types/styled-components': '5.1.32',
};

const { adminTsconfigFiles } = await import('./files/typescript');
Expand Down Expand Up @@ -526,7 +533,8 @@ const resolveLatestVerisonOfDeps = async (

for (const [name, version] of Object.entries(deps)) {
try {
const latestVersion = await getLatestVersion(name, version);
const range = USE_BETA_VERSIONS.includes(name) ? 'beta' : version;
const latestVersion = await getLatestVersion(name, { range });
latestDeps[name] = latestVersion ? `^${latestVersion}` : '*';
} catch (err) {
latestDeps[name] = '*';
Expand Down
18 changes: 8 additions & 10 deletions src/cli/commands/plugin/init/files/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ export { PluginIcon };
`;

const APP_CODE = outdent`
import { Page } from '@strapi/strapi/admin';
import { Switch, Route } from 'react-router-dom';
import { PLUGIN_ID } from '../pluginId';
import { Page } from '@strapi/design-system';
import { Routes, Route } from 'react-router-dom';
import { HomePage } from './HomePage';
const App = () => {
return (
<Switch>
<Routes>
<Route index element={<HomePage />} />
<Route path="*" element={<Page.Error />} />
</Switch>
</Routes>
);
};
Expand Down Expand Up @@ -53,7 +51,7 @@ const TYPESCRIPT: TemplateFile[] = [
{
name: 'admin/src/index.ts',
contents: outdent`
import { prefixPluginTranslations } from './utils/prefixPluginTranslations';
import { getTranslation } from './utils/getTranslation';
import { PLUGIN_ID } from './pluginId';
import { Initializer } from './components/Initializer';
import { PluginIcon } from './components/PluginIcon';
Expand Down Expand Up @@ -90,7 +88,7 @@ const TYPESCRIPT: TemplateFile[] = [
return import(\`./translations/\${locale}.json\`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, PLUGIN_ID),
data: getTranslation(data),
locale,
};
})
Expand Down Expand Up @@ -176,7 +174,7 @@ const JAVASCRIPT: TemplateFile[] = [
{
name: 'admin/src/index.js',
contents: outdent`
import { prefixPluginTranslations } from './utils/prefixPluginTranslations';
import { getTranslation } from './utils/getTranslation';
import { PLUGIN_ID } from './pluginId';
import { Initializer } from './components/Initializer';
import { PluginIcon } from './components/PluginIcon';
Expand Down Expand Up @@ -213,7 +211,7 @@ const JAVASCRIPT: TemplateFile[] = [
return import(\`./translations/\${locale}.json\`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, PLUGIN_ID),
data: getTranslation(data),
locale,
};
})
Expand Down

0 comments on commit 8891da5

Please sign in to comment.