Skip to content

Commit 8706ecf

Browse files
authored
chore(): React Build Scripts (ionic-team#19501)
1 parent aed2dba commit 8706ecf

26 files changed

+1624
-1268
lines changed

.circleci/config.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,58 @@ jobs:
108108
paths:
109109
- "*"
110110

111+
build-react:
112+
<<: *defaults
113+
steps:
114+
- checkout
115+
- attach_workspace:
116+
at: /tmp/workspace
117+
- run:
118+
command: npm install
119+
working_directory: /tmp/workspace/packages/react
120+
- run:
121+
command: sudo npm link
122+
working_directory: /tmp/workspace/core
123+
- run:
124+
command: sudo npm link @ionic/core
125+
working_directory: /tmp/workspace/packages/react
126+
- run:
127+
command: npm run build
128+
working_directory: /tmp/workspace/packages/react
129+
- persist_to_workspace:
130+
root: /tmp/workspace
131+
paths:
132+
- "*"
133+
134+
build-react-router:
135+
<<: *defaults
136+
steps:
137+
- checkout
138+
- attach_workspace:
139+
at: /tmp/workspace
140+
- run:
141+
command: npm install
142+
working_directory: /tmp/workspace/packages/react-router
143+
- run:
144+
command: sudo npm link
145+
working_directory: /tmp/workspace/core
146+
- run:
147+
command: sudo npm link @ionic/core
148+
working_directory: /tmp/workspace/packages/react-router
149+
- run:
150+
command: sudo npm link
151+
working_directory: /tmp/workspace/packages/react
152+
- run:
153+
command: sudo npm link @ionic/react
154+
working_directory: /tmp/workspace/packages/react-router
155+
- run:
156+
command: npm run build
157+
working_directory: /tmp/workspace/packages/react-router
158+
- persist_to_workspace:
159+
root: /tmp/workspace
160+
paths:
161+
- "*"
162+
111163
test-core-clean-build:
112164
<<: *defaults
113165
steps:
@@ -181,6 +233,64 @@ jobs:
181233
command: npm run lint
182234
working_directory: /tmp/workspace/angular
183235

236+
test-react-lint:
237+
<<: *defaults
238+
steps:
239+
- checkout
240+
- attach_workspace:
241+
at: /tmp/workspace
242+
- run:
243+
command: npm run lint
244+
working_directory: /tmp/workspace/packages/react
245+
246+
test-react-router-lint:
247+
<<: *defaults
248+
steps:
249+
- checkout
250+
- attach_workspace:
251+
at: /tmp/workspace
252+
- run:
253+
command: npm run lint
254+
working_directory: /tmp/workspace/packages/react-router
255+
256+
test-react-spec:
257+
<<: *defaults
258+
steps:
259+
- checkout
260+
- attach_workspace:
261+
at: /tmp/workspace
262+
- run:
263+
command: sudo npm link
264+
working_directory: /tmp/workspace/core
265+
- run:
266+
command: sudo npm link @ionic/core
267+
working_directory: /tmp/workspace/packages/react
268+
- run:
269+
command: npm run test.spec
270+
working_directory: /tmp/workspace/packages/react
271+
272+
test-react-router-spec:
273+
<<: *defaults
274+
steps:
275+
- checkout
276+
- attach_workspace:
277+
at: /tmp/workspace
278+
- run:
279+
command: sudo npm link
280+
working_directory: /tmp/workspace/core
281+
- run:
282+
command: sudo npm link @ionic/core
283+
working_directory: /tmp/workspace/packages/react
284+
- run:
285+
command: sudo npm link
286+
working_directory: /tmp/workspace/packages/react
287+
- run:
288+
command: sudo npm link @ionic/react
289+
working_directory: /tmp/workspace/packages/react-router
290+
- run:
291+
command: npm run test.spec
292+
working_directory: /tmp/workspace/packages/react-router
293+
184294
test-angular-e2e:
185295
<<: *defaults
186296
steps:
@@ -227,6 +337,18 @@ workflows:
227337
requires: [build-core]
228338
- build-angular-server:
229339
requires: [build-angular]
340+
- build-react:
341+
requires: [build-core]
342+
- build-react-router:
343+
requires: [build-core, build-react]
344+
- test-react-lint:
345+
requires: [build-react]
346+
- test-react-router-lint:
347+
requires: [build-react-router]
348+
- test-react-spec:
349+
requires: [build-react]
350+
- test-react-router-spec:
351+
requires: [build-react-router]
230352
- test-angular-lint:
231353
requires: [build-angular]
232354
- test-angular-e2e:

.scripts/common.js

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const packages = [
1111
'core',
1212
'docs',
1313
'angular',
14+
'packages/react',
15+
'packages/react-router'
1416
];
1517

1618
function readPkg(project) {
@@ -36,33 +38,47 @@ function checkGit(tasks) {
3638
tasks.push(
3739
{
3840
title: 'Check current branch',
39-
task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
40-
if (branch.indexOf('release') === -1 && branch.indexOf('hotfix') === -1) {
41-
throw new Error(`Must be on a "release" or "hotfix" branch.`);
42-
}
43-
})
41+
task: () =>
42+
execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
43+
if (branch.indexOf('release') === -1 && branch.indexOf('hotfix') === -1) {
44+
throw new Error(`Must be on a "release" or "hotfix" branch.`);
45+
}
46+
})
4447
},
4548
{
4649
title: 'Check local working tree',
47-
task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
48-
if (status !== '') {
49-
throw new Error(`Unclean working tree. Commit or stash changes first.`);
50-
}
51-
})
50+
task: () =>
51+
execa.stdout('git', ['status', '--porcelain']).then(status => {
52+
if (status !== '') {
53+
throw new Error(`Unclean working tree. Commit or stash changes first.`);
54+
}
55+
})
5256
},
5357
{
5458
title: 'Check remote history',
55-
task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
56-
if (result !== '0') {
57-
throw new Error(`Remote history differs. Please pull changes.`);
58-
}
59-
})
59+
task: () =>
60+
execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
61+
if (result !== '0') {
62+
throw new Error(`Remote history differs. Please pull changes.`);
63+
}
64+
})
6065
}
6166
);
6267
}
6368

