storyblok 3.28.0 → 3.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.github/.dependabot.yml +13 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  4. package/.github/workflows/release.yml +23 -0
  5. package/.github/workflows/unit-tests.yml +22 -0
  6. package/README.md +1 -87
  7. package/__mocks__/axios.js +31 -0
  8. package/__mocks__/fs-extra.js +63 -0
  9. package/__mocks__/fs.js +51 -0
  10. package/package.json +7 -19
  11. package/pull_request_template.md +29 -0
  12. package/src/cli.js +540 -0
  13. package/src/constants.js +29 -0
  14. package/src/tasks/delete-component.js +32 -0
  15. package/src/tasks/delete-components.js +112 -0
  16. package/src/tasks/delete-datasources.js +41 -0
  17. package/src/tasks/import/import.js +40 -0
  18. package/src/tasks/import/utils.js +234 -0
  19. package/src/tasks/index.js +16 -0
  20. package/src/tasks/list-spaces.js +63 -0
  21. package/src/tasks/migrations/generate.js +61 -0
  22. package/src/tasks/migrations/rollback.js +70 -0
  23. package/src/tasks/migrations/run.js +159 -0
  24. package/src/tasks/migrations/utils.js +336 -0
  25. package/src/tasks/pull-components.js +84 -0
  26. package/src/tasks/pull-languages.js +39 -0
  27. package/src/tasks/push-components.js +207 -0
  28. package/src/tasks/quickstart.js +91 -0
  29. package/src/tasks/scaffold.js +29 -0
  30. package/src/tasks/sync-commands/component-groups.js +140 -0
  31. package/src/tasks/sync-commands/components.js +263 -0
  32. package/src/tasks/sync-commands/datasources.js +305 -0
  33. package/src/tasks/sync.js +288 -0
  34. package/src/tasks/templates/migration-file.js +8 -0
  35. package/src/tasks/templates/teaser.js +25 -0
  36. package/src/utils/api.js +316 -0
  37. package/src/utils/capitalize.js +12 -0
  38. package/src/utils/creds.js +83 -0
  39. package/src/utils/find-by-property.js +12 -0
  40. package/src/utils/get-questions.js +317 -0
  41. package/src/utils/index.js +11 -0
  42. package/src/utils/last-step.js +108 -0
  43. package/src/utils/parse-error.js +25 -0
  44. package/src/utils/presets-lib.js +137 -0
  45. package/src/utils/region.js +7 -0
  46. package/src/utils/replace.js +23 -0
  47. package/src/utils/save-file-factory.js +16 -0
  48. package/tests/constants.js +310 -0
  49. package/tests/units/delete-component.spec.js +53 -0
  50. package/tests/units/delete-components.spec.js +94 -0
  51. package/tests/units/generate.spec.js +183 -0
  52. package/tests/units/import.spec.js +112 -0
  53. package/tests/units/is-authorized.spec.js +37 -0
  54. package/tests/units/list-spaces.spec.js +52 -0
  55. package/tests/units/login.spec.js +37 -0
  56. package/tests/units/logout.spec.js +19 -0
  57. package/tests/units/migrations/change_teaser_date.js +5 -0
  58. package/tests/units/migrations/change_teaser_headline.js +4 -0
  59. package/tests/units/migrations/change_teaser_subtitle.js +3 -0
  60. package/tests/units/pull-components.spec.js +149 -0
  61. package/tests/units/pull-languages.spec.js +62 -0
  62. package/tests/units/push-components.spec.js +86 -0
  63. package/tests/units/quickstart.spec.js +76 -0
  64. package/tests/units/run-migration.spec.js +538 -0
  65. package/tests/units/scaffold.spec.js +77 -0
  66. package/tests/units/signup.spec.js +36 -0
  67. package/tests/units/sync-components.spec.js +369 -0
  68. package/tests/units/sync.spec.js +68 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,23 @@
