-
Notifications
You must be signed in to change notification settings - Fork 12k
/
extract-ivy-libraries.ts
80 lines (69 loc) · 2.13 KB
/
extract-ivy-libraries.ts
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
import { getGlobalVariable } from '../../utils/env';
import { expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
import { ng, npm } from '../../utils/process';
import { expectToFail } from '../../utils/utils';
import { readNgVersion } from '../../utils/version';
export default async function() {
// Ivy only test
if (getGlobalVariable('argv')['ve']) {
return;
}
// Setup a library
await ng('generate', 'library', 'i18n-lib-test');
await replaceInFile(
'projects/i18n-lib-test/src/lib/i18n-lib-test.component.ts',
'<p>',
'<p i18n>',
);
// Build library
await ng('build', 'i18n-lib-test');
// Consume library in application
await writeFile(
'src/app/app.module.ts',
`
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { I18nLibTestModule } from 'i18n-lib-test';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
I18nLibTestModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`,
);
await writeFile(
'src/app/app.component.html',
`
<p i18n>Hello world</p>
<lib-i18n-lib-test></lib-i18n-lib-test>
`,
);
// Install correct version
let localizeVersion = '@angular/localize@' + readNgVersion();
if (getGlobalVariable('argv')['ng-snapshots']) {
localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize'];
}
await npm('install', `${localizeVersion}`);
// Extract messages
await ng('xi18n', '--ivy');
await expectFileToMatch('messages.xlf', 'Hello world');
await expectFileToMatch('messages.xlf', 'i18n-lib-test works!');
await npm('uninstall', '@angular/localize');
// TODO: Investigate failures on Windows and remove this check
if (process.platform === 'win32') {
return;
}
await expectFileToMatch('messages.xlf', 'src/app/app.component.html');
await expectFileToMatch(
'messages.xlf',
`projects/i18n-lib-test/src/lib/i18n-lib-test.component.ts`,
);
}