Skip to content

Commit

Permalink
fix: add readme, fix release
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza-Bouhelal committed Oct 7, 2023
1 parent e09a9e7 commit 78dcc20
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Cypress-fs

Cypress-fs is a utility package that extends the capabilities of [Cypress](https://www.cypress.io/) for working with the file system. It provides a set of custom Cypress commands for performing file and directory operations, making it easier to interact with files in your end-to-end tests.

## Installation

You can install Cypress-fs using npm or yarn. Here's how to do it:

### npm

```bash
npm install cypress-fs --save-dev
```

### yarn

```bash
yarn add --dev cypress-fs
```

## Extra setup

### Importing the commands

To use Cypress-fs, you need to import the commands into your Cypress project. To do this, add the following line to your project's `cypress/support/commands.js` file:

```js
import "cypress-fs";
```

### Adding Required Dependencies

Cypress-fs requires some cypress tasks to be registered in order to work. To do this, update your cypress.config.ts to look like the following:

```js
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
return require("./node_modules/cypress-fs/plugins/index.js")(on, config);
},
},
});
```

## Usage

### Commands

Cypress-fs provides the following custom Cypress commands:

#### `cy.fsCopyFile({ path, newPath, mode })`

Copies a file from one location to another. - `path` - The path to the file to copy. - `newPath` - The path to the new file. - `mode` - The mode to apply to the new file.

#### `cy.fsFileExists(path)`

Checks if a file exists. - `path` - The path to the file to check.

#### `cy.fsReadFile(path, options)`

Reads the contents of a file. - `path` - The path to the file to read. - `options` - The options to use when reading the file.

#### `cy.fsWriteFile(path, content, options)`

Writes content to a file. - `path` - The path to the file to write to. - `content` - The content to write to the file. - `options` - The options to use when writing the file.

#### `cy.fsDeleteFile(path)`

Deletes a file. - `path` - The path to the file to delete.

#### `cy.fsCreateDirectory(path, options)`

Creates a directory. - `path` - The path to the directory to create. - `options` - The options to use when creating the directory.

#### `cy.fsDeleteDirectory(path, options)`

Deletes a directory. - `path` - The path to the directory to delete. - `options` - The options to use when deleting the directory.

#### `cy.fsChmod({ path, mode })`

Changes the mode of a file. - `path` - The path to the file to change the mode of. - `mode` - The mode to apply to the file.

#### `cy.fsAppendFile({ path, content })`

Appends content to a file. - `path` - The path to the file to append to. - `content` - The content to append to the file.

#### `cy.fsRename({ path, newPath })`

Renames a file. - `path` - The path to the file to rename. - `newPath` - The new path for the file.

#### `cy.fsDirExists(path)`

Checks if a directory exists. - `path` - The path to the directory to check.

### Note

The types used are the same as the ones used each corresponding method by [fs](https://nodejs.org/api/fs.html) module.
24 changes: 22 additions & 2 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if (!commitMessage) {
process.exit(1);
}

const versionUpdate = versionUpdateType(commitMessage);
const NEW_VERSION = execSync(`npm version ${versionUpdate} --force`, { encoding: 'utf-8' });

const newPackage = {
...packageJson,
main: "./support.js",
Expand All @@ -36,8 +39,25 @@ fs.copy(
path.resolve(__dirname, "..", "dist", "index.d.ts")
);

const versionUpdate = versionUpdateType(commitMessage);
const NEW_VERSION = execSync(`npm version ${versionUpdate} --force`, { encoding: 'utf-8' });
fs.copy(
path.resolve(__dirname, "..", "src", ".npmignore",
path.resolve(__dirname, "..", "dist", ".npmignore"))
);

fs.copy(
path.resolve(__dirname, "..", "src", ".npmrc"),
path.resolve(__dirname, "..", "dist", ".npmrc")
);

fs.copy(
path.resolve(__dirname, "..", "README.md"),
path.resolve(__dirname, "..", "dist", "README.md")
);

fs.copy(
path.resolve(__dirname, "..", "LICENSE"),
path.resolve(__dirname, "..", "dist", "LICENSE")
);

console.log(`Releasing package cypress-fs@${NEW_VERSION}`);

Expand Down

0 comments on commit 78dcc20

Please sign in to comment.