Skip to content

Commit 297e47a

Browse files
fix: Clone functions through function-examples [EXT-6257] (#2370)
* fix: Including function uses app-scripts generate-function * fix: merge conflicts * fix: Remove dashes from function name when cloning * chore: prettier * chore: remove console log
1 parent d382727 commit 297e47a

File tree

7 files changed

+26
-148
lines changed

7 files changed

+26
-148
lines changed

packages/contentful--create-contentful-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"create-contentful-app": "lib/index.js"
2929
},
3030
"scripts": {
31-
"prettier": "prettier **/*.js --write --ignore-path .gitignore",
31+
"prettier": "prettier **/*.ts --write --ignore-path .gitignore",
3232
"lint": "eslint ./src",
3333
"lint:fix": "npm run lint -- --fix",
3434
"pre-commit": "lint-staged",

packages/contentful--create-contentful-app/src/getTemplateSource.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ async function promptExampleSelection(): Promise<string> {
4545
// get available templates from examples
4646
const availableTemplates = await getGithubFolderNames();
4747
// filter out the ignored ones that are listed as templates instead of examples
48-
const filteredTemplates = availableTemplates.filter(
49-
(template) =>
50-
!IGNORED_EXAMPLE_FOLDERS.includes(template as (typeof IGNORED_EXAMPLE_FOLDERS)[number])
51-
);
48+
const filteredTemplates = availableTemplates
49+
.filter(
50+
(template) =>
51+
!IGNORED_EXAMPLE_FOLDERS.includes(template as (typeof IGNORED_EXAMPLE_FOLDERS)[number])
52+
)
53+
.filter((template) => !template.includes('function'));
5254
console.log(availableTemplates.length, filteredTemplates.length);
5355

5456
// ask user to select a template from the available examples

packages/contentful--create-contentful-app/src/includeFunction.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/contentful--create-contentful-app/src/index.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import chalk from 'chalk';
1414
import { CREATE_APP_DEFINITION_GUIDE_URL, EXAMPLES_REPO_URL } from './constants';
1515
import { getTemplateSource } from './getTemplateSource';
1616
import { track } from './analytics';
17-
import { cloneFunction } from './includeFunction';
17+
import { generateFunction } from '@contentful/app-scripts';
1818

1919
const DEFAULT_APP_NAME = 'contentful-app';
2020

@@ -130,12 +130,23 @@ async function initProject(appName: string, options: CLIOptions) {
130130
if (normalizedOptions.function === true) {
131131
normalizedOptions.function = 'external-references';
132132
}
133-
134-
await cloneFunction(
135-
fullAppFolder,
136-
!!normalizedOptions.javascript,
137-
normalizedOptions.function
138-
);
133+
process.chdir(fullAppFolder);
134+
`To add additional function templates to your app, use ${highlight(
135+
chalk.green(`
136+
npx @contentful/app-scripts@latest generate-function \\
137+
--ci \\
138+
--name <name> \\
139+
--example <example> \\
140+
--language <typescript/javascript>`)
141+
)}`;
142+
const functionName = normalizedOptions.function
143+
.toLowerCase()
144+
.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
145+
await generateFunction.nonInteractive({
146+
example: normalizedOptions.function,
147+
language: 'typescript',
148+
name: functionName,
149+
});
139150
}
140151

141152
updatePackageName(fullAppFolder);

packages/contentful--create-contentful-app/test/includeFunction.spec.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

packages/contentful--create-contentful-app/typings/contentful--app-scripts.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare module 'tiged';
1+
declare module 'tiged';

0 commit comments

Comments
 (0)