1
+ module.exports = {
2
+ env: {
3
+ commonjs: true,
4
+ es6: true,
5
+ node: true,
6
+ 'jest/globals': true
7
+ },
8
+ extends: [
9
+ 'standard'
10
+ ],
11
+ globals: {
12
+ Atomics: 'readonly',
13
+ SharedArrayBuffer: 'readonly'
14
+ },
15
+ parserOptions: {
16
+ ecmaVersion: 2018
17
+ },
18
+ plugins: [
19
+ 'jest'
20
+ ],
21
+ rules: {
22
+ }
23
+ }
@@ -0,0 +1,13 @@
1
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2
+ # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3
+
4
+ version: 2
5
+ updates:
6
+ - package-ecosystem: "npm"
7
+ directory: "/"
8
+ schedule:
9
+ interval: "monthly"
10
+ allow:
11
+ - dependency-name: "@storyblok/region-helper"
12
+ reviewers:
13
+ - "storyblok/plugins-team"
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve the CLI
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+
11
+ **Current behavior:**
12
+ <!-- Describe how the bug manifests. -->
13
+
14
+ **Expected behavior:**
15
+ <!-- Describe what the behavior would be without the bug. -->
16
+
17
+ **Steps to reproduce:**
18
+ <!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce and if possible also a demo.-->
19
+
20
+ **Related code:**
21
+
22
+ ```
23
+ insert any relevant code here
24
+ ```
25
+
26
+ **Other information:**
27
+ <!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->
@@ -0,0 +1,23 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: actions/setup-node@v3
14
+ with:
15
+ node-version: 20.11
16
+ cache: 'yarn'
17
+ - name: Install dependencies
18
+ run: yarn
19
+ - name: Release
20
+ env:
21
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22
+ NPM_TOKEN: ${{ secrets.NPM_PUBLISH }}
23
+ run: npx semantic-release
@@ -0,0 +1,22 @@
1
+ name: 'Unit Tests Production'
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - 'master'
7
+
8
+ jobs:
9
+ unit-tests:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: actions/setup-node@v3
14
+ with:
15
+ node-version: 18
16
+ cache: 'yarn'
17
+ - name: Install dependencies
18
+ run: yarn install --frozen-lockfile
19
+ - name: Clear jest cache
20
+ run: yarn test:unit --clearCache
21
+ - name: Run unit tests
22
+ run: yarn test:unit --silent --ci
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <h1 align="center">Storyblok CLI</h1>
3
- <p align="center">A simple CLI for scaffolding <a href="https://www.storyblok.com" target="_blank">Storyblok</a> projects and fieldtypes.</p>
3
+ <p align="center">A simple CLI for scaffolding <a href="https://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok" target="_blank">Storyblok</a> projects and fieldtypes.</p>
4
4
  </p>
5
5
 
