Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsingwersen committed Oct 21, 2024
2 parents e9a6b5d + 20afc21 commit 1308bee
Show file tree
Hide file tree
Showing 29 changed files with 688 additions and 1,201 deletions.
2 changes: 2 additions & 0 deletions .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ backend:
- 'packages/{utils,generators,cli,providers}/**'
- 'packages/core/*/{lib,bin,ee,src}/**'
- 'packages/core/database/**'
- 'yarn.lock'
frontend:
- '.github/actions/yarn-nm-install/*.yml'
- '.github/workflows/**'
Expand All @@ -15,6 +16,7 @@ frontend:
- 'packages/**/admin/ee/admin/**'
- 'packages/**/strapi-admin.js'
- 'packages/admin-test-utils/**'
- 'yarn.lock'
api:
- 'tests/api/**'
e2e:
Expand Down
16 changes: 8 additions & 8 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4584,10 +4584,10 @@ __metadata:
languageName: node
linkType: hard

"cookie@npm:0.6.0":
version: 0.6.0
resolution: "cookie@npm:0.6.0"
checksum: 10c0/f2318b31af7a31b4ddb4a678d024514df5e705f9be5909a192d7f116cfb6d45cbacf96a473fa733faa95050e7cff26e7832bb3ef94751592f1387b71c8956686
"cookie@npm:0.7.1":
version: 0.7.1
resolution: "cookie@npm:0.7.1"
checksum: 10c0/5de60c67a410e7c8dc8a46a4b72eb0fe925871d057c9a5d2c0e8145c4270a4f81076de83410c4d397179744b478e33cd80ccbcc457abf40a9409ad27dcd21dde
languageName: node
linkType: hard

Expand Down Expand Up @@ -6071,15 +6071,15 @@ __metadata:
linkType: hard

