Skip to content

Commit 893e936

Browse files
fix: no longer copy build-functions script, copy build script from example package [EXT-6084] (#2267)
fix: lint chore: comment change
1 parent 14a49c8 commit 893e936

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { rename } from 'fs/promises';
21
import { resolve, join } from 'path';
32
import { CONTENTFUL_APP_MANIFEST, IGNORED_CLONED_FILES } from './constants';
43
import tiged from 'tiged';
54
import { highlight } from './logger';
65
import { exists, mergeJsonIntoFile } from './utils/file';
76
import { getAddBuildCommandFn } from './utils/package';
87

8+
// TODO: after appActions work we can change this getAddBuildCommandFn params from command -> defaultCommand as examples will have build commands
99
const addBuildCommand = getAddBuildCommandFn({
1010
name: 'build:functions',
11-
command: 'node build-functions.js',
11+
command: 'contentful-app-scripts build-functions --ci',
1212
});
1313

1414
const VALID_FUNCTION_TEMPLATES_DIRS = [
@@ -57,12 +57,6 @@ export async function cloneFunction(
5757
destination: `${destination}/${CONTENTFUL_APP_MANIFEST}`,
5858
});
5959

60-
// move the build file from the actions folder to the root folder
61-
const copyBuildFile = rename(
62-
`${functionDirectoryPath}/build-functions.js`,
63-
`${destination}/build-functions.js`
64-
);
65-
6660
// modify package.json build commands
6761
const packageJsonLocation = resolve(`${destination}/package.json`);
6862
const packageJsonExists = await exists(packageJsonLocation);
@@ -80,7 +74,7 @@ export async function cloneFunction(
8074
mergeFn: addBuildCommand,
8175
});
8276

83-
await Promise.all([writeAppManifest, copyBuildFile, writeBuildCommand]);
77+
await Promise.all([writeAppManifest, writeBuildCommand]);
8478

8579
await d.remove(functionDirectoryPath, destination, {
8680
action: 'remove',

packages/contentful--create-contentful-app/src/utils/package.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ export function getAddBuildCommandFn({ name, command }: BuildCommandOptions) {
1010
packageJson?: Record<string, any>,
1111
additionalProperties?: Record<string, any>,
1212
): Record<string, any> => {
13-
let buildCommand = packageJson?.scripts?.build ?? '';
13+
let destBuildCommand = packageJson?.scripts?.build ?? '';
14+
const sourceBuildCommand = additionalProperties?.scripts?.build ?? command;
1415
const triggerCommand = `npm run ${name}`;
1516

16-
if (buildCommand === '') {
17-
buildCommand = triggerCommand;
18-
} else if (!buildCommand.split(/\s*&+\s*/).includes(triggerCommand)) {
19-
buildCommand += ` && ${triggerCommand}`;
17+
if (destBuildCommand === '') {
18+
destBuildCommand = triggerCommand;
19+
} else if (!destBuildCommand.split(/\s*&+\s*/).includes(triggerCommand)) {
20+
destBuildCommand += ` && ${triggerCommand}`;
2021
}
2122

2223
return mergeOptions({}, packageJson, additionalProperties, {
23-
scripts: { [name]: command, build: buildCommand },
24+
scripts: { [name]: sourceBuildCommand, build: destBuildCommand },
2425
});
2526
};
2627
}

0 commit comments

Comments
 (0)