-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathjust-task.js
More file actions
51 lines (43 loc) · 1.46 KB
/
just-task.js
File metadata and controls
51 lines (43 loc) · 1.46 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
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
* @format
* @ts-check
*/
const {task, series} = require('just-scripts');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
// Use the shared base configuration
require('@rnw-scripts/just-task');
// The TS build process will strip all the types from the NativeComponent spec file. Which means that the codegen babel will not correctly generate the JS view config for the component.
// So here we manually run babel, overwriting the tsc output, so that we ship the generated code.
task('codegenNativeComponents', () => {
const babel = require('@babel/core');
const matches = glob.sync('src/**/*NativeComponent.ts');
matches.forEach(matchedPath => {
const relativePath = path.relative(
path.resolve(process.cwd(), 'src'),
matchedPath,
);
const code = fs.readFileSync(matchedPath).toString();
const filename = path.resolve(process.cwd(), matchedPath);
const res = babel.transformSync(code, {
ast: false,
filename,
cwd: process.cwd(),
sourceRoot: process.cwd(),
root: process.cwd(),
babelrc: true,
});
const relativeOutputPath = relativePath.replace(/\.ts$/, '.js');
fs.writeFileSync(
path.resolve(process.cwd(), 'lib-commonjs', relativeOutputPath),
res?.code,
);
});
});
task(
'buildWithCodegetNativeComponents',
series('build', 'codegenNativeComponents'),
);