diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 57b84d6c3..034a9a2cf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -13,6 +13,7 @@ jobs:
node-version: 17
cache: 'yarn'
- run: yarn
+ - run: yarn run build
- run: yarn run lint
test:
runs-on: ubuntu-20.04
@@ -27,25 +28,12 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'yarn'
- run: yarn
+ - run: yarn run build
- run: yarn run test:coverage
- uses: codecov/codecov-action@v2.1.0
- build:
- runs-on: ubuntu-20.04
- strategy:
- matrix:
- node: [ '14', '16', '17' ]
- needs: [lint, test]
- steps:
- - uses: actions/checkout@v2.3.5
- - name: Use Node.js
- uses: actions/setup-node@v2.4.1
- with:
- node-version: ${{ matrix.node }}
- - run: yarn --pure-lockfile
- - run: yarn run build
deploy:
runs-on: ubuntu-20.04
- needs: [build]
+ needs: [test]
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2.3.5
diff --git a/packages/random-name/README.md b/packages/random-name/README.md
index ffd0138f4..54e368100 100644
--- a/packages/random-name/README.md
+++ b/packages/random-name/README.md
@@ -24,17 +24,3 @@ randomName('superb') // => "superb-admiring-allen"
randomName('superb', '_') // => "superb_admiring_allen"
randomName('', '_') // => "admiring_allen"
```
-
-As a React hook
-```js
-import React from 'react'
-import { useRandomName } from '@scaleway/random-name'
-
-const Component = () => {
- const name = useRandomName()
-
- return (
- {name}
- )
-}
-```
diff --git a/packages/random-name/package.json b/packages/random-name/package.json
index a1a482278..6a0d2f7d5 100644
--- a/packages/random-name/package.json
+++ b/packages/random-name/package.json
@@ -17,8 +17,5 @@
"url": "https://github.com/scaleway/scaleway-lib",
"directory": "packages/random-name"
},
- "license": "MIT",
- "peerDependencies": {
- "react": ">=16.8"
- }
+ "license": "MIT"
}
diff --git a/packages/random-name/src/__tests__/__snapshots__/index.ts.snap b/packages/random-name/src/__tests__/__snapshots__/index.ts.snap
deleted file mode 100644
index ec016ea2e..000000000
--- a/packages/random-name/src/__tests__/__snapshots__/index.ts.snap
+++ /dev/null
@@ -1,3 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`randomName useRandomName useTranslation should not be defined without I18nProvider 1`] = `"gracious-hermann"`;
diff --git a/packages/random-name/src/__tests__/index.ts b/packages/random-name/src/__tests__/index.ts
index b1e144706..9685efe3a 100644
--- a/packages/random-name/src/__tests__/index.ts
+++ b/packages/random-name/src/__tests__/index.ts
@@ -1,5 +1,4 @@
-import { renderHook } from '@testing-library/react-hooks'
-import randomName, { useRandomName } from '..'
+import randomName from '..'
describe('randomName', () => {
it('should return a random name separated by a dash', () => {
@@ -28,20 +27,4 @@ describe('randomName', () => {
expect.arrayContaining([expect.stringMatching('boring-wozniak')]),
)
})
-
- describe('useRandomName', () => {
- beforeAll(() => {
- jest.spyOn(global.Math, 'random').mockReturnValue(0.4155913669444804)
- })
-
- afterAll(() => {
- jest.spyOn(global.Math, 'random').mockRestore()
- })
-
- it('useTranslation should not be defined without I18nProvider', () => {
- const { result } = renderHook(() => useRandomName())
- expect(result.current).toMatchSnapshot()
- })
- })
-
})
diff --git a/packages/random-name/src/index.ts b/packages/random-name/src/index.ts
index 0e658812b..5f6e90fec 100644
--- a/packages/random-name/src/index.ts
+++ b/packages/random-name/src/index.ts
@@ -1,5 +1,3 @@
-import { useCallback } from 'react'
-
const ADJECTIVES = [
'admiring',
'adoring',
@@ -839,8 +837,4 @@ const randomName = (prefix = '', separator = '-'): string => {
return prefix.length > 0 ? `${prefix}${separator}${name}` : name
}
-const useRandomName = (prefix = '', separator = '-'): string =>
- useCallback(() => randomName(prefix, separator), [prefix, separator])()
-
-export { useRandomName }
export default randomName
diff --git a/packages/use-random-name/.eslintrc.cjs b/packages/use-random-name/.eslintrc.cjs
new file mode 100644
index 000000000..f4bd0a419
--- /dev/null
+++ b/packages/use-random-name/.eslintrc.cjs
@@ -0,0 +1,10 @@
+const { join } = require('path');
+
+module.exports = {
+ rules: {
+ 'import/no-extraneous-dependencies': [
+ 'error',
+ { packageDir: [__dirname, join(__dirname, '../../')] }
+ ]
+ }
+};
diff --git a/packages/use-random-name/.npmignore b/packages/use-random-name/.npmignore
new file mode 100644
index 000000000..4b70adadf
--- /dev/null
+++ b/packages/use-random-name/.npmignore
@@ -0,0 +1,4 @@
+**/__tests__/**
+src
+.eslintrc.cjs
+!.npmignore
diff --git a/packages/use-random-name/CHANGELOG.md b/packages/use-random-name/CHANGELOG.md
new file mode 100644
index 000000000..37da9da08
--- /dev/null
+++ b/packages/use-random-name/CHANGELOG.md
@@ -0,0 +1,123 @@
+# Change Log
+
+All notable changes to this project will be documented in this file.
+See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
+
+### 2.1.1 (2021-10-21)
+
+**Note:** Version bump only for package @scaleway/random-name
+
+
+
+
+
+## [2.1.0](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@2.0.0...@scaleway/random-name@2.1.0) (2021-07-21)
+
+
+### Features
+
+* **random-name:** base the generator on moby and expose react hook ([#281](https://github.com/scaleway/scaleway-lib/issues/281)) ([6e986be](https://github.com/scaleway/scaleway-lib/commit/6e986beb2609e533199a2b38b989c3b8b0c3c56b))
+
+
+
+## 2.0.0 (2021-07-20)
+
+
+### ⚠ BREAKING CHANGES
+
+* migrate the codebase to typescript
+
+### Code Refactoring
+
+* migrate to typescript ([#272](https://github.com/scaleway/scaleway-lib/issues/272)) ([3923c68](https://github.com/scaleway/scaleway-lib/commit/3923c68d6f7feadee7e2e30e32c9ef5d1f3003b9))
+
+
+
+### 1.3.2 (2021-05-11)
+
+**Note:** Version bump only for package @scaleway/random-name
+
+
+
+
+
+### 1.3.1 (2021-05-10)
+
+**Note:** Version bump only for package @scaleway/random-name
+
+
+
+
+
+# 1.3.0 (2021-03-04)
+
+
+### Features
+
+* updated eslint setting to force carriage return before return ([3514034](https://github.com/scaleway/scaleway-lib/commit/3514034804ae06083825adc3e57003ed8dba4933))
+
+
+
+
+
+## 1.2.1 (2021-02-15)
+
+**Note:** Version bump only for package @scaleway/random-name
+
+
+
+
+
+# 1.2.0 (2021-01-28)
+
+
+### Bug Fixes
+
+* correct browser entrypoints ([2c0724d](https://github.com/scaleway/scaleway-lib/commit/2c0724d00b45664757c380188618908fcae2c606))
+* **random-name:** add npmignore ([d7b7e70](https://github.com/scaleway/scaleway-lib/commit/d7b7e701db4ae090650408794a380ebe084e8407))
+
+
+### Features
+
+* migrate randomName from shire and scw-ui ([5729af8](https://github.com/scaleway/scaleway-lib/commit/5729af8c38a436679e948025dfff89c45a9b8e5c))
+
+
+
+
+
+## [1.1.3](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@1.1.2...@scaleway/random-name@1.1.3) (2020-11-08)
+
+**Note:** Version bump only for package @scaleway/random-name
+
+
+
+
+
+## [1.1.2](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@1.1.1...@scaleway/random-name@1.1.2) (2020-10-28)
+
+
+### Bug Fixes
+
+* correct browser entrypoints ([8a7d0b5](https://github.com/scaleway/scaleway-lib/commit/8a7d0b503ee22eedb07d5021b3a3fd4e059e627a))
+
+
+
+
+
+## [1.1.1](https://github.com/scaleway/scaleway-lib/compare/@scaleway/random-name@1.1.0...@scaleway/random-name@1.1.1) (2020-10-28)
+
+
+### Bug Fixes
+
+* **random-name:** add npmignore ([2731b54](https://github.com/scaleway/scaleway-lib/commit/2731b5452bb33fb369ee2370156e565b5a328d42))
+
+
+
+
+
+# 1.1.0 (2020-10-28)
+
+
+### Features
+
+* migrate randomName from shire and scw-ui ([331a2f9](https://github.com/scaleway/scaleway-lib/commit/331a2f91a5aa777806bbc1dc1014fc5b6987db8c))
diff --git a/packages/use-random-name/README.md b/packages/use-random-name/README.md
new file mode 100644
index 000000000..8c5a7a88e
--- /dev/null
+++ b/packages/use-random-name/README.md
@@ -0,0 +1,41 @@
+# `@scaleway/random-name`
+
+A tiny utility to generate random names
+
+Fully inspired by [Moby name generator](https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go)
+
+---
+
+## Install
+
+```bash
+$ yarn add @scaleway/use-random-name
+```
+
+## Usage
+
+As a React hook
+```js
+import React from 'react'
+import useRandomName from '@scaleway/random-name'
+
+const Component = () => {
+ const name = useRandomName()
+
+ return (
+ {name}
+ )
+}
+```
+
+You can also access the underlying @scaleway/random-name package with a named export
+```js
+import { randomName } from '@scaleway/use-random-name'
+
+// randomName(prefix: string = '', separator: string = '-'): string
+
+randomName() // => "admiring-allen"
+randomName('superb') // => "superb-admiring-allen"
+randomName('superb', '_') // => "superb_admiring_allen"
+randomName('', '_') // => "admiring_allen"
+```
diff --git a/packages/use-random-name/package.json b/packages/use-random-name/package.json
new file mode 100644
index 000000000..4c3cc78b7
--- /dev/null
+++ b/packages/use-random-name/package.json
@@ -0,0 +1,27 @@
+{
+ "name": "@scaleway/use-random-name",
+ "version": "0.1.0",
+ "description": "A small react utility to generate a random name",
+ "type": "module",
+ "main": "dist/index.js",
+ "module": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "browser": {
+ "dist/index.js": "./dist/index.browser.js"
+ },
+ "publishConfig": {
+ "access": "public"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/scaleway/scaleway-lib",
+ "directory": "packages/use-random-name"
+ },
+ "license": "MIT",
+ "peerDependencies": {
+ "react": ">=16.8"
+ },
+ "dependencies": {
+ "@scaleway/random-name": "^2.1.1"
+ }
+}
diff --git a/packages/use-random-name/src/__tests__/__snapshots__/index.ts.snap b/packages/use-random-name/src/__tests__/__snapshots__/index.ts.snap
new file mode 100644
index 000000000..d26e91275
--- /dev/null
+++ b/packages/use-random-name/src/__tests__/__snapshots__/index.ts.snap
@@ -0,0 +1,3 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`useRandomName useTranslation should not be defined without I18nProvider 1`] = `"gracious-hermann"`;
diff --git a/packages/use-random-name/src/__tests__/index.ts b/packages/use-random-name/src/__tests__/index.ts
new file mode 100644
index 000000000..93ede85d9
--- /dev/null
+++ b/packages/use-random-name/src/__tests__/index.ts
@@ -0,0 +1,17 @@
+import { renderHook } from '@testing-library/react-hooks'
+import useRandomName from '..'
+
+describe('useRandomName', () => {
+ beforeAll(() => {
+ jest.spyOn(global.Math, 'random').mockReturnValue(0.4155913669444804)
+ })
+
+ afterAll(() => {
+ jest.spyOn(global.Math, 'random').mockRestore()
+ })
+
+ it('useTranslation should not be defined without I18nProvider', () => {
+ const { result } = renderHook(() => useRandomName())
+ expect(result.current).toMatchSnapshot()
+ })
+})
diff --git a/packages/use-random-name/src/index.ts b/packages/use-random-name/src/index.ts
new file mode 100644
index 000000000..be47f4ab4
--- /dev/null
+++ b/packages/use-random-name/src/index.ts
@@ -0,0 +1,8 @@
+import randomName from '@scaleway/random-name'
+import { useCallback } from 'react'
+
+const useRandomName = (prefix = '', separator = '-'): string =>
+ useCallback(() => randomName(prefix, separator), [prefix, separator])()
+
+export default useRandomName
+export { randomName }