"express@npm:^4.17.3":
version: 4.21.0
resolution: "express@npm:4.21.0"
version: 4.21.1
resolution: "express@npm:4.21.1"
dependencies:
accepts: "npm:~1.3.8"
array-flatten: "npm:1.1.1"
body-parser: "npm:1.20.3"
content-disposition: "npm:0.5.4"
content-type: "npm:~1.0.4"
cookie: "npm:0.6.0"
cookie: "npm:0.7.1"
cookie-signature: "npm:1.0.6"
debug: "npm:2.6.9"
depd: "npm:2.0.0"
Expand All @@ -6105,7 +6105,7 @@ __metadata:
type-is: "npm:~1.6.18"
utils-merge: "npm:1.0.1"
vary: "npm:~1.1.2"
checksum: 10c0/4cf7ca328f3fdeb720f30ccb2ea7708bfa7d345f9cc460b64a82bf1b2c91e5b5852ba15a9a11b2a165d6089acf83457fc477dc904d59cd71ed34c7a91762c6cc
checksum: 10c0/0c287867e5f6129d3def1edd9b63103a53c40d4dc8628839d4b6827e35eb8f0de5a4656f9d85f4457eba584f9871ebb2ad26c750b36bd75d9bbb8bcebdc4892c
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"lint-staged": "15.2.10",
"lodash": "4.17.21",
"nx": "18.2.2",
"plop": "2.7.6",
"plop": "4.0.1",
"prettier": "3.3.3",
"prettier-2": "npm:prettier@^2",
"qs": "6.11.1",
Expand Down
1 change: 1 addition & 0 deletions packages/core/admin/admin/src/features/Tracking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ interface EventWithoutProperties {
| 'willSaveComponent'
| 'willSaveContentType'
| 'willSaveContentTypeLayout'
| 'willOpenPreview'
| 'didEditFieldNameOnContentType'
| 'didCreateRelease';
properties?: never;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { useClipboard, useNotification } from '@strapi/admin/strapi-admin';
import { useClipboard, useNotification, useTracking } from '@strapi/admin/strapi-admin';
import { Button, Flex, IconButton } from '@strapi/design-system';
import { Link as LinkIcon } from '@strapi/icons';
import { UID } from '@strapi/types';
Expand All @@ -15,6 +15,7 @@ const PreviewSidePanel: PanelComponent = ({ model, documentId, document }) => {
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const { copy } = useClipboard();
const { trackUsage } = useTracking();
const { data, error } = useGetPreviewUrlQuery({
params: {
contentType: model as UID.ContentType,
Expand Down Expand Up @@ -43,11 +44,22 @@ const PreviewSidePanel: PanelComponent = ({ model, documentId, document }) => {
});
};

const handleClick = () => {
trackUsage('willOpenPreview');
};

return {
title: formatMessage({ id: 'content-manager.preview.panel.title', defaultMessage: 'Preview' }),
content: (
<Flex gap={2} width="100%">
<Button variant="tertiary" tag={Link} to={url} target="_blank" flex="auto">
<Button
variant="tertiary"
tag={Link}
to={url}
onClick={handleClick}
target="_blank"
flex="auto"
>
{formatMessage({
id: 'content-manager.preview.panel.button',
defaultMessage: 'Open preview',
Expand Down
21 changes: 21 additions & 0 deletions packages/core/types/src/schema/attribute/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ export interface Attribute<TKind extends Kind = Kind> {
* Meaning that, if it's set to 'true', the attribute would be considered while performing a search operation.
*/
searchable?: boolean;

/**
* Database validations and settings
* https://docs.strapi.io/dev-docs/backend-customization/models#database-validations-and-settings
*
* @experimental
* @deprecated The column property is experimental and can be deprecated/changed at any time in the future.
*/
column?: Partial<Column>;
}

// NOTE: Copied directly from @strapi/database package
export interface Column {
type?: string;
name?: string;
args?: unknown[];
defaultTo?: unknown;
notNullable?: boolean;
unsigned?: boolean;
unique?: boolean;
primary?: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"copyfiles": "2.4.1",
"fs-extra": "11.2.0",
"node-plop": "0.26.3",
"plop": "2.7.6",
"plop": "4.0.1",
"pluralize": "8.0.0"
},
"devDependencies": {
Expand Down
24 changes: 15 additions & 9 deletions packages/generators/generators/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { join } from 'node:path';
import { Plop, run } from 'plop';
import nodePlop from 'node-plop';

// Starts the Plop CLI programmatically
export const runCLI = () => {
Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, (env) => {
const options = { ...env, dest: join(process.cwd(), 'src') };
run(options, undefined, true);
});
export const runCLI = async () => {
const { Plop, run } = await import('plop');

Plop.prepare(
{
configPath: join(__dirname, 'plopfile.js'),
},
(env) => {
const argv = process.argv.slice(2); // Extract command-line arguments
Plop.execute(env, argv, (env, argv) => run(env, argv, true)); // Pass the third argument 'true' for passArgsBeforeDashes
}
);
};

// Runs a generator programmatically without prompts
export const generate = async (
export const generate = async <T extends Record<string, any>>(
generatorName: string,
options: unknown,
options: T,
{ dir = process.cwd(), plopFile = 'plopfile.js' } = {}
) => {
const plop = nodePlop(join(__dirname, plopFile), {
Expand All @@ -22,7 +28,7 @@ export const generate = async (
});

const generator = plop.getGenerator(generatorName);
await generator.runActions(options, {
await generator.runActions(options satisfies T, {
onSuccess() {},
onFailure() {},
onComment() {},
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plopfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pluralize from 'pluralize';
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';

import generateApi from './plops/api';
import generateController from './plops/controller';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path';
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import fs from 'fs-extra';
import tsUtils from '@strapi/typescript-utils';

Expand Down
3 changes: 2 additions & 1 deletion packages/generators/generators/src/plops/content-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path';
import { NodePlopAPI, ActionType } from 'plop';
import type { NodePlopAPI, ActionType } from 'plop';
import slugify from '@sindresorhus/slugify';
import fs from 'fs-extra';
import { strings } from '@strapi/utils';
Expand All @@ -18,6 +18,7 @@ export default (plop: NodePlopAPI) => {
description: 'Generate a content type for an API',
async prompts(inquirer) {
const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);
// @ts-expect-error issue with deprecated inquirer.prompts attribute to fix with ugprade to inquirer
const attributes = await getAttributesPrompts(inquirer);

const api = await inquirer.prompt([
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/migration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';
import validateFileNameInput from './utils/validate-file-name-input';
import getFormattedDate from './utils/get-formatted-date';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/policy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/typescript/lib/generators/common/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = {
},

generateImportDefinition() {
const formattedImports = imports.map((key) =>
factory.createImportSpecifier(false, undefined, factory.createIdentifier(key))
);
const formattedImports = imports
.sort()
.map((key) => factory.createImportSpecifier(false, undefined, factory.createIdentifier(key)));

return [
factory.createImportDeclaration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ const { addImport } = require('../imports');
const generateAttributePropertySignature = (schema) => {
const { attributes } = schema;

const properties = Object.entries(attributes).map(([attributeName, attribute]) => {
return attributeToPropertySignature(schema, attributeName, attribute);
});
const properties = Object.entries(attributes)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([attributeName, attribute]) => {
return attributeToPropertySignature(schema, attributeName, attribute);
});

return factory.createPropertySignature(
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const toTypeLiteral = (data) => {
throw new Error(`Cannot convert to object literal. Unknown type "${typeof data}"`);
}

const entries = Object.entries(data);
const entries = Object.entries(data).sort((a, b) => a[0].localeCompare(b[0]));

const props = entries.reduce((acc, [key, value]) => {
// Handle keys such as content-type-builder & co.
Expand Down
13 changes: 9 additions & 4 deletions packages/utils/typescript/lib/generators/components/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { factory } = require('typescript');
const { pipe, values, sortBy, map } = require('lodash/fp');

const { models } = require('../common');
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
Expand All @@ -23,10 +24,14 @@ const generateComponentsDefinitions = async (options = {}) => {

const { components } = strapi;

const componentsDefinitions = Object.values(components).map((contentType) => ({
uid: contentType.uid,
definition: models.schema.generateSchemaDefinition(contentType),
}));
const componentsDefinitions = pipe(
values,
sortBy('uid'),
map((component) => ({
uid: component.uid,
definition: models.schema.generateSchemaDefinition(component),
}))
)(components);

options.logger.debug(`Found ${componentsDefinitions.length} components.`);

Expand Down
13 changes: 9 additions & 4 deletions packages/utils/typescript/lib/generators/content-types/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { factory } = require('typescript');
const { values, pipe, map, sortBy } = require('lodash/fp');

const { models } = require('../common');
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
Expand All @@ -23,10 +24,14 @@ const generateContentTypesDefinitions = async (options = {}) => {

const { contentTypes } = strapi;

const contentTypesDefinitions = Object.values(contentTypes).map((contentType) => ({
uid: contentType.uid,
definition: models.schema.generateSchemaDefinition(contentType),
}));
const contentTypesDefinitions = pipe(
values,
sortBy('uid'),
map((contentType) => ({
uid: contentType.uid,
definition: models.schema.generateSchemaDefinition(contentType),
}))
)(contentTypes);

options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);

Expand Down
16 changes: 8 additions & 8 deletions templates/website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6444,10 +6444,10 @@ __metadata:
languageName: node
linkType: hard

"cookie@npm:0.6.0":
version: 0.6.0
resolution: "cookie@npm:0.6.0"
checksum: 10c0/f2318b31af7a31b4ddb4a678d024514df5e705f9be5909a192d7f116cfb6d45cbacf96a473fa733faa95050e7cff26e7832bb3ef94751592f1387b71c8956686
"cookie@npm:0.7.1":
version: 0.7.1
resolution: "cookie@npm:0.7.1"
checksum: 10c0/5de60c67a410e7c8dc8a46a4b72eb0fe925871d057c9a5d2c0e8145c4270a4f81076de83410c4d397179744b478e33cd80ccbcc457abf40a9409ad27dcd21dde
languageName: node
linkType: hard

Expand Down Expand Up @@ -7903,15 +7903,15 @@ __metadata:
linkType: hard

"express@npm:^4.17.1":
version: 4.21.0
resolution: "express@npm:4.21.0"
version: 4.21.1
resolution: "express@npm:4.21.1"
dependencies:
accepts: "npm:~1.3.8"
array-flatten: "npm:1.1.1"
body-parser: "npm:1.20.3"
content-disposition: "npm:0.5.4"
content-type: "npm:~1.0.4"
cookie: "npm:0.6.0"
cookie: "npm:0.7.1"
cookie-signature: "npm:1.0.6"
debug: "npm:2.6.9"
depd: "npm:2.0.0"
Expand All @@ -7937,7 +7937,7 @@ __metadata:
type-is: "npm:~1.6.18"
utils-merge: "npm:1.0.1"
vary: "npm:~1.1.2"
checksum: 10c0/4cf7ca328f3fdeb720f30ccb2ea7708bfa7d345f9cc460b64a82bf1b2c91e5b5852ba15a9a11b2a165d6089acf83457fc477dc904d59cd71ed34c7a91762c6cc
checksum: 10c0/0c287867e5f6129d3def1edd9b63103a53c40d4dc8628839d4b6827e35eb8f0de5a4656f9d85f4457eba584f9871ebb2ad26c750b36bd75d9bbb8bcebdc4892c
languageName: node
linkType: hard

Expand Down
Loading

0 comments on commit 1308bee

Please sign in to comment.