6
6
  [![npm](https://img.shields.io/npm/v/storyblok.svg)](https://www.npmjs.com/package/storyblok)
@@ -554,92 +554,6 @@ module.exports = function (block) {
554
554
  }
555
555
  ```
556
556
 
557
- ## Typescript
558
- It is possible to generate Typescript type definitions for your Storyblok components. The type definitions are based on the components' JSON Schema that can be retrieved with the [pull-components](#pull-components) command.
559
-
560
- ### generate-typescript-typedefs
561
-
562
- Generate a file with the type definitions for the specified components' JSON Schemas.
563
-
564
- ```sh
565
- $ storyblok generate-typescript-typedefs
566
- --sourceFilePaths <PATHS>
567
- --destinationFilePath <PATH>
568
- --typeNamesPrefix <STRING>
569
- --typeNamesSuffix <STRING>
570
- --JSONSchemaToTSOptionsPath <PATH>
571
- --customFieldTypesParserPath <PATH>
572
- ```
573
-
574
- #### Options
575
-
576
- * `sourceFilePaths` <sub>(alias `source`)</sub> : Path(s) to the components JSON file(s) as comma separated values
577
- * `destinationFilePath` <sub>(alias `target`) *optional*</sub> : Path to the Typescript file that will be generated (*default*: `storyblok-component-types.d.ts`)
578
- * `typeNamesPrefix` <sub>(alias `titlePrefix`) *optional*</sub> : A prefix that will be prepended to all the names of the generated types
579
- * `typeNamesSuffix` <sub>(alias `titleSuffix`) *optional*</sub> : A suffix that will be appended to all the names of the generated types (*default*: `Storyblok`)
580
- * `JSONSchemaToTSOptionsPath` <sub>(alias `compilerOptions`) *optional*</sub> : Path to a JSON file with a list of options supported by `json-schema-to-typescript`
581
- * `customFieldTypesParserPath` <sub>(alias `customTypeParser`) *optional*</sub> : Path to the parser file for Custom Field Types
582
-
583
- #### Examples
584
-
585
- ```sh
586
- # Generate typedefs for the components retrieved for the space `12345` via the `storyblok pull-components` command
587
- $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json
588
-
589
- # Generate typedefs for multiple components sources
590
- $ storyblok generate-typescript-typedefs --sourceFilePaths ./fooComponent-12345.json,./barComponent-12345.json
591
-
592
- # Custom path for the typedefs file
593
- $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --destinationFilePath ./types/my-custom-type-file.d.ts
594
-
595
- # Provide customized options for the JSON-schema-to-typescript lib
596
- $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --JSONSchemaToTSOptionsPath ./PathToJSONFileWithCustomOptions.json
597
-
598
- # Provide a custom field types parser
599
- $ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --customFieldTypesParserPath ./customFieldTypesParser.js
600
-
601
- ```
602
-
603
- ##### JSON Schema to Typescript options
604
- This script uses the `json-schema-to-typescript` library under the hood. Values of the [JSON Schema to Typescript options](https://www.npmjs.com/package/json-schema-to-typescript#options) can be customized providing a JSON file to the `JSONSchemaToTSOptionsPath`.
605
-
606
- The default values used for the `storyblok generate-typescript-typedefs` command are the same defaults for the library except for two properties:
607
- * `bannerComment` - The default value is `""` to remove noise from the generated Typedefs file
608
- * `unknownAny` - The default value is `false` because it can help a smoother Typescript adoption on a JS project
609
-
610
- Example `JSONSchemaToTSOptions` JSON file to remove `additionalProperties` from the generated type definitions:
611
-
612
- ```json
613
- {
614
- "additionalProperties": false,
615
- }
616
- ```
617
-
618
- ##### Custom Field Types parser
619
- Storyblok [Custom Field Types](https://www.storyblok.com/docs/plugins/field-plugins/introduction) do not have inherent JSONSchema definitions. To overcome this issue, you can provide a path to a script exporting a parser function that should render a [JSONSchema Node](https://json-schema.org/learn/getting-started-step-by-step#define-properties) for each of your Custom Field Types. The parser function should be exported as a default export, like in the following example:
620
- ```js
621
- export default function (key, obj) {
622
- switch (obj.field_type) {
623
- case 'my-custom-field-type-name':
624
- return {
625
- [key]: {
626
- type: 'object',
627
- properties: {
628
- color: { type: 'string' }
629
- },
630
- required: ['color']
631
- }
632
- }
633
- default:
634
- return {}
635
- }
636
- }
637
- ```
638
-
639
-
640
-
641
-
642
-
643
557
  ## You're looking for a headstart?
644
558
 
645
559
  Check out our guides for client side apps (VueJS, Angular, React, ...), static site (Jekyll, NuxtJs, ...), dynamic site examples (Node, PHP, Python, Laravel, ...) on our [Getting Started](https://www.storyblok.com/getting-started) page.
@@ -0,0 +1,31 @@
1
+ const { USERS_ROUTES, EMAIL_TEST, PASSWORD_TEST, TOKEN_TEST } = require('../tests/constants')
2
+
3
+ const isCredCorrects = (email, pass) => {
4
+ return email === EMAIL_TEST && pass === PASSWORD_TEST
5
+ }
6
+
7
+ const axios = {
8
+ post: jest.fn((path, data) => {
9
+ const { email, password } = data || {}
10
+
11
+ if (path === USERS_ROUTES.LOGIN && isCredCorrects(email, password)) {
12
+ return Promise.resolve({
13
+ data: {
14
+ access_token: TOKEN_TEST
15
+ }
16
+ })
17
+ }
18
+
19
+ if (path === USERS_ROUTES.SIGNUP && isCredCorrects(email, password)) {
20
+ return Promise.resolve({
21
+ data: {
22
+ access_token: TOKEN_TEST
23
+ }
24
+ })
25
+ }
26
+
27
+ return Promise.reject(new Error('Incorrect access'))
28
+ })
29
+ }
30
+
31
+ module.exports = axios
@@ -0,0 +1,63 @@
1
+ const fs = jest.genMockFromModule('fs-extra')
2
+
3
+ let mockFiles = Object.create(null)
4
+
5
+ // used by pull-components.spec.js
6
+ const pathExists = jest.fn((key) => {
7
+ return !!mockFiles[key]
8
+ })
9
+
10
+ const existsSync = jest.fn((key) => {
11
+ return `${process.cwd()}/migrations/rollback`
12
+ })
13
+
14
+ const readdirSync = jest.fn((key) => {
15
+ return ['rollback_product_title.json', 'rollback_product_text.json']
16
+ })
17
+
18
+ const readFile = jest.fn((path) => {
19
+ mockFiles = path
20
+ return Promise.resolve(JSON.stringify([
21
+ {
22
+ "id": 0,
23
+ "full_slug": "another-post",
24
+ "content": {
25
+ "_uid": "5647c21f-8813-4f8a-ad38-b9f74e0e7c89",
26
+ "text": "Donec tortor mauris, mollis vel pretium vitae, lacinia nec sapien. Donec erat neque, ullamcorper tincidunt iaculis sit amet, pharetra bibendum ipsum. Nunc mattis risus ac ante consequat nec pulvinar neque molestie. Etiam interdum nunc at metus lacinia non varius erat dignissim. Integer elementum, felis id facilisis vulputate, ipsum tellus venenatis dui, at blandit nibh massa in dolor. Cras a ultricies sapien. Vivamus adipiscing feugiat pharetra.",
27
+ "image": "https://a.storyblok.com/f/51376/884x750/3bff01d851/international.svg",
28
+ "title": "test",
29
+ "category": "news",
30
+ "component": "Product"
31
+ }
32
+ }
33
+ ]))
34
+ })
35
+
36
+ const outputFile = jest.fn((path, data, fn) => {
37
+ mockFiles[path] = data
38
+ return Promise.resolve(true)
39
+ })
40
+
41
+ const __clearMockFiles = () => {
42
+ mockFiles = Object.create(null)
43
+ }
44
+
45
+ const __setMockFiles = (mock) => {
46
+ mockFiles = mock
47
+ }
48
+
49
+ fs.pathExists = pathExists
50
+
51
+ fs.existsSync = existsSync
52
+
53
+ fs.readdirSync = readdirSync
54
+
55
+ fs.readFile = readFile
56
+
57
+ fs.outputFile = outputFile
58
+
59
+ fs.__clearMockFiles = __clearMockFiles
60
+
61
+ fs.__setMockFiles = __setMockFiles
62
+
63
+ module.exports = fs
@@ -0,0 +1,51 @@
1
+ const fs = jest.genMockFromModule('fs')
2
+
3
+ const mockFiles = Object.create(null)
4
+
5
+ // used by pull-components.spec.js
6
+ const writeFile = jest.fn((key, data, _) => {
7
+ mockFiles[key] = data
8
+ })
9
+
10
+ // used by scaffold.spec.js
11
+ const writeFileSync = jest.fn((key, data) => {
12
+ mockFiles[key] = data
13
+ })
14
+
15
+ // used by push-components.spec.js
16
+ const readFileSync = jest.fn((key) => {
17
+ if (key === 'components.js') {
18
+ return JSON.stringify({
19
+ components: [
20
+ {
21
+ name: 'doc',
22
+ display_name: null,
23
+ created_at: '2018-04-06T12:26:58.539Z',
24
+ id: 66594,
25
+ schema: {
26
+ content: {
27
+ type: 'markdown'
28
+ },
29
+ summary: {
30
+ type: 'textarea'
31
+ }
32
+ },
33
+ image: null,
34
+ preview_field: null,
35
+ is_root: true,
36
+ is_nestable: false
37
+ }
38
+ ]
39
+ })
40
+ }
41
+
42
+ return {}
43
+ })
44
+
45
+ fs.writeFile = writeFile
46
+
47
+ fs.readFileSync = readFileSync
48
+
49
+ fs.writeFileSync = writeFileSync
50
+
51
+ module.exports = fs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storyblok",
3
- "version": "3.28.0",
3
+ "version": "3.28.1",
4
4
  "description": "A simple CLI to start Storyblok from your command line.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,21 +12,15 @@
12
12
  "node",
13
13
  "javascript"
14
14
  ],
15
- "main": "./dist/cli.mjs",
16
- "files": [
17
- "dist/**"
18
- ],
15
+ "main": "src/cli.js",
19
16
  "bin": {
20
- "storyblok": "./dist/cli.mjs"
17
+ "storyblok": "src/cli.js"
21
18
  },
22
- "type": "module",
23
19
  "scripts": {
24
- "build": "unbuild",
25
- "dev": "npm run build && ./dist/cli.mjs",
26
20
  "lint": "eslint src/",
27
21
  "lint:fix": "eslint src/ --fix",
28
- "test:unit": "node --experimental-vm-modules ./node_modules/.bin/jest --silent",
29
- "test:coverage": "node --experimental-vm-modules ./node_modules/.bin/jest --coverage"
22
+ "test:unit": "jest --silent",
23
+ "test:coverage": "jest --coverage"
30
24
  },
31
25
  "author": "Dominik Angerer <dominikangerer1@gmail.com>, Alexander Feiglstorfer <delooks@gmail.com>",
32
26
  "license": "MIT",
@@ -42,7 +36,6 @@
42
36
  "fs-extra": "^9.0.1",
43
37
  "git-clone": "^0.1.0",
44
38
  "inquirer": "^7.3.2",
45
- "json-schema-to-typescript": "^13.1.2",
46
39
  "lodash": "^4.17.21",
47
40
  "netrc": "0.1.4",
48
41
  "on-change": "^2.0.1",
@@ -50,7 +43,7 @@
50
43
  "p-series": "^2.1.0",
51
44
  "path": "^0.12.7",
52
45
  "simple-uuid": "^0.0.1",
53
- "storyblok-js-client": "^6.7.1",
46
+ "storyblok-js-client": "^5.14.0",
54
47
  "update-notifier": "^5.1.0",
55
48
  "xml-js": "^1.6.11"
56
49
  },
@@ -66,16 +59,11 @@
66
59
  "eslint-plugin-node": "^11.1.0",
67
60
  "eslint-plugin-promise": "^4.2.1",
68
61
  "eslint-plugin-standard": "^4.0.1",
69
- "jest": "^29.7.0",
70
- "typescript": "^5.3.3",
71
- "unbuild": "^2.0.0"
62
+ "jest": "^26.1.0"
72
63
  },
73
64
  "release": {
74
65
  "branches": [
75
66
  "master"
76
67
  ]
77
- },
78
- "prettier": {
79
- "printWidth": 120
80
68
  }
81
69
  }
@@ -0,0 +1,29 @@
1
+ <!--- Please provide a general summary of your changes in the title above -->
2
+
3
+ ## Pull request type
4
+
5
+ Jira Link: [INT-](url)
6
+
7
+ <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed.
8
+
9
+ Please check the type of change your PR introduces:-->
10
+
11
+ - [ ] Bugfix
12
+ - [ ] Feature
13
+ - [ ] Code style update (formatting, renaming)
14
+ - [ ] Refactoring (no functional changes, no api changes)
15
+ - [ ] Other (please describe):
16
+
17
+ ## How to test this PR
18
+
19
+ <!-- Please provide the steps on how to test this PR. -->
20
+
21
+ ## What is the new behavior?
22
+
23
+ <!-- Please describe the behavior or changes that are being added by this PR. -->
24
+
25
+ -
26
+ -
27
+ -
28
+
29
+ ## Other information