Skip to content

Commit 386834e

Browse files
committed
prepare script for firestore exp release
1 parent 4b7cbe4 commit 386834e

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

packages/firestore/exp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"main": "../dist/exp/index.node.esm2017.js",
55
"browser": "../dist/exp/index.browser.esm2017.js",
66
"react-native": "../dist/exp/index.rn.esm2017.js",
7+
"typings": "../exp-types/index.d.ts",
78
"private": true
89
}

packages/firestore/lite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"main": "../dist/lite/index.node.esm2017.js",
55
"browser": "../dist/lite/index.browser.esm2017.js",
66
"react-native": "../dist/lite/index.rn.esm2017.js",
7+
"typings": "../lite-types/index.d.ts",
78
"private": true
89
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { spawn } from 'child-process-promise';
19+
import { projectRoot, readPackageJson } from '../utils';
20+
import { writeFile as _writeFile } from 'fs';
21+
import { promisify } from 'util';
22+
const writeFile = promisify(_writeFile);
23+
const packagePath = `${projectRoot}/packages/firestore`;
24+
25+
// Prepare @firebase/firestore, so scripts/exp/release.ts can be used to release it
26+
async function prepare() {
27+
// Build exp and lite packages
28+
await spawn('yarn', ['build:exp'], {
29+
cwd: packagePath,
30+
stdio: 'inherit'
31+
});
32+
33+
await spawn('yarn', ['build:lite'], {
34+
cwd: packagePath,
35+
stdio: 'inherit'
36+
});
37+
38+
// Update package.json
39+
const packageJson = await readPackageJson(packagePath);
40+
const expPackageJson = await readPackageJson(`${packageJson}/exp`);
41+
packageJson.version = '0.0.800';
42+
43+
packageJson.peerDependencies = {
44+
'@firebase/app-exp': '0.x',
45+
'@firebase/app-exp-types': '0.x'
46+
};
47+
48+
packageJson.main = expPackageJson.main.replace('../', '');
49+
packageJson.module = expPackageJson.module.replace('../', '');
50+
packageJson.browser = expPackageJson.browser.replace('../', '');
51+
packageJson['react-native'] = expPackageJson['react-native'].replace(
52+
'../',
53+
''
54+
);
55+
56+
packageJson.typing = expPackageJson.typings.replace('../', '');
57+
58+
delete packageJson.scripts.prepare;
59+
60+
// update package.json files
61+
await writeFile(
62+
`${packagePath}/package.json`,
63+
`${JSON.stringify(packageJson, null, 2)}\n`,
64+
{ encoding: 'utf-8' }
65+
);
66+
}
67+
68+
prepare();

scripts/exp/release.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717

1818
import { spawn, exec } from 'child-process-promise';
1919
import ora from 'ora';
20-
import { projectRoot } from '../utils';
20+
import { projectRoot, readPackageJson } from '../utils';
2121
import simpleGit from 'simple-git/promise';
2222

2323
import { mapWorkspaceToPackages } from '../release/utils/workspace';
2424
import { inc } from 'semver';
25-
import { readFile as _readFile, writeFile as _writeFile } from 'fs';
25+
import { writeFile as _writeFile } from 'fs';
2626
import { promisify } from 'util';
2727
import chalk from 'chalk';
2828
import Listr from 'listr';
2929

30-
const readFile = promisify(_readFile);
3130
const writeFile = promisify(_writeFile);
3231
const git = simpleGit(projectRoot);
3332
const FIREBASE_UMBRELLA_PACKAGE_NAME = 'firebase-exp';
@@ -266,14 +265,6 @@ function removeExpInPackageName(name: string) {
266265
return `${captures[1]}${captures[2]}`;
267266
}
268267

269-
async function readPackageJson(packagePath: string) {
270-
/**
271-
* Can't require here because require caches the file
272-
* in memory, so it may not contain the updates that are made by e.g. git commands
273-
*/
274-
return JSON.parse(await readFile(`${packagePath}/package.json`, 'utf8'));
275-
}
276-
277268
async function getCurrentSha() {
278269
return (await git.revparse(['--short', 'HEAD'])).trim();
279270
}

scripts/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import { dirname, resolve } from 'path';
1919
import simpleGit from 'simple-git/promise';
2020
import { exec } from 'child-process-promise';
21+
import { readFile as _readFile } from 'fs';
22+
import { promisify } from 'util';
23+
24+
const readFile = promisify(_readFile);
2125

2226
export const projectRoot = dirname(resolve(__dirname, '../package.json'));
2327

@@ -59,3 +63,11 @@ export async function getPackageInfo(
5963

6064
return packageInfo;
6165
}
66+
67+
export async function readPackageJson(packagePath: string) {
68+
/**
69+
* Nout using require here because require caches the file
70+
* in memory, so it may not contain the updates that are made by e.g. git commands
71+
*/
72+
return JSON.parse(await readFile(`${packagePath}/package.json`, 'utf8'));
73+
}

0 commit comments

Comments
 (0)