-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpdk.config.js
95 lines (80 loc) · 2.34 KB
/
pdk.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import {spawnSync} from 'node:child_process';
import {
PdkPlatformName,
addPlatformToContext,
defineConfig,
exists,
getPlatformDistPath,
renameFile,
reportFileDoesNotExist,
resolvePath,
resolveString,
} from '@myparcel-pdk/app-builder';
const ENTRY_FILE = 'woocommerce-myparcel.php';
export default defineConfig({
name: 'woocommerce',
platforms: [PdkPlatformName.MyParcelNl, PdkPlatformName.MyParcelBe],
source: [
'!**/node_modules/**',
'views/**/dist/**/*',
'views/blocks/*/block.json',
'CONTRIBUTING.md',
'LICENSE.txt',
'README.md',
'readme.txt',
'wpm-config.json',
],
platformFolderName(platform) {
switch (platform) {
case PdkPlatformName.MyParcelNl:
return 'woocommerce-myparcel';
case PdkPlatformName.MyParcelBe:
return 'wc-myparcel-belgium';
}
return '{{name}}';
},
versionSource: [
{path: 'package.json'},
{path: 'composer.json'},
{path: ENTRY_FILE, regex: /Version:\s*(.+)/},
// TODO: Uncomment when this version is stable.
// {path: 'readme.txt', regex: /Stable tag:\s*(.+)/},
],
rootCommand: 'docker compose run --rm -T php',
translations: {
// eslint-disable-next-line no-magic-numbers
additionalSheet: 535277615,
},
hooks: {
/**
* Run the build target in all workspaces.
*/
beforeCopy() {
const buffer = spawnSync('yarn', ['nx', 'run-many', '--target=build', '--output-style=stream'], {
stdio: 'inherit',
});
if (buffer.status !== 0) {
throw new Error('Build failed.');
}
},
/**
* Rename the entry file.
*/
async afterCopy({context}) {
const {config} = context;
await Promise.all(
config.platforms.map(async(platform) => {
const platformContext = addPlatformToContext(context, platform);
const platformDistPath = getPlatformDistPath(platformContext);
const sourcePath = resolvePath([platformDistPath, ENTRY_FILE], context);
if (!await exists(sourcePath)) {
reportFileDoesNotExist(sourcePath, platformContext);
return;
}
const newFilename = `${resolveString(config.platformFolderName, platformContext)}.php`;
await renameFile(sourcePath, sourcePath.replace(ENTRY_FILE, newFilename), platformContext);
}),
);
},
},
});