64-
const isValidVersion = input => Boolean(semver.valid(input));
69+
function checkTestDist(tasks) {
70+
tasks.push({
71+
title: 'Check dist folders for required files',
72+
task: () =>
73+
execa.stdout('node', ['.scripts/test-dist.js']).then(status => {
74+
if (status.indexOf('✅ test.dist') === -1) {
75+
throw new Error(`Test Dist did not find some required files`);
76+
}
77+
})
78+
});
79+
}
6580

81+
const isValidVersion = input => Boolean(semver.valid(input));
6682

6783
function preparePackage(tasks, package, version, install) {
6884
const projectRoot = projectPath(package);
@@ -74,15 +90,17 @@ function preparePackage(tasks, package, version, install) {
7490
title: `${pkg.name}: validate new version`,
7591
task: () => {
7692
if (!isVersionGreater(pkg.version, version)) {
77-
throw new Error(`New version \`${version}\` should be higher than current version \`${pkg.version}\``);
93+
throw new Error(
94+
`New version \`${version}\` should be higher than current version \`${pkg.version}\``
95+
);
7896
}
7997
}
8098
});
8199
if (install) {
82100
projectTasks.push({
83101
title: `${pkg.name}: install npm dependencies`,
84102
task: async () => {
85-
await fs.remove(path.join(projectRoot, 'node_modules'))
103+
await fs.remove(path.join(projectRoot, 'node_modules'));
86104
await execa('npm', ['i'], { cwd: projectRoot });
87105
}
88106
});
@@ -95,6 +113,13 @@ function preparePackage(tasks, package, version, install) {
95113
title: `${pkg.name}: npm link @ionic/core`,
96114
task: () => execa('npm', ['link', '@ionic/core'], { cwd: projectRoot })
97115
});
116+
117+
if (package === 'packages/react-router') {
118+
projectTasks.push({
119+
title: `${pkg.name}: npm link @ionic/react`,
120+
task: () => execa('npm', ['link', '@ionic/react'], { cwd: projectRoot })
121+
});
122+
}
98123
}
99124

100125
if (version) {
@@ -105,7 +130,7 @@ function preparePackage(tasks, package, version, install) {
105130
projectTasks.push({
106131
title: `${pkg.name}: update ionic/core dep to ${version}`,
107132
task: () => {
108-
updateDependency(pkg, "@ionic/core", version);
133+
updateDependency(pkg, '@ionic/core', version);
109134
writePkg(package, pkg);
110135
}
111136
});
@@ -134,7 +159,6 @@ function preparePackage(tasks, package, version, install) {
134159
});
135160
}
136161

