Skip to content

Commit 4fd1bdd

Browse files
committed
add admin section to the hosted app specification
1 parent d296cb0 commit 4fd1bdd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ vi.mock('@shopify/cli-kit/node/fs')
77

88
describe('hosted_app_home', () => {
99
describe('transform', () => {
10-
test('should return the transformed object with static_root', () => {
10+
test('should return the transformed object with static_root (local admin subsection to flat remote)', () => {
1111
const object = {
12-
static_root: 'public',
12+
admin: {static_root: 'public'},
1313
}
1414
const appConfigSpec = spec
1515

@@ -20,7 +20,7 @@ describe('hosted_app_home', () => {
2020
})
2121
})
2222

23-
test('should return empty object when static_root is not provided', () => {
23+
test('should return empty object when admin.static_root is not provided', () => {
2424
const object = {}
2525
const appConfigSpec = spec
2626

@@ -31,7 +31,7 @@ describe('hosted_app_home', () => {
3131
})
3232

3333
describe('reverseTransform', () => {
34-
test('should return the reversed transformed object with static_root', () => {
34+
test('should return the reversed transformed object (flat remote to local admin subsection)', () => {
3535
const object = {
3636
static_root: 'public',
3737
}
@@ -40,7 +40,7 @@ describe('hosted_app_home', () => {
4040
const result = appConfigSpec.transformRemoteToLocal!(object)
4141

4242
expect(result).toMatchObject({
43-
static_root: 'public',
43+
admin: {static_root: 'public'},
4444
})
4545
})
4646

@@ -57,7 +57,7 @@ describe('hosted_app_home', () => {
5757
describe('copyStaticAssets', () => {
5858
test('should copy static assets from source to output directory', async () => {
5959
vi.mocked(copyDirectoryContents).mockResolvedValue(undefined)
60-
const config = {static_root: 'public'}
60+
const config = {admin: {static_root: 'public'}}
6161
const directory = '/app/root'
6262
const outputPath = '/output/dist/bundle.js'
6363

@@ -66,7 +66,7 @@ describe('hosted_app_home', () => {
6666
expect(copyDirectoryContents).toHaveBeenCalledWith('/app/root/public', '/output/dist')
6767
})
6868

69-
test('should not copy assets when static_root is not provided', async () => {
69+
test('should not copy assets when admin.static_root is not provided', async () => {
7070
const config = {}
7171
const directory = '/app/root'
7272
const outputPath = '/output/dist/bundle.js'
@@ -78,7 +78,7 @@ describe('hosted_app_home', () => {
7878

7979
test('should throw error when copy fails', async () => {
8080
vi.mocked(copyDirectoryContents).mockRejectedValue(new Error('Permission denied'))
81-
const config = {static_root: 'public'}
81+
const config = {admin: {static_root: 'public'}}
8282
const directory = '/app/root'
8383
const outputPath = '/output/dist/bundle.js'
8484

packages/app/src/cli/models/extensions/specifications/app_config_hosted_app_home.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ import {dirname, joinPath} from '@shopify/cli-kit/node/path'
55
import {zod} from '@shopify/cli-kit/node/schema'
66

77
const HostedAppHomeSchema = BaseSchemaWithoutHandle.extend({
8-
static_root: zod.string().optional(),
8+
admin: zod
9+
.object({
10+
static_root: zod.string().optional(),
11+
})
12+
.optional(),
913
})
1014

1115
const HostedAppHomeTransformConfig: TransformationConfig = {
12-
static_root: 'static_root',
16+
static_root: 'admin.static_root',
1317
}
1418

15-
export const HostedAppHomeSpecIdentifier = 'hosted_app_home'
19+
export const HostedAppHomeSpecIdentifier = 'admin'
1620

1721
const hostedAppHomeSpec = createConfigExtensionSpecification({
1822
identifier: HostedAppHomeSpecIdentifier,
1923
buildConfig: {mode: 'hosted_app_home'} as const,
2024
schema: HostedAppHomeSchema,
2125
transformConfig: HostedAppHomeTransformConfig,
2226
copyStaticAssets: async (config, directory, outputPath) => {
23-
if (!config.static_root) return
24-
const sourceDir = joinPath(directory, config.static_root)
27+
const staticRoot = config.admin?.static_root
28+
if (!staticRoot) return
29+
const sourceDir = joinPath(directory, staticRoot)
2530
const outputDir = dirname(outputPath)
2631

2732
return copyDirectoryContents(sourceDir, outputDir).catch((error) => {

0 commit comments

Comments
 (0)