Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"lint": "eslint --max-warnings 0 .",
"preinstall": "node ./scripts/try-set-nightly-hermes-compiler.js",
"prettier": "prettier --write \"./**/*.{js,md,yml,ts,tsx}\"",
"print-packages": "node ./scripts/monorepo/print",
"shellcheck": "./.github/workflow-scripts/analyze_scripts.sh",
"start": "yarn --cwd packages/rn-tester start",
"set-version": "node ./scripts/releases/set-version.js",
Expand Down
132 changes: 0 additions & 132 deletions scripts/monorepo/print/index.js

This file was deleted.

44 changes: 2 additions & 42 deletions scripts/releases/utils/__tests__/scm-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
* @format
*/

const {isTaggedLatest, revertFiles, saveFiles} = require('../scm-utils');
const {isTaggedLatest} = require('../scm-utils');

let execResult = null;
const cpMock = jest.fn();
const mkdirSyncMock = jest.fn();

jest
.mock('shelljs', () => ({
exec: () => {
Expand All @@ -26,11 +25,9 @@ jest
exit: exitCode => {
process.exit(exitCode);
},
cp: cpMock,
}))
.mock('fs', () => ({
existsSync: jest.fn().mockImplementation(_ => true),
mkdirSync: mkdirSyncMock,
}))
.mock('path', () => ({
dirname: jest
Expand Down Expand Up @@ -58,41 +55,4 @@ describe('scm-utils', () => {
expect(isTaggedLatest('6c19dc3266b8')).toBe(false);
});
});

describe('saveFiles', () => {
it('it should save files in the temp folder', () => {
const tmpFolder = '/tmp';
saveFiles(['package.json', 'android/package.json'], tmpFolder);
expect(mkdirSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`, {
recursive: true,
});
expect(cpMock).toHaveBeenNthCalledWith(
1,
'package.json',
'/tmp/package.json',
);
expect(cpMock).toHaveBeenNthCalledWith(
2,
'android/package.json',
`${tmpFolder}/android/package.json`,
);
});
});

describe('revertFiles', () => {
it('it should revert files from the temp folder', () => {
const tmpFolder = '/tmp';
revertFiles(['package.json', 'android/package.json'], tmpFolder);
expect(cpMock).toHaveBeenNthCalledWith(
1,
`${tmpFolder}/package.json`,
'package.json',
);
expect(cpMock).toHaveBeenNthCalledWith(
2,
`${tmpFolder}/android/package.json`,
'android/package.json',
);
});
});
});
70 changes: 4 additions & 66 deletions scripts/releases/utils/scm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,8 @@

'use strict';

const fs = require('fs');
const path = require('path');
const {cp, echo, exec, exit} = require('shelljs');

/*::
type Commit = string;
*/

function isGitRepo() /*: boolean */ {
try {
return (
exec('git rev-parse --is-inside-work-tree', {
silent: true,
}).stdout.trim() === 'true'
);
} catch (error) {
echo(
`It wasn't possible to check if we are in a git repository. Details: ${error}`,
);
}
return false;
}
const isGitRepo = require('../../shared/isGitRepo');
const {echo, exec, exit} = require('shelljs');

function exitIfNotOnGit /*::<T>*/(
command /*: () => T */,
Expand All @@ -47,7 +27,7 @@ function exitIfNotOnGit /*::<T>*/(
}
}

function isTaggedLatest(commitSha /*: Commit */) /*: boolean */ {
function isTaggedLatest(commitSha /*: string */) /*: boolean */ {
return (
exec(`git rev-list -1 latest | grep ${commitSha}`, {
silent: true,
Expand All @@ -61,59 +41,17 @@ function getBranchName() /*: string */ {
}).stdout.trim();
}

function getCurrentCommit() /*: Commit */ {
function getCurrentCommit() /*: string */ {
return isGitRepo()
? exec('git rev-parse HEAD', {
silent: true,
}).stdout.trim()
: 'TEMP';
}

function saveFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
for (const filePath of filePaths) {
const dirName = path.dirname(filePath);
if (dirName !== '.') {
const destFolder = `${tmpFolder}/${dirName}`;
fs.mkdirSync(destFolder, {recursive: true});
}
cp(filePath, `${tmpFolder}/${filePath}`);
}
}

function revertFiles(filePaths /*: Array<string> */, tmpFolder /*: string */) {
for (const filePath of filePaths) {
const absoluteTmpPath = `${tmpFolder}/${filePath}`;
if (fs.existsSync(absoluteTmpPath)) {
cp(absoluteTmpPath, filePath);
} else {
echo(
`It was not possible to revert ${filePath} since ${absoluteTmpPath} does not exist.`,
);
exit(1);
}
}
}

// git restore for local path
function restore(repoPath /*: string */) {
const result = exec('git restore .', {
cwd: repoPath,
});

if (result.code !== 0) {
throw new Error(result.stderr);
}

return;
}

module.exports = {
exitIfNotOnGit,
getCurrentCommit,
getBranchName,
isGitRepo,
isTaggedLatest,
revertFiles,
saveFiles,
restore,
};
4 changes: 0 additions & 4 deletions scripts/shared/isGitRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

const childProcess = require('child_process');

/*::
type Commit = string;
*/

function isGitRepo() /*: boolean */ {
try {
const result = childProcess.execSync(
Expand Down
Loading