137-
138162
function prepareDevPackage(tasks, package, version) {
139163
const projectRoot = projectPath(package);
140164
const pkg = readPkg(package);
@@ -152,7 +176,7 @@ function prepareDevPackage(tasks, package, version) {
152176
projectTasks.push({
153177
title: `${pkg.name}: update ionic/core dep to ${version}`,
154178
task: () => {
155-
updateDependency(pkg, "@ionic/core", version);
179+
updateDependency(pkg, '@ionic/core', version);
156180
writePkg(package, pkg);
157181
}
158182
});
@@ -181,33 +205,38 @@ function updatePackageVersions(tasks, packages, version) {
181205
packages.forEach(package => {
182206
updatePackageVersion(tasks, package, version);
183207

184-
tasks.push(
185-
{
186-
title: `${package} update @ionic/core dependency, if present ${tc.dim(`(${version})`)}`,
187-
task: async () => {
188-
if (package !== 'core') {
189-
const pkg = readPkg(package);
190-
updateDependency(pkg, '@ionic/core', version);
191-
writePkg(package, pkg);
192-
}
193-
},
208+
tasks.push({
209+
title: `${package} update @ionic/core dependency, if present ${tc.dim(`(${version})`)}`,
210+
task: async () => {
211+
if (package !== 'core') {
212+
const pkg = readPkg(package);
213+
updateDependency(pkg, '@ionic/core', version);
214+
writePkg(package, pkg);
215+
}
194216
}
195-
)
217+
});
218+
if (package === 'packages/react-router') {
219+
tasks.push({
220+
title: `${package} update @ionic/react dependency, if present ${tc.dim(`(${version})`)}`,
221+
task: async () => {
222+
const pkg = readPkg(package);
223+
updateDependency(pkg, '@ionic/react', version);
224+
writePkg(package, pkg);
225+
}
226+
});
227+
}
196228
});
197229
}
198230

199-
200231
function updatePackageVersion(tasks, package, version) {
201232
const projectRoot = projectPath(package);
202233

203-
tasks.push(
204-
{
205-
title: `${package}: update package.json ${tc.dim(`(${version})`)}`,
206-
task: async () => {
207-
await execa('npm', ['version', version], { cwd: projectRoot });
208-
}
234+
tasks.push({
235+
title: `${package}: update package.json ${tc.dim(`(${version})`)}`,
236+
task: async () => {
237+
await execa('npm', ['version', version], { cwd: projectRoot });
209238
}
210-
);
239+
});
211240
}
212241

213242
function publishPackages(tasks, packages, version, tag = 'latest') {
@@ -237,7 +266,7 @@ function publishPackages(tasks, packages, version, tag = 'latest') {
237266
title: `${package}: publish to ${tag} tag`,
238267
task: async () => {
239268
await execa('npm', ['publish', '--tag', tag], { cwd: projectRoot });
240-
},
269+
}
241270
});
242271
});
243272
}
@@ -261,11 +290,12 @@ function isVersionGreater(oldVersion, newVersion) {
261290
function copyCDNLoader(tasks, version) {
262291
tasks.push({
263292
title: `Copy CDN loader`,
264-
task: () => execa('node', ['copy-cdn-loader.js', version], { cwd: path.join(rootDir, 'core', 'scripts') }),
293+
task: () => execa('node', ['copy-cdn-loader.js', version], { cwd: path.join(rootDir, 'core', 'scripts') })
265294
});
266295
}
267296

268297
module.exports = {
298+
checkTestDist,
269299
checkGit,
270300
isValidVersion,
271301
isVersionGreater,
@@ -281,5 +311,5 @@ module.exports = {
281311
updateDependency,
282312
updatePackageVersion,
283313
updatePackageVersions,
284-
writePkg,
314+
writePkg
285315
};

.scripts/prepare.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,14 @@ async function preparePackages(packages, version, install) {
107107
});
108108

109109
// add update package.json of each project
110-
packages.forEach(package => {
111-
common.updatePackageVersion(tasks, package, version);
112-
});
110+
common.updatePackageVersions(tasks, packages, version);
113111

114112
// generate changelog
115113
generateChangeLog(tasks);
116114

115+
// check dist folders
116+
common.checkTestDist(tasks);
117+
117118
// update core readme with version number
118119
updateCoreReadme(tasks, version);
119120
common.copyCDNLoader(tasks, version);

0 commit comments

Comments
 (0)