-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathbuild.ts
More file actions
90 lines (74 loc) · 2.5 KB
/
build.ts
File metadata and controls
90 lines (74 loc) · 2.5 KB
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
import path from 'path';
import execa from 'execa';
import { CliBuildOptions, Config } from '../types';
import { Logger } from '../logger';
import { getConfig } from './config';
export const ENTRY_FILE =
'./node_modules/react-native-owl/dist/client/index.app.js';
export const buildIOS = async (
config: Config,
logger: Logger
): Promise<void> => {
const buildCommand = config.ios?.buildCommand
? [config.ios?.buildCommand]
: [
`env OWL_BUILD=1 xcodebuild`,
`-workspace ${config.ios?.workspace}`,
`-scheme ${config.ios?.scheme?.split(' ').join('\\ ')}`,
`-configuration ${config.ios?.configuration}`,
`-sdk iphonesimulator`,
`-derivedDataPath ios/build`,
];
if (!config.ios?.buildCommand && config.ios?.quiet) {
buildCommand.push('-quiet');
}
logger.info(`[OWL - CLI] Building the app with: ${buildCommand.join(' ')}.`);
await execa.command(buildCommand.join(' '), {
stdio: 'inherit',
env: {
ENTRY_FILE,
},
});
};
export const buildAndroid = async (
config: Config,
logger: Logger
): Promise<void> => {
const buildCommand = config.android?.buildCommand
? [config.android?.buildCommand]
: [
`./gradlew`,
config.android?.buildType === 'Debug'
? `assembleDebug`
: 'assembleRelease',
'--console plain',
];
if (!config.android?.buildCommand && config.android?.quiet) {
buildCommand.push('--quiet');
}
// Add a project environmental to tell build.gradle to use a specific Android Manifest that allows WebSocket usage.
// (https://docs.gradle.org/current/userguide/command_line_interface.html#sec:environment_options)
buildCommand.push('-PisOwlBuild=true');
const cwd = config.android?.buildCommand
? undefined
: path.join(process.cwd(), 'android');
logger.info(`[OWL - CLI] Building the app with: ${buildCommand.join(' ')}.`);
await execa.command(buildCommand.join(' '), {
stdio: 'inherit',
cwd,
env: {
ENTRY_FILE,
},
});
};
export const buildHandler = async (args: CliBuildOptions) => {
const config = await getConfig(args.config);
const logger = new Logger(config.debug);
const buildProject = args.platform === 'ios' ? buildIOS : buildAndroid;
logger.print(`[OWL - CLI] Building the app on ${args.platform} platform.`);
logger.info(`[OWL - CLI] Using the config file ${args.config}.`);
await buildProject(config, logger);
logger.info(
`[OWL - CLI] Successfully built for the ${args.platform} platform.`
);
};