├── .husky ├── .gitignore ├── pre-commit └── commit-msg ├── README.md ├── CHANGELOG.md ├── packages ├── generator-prismic-nuxt │ ├── generators │ │ ├── app │ │ │ └── templates │ │ │ │ └── dummyfile.txt │ │ ├── create-slice │ │ │ ├── templates │ │ │ │ └── library │ │ │ │ │ ├── index.js │ │ │ │ │ └── slice │ │ │ │ │ ├── mocks.json │ │ │ │ │ ├── index.stories.js │ │ │ │ │ ├── index.vue │ │ │ │ │ └── model.json │ │ │ └── index.ts │ │ ├── slicemachine │ │ │ ├── templates │ │ │ │ └── sm.json │ │ │ └── modify-nuxt-config.ts │ │ └── storybook │ │ │ └── index.ts │ ├── test │ │ ├── mocha.opts │ │ └── slicemachine │ │ │ └── modify-nuxt-config.test.ts │ ├── .gitignore │ ├── tsconfig.json │ └── package.json ├── generator-prismic-react │ ├── generators │ │ └── app │ │ │ ├── templates │ │ │ └── dummyfile.txt │ │ │ └── index.ts │ ├── .gitignore │ ├── tsconfig.json │ └── package.json ├── generator-prismic-vue │ ├── generators │ │ └── app │ │ │ ├── templates │ │ │ └── dummyfile.txt │ │ │ └── index.ts │ ├── .gitignore │ ├── tsconfig.json │ └── package.json ├── prismic-cli │ ├── src │ │ ├── index.ts │ │ ├── prismic │ │ │ ├── index.ts │ │ │ └── yeoman-env.ts │ │ ├── utils │ │ │ ├── cookie.ts │ │ │ ├── index.ts │ │ │ ├── fs.ts │ │ │ ├── data-dog.ts │ │ │ ├── logDecoration.ts │ │ │ ├── framework │ │ │ │ ├── index.ts │ │ │ │ └── project-types.ts │ │ │ └── server.ts │ │ ├── commands │ │ │ ├── logout.ts │ │ │ ├── whoami.ts │ │ │ ├── list.ts │ │ │ ├── login.ts │ │ │ ├── signup.ts │ │ │ ├── create-generator.ts │ │ │ ├── theme.ts │ │ │ └── new.ts │ │ ├── hooks │ │ │ └── postrun │ │ │ │ └── updates.ts │ │ └── generators │ │ │ └── theme.ts │ ├── bin │ │ ├── run.cmd │ │ └── run │ ├── .eslintignore │ ├── test │ │ ├── __stubs__ │ │ │ ├── fake-generator │ │ │ │ ├── package.json │ │ │ │ └── index.js │ │ │ ├── nuxt-template │ │ │ │ ├── README.md │ │ │ │ ├── static │ │ │ │ │ ├── favicon.ico │ │ │ │ │ └── README.md │ │ │ │ ├── components │ │ │ │ │ ├── README.md │ │ │ │ │ └── Logo.vue │ │ │ │ ├── .editorconfig │ │ │ │ ├── layouts │ │ │ │ │ ├── README.md │ │ │ │ │ └── default.vue │ │ │ │ ├── pages │ │ │ │ │ ├── README.md │ │ │ │ │ └── index.vue │ │ │ │ ├── assets │ │ │ │ │ └── README.md │ │ │ │ ├── plugins │ │ │ │ │ └── README.md │ │ │ │ ├── package.json │ │ │ │ ├── middleware │ │ │ │ │ └── README.md │ │ │ │ ├── store │ │ │ │ │ └── README.md │ │ │ │ ├── nuxt.config.js │ │ │ │ └── .gitignore │ │ │ ├── fake-theme-master │ │ │ │ ├── documents │ │ │ │ │ ├── index.json │ │ │ │ │ ├── en-us │ │ │ │ │ │ └── Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json │ │ │ │ │ └── fr-fr │ │ │ │ │ │ └── Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json │ │ │ │ ├── prismic-configuration.js │ │ │ │ └── custom_types │ │ │ │ │ ├── index.json │ │ │ │ │ └── top_menu.json │ │ │ ├── fake-theme-with-config-master │ │ │ │ ├── prismic-theme.json │ │ │ │ ├── documents │ │ │ │ │ ├── index.json │ │ │ │ │ ├── en-us │ │ │ │ │ │ └── Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json │ │ │ │ │ └── fr-fr │ │ │ │ │ │ └── Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json │ │ │ │ ├── prismic-configuration.js │ │ │ │ └── custom_types │ │ │ │ │ ├── index.json │ │ │ │ │ └── top_menu.json │ │ │ ├── nodejs-sdk-master │ │ │ │ ├── custom_types │ │ │ │ │ ├── index.json │ │ │ │ │ └── page.json │ │ │ │ └── prismic-configuration.js │ │ │ └── template.ts │ │ ├── mocha.opts │ │ ├── tsconfig.json │ │ ├── commands │ │ │ ├── list.test.ts │ │ │ ├── logout.test.ts │ │ │ ├── whoami.test.ts │ │ │ ├── create-generator.test.ts │ │ │ ├── updates.test.ts │ │ │ ├── signup.test.ts │ │ │ └── login.test.ts │ │ └── utils │ │ │ ├── framework.test.ts │ │ │ ├── index.test.ts │ │ │ └── data-dog.test.ts │ ├── .eslintrc │ ├── tsconfig.json │ ├── .npmignore │ ├── .gitignore │ └── package.json ├── generator-prismic-angular2 │ ├── generators │ │ └── app │ │ │ ├── templates │ │ │ └── dummyfile.txt │ │ │ └── index.ts │ ├── .gitignore │ ├── tsconfig.json │ └── package.json ├── prismic-generator-generator │ ├── app │ │ ├── templates │ │ │ ├── javascript │ │ │ │ ├── .gitignore │ │ │ │ ├── generators │ │ │ │ │ ├── app │ │ │ │ │ │ ├── templates │ │ │ │ │ │ │ └── dummyfile.txt │ │ │ │ │ │ └── index.js │ │ │ │ │ ├── create-slice │ │ │ │ │ │ ├── templates │ │ │ │ │ │ │ └── library │ │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ │ └── slice │ │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ │ ├── index.stories.js │ │ │ │ │ │ │ │ ├── mocks.json │ │ │ │ │ │ │ │ └── model.json │ │ │ │ │ │ └── index.js │ │ │ │ │ ├── slicemachine │ │ │ │ │ │ ├── templates │ │ │ │ │ │ │ └── sm.json │ │ │ │ │ │ └── index.js │ │ │ │ │ └── storybook │ │ │ │ │ │ └── index.js │ │ │ │ └── package.json │ │ │ └── typescript │ │ │ │ ├── generators │ │ │ │ ├── app │ │ │ │ │ ├── templates │ │ │ │ │ │ └── dummyfile.txt │ │ │ │ │ └── index.ts │ │ │ │ ├── create-slice │ │ │ │ │ ├── templates │ │ │ │ │ │ └── library │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ └── slice │ │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ │ ├── index.stories.js │ │ │ │ │ │ │ ├── mocks.json │ │ │ │ │ │ │ └── model.json │ │ │ │ │ └── index.ts │ │ │ │ ├── slicemachine │ │ │ │ │ ├── templates │ │ │ │ │ │ └── sm.json │ │ │ │ │ └── index.ts │ │ │ │ └── storybook │ │ │ │ │ └── index.ts │ │ │ │ ├── .gitignore │ │ │ │ ├── tsconfig.json │ │ │ │ └── package.json │ │ └── index.ts │ ├── .gitignore │ ├── .eslintrc │ ├── .eslintignore │ ├── tsconfig.json │ ├── package.json │ └── README.md ├── prismic-yeoman-generator │ ├── .eslintrc │ ├── .eslintignore │ ├── test │ │ ├── __stubs__ │ │ │ ├── fake-theme-master │ │ │ │ ├── documents │ │ │ │ │ ├── index.json │ │ │ │ │ ├── en-us │ │ │ │ │ │ └── Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json │ │ │ │ │ └── fr-fr │ │ │ │ │ │ └── Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json │ │ │ │ ├── prismic-configuration.js │ │ │ │ └── custom_types │ │ │ │ │ ├── index.json │ │ │ │ │ └── top_menu.json │ │ │ ├── fake-theme-new-custom-types │ │ │ │ ├── documents │ │ │ │ │ ├── index.json │ │ │ │ │ ├── en-us │ │ │ │ │ │ └── Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json │ │ │ │ │ └── fr-fr │ │ │ │ │ │ └── Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json │ │ │ │ └── customtypes │ │ │ │ │ └── top_menu │ │ │ │ │ └── index.json │ │ │ └── index.ts │ │ ├── mocha.opts │ │ └── tsconfig.json │ ├── tsconfig.json │ ├── .npmignore │ ├── README.md │ ├── .gitignore │ └── package.json ├── generator-prismic-nextjs │ ├── .gitignore │ ├── generators │ │ ├── create-slice │ │ │ ├── templates │ │ │ │ └── library │ │ │ │ │ ├── index.js │ │ │ │ │ └── slice │ │ │ │ │ ├── index.stories.js │ │ │ │ │ ├── mocks.json │ │ │ │ │ ├── model.json │ │ │ │ │ └── index.js │ │ │ └── index.ts │ │ ├── app │ │ │ ├── templates │ │ │ │ ├── public │ │ │ │ │ ├── favicon.ico │ │ │ │ │ └── vercel.svg │ │ │ │ ├── pages │ │ │ │ │ ├── _app.js │ │ │ │ │ ├── api │ │ │ │ │ │ └── hello.js │ │ │ │ │ └── index.js │ │ │ │ ├── styles │ │ │ │ │ ├── globals.css │ │ │ │ │ └── Home.module.css │ │ │ │ ├── .gitignore │ │ │ │ └── README.md │ │ │ └── index.ts │ │ ├── slicemachine │ │ │ └── templates │ │ │ │ ├── next.config.js │ │ │ │ ├── sm.json │ │ │ │ ├── pages │ │ │ │ ├── _app.js │ │ │ │ ├── _document.js │ │ │ │ └── [uid].js │ │ │ │ ├── sm-resolver.js │ │ │ │ └── prismic.js │ │ └── storybook │ │ │ ├── templates │ │ │ └── .storybook │ │ │ │ └── main.js │ │ │ └── index.ts │ ├── test │ │ └── mocha.opts │ ├── tsconfig.json │ └── package.json └── generator-prismic-nodejs │ ├── .gitignore │ ├── tsconfig.json │ ├── package.json │ └── generators │ └── app │ └── index.ts ├── .eslintrc ├── .gitattributes ├── .eslintignore ├── lerna.json ├── .editorconfig ├── .github └── dependabot.yml ├── .travis.yml ├── package.json └── .gitignore /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | packages/prismic-cli/README.md -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | packages/prismic-cli/CHANGELOG.md -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/app/templates/dummyfile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/generator-prismic-react/generators/app/templates/dummyfile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/generator-prismic-vue/generators/app/templates/dummyfile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/index.ts: -------------------------------------------------------------------------------- 1 | export {run} from '@oclif/command' 2 | -------------------------------------------------------------------------------- /packages/generator-prismic-angular2/generators/app/templates/dummyfile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/prismic-cli/bin/run.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | node "%~dp0\run" %* 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "oclif", 4 | "oclif-typescript" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.json text eol=lf 3 | *.js text eol=lf 4 | *.ts text eol=lf -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint-staged 5 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn commitlint --edit $1 -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log -------------------------------------------------------------------------------- /packages/prismic-cli/src/prismic/index.ts: -------------------------------------------------------------------------------- 1 | export {default as Command} from './base-command' 2 | 3 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/app/templates/dummyfile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/app/templates/dummyfile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | templates 3 | node_modules 4 | **/test/__stubs__/** 5 | .env* 6 | __tmp__ 7 | *.d.ts -------------------------------------------------------------------------------- /packages/prismic-cli/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | templates 3 | node_modules 4 | test/__stubs__/** 5 | .env* 6 | __tmp__ 7 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fake", 3 | "main": "index.js" 4 | } -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/README.md: -------------------------------------------------------------------------------- 1 | # nuxt-template 2 | 3 | For testing slicemachine 4 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | app/*.d.ts 4 | app/*.js 5 | !**/templates -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "oclif", 4 | "oclif-typescript" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "oclif", 4 | "oclif-typescript" 5 | ], 6 | } 7 | -------------------------------------------------------------------------------- /packages/generator-prismic-vue/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-master/documents/index.json: -------------------------------------------------------------------------------- 1 | {"signature":"34fbecc5b263e17dba2cd597119489a17b7343d6"} 2 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/prismic-theme.json: -------------------------------------------------------------------------------- 1 | { 2 | "replaceRepositoryName": "qwerty" 3 | } 4 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | templates 3 | node_modules 4 | test/__stubs__/** 5 | .env* 6 | __tmp__ 7 | *.d.ts -------------------------------------------------------------------------------- /packages/generator-prismic-angular2/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates -------------------------------------------------------------------------------- /packages/generator-prismic-nodejs/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates -------------------------------------------------------------------------------- /packages/generator-prismic-react/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates -------------------------------------------------------------------------------- /packages/prismic-generator-generator/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | templates 3 | node_modules 4 | test/__stubs__/** 5 | .env* 6 | __tmp__ 7 | *.d.ts -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/create-slice/templates/library/index.js: -------------------------------------------------------------------------------- 1 | export { default as <%= sliceName %> } from './<%= sliceName %>' -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/create-slice/templates/library/index.js: -------------------------------------------------------------------------------- 1 | export { default as <%= sliceName %> } from './<%= sliceName %>' -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/documents/index.json: -------------------------------------------------------------------------------- 1 | {"signature":"34fbecc5b263e17dba2cd597119489a17b7343d6"} 2 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-master/documents/index.json: -------------------------------------------------------------------------------- 1 | {"signature":"34fbecc5b263e17dba2cd597119489a17b7343d6"} 2 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "4.2.3", 6 | "useWorkspaces": true, 7 | "npmClient": "yarn" 8 | } 9 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-master/prismic-configuration.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | prismicRepo: 'your-repo-name', 4 | } 5 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/prismic-configuration.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | prismicRepo: 'qwerty', 4 | } 5 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node/register 2 | --watch-extensions ts 3 | --recursive 4 | --reporter spec 5 | --timeout 15000 6 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-new-custom-types/documents/index.json: -------------------------------------------------------------------------------- 1 | {"signature":"34fbecc5b263e17dba2cd597119489a17b7343d6"} 2 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node/register 2 | --watch-extensions ts 3 | --recursive 4 | --reporter spec 5 | --timeout 5000 6 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node/register 2 | --watch-extensions ts 3 | --recursive 4 | --reporter spec 5 | --timeout 5000 6 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-master/prismic-configuration.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | prismicRepo: 'your-repo-name', 4 | } 5 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node/register 2 | --watch-extensions ts 3 | --recursive 4 | --reporter spec 5 | --timeout 5000 6 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | generators/*/*.d.ts 4 | generators/*/*.js 5 | !generators/**/templates 6 | test/**/*.js 7 | test/**/*.d.ts -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/create-slice/templates/library/index.js: -------------------------------------------------------------------------------- 1 | export { default as <%%= sliceName %> } from './<%%= sliceName %>' -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/create-slice/templates/library/index.js: -------------------------------------------------------------------------------- 1 | export { default as <%%= sliceName %> } from './<%%= sliceName %>' -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nodejs-sdk-master/custom_types/index.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": "page", 3 | "name": "Page", 4 | "repeatable": true, 5 | "value": "page.json" 6 | }] 7 | -------------------------------------------------------------------------------- /packages/prismic-cli/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "oclif", 4 | "oclif-typescript" 5 | ], 6 | "ignorePatterns": [ 7 | "src/utils/logDecoration.ts" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/prismic-cli/master/packages/prismic-cli/test/__stubs__/nuxt-template/static/favicon.ico -------------------------------------------------------------------------------- /packages/prismic-cli/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig", 3 | "compilerOptions": { 4 | "noEmit": true 5 | }, 6 | "references": [ 7 | {"path": ".."} 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/prismic-cli/master/packages/generator-prismic-nextjs/generators/app/templates/public/favicon.ico -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/next.config.js: -------------------------------------------------------------------------------- 1 | const withTM = require('next-transpile-modules')(['next-slicezone', 'essential-slices']); 2 | 3 | module.exports = withTM(); 4 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig", 3 | "compilerOptions": { 4 | "noEmit": true 5 | }, 6 | "references": [ 7 | {"path": ".."} 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/prismic-cli/bin/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | process.removeAllListeners('warning') 4 | 5 | require('@oclif/command').run() 6 | .then(require('@oclif/command/flush')) 7 | .catch(require('@oclif/errors/handle')) 8 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/create-slice/templates/library/slice/index.js: -------------------------------------------------------------------------------- 1 | 2 | /* EJS template for the slice */ 3 | /* 4 | * vars 5 | * sliceName, 6 | * displayName 7 | */ 8 | 9 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/create-slice/templates/library/slice/index.js: -------------------------------------------------------------------------------- 1 | 2 | /* EJS template for the slice */ 3 | /* 4 | * vars 5 | * sliceName, 6 | * displayName 7 | */ 8 | 9 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/pages/_app.js: -------------------------------------------------------------------------------- 1 | import '../styles/globals.css' 2 | 3 | function MyApp({ Component, pageProps }) { 4 | return 5 | } 6 | 7 | export default MyApp 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/storybook/templates/.storybook/main.js: -------------------------------------------------------------------------------- 1 | const { getStoriesPaths } = require('slice-machine-ui/helpers/storybook') 2 | 3 | module.exports = { 4 | stories: [ 5 | ...getStoriesPaths(), 6 | ] 7 | } -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/pages/api/hello.js: -------------------------------------------------------------------------------- 1 | // Next.js API route support: https://nextjs.org/docs/api-routes/introduction 2 | 3 | export default (req, res) => { 4 | res.statusCode = 200 5 | res.json({ name: 'John Doe' }) 6 | } 7 | -------------------------------------------------------------------------------- /packages/generator-prismic-nodejs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017", 8 | // "esModuleInterop": true 9 | }, 10 | } -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/slicemachine/templates/sm.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiEndpoint": "https://<%= domain %>.cdn.prismic.io/api/v2", 3 | "libraries": [ 4 | <% if (typeof defaultLibrary != 'undefined' && defaultLibrary) { %>"<%= defaultLibrary %>"<% } %> 5 | ] 6 | } -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/sm.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiEndpoint": "https://<%= domain %>.cdn.prismic.io/api/v2", 3 | "libraries": [ 4 | <% if (typeof defaultLibrary != 'undefined' && defaultLibrary) { %>"<%= defaultLibrary %>"<% } %> 5 | ] 6 | } -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/components/README.md: -------------------------------------------------------------------------------- 1 | # COMPONENTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | The components directory contains your Vue.js Components. 6 | 7 | _Nuxt.js doesn't supercharge these components._ 8 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "app/templates" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/generator-prismic-vue/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "generators/app/templates" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/generator-prismic-angular2/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "generators/app/templates" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "generators/app/templates" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/generator-prismic-react/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "generators/app/templates" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017", 8 | // "esModuleInterop": true 9 | }, 10 | "exclude": ["test"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/slicemachine/templates/sm.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiEndpoint": "https://<%%= domain %>.cdn.prismic.io/api/v2", 3 | "libraries": [ 4 | <%% if (typeof defaultLibrary != 'undefined' && defaultLibrary) { %>"<%%= defaultLibrary %>"<%% } %> 5 | ] 6 | } -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/slicemachine/templates/sm.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiEndpoint": "https://<%%= domain %>.cdn.prismic.io/api/v2", 3 | "libraries": [ 4 | <%% if (typeof defaultLibrary != 'undefined' && defaultLibrary) { %>"<%%= defaultLibrary %>"<%% } %> 5 | ] 6 | } -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "generators/app/templates", 11 | "test" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/index.ts: -------------------------------------------------------------------------------- 1 | import * as AdmZip from 'adm-zip' 2 | import * as path from 'path' 3 | 4 | const Theme = new AdmZip() 5 | const themePath = path.resolve(__dirname, 'fake-theme-master') 6 | 7 | Theme.addLocalFolder(themePath, 'fake-theme-master') 8 | 9 | export { 10 | Theme, 11 | } 12 | 13 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/layouts/README.md: -------------------------------------------------------------------------------- 1 | # LAYOUTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Application Layouts. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts). 8 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "strict": true, 7 | "target": "es2017" 8 | }, 9 | "exclude": [ 10 | "generators/app/templates", 11 | "test" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/prismic-cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "importHelpers": true, 5 | "module": "commonjs", 6 | "outDir": "lib", 7 | "rootDir": "src", 8 | "strict": true, 9 | "target": "es2017", 10 | // "esModuleInterop": true 11 | }, 12 | "include": [ 13 | "src/**/*" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/pages/README.md: -------------------------------------------------------------------------------- 1 | # PAGES 2 | 3 | This directory contains your Application Views and Routes. 4 | The framework reads all the `*.vue` files inside this directory and creates the router of your application. 5 | 6 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing). 7 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/assets/README.md: -------------------------------------------------------------------------------- 1 | # ASSETS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked). 8 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/plugins/README.md: -------------------------------------------------------------------------------- 1 | # PLUGINS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains Javascript plugins that you want to run before mounting the root Vue.js application. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins). 8 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/styles/globals.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 6 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 7 | } 8 | 9 | a { 10 | color: inherit; 11 | text-decoration: none; 12 | } 13 | 14 | * { 15 | box-sizing: border-box; 16 | } 17 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/cookie.ts: -------------------------------------------------------------------------------- 1 | import * as cookie from 'cookie' 2 | 3 | const noEscape = (str: any) => str 4 | 5 | export const parse = (cookieString: string, opts?: cookie.CookieParseOptions) => cookie.parse(cookieString, {decode: noEscape, ...opts}) 6 | 7 | export const serialize = (name: string, value: string, opts?: cookie.CookieSerializeOptions) => cookie.serialize(name, value, {encode: noEscape, ...opts}) 8 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuxt-template", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "nuxt", 7 | "build": "nuxt build", 8 | "start": "nuxt start", 9 | "generate": "nuxt generate" 10 | }, 11 | "dependencies": { 12 | "core-js": "^3.8.3", 13 | "nuxt": "^2.14.12" 14 | }, 15 | "devDependencies": {} 16 | } -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/create-slice/templates/library/slice/index.stories.js: -------------------------------------------------------------------------------- 1 | import MyComponent from './<%- pathToComponentFromStory %>'; 2 | 3 | export default { 4 | title: '<%- componentTitle %>' 5 | } 6 | 7 | <% mocks.forEach((variation) => { %> 8 | export const <%- variation.id %> = () => } /> 9 | <%- variation.id %>.storyName = '<%- variation.name %>' 10 | <% }) %> 11 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/middleware/README.md: -------------------------------------------------------------------------------- 1 | # MIDDLEWARE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your application middleware. 6 | Middleware let you define custom functions that can be run before rendering either a page or a group of pages. 7 | 8 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing#middleware). 9 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-master/custom_types/index.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "homepage", 4 | "name": "Homepage", 5 | "repeatable": false, 6 | "value": "homepage.json" 7 | }, 8 | { 9 | "id": "page", 10 | "name": "Page", 11 | "repeatable": true, 12 | "value": "page.json" 13 | }, 14 | { 15 | "id": "top_menu", 16 | "name": "Top Menu", 17 | "repeatable": false, 18 | "value": "top_menu.json" 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/create-slice/templates/library/slice/index.stories.js: -------------------------------------------------------------------------------- 1 | import MyComponent from './<%%- pathToComponentFromStory %>'; 2 | 3 | export default { 4 | title: '<%%- componentTitle %>' 5 | } 6 | 7 | <%% mocks.forEach((variation) => { %> 8 | export const <%%- variation.id %> = () => } /> 9 | <%%- variation.id %>.storyName = '<%%- variation.name %>' 10 | <%% }) %> -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/create-slice/templates/library/slice/index.stories.js: -------------------------------------------------------------------------------- 1 | import MyComponent from './<%%- pathToComponentFromStory %>'; 2 | 3 | export default { 4 | title: '<%%- componentTitle %>' 5 | } 6 | 7 | <%% mocks.forEach((variation) => { %> 8 | export const <%%- variation.id %> = () => } /> 9 | <%%- variation.id %>.storyName = '<%%- variation.name %>' 10 | <%% }) %> -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/custom_types/index.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "homepage", 4 | "name": "Homepage", 5 | "repeatable": false, 6 | "value": "homepage.json" 7 | }, 8 | { 9 | "id": "page", 10 | "name": "Page", 11 | "repeatable": true, 12 | "value": "page.json" 13 | }, 14 | { 15 | "id": "top_menu", 16 | "name": "Top Menu", 17 | "repeatable": false, 18 | "value": "top_menu.json" 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-master/custom_types/index.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "homepage", 4 | "name": "Homepage", 5 | "repeatable": false, 6 | "value": "homepage.json" 7 | }, 8 | { 9 | "id": "page", 10 | "name": "Page", 11 | "repeatable": true, 12 | "value": "page.json" 13 | }, 14 | { 15 | "id": "top_menu", 16 | "name": "Top Menu", 17 | "repeatable": false, 18 | "value": "top_menu.json" 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/store/README.md: -------------------------------------------------------------------------------- 1 | # STORE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Vuex Store files. 6 | Vuex Store option is implemented in the Nuxt.js framework. 7 | 8 | Creating a file in this directory automatically activates the option in the framework. 9 | 10 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store). 11 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/logout.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import {Command} from '../prismic' 3 | 4 | export default class Logout extends Command { 5 | static description = 'Log out of Prismic.' 6 | 7 | static flags = { 8 | help: flags.help({char: 'h'}), // -h causes errors? 9 | } 10 | 11 | async run() { 12 | this.parse(Logout) 13 | /* istanbul ignore next: covered else where */ 14 | return this.prismic.logout().then(() => this.log('Logged out')) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/list.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | 3 | describe('list', () => { 4 | test 5 | .stdout() 6 | .command(['list']) 7 | .it('lists local generators', ctx => { 8 | expect(ctx.stdout).to.contain('Next') 9 | expect(ctx.stdout).to.contain('Nuxt') 10 | expect(ctx.stdout).to.contain('React') 11 | expect(ctx.stdout).to.contain('Vue') 12 | expect(ctx.stdout).to.contain('Angular2') 13 | expect(ctx.stdout).to.contain('NodeJS') 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/static/README.md: -------------------------------------------------------------------------------- 1 | # STATIC 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your static files. 6 | Each file inside this directory is mapped to `/`. 7 | Thus you'd want to delete this README.md before deploying to production. 8 | 9 | Example: `/static/robots.txt` is mapped as `/robots.txt`. 10 | 11 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static). 12 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= packageName %>", 3 | "version": "1.0.0", 4 | "main": "generators/app", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@prismicio/prismic-yeoman-generator": "^4.0.0" <% if(slicemachine) { %>, 15 | "inquirer": "^7.3.3", 16 | "is-valid-path": "^0.1.1", 17 | "sm-commons": "^0.0.23" <% } %> 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | os: 3 | - linux 4 | # - osx 5 | 6 | node_js: 7 | - node 8 | - 16 9 | - 14 10 | 11 | jobs: 12 | include: 13 | - os: windows 14 | env: YARN_GPG=no # so windows exits 15 | 16 | - os: windows 17 | node_js: 16 18 | env: YARN_GPG=no # so windows exits 19 | 20 | - os: windows 21 | node_js: 14 22 | env: YARN_GPG=no # so windows exits 23 | 24 | 25 | cache: yarn 26 | 27 | script: 28 | - ./packages/prismic-cli/bin/run --version 29 | - ./packages/prismic-cli/bin/run --help 30 | - yarn run test 31 | 32 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * as fs from './fs' 2 | 3 | export function parseJson(jsonString: string): Promise { 4 | return new Promise((resolve, reject) => { 5 | try { 6 | const obj: T = JSON.parse(jsonString) 7 | return resolve(obj) 8 | } catch (error) /* istanbul ignore next */ { 9 | return reject(error) 10 | } 11 | }) 12 | } 13 | 14 | export function parseJsonSync(jsonString: string): T { 15 | const obj: T = JSON.parse(jsonString) 16 | return obj 17 | } 18 | 19 | // proxies to prevent mocking of node.js internal functions. 20 | 21 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # vercel 34 | .vercel 35 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/create-slice/templates/library/slice/mocks.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "variation": "default-slice", 3 | "name": "Default slice", 4 | "docURL": "...", 5 | "version": "sktwi1xtmkfgx8626", 6 | "description": "<%= description %>", 7 | "primary": { 8 | "title": [{ 9 | "type": "heading1", 10 | "text": "This is where it all begins...", 11 | "spans": [] 12 | }], 13 | "description": [{ 14 | "type": "paragraph", 15 | "text": "start by editing this slice from inside the SliceMachine builder!", 16 | "spans": [] 17 | }] 18 | } 19 | }] 20 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/create-slice/templates/library/slice/mocks.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "variation": "default-slice", 3 | "name": "Default slice", 4 | "docURL": "...", 5 | "version": "sktwi1xtmkfgx8626", 6 | "description": "<%= description %>", 7 | "primary": { 8 | "title": [{ 9 | "type": "heading1", 10 | "text": "This is where it all begins...", 11 | "spans": [] 12 | }], 13 | "description": [{ 14 | "type": "paragraph", 15 | "text": "start by editing this slice from inside the SliceMachine builder!", 16 | "spans": [] 17 | }] 18 | } 19 | }] 20 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/pages/_app.js: -------------------------------------------------------------------------------- 1 | // pages/_app.js 2 | import React from 'react' 3 | import NextApp from 'next/app' 4 | 5 | import { theme } from 'essential-slices'// this is new 6 | 7 | import { ThemeProvider, BaseStyles } from 'theme-ui' // this is new 8 | 9 | export default class App extends NextApp { 10 | render() { 11 | const { Component, pageProps } = this.props 12 | return ( 13 | 14 | 15 | 16 | 17 | 18 | ) 19 | } 20 | } -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/create-slice/templates/library/slice/mocks.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "variation": "default-slice", 3 | "name": "Default slice", 4 | "docURL": "...", 5 | "version": "sktwi1xtmkfgx8626", 6 | "description": "<%%= description %>", 7 | "primary": { 8 | "title": [{ 9 | "type": "heading1", 10 | "text": "This is where it all begins...", 11 | "spans": [] 12 | }], 13 | "description": [{ 14 | "type": "paragraph", 15 | "text": "start by editing this slice from inside the SliceMachine builder!", 16 | "spans": [] 17 | }] 18 | } 19 | }] 20 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/create-slice/templates/library/slice/mocks.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "variation": "default-slice", 3 | "name": "Default slice", 4 | "docURL": "...", 5 | "version": "sktwi1xtmkfgx8626", 6 | "description": "<%%= description %>", 7 | "primary": { 8 | "title": [{ 9 | "type": "heading1", 10 | "text": "This is where it all begins...", 11 | "spans": [] 12 | }], 13 | "description": [{ 14 | "type": "paragraph", 15 | "text": "start by editing this slice from inside the SliceMachine builder!", 16 | "spans": [] 17 | }] 18 | } 19 | }] 20 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/logout.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | import Logout from '../../src/commands/logout' 3 | import * as sinon from 'sinon' 4 | 5 | import {fs} from '../../src/utils' 6 | 7 | describe('logout', () => { 8 | test.it('lgout flags', () => { 9 | expect(Logout.flags.help).exist 10 | }) 11 | 12 | const fakeUnlink = sinon.fake.resolves(null) 13 | 14 | test 15 | .stdout() 16 | .stub(fs, 'unlink', fakeUnlink) 17 | .command(['logout']) 18 | .do(ctx => { 19 | expect(fakeUnlink.called).to.be.true 20 | expect(ctx.stdout).to.contain('Logged out') 21 | }) 22 | .it('runs logout') 23 | }) 24 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nodejs-sdk-master/custom_types/page.json: -------------------------------------------------------------------------------- 1 | { 2 | "Get Started" : { 3 | "uid" : { 4 | "type" : "UID", 5 | "config" : { 6 | "placeholder" : "UID" 7 | } 8 | }, 9 | "image" : { 10 | "type" : "Image" 11 | }, 12 | "title" : { 13 | "type" : "StructuredText", 14 | "config" : { 15 | "single" : "heading1", 16 | "placeholder" : "Title..." 17 | } 18 | }, 19 | "description" : { 20 | "type" : "StructuredText", 21 | "config" : { 22 | "multi" : "paragraph,em,strong,hyperlink", 23 | "placeholder" : "Description..." 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nodejs-sdk-master/prismic-configuration.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | apiEndpoint: 'https://your-repo-name.prismic.io/api/v2', 4 | 5 | // -- Access token if the Master is not open 6 | // accessToken: 'xxxxxx', 7 | 8 | // OAuth 9 | // clientId: 'xxxxxx', 10 | // clientSecret: 'xxxxxx', 11 | 12 | // -- Links resolution rules 13 | // This function will be used to generate links to Prismic.io documents 14 | // As your project grows, you should update this function according to your routes 15 | linkResolver(doc) { 16 | if (doc.type === 'page') { 17 | return `/page/${doc.uid}` 18 | } 19 | 20 | return '/' 21 | }, 22 | } 23 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/whoami.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import {Command} from '../prismic' 3 | 4 | export default class Whoami extends Command { 5 | static description = 'Shows the email of the current user.' 6 | 7 | static flags = { 8 | help: flags.help({char: 'h'}), 9 | } 10 | 11 | async run() { 12 | return this.prismic.validateSession() 13 | .then(res => { 14 | return this.log(res.data.email) 15 | }) 16 | .catch(error => { 17 | const status = error?.response?.status || 100 18 | if (Math.floor(status / 100) === 4) { 19 | return this.log('Not logged in') 20 | } 21 | throw error 22 | }) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/fs.ts: -------------------------------------------------------------------------------- 1 | // proxies to prevent mocking of node.js functions. 2 | /** 3 | * import { readFile } from ../utls 4 | * */ 5 | 6 | import * as fs from 'fs' 7 | 8 | export const readFile = fs.promises.readFile 9 | 10 | export const writeFile = fs.promises.writeFile 11 | 12 | export const unlink = fs.promises.unlink 13 | 14 | export const rmdir = fs.promises.rmdir 15 | 16 | export const mkdir = fs.promises.mkdir 17 | 18 | export const readFileSync = fs.readFileSync 19 | 20 | export const writeFileSync = fs.writeFileSync 21 | 22 | export const existsSync = fs.existsSync 23 | 24 | export const createWriteStream = fs.createWriteStream 25 | 26 | export {copy} from 'fs-extra' 27 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/list.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import {Command} from './../prismic' 3 | import {names} from '../prismic/yeoman-env' 4 | 5 | export default class List extends Command { 6 | static description = 'List all the available project template generators.' 7 | 8 | static flags = { 9 | help: flags.help({char: 'h'}), 10 | } 11 | 12 | async run() { 13 | const generators = names.map(name => { 14 | const nameWithOutPrismicPrefix = name.replace('prismic-', '').replace(/js$/i, 'JS') 15 | return nameWithOutPrismicPrefix.charAt(0).toUpperCase() + nameWithOutPrismicPrefix.slice(1) 16 | }) 17 | 18 | generators.forEach(d => this.log(d)) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/template.ts: -------------------------------------------------------------------------------- 1 | import * as AdmZip from 'adm-zip' 2 | import * as path from 'path' 3 | 4 | const nodejsPath = path.resolve(__dirname, 'nodejs-sdk-master') 5 | const NodeJS = new AdmZip() 6 | 7 | NodeJS.addLocalFolder(nodejsPath, 'nodejs-sdk-master') 8 | 9 | const Theme = new AdmZip() 10 | const themePath = path.resolve(__dirname, 'fake-theme-master') 11 | 12 | Theme.addLocalFolder(themePath, 'fake-theme-master') 13 | 14 | const ThemeWithConfig = new AdmZip() 15 | const themeWithConfigPath = path.resolve(__dirname, 'fake-theme-with-config-master') 16 | 17 | ThemeWithConfig.addLocalFolder(themeWithConfigPath, 'fake-theme-with-config-master') 18 | 19 | export { 20 | Theme, 21 | ThemeWithConfig, 22 | NodeJS, 23 | } 24 | 25 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/create-slice/templates/library/slice/index.stories.js: -------------------------------------------------------------------------------- 1 | import MyComponent from './<%- pathToComponentFromStory %>'; 2 | import SliceZone from 'vue-slicezone' 3 | 4 | export default { 5 | title: '<%- componentTitle %>' 6 | } 7 | 8 | <% mocks.forEach((variation) => { %> 9 | export const <%- variation.id %> = () => ({ 10 | components: { 11 | MyComponent, 12 | SliceZone 13 | }, 14 | methods: { 15 | resolve() { 16 | return MyComponent 17 | } 18 | }, 19 | data() { 20 | return { 21 | mock: <%- JSON.stringify(variation) %> 22 | } 23 | }, 24 | template: '' 25 | }) 26 | <%- variation.id %>.storyName = '<%- variation.name %>' 27 | <% }) %> -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/pages/_document.js: -------------------------------------------------------------------------------- 1 | // pages/_document.js 2 | import Document, { Html, Head, Main, NextScript } from 'next/document' 3 | import { InitializeColorMode } from 'theme-ui' 4 | 5 | import { createResolver } from 'next-slicezone/resolver' 6 | 7 | export default class extends Document { 8 | static async getInitialProps(ctx) { 9 | const initialProps = await Document.getInitialProps(ctx) 10 | await createResolver() 11 | return { ...initialProps } 12 | } 13 | 14 | render() { 15 | return ( 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | ) 25 | } 26 | } -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | .env 40 | -------------------------------------------------------------------------------- /packages/prismic-cli/.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | __tmp__ 40 | __e2e__ 41 | .env 42 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/create-slice/templates/library/slice/index.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 22 | 23 | 38 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/pages/[uid].js: -------------------------------------------------------------------------------- 1 | import { Client } from '../prismic' 2 | import SliceZone from 'next-slicezone' 3 | import { useGetStaticProps, useGetStaticPaths } from 'next-slicezone/hooks' 4 | 5 | import resolver from <% if (useSrc === true) { %> '../../sm-resolver' <% } else { %> '../sm-resolver' <% } %> 6 | 7 | const Page = (props) => 8 | 9 | 10 | // Fetch content from prismic 11 | export const getStaticProps = useGetStaticProps({ 12 | client: Client(), 13 | uid: ({ params }) => params.uid 14 | }) 15 | 16 | export const getStaticPaths = useGetStaticPaths({ 17 | client: Client(), 18 | type: 'page', 19 | fallback: true,// process.env.NODE_ENV === 'development', 20 | formatPath: ({ uid }) => ({ params: { uid }}) 21 | }) 22 | 23 | export default Page -------------------------------------------------------------------------------- /packages/prismic-generator-generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@prismicio/prismic-generator-generator", 3 | "version": "4.2.1", 4 | "main": "app", 5 | "author": "MarcMcIntosh", 6 | "license": "Apache-2.0", 7 | "files": [ 8 | "app" 9 | ], 10 | "scripts": { 11 | "clean": "rimraf !app/**/templates app/index.js app/index.d.ts", 12 | "prepack": "rimraf !app/**/templates app/index.js app/index.d.ts && tsc -b", 13 | "test": "echo \"Error: no test specified\" && exit 0" 14 | }, 15 | "dependencies": { 16 | "inquirer": "^7.3.3", 17 | "tslib": "^1", 18 | "yeoman-generator": "^4.11.3" 19 | }, 20 | "devDependencies": { 21 | "@types/node": "^14.14.10", 22 | "@types/yeoman-generator": "^4.11.3", 23 | "rimraf": "^3.0.2", 24 | "typescript": "^3.3" 25 | }, 26 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 27 | } 28 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-master/custom_types/top_menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "Main": { 3 | "display_title": { 4 | "type": "StructuredText", 5 | "config": { 6 | "single": "heading1", 7 | "label": "display_title" 8 | } 9 | }, 10 | "menu_links": { 11 | "type": "Group", 12 | "config": { 13 | "fields": { 14 | "label": { 15 | "type": "StructuredText", 16 | "config": { 17 | "single": "paragraph", 18 | "label": "label" 19 | } 20 | }, 21 | "link": { 22 | "type": "Link", 23 | "config": { 24 | "label": "link", 25 | "placeholder": "Select a Link..." 26 | } 27 | } 28 | }, 29 | "label": "menu_links" 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "devDependencies": { 5 | "@commitlint/cli": "^11.0.0", 6 | "@commitlint/config-conventional": "^11.0.0", 7 | "eslint": "^7", 8 | "eslint-config-oclif": "^3.1", 9 | "eslint-config-oclif-typescript": "^0.1", 10 | "husky": "^6.0.0", 11 | "lerna": "^3.22.1", 12 | "lint-staged": "^11.1.2" 13 | }, 14 | "workspaces": [ 15 | "packages/*" 16 | ], 17 | "commitlint": { 18 | "extends": [ 19 | "@commitlint/config-conventional" 20 | ] 21 | }, 22 | "lint-staged": { 23 | "*.ts": "yarn posttest" 24 | }, 25 | "scripts": { 26 | "clean": "yarn workspaces run clean", 27 | "prepack": "yarn workspaces run prepack", 28 | "test": "yarn workspaces run test", 29 | "posttest": "eslint . --ext .ts --config .eslintrc", 30 | "prepare": "husky install" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/custom_types/top_menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "Main": { 3 | "display_title": { 4 | "type": "StructuredText", 5 | "config": { 6 | "single": "heading1", 7 | "label": "display_title" 8 | } 9 | }, 10 | "menu_links": { 11 | "type": "Group", 12 | "config": { 13 | "fields": { 14 | "label": { 15 | "type": "StructuredText", 16 | "config": { 17 | "single": "paragraph", 18 | "label": "label" 19 | } 20 | }, 21 | "link": { 22 | "type": "Link", 23 | "config": { 24 | "label": "link", 25 | "placeholder": "Select a Link..." 26 | } 27 | } 28 | }, 29 | "label": "menu_links" 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-master/custom_types/top_menu.json: -------------------------------------------------------------------------------- 1 | { 2 | "Main": { 3 | "display_title": { 4 | "type": "StructuredText", 5 | "config": { 6 | "single": "heading1", 7 | "label": "display_title" 8 | } 9 | }, 10 | "menu_links": { 11 | "type": "Group", 12 | "config": { 13 | "fields": { 14 | "label": { 15 | "type": "StructuredText", 16 | "config": { 17 | "single": "paragraph", 18 | "label": "label" 19 | } 20 | }, 21 | "link": { 22 | "type": "Link", 23 | "config": { 24 | "label": "link", 25 | "placeholder": "Select a Link..." 26 | } 27 | } 28 | }, 29 | "label": "menu_links" 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/generator-prismic-vue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-prismic-vue", 3 | "version": "4.2.3", 4 | "main": "generators/app/index.js", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@prismicio/prismic-yeoman-generator": "4.2.3", 15 | "tslib": "^1" 16 | }, 17 | "devDependencies": { 18 | "@types/node": "^14.14.10", 19 | "rimraf": "^3.0.2", 20 | "typescript": "^3.3" 21 | }, 22 | "scripts": { 23 | "clean": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates", 24 | "prepack": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates && tsc -b", 25 | "test": "echo \"Error: no test specified\" && exit 0" 26 | }, 27 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 28 | } 29 | -------------------------------------------------------------------------------- /packages/generator-prismic-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-prismic-react", 3 | "version": "4.2.3", 4 | "main": "generators/app/index.js", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@prismicio/prismic-yeoman-generator": "4.2.3", 15 | "tslib": "^1" 16 | }, 17 | "devDependencies": { 18 | "@types/node": "^14.14.10", 19 | "rimraf": "^3.0.2", 20 | "typescript": "^3.3" 21 | }, 22 | "scripts": { 23 | "clean": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates", 24 | "prepack": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates && tsc -b", 25 | "test": "echo \"Error: no test specified\" && exit 0" 26 | }, 27 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 28 | } 29 | -------------------------------------------------------------------------------- /packages/generator-prismic-angular2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-prismic-angular2", 3 | "version": "4.2.3", 4 | "main": "generators/app/index.js", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@prismicio/prismic-yeoman-generator": "4.2.3", 15 | "tslib": "^1" 16 | }, 17 | "devDependencies": { 18 | "@types/node": "^14.14.10", 19 | "rimraf": "^3.0.2", 20 | "typescript": "^3.3" 21 | }, 22 | "scripts": { 23 | "clean": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates", 24 | "test": "echo \"Error: no test specified\" && exit 0", 25 | "prepack": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates && tsc -b" 26 | }, 27 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 28 | } 29 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= packageName %>", 3 | "version": "1.0.0", 4 | "main": "generators/app", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@prismicio/prismic-yeoman-generator": "^4.0.0", <% if(slicemachine) { %> 15 | "inquirer": "^7.3.3", 16 | "is-valid-path": "^0.1.1", 17 | "sm-commons": "^0.0.23",<% } %> 18 | "tslib": "^1" 19 | }, 20 | "devDependencies": { 21 | "@types/node": "^14.14.10", 22 | "del-cli": "^3.0.1", 23 | "typescript": "^3.3" 24 | }, 25 | "scripts": { 26 | "clean": "del-cli generators/**/*.js generators/**/*.d.tsm !generators/**/templates/**/*.js", 27 | "prepack": "del-cli generators/**/*.js generators/**/*.d.ts !generators/**/templates/**/*.js' && tsc -b" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/README.md: -------------------------------------------------------------------------------- 1 |

Welcome to @prismicio/prismic-yeoman-generator 👋

2 |

3 | Version 4 | 5 | 6 | License: Apache--2.0 7 | 8 |

9 | 10 | > custom yeoman generator for building projects with prismic this provides methods that help write yeoman generators for prismic projects 11 | 12 | ## Install 13 | 14 | ```sh 15 | yarn install @prismicio/prismic-yeoman-generator 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```js 21 | 22 | import Generator from '@prismicio/prismic-yeoman-generator' 23 | 24 | export default class extends Generator {} 25 | 26 | ``` 27 | 28 | ## Run tests 29 | 30 | ```sh 31 | yarn test 32 | ``` 33 | 34 | 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # /package-lock.json 2 | # Compiled binary addons (http://nodejs.org/api/addons.html) 3 | # Coverage directory used by tools like istanbul 4 | # Dependency directories 5 | # Directory for instrumented libs generated by jscoverage/JSCover 6 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 7 | # Logs 8 | # MAC OS X 9 | # Optional REPL history 10 | # Optional npm cache directory 11 | # Runtime data 12 | # bin folder 13 | # env 14 | .env 15 | 16 | # node-waf configuration 17 | # nyc test coverage 18 | # temp folder for tests 19 | *-debug.log 20 | *-error.log 21 | *.log 22 | *.pid 23 | *.seed 24 | .DS_Store 25 | 26 | .grunt 27 | .lock-wscript 28 | .node_repl_history 29 | .npm 30 | .nyc_output 31 | /.nyc_output 32 | /dist 33 | /lib 34 | /package-lock.json 35 | /tmp 36 | __tmp__ 37 | build/Release 38 | coverage 39 | jspm_packages 40 | lib-cov 41 | logs 42 | node_modules 43 | npm-debug.log* 44 | pids 45 | 46 | #/old 47 | .metals -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/create-slice/templates/library/slice/model.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "<%= sliceId %>", 3 | "type": "SharedSlice", 4 | "name": "<%= sliceName %>", 5 | "description": "<%= description %>", 6 | "variations": [{ 7 | "id": "default", 8 | "name": "Default Slice", 9 | "docURL": "...", 10 | "version": "sktwi1xtmkfgx8626", 11 | "description": "<%= description %>", 12 | "primary": { 13 | "title": { 14 | "type": "StructuredText", 15 | "config": { 16 | "single": "heading1", 17 | "label": "Title", 18 | "placeholder": "This is where it all begins..." 19 | } 20 | }, 21 | "description": { 22 | "type": "StructuredText", 23 | "config": { 24 | "single": "paragraph", 25 | "label": "Description", 26 | "placeholder": "A nice description of your product" 27 | } 28 | } 29 | } 30 | }] 31 | } 32 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/create-slice/templates/library/slice/model.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "<%= sliceId %>", 3 | "type": "SharedSlice", 4 | "name": "<%= sliceName %>", 5 | "description": "<%= description %>", 6 | "variations": [{ 7 | "id": "default", 8 | "name": "Default Slice", 9 | "docURL": "...", 10 | "version": "sktwi1xtmkfgx8626", 11 | "description": "<%= description %>", 12 | "primary": { 13 | "title": { 14 | "type": "StructuredText", 15 | "config": { 16 | "single": "heading1", 17 | "label": "Title", 18 | "placeholder": "This is where it all begins..." 19 | } 20 | }, 21 | "description": { 22 | "type": "StructuredText", 23 | "config": { 24 | "single": "paragraph", 25 | "label": "Description", 26 | "placeholder": "A nice description of your product" 27 | } 28 | } 29 | } 30 | }] 31 | } 32 | -------------------------------------------------------------------------------- /packages/prismic-cli/.gitignore: -------------------------------------------------------------------------------- 1 | # /package-lock.json 2 | # Compiled binary addons (http://nodejs.org/api/addons.html) 3 | # Coverage directory used by tools like istanbul 4 | # Dependency directories 5 | # Directory for instrumented libs generated by jscoverage/JSCover 6 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 7 | # Logs 8 | # MAC OS X 9 | # Optional REPL history 10 | # Optional npm cache directory 11 | # Runtime data 12 | # bin folder 13 | # env 14 | .env 15 | 16 | # node-waf configuration 17 | # nyc test coverage 18 | # temp folder for tests 19 | *-debug.log 20 | *-error.log 21 | *.log 22 | *.pid 23 | *.seed 24 | .DS_Store 25 | 26 | .grunt 27 | .lock-wscript 28 | .node_repl_history 29 | .npm 30 | .nyc_output 31 | /.nyc_output 32 | /dist 33 | /lib 34 | /package-lock.json 35 | /tmp 36 | __tmp__ 37 | build/Release 38 | coverage 39 | jspm_packages 40 | lib-cov 41 | logs 42 | node_modules 43 | npm-debug.log* 44 | pids 45 | 46 | oclif.manifest.json -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/create-slice/templates/library/slice/model.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "<%%= sliceId %>", 3 | "type": "SharedSlice", 4 | "name": "<%%= sliceName %>", 5 | "description": "<%%= description %>", 6 | "variations": [{ 7 | "id": "default", 8 | "name": "Default Slice", 9 | "docURL": "...", 10 | "version": "sktwi1xtmkfgx8626", 11 | "description": "<%%= description %>", 12 | "primary": { 13 | "title": { 14 | "type": "StructuredText", 15 | "config": { 16 | "single": "heading1", 17 | "label": "Title", 18 | "placeholder": "This is where it all begins..." 19 | } 20 | }, 21 | "description": { 22 | "type": "StructuredText", 23 | "config": { 24 | "single": "paragraph", 25 | "label": "Description", 26 | "placeholder": "A nice description of your product" 27 | } 28 | } 29 | } 30 | }] 31 | } 32 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/create-slice/templates/library/slice/model.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "<%%= sliceId %>", 3 | "type": "SharedSlice", 4 | "name": "<%%= sliceName %>", 5 | "description": "<%%= description %>", 6 | "variations": [{ 7 | "id": "default", 8 | "name": "Default Slice", 9 | "docURL": "...", 10 | "version": "sktwi1xtmkfgx8626", 11 | "description": "<%%= description %>", 12 | "primary": { 13 | "title": { 14 | "type": "StructuredText", 15 | "config": { 16 | "single": "heading1", 17 | "label": "Title", 18 | "placeholder": "This is where it all begins..." 19 | } 20 | }, 21 | "description": { 22 | "type": "StructuredText", 23 | "config": { 24 | "single": "paragraph", 25 | "label": "Description", 26 | "placeholder": "A nice description of your product" 27 | } 28 | } 29 | } 30 | }] 31 | } 32 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/create-slice/templates/library/slice/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { RichText } from 'prismic-reactjs'; 3 | 4 | const <%= sliceName %> = ({ slice }) => ( 5 |
6 | 7 | { 8 | slice.primary.title ? 9 | 10 | :

Template slice, update me!

11 | } 12 |
13 | { 14 | slice.primary.description ? 15 | 16 | :

start by editing this slice from inside the SliceMachine builder!

17 | } 18 | 28 |
29 | ); 30 | 31 | <%= sliceName %>.displayName = <%= sliceName %> 32 | 33 | export default <%= sliceName %>; 34 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/data-dog.ts: -------------------------------------------------------------------------------- 1 | import axios, {AxiosResponse} from 'axios' 2 | import PrismicCommand from './../prismic/base-command' 3 | import {serializeError} from 'serialize-error' 4 | 5 | export default async function datadog(error: string | Error, payload: PrismicCommand): Promise { 6 | const maybeError = typeof error === 'string' ? {} : serializeError(error) 7 | 8 | const sainPayload = { 9 | ...maybeError, 10 | context: { 11 | ...payload, 12 | config: { 13 | ...payload.config, 14 | plugins: [], 15 | pjson: {}, 16 | }, 17 | }, 18 | } 19 | 20 | const data = { 21 | alert_type: 'error', 22 | priority: 'normal', 23 | source_type_name: 'NODE', 24 | host: 'prismic-cli', 25 | date_happened: Date.now(), 26 | title: typeof error === 'string' ? error : error.message, 27 | text: sainPayload, 28 | } 29 | return axios.post('https://ykz3r8yyd6.execute-api.us-east-1.amazonaws.com/stage/', data) 30 | } 31 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/prismic/yeoman-env.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable unicorn/no-abusive-eslint-disable, @typescript-eslint/ban-ts-ignore */ 2 | 3 | import {createEnv, GeneratorMeta} from 'yeoman-environment' 4 | 5 | const env = createEnv() 6 | 7 | export const all = env.lookup({ 8 | // @ts-ignore 9 | lookups: ['generators'], 10 | packagePatterns: ['generator-prismic-*'], 11 | }) 12 | 13 | export const names = env.getGeneratorNames() // names of the generators 14 | 15 | export const meta = env.getGeneratorsMeta() // local first logic 16 | 17 | export function filterMetaFor(generatorsMeta: Record, subGeneratorName: string): Record { 18 | return Object.entries(generatorsMeta) 19 | .reduce>((acc, [key, value]) => { 20 | if (key.endsWith(`:${subGeneratorName}`)) { 21 | return {...acc, [key]: value} 22 | } 23 | return acc 24 | }, {}) 25 | } 26 | 27 | export const apps = filterMetaFor(meta, 'app') 28 | 29 | export default env 30 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/components/Logo.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 30 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/.gitignore: -------------------------------------------------------------------------------- 1 | # /package-lock.json 2 | # Compiled binary addons (http://nodejs.org/api/addons.html) 3 | # Coverage directory used by tools like istanbul 4 | # Dependency directories 5 | # Directory for instrumented libs generated by jscoverage/JSCover 6 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 7 | # Logs 8 | # MAC OS X 9 | # Optional REPL history 10 | # Optional npm cache directory 11 | # Runtime data 12 | # bin folder 13 | # env 14 | .env 15 | 16 | # node-waf configuration 17 | # nyc test coverage 18 | # temp folder for tests 19 | *-debug.log 20 | *-error.log 21 | *.log 22 | *.pid 23 | *.seed 24 | .DS_Store 25 | 26 | .grunt 27 | .lock-wscript 28 | .node_repl_history 29 | .npm 30 | .nyc_output 31 | /.nyc_output 32 | /dist 33 | /lib 34 | src/*.js 35 | src/*.d.ts 36 | /package-lock.json 37 | /tmp 38 | __tmp__ 39 | build/Release 40 | coverage 41 | jspm_packages 42 | lib-cov 43 | logs 44 | node_modules 45 | npm-debug.log* 46 | pids 47 | 48 | test/**/*.js 49 | test/**/*.d.ts -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-new-custom-types/customtypes/top_menu/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "top_menu", 3 | "label": "Top Menu", 4 | "repeatable": false, 5 | "json": { 6 | "Main": { 7 | "display_title": { 8 | "type": "StructuredText", 9 | "config": { 10 | "single": "heading1", 11 | "label": "display_title" 12 | } 13 | }, 14 | "menu_links": { 15 | "type": "Group", 16 | "config": { 17 | "fields": { 18 | "label": { 19 | "type": "StructuredText", 20 | "config": { 21 | "single": "paragraph", 22 | "label": "label" 23 | } 24 | }, 25 | "link": { 26 | "type": "Link", 27 | "config": { 28 | "label": "link", 29 | "placeholder": "Select a Link..." 30 | } 31 | } 32 | }, 33 | "label": "menu_links" 34 | } 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/logDecoration.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | /* Colors and effects to be used on a console.log or cli.log 4 | * example: console.log(LogDecorations., 'Prismic'); 5 | */ 6 | 7 | //TODO: This breaks eslint 8 | export const LogDecorations = { 9 | // effects 10 | Reset: '\x1b[0m', 11 | Bright: '\x1b[1m', 12 | Dim: '\x1b[2m', 13 | Underscore: '\x1b[4m', 14 | Blink: '\x1b[5m', 15 | Reverse: '\x1b[7m', 16 | Hidden: '\x1b[8m', 17 | 18 | // font color 19 | FgBlack: '\x1b[30m', 20 | FgRed: '\x1b[31m', 21 | FgGreen: '\x1b[32m', 22 | FgYellow: '\x1b[33m', 23 | FgBlue: '\x1b[34m', 24 | FgMagenta: '\x1b[35m', 25 | FgCyan: '\x1b[36m', 26 | FgWhite: '\x1b[37m', 27 | 28 | // background color 29 | BgBlack: '\x1b[40m', 30 | BgRed: '\x1b[41m', 31 | BgGreen: '\x1b[42m', 32 | BgYellow: '\x1b[43m', 33 | BgBlue: '\x1b[44m', 34 | BgMagenta: '\x1b[45m', 35 | BgCyan: '\x1b[46m', 36 | BgWhite: '\x1b[47m' 37 | } 38 | 39 | export const PRISMIC_LOG_HEADER = LogDecorations.FgMagenta + 'Prismic' + LogDecorations.Reset + ': ' -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-generator/index.js: -------------------------------------------------------------------------------- 1 | import Generator from '../../../src/generators/base' 2 | 3 | export default class extends Generator { 4 | async initializing() { 5 | // Your initialization methods (checking current project state, getting configs, etc) 6 | } 7 | async prompting() { 8 | // Where you prompt users for options (where you’d call this.prompt()) 9 | } 10 | async configuring() { 11 | // Saving configurations and configure the project (creating .editorconfig files and other metadata files) 12 | } 13 | async default() { 14 | // If the method name doesn’t match a priority, it will be pushed to this group. 15 | } 16 | async writing() { 17 | // Where you write the generator specific files (routes, controllers, etc) 18 | } 19 | async conflicts() { 20 | // Where conflicts are handled (used internally) 21 | } 22 | async install() { 23 | // Where installations are run (npm, bower) 24 | } 25 | async end() { 26 | // Called last, cleanup, say good bye, etc 27 | this.log("Done running the generator") 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/utils/framework.test.ts: -------------------------------------------------------------------------------- 1 | import {test, expect} from '@oclif/test' 2 | import {detect, parse, PkgJson} from '../../src/utils/framework' 3 | import {ProjectType} from '../../src/utils/framework/project-types' 4 | 5 | describe('utils/framework', () => { 6 | test.it('#parse', () => { 7 | expect(parse('NUXT')).equal('nuxt') 8 | expect(parse('Next')).equal('next') 9 | expect(parse('Vue.js')).equal('vue.js') 10 | expect(parse('react')).equal('react') 11 | expect(parse('svelte')).equal('svelte') 12 | expect(parse('gatsby')).equal('gatsby') 13 | expect(parse('node')).equal('node') 14 | expect(parse('go')).equal(null) 15 | }) 16 | 17 | test.it('#detect', () => { 18 | const nuxt: PkgJson = {dependencies: {nuxt: '1'}} 19 | expect(detect(nuxt)).equal(ProjectType.NUXT) 20 | 21 | expect(detect({dependencies: {lodash: '1'}})).to.be.null 22 | 23 | expect(detect({ 24 | devDependencies: {}, 25 | dependencies: {}, 26 | peerDependencies: {}, 27 | })).to.be.null 28 | 29 | expect(detect({devDependencies: {next: '1'}})).equal(ProjectType.NEXT) 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /packages/generator-prismic-nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-prismic-nodejs", 3 | "version": "4.2.3", 4 | "description": "This is a blank NodeJS (using express) project that will connect to any prismic.io repository. It uses the prismic.io JavaScript development kit, and provides a few helpers to integrate with express.", 5 | "main": "generators/app/index.js", 6 | "author": "MarcMcIntosh", 7 | "license": "Apache-2.0", 8 | "private": false, 9 | "engines": { 10 | "node": ">=14.0.0" 11 | }, 12 | "files": [ 13 | "generators" 14 | ], 15 | "dependencies": { 16 | "@prismicio/prismic-yeoman-generator": "4.2.3", 17 | "tslib": "^1" 18 | }, 19 | "devDependencies": { 20 | "@types/node": "^14.14.10", 21 | "rimraf": "^3.0.2", 22 | "typescript": "^3.3" 23 | }, 24 | "scripts": { 25 | "clean": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates", 26 | "prepack": "rimraf generators/**/*.js generators/**/*.d.ts !generators/**/templates && tsc -b", 27 | "test": "echo \"Error: no test specified\" && exit 0" 28 | }, 29 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 30 | } 31 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/nuxt.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | // Global page headers: https://go.nuxtjs.dev/config-head 3 | head: { 4 | title: 'nuxt-template', 5 | htmlAttrs: { 6 | lang: 'en' 7 | }, 8 | meta: [ 9 | { charset: 'utf-8' }, 10 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 11 | { hid: 'description', name: 'description', content: '' } 12 | ], 13 | link: [ 14 | { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 15 | ] 16 | }, 17 | 18 | // Global CSS: https://go.nuxtjs.dev/config-css 19 | css: [ 20 | ], 21 | 22 | // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins 23 | plugins: [ 24 | ], 25 | 26 | // Auto import components: https://go.nuxtjs.dev/config-components 27 | components: true, 28 | 29 | // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules 30 | buildModules: [ 31 | ], 32 | 33 | // Modules: https://go.nuxtjs.dev/config-modules 34 | modules: [ 35 | ], 36 | 37 | // Build Configuration: https://go.nuxtjs.dev/config-build 38 | build: { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/login.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import {Command} from '../prismic' 3 | import {DEFAULT_PORT} from '../utils/server' 4 | export default class Login extends Command { 5 | static description = 'Log in to Prismic.' 6 | 7 | static flags = { 8 | ...Command.flags, 9 | 10 | help: flags.help({char: 'h'}), 11 | 12 | base: flags.string({ 13 | name: 'base', 14 | hidden: true, 15 | description: 'Base URL to authenticate with.', 16 | default: 'https://prismic.io', 17 | }), 18 | 19 | port: flags.integer({ 20 | name: 'port', 21 | hidden: false, 22 | description: 'Port to start the local login server.', 23 | default: DEFAULT_PORT, 24 | }), 25 | 26 | 'auth-url': flags.string({ 27 | name: 'auth url', 28 | hidden: true, 29 | description: 'URL to validate and refresh tokens.', 30 | required: false, 31 | }), 32 | } 33 | 34 | static args = [] 35 | 36 | async run() { 37 | const {flags} = this.parse(Login) 38 | const {base, port, 'auth-url': authUrl} = flags 39 | 40 | return this.login(port, base, authUrl) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/layouts/default.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 63 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/hooks/postrun/updates.ts: -------------------------------------------------------------------------------- 1 | import {Hook} from '@oclif/config' 2 | import * as semver from 'semver' 3 | import axios from 'axios' 4 | 5 | const libnpmconfig = require('libnpmconfig') 6 | 7 | interface DistTags { 8 | latest: string; 9 | [key: string]: string; 10 | } 11 | 12 | interface PackageMetaData { 13 | name: string; 14 | 'dist-tags': DistTags; 15 | modified: string; 16 | versions: any; // package.json 17 | } 18 | 19 | const hook: Hook<'postrun'> = async function (opts) { 20 | const npmconfig = libnpmconfig.read() 21 | const registry: string = npmconfig.registry || 'https://registry.npmjs.org/' 22 | const {name, version} = opts.config.pjson 23 | 24 | const remoteVersionUrl = new URL(registry) 25 | remoteVersionUrl.pathname = name 26 | 27 | return axios.get(remoteVersionUrl.toString(), {headers: {Accept: 'application/vnd.npm.install-v1+json'}}) 28 | .then(res => res.data['dist-tags'].latest) 29 | .then(latest => { 30 | if (semver.lt(version, latest)) { 31 | // eslint-disable-next-line no-console 32 | console.info(`A new version of ${name} is available!`) 33 | // eslint-disable-next-line no-console 34 | console.info(`Update now by running "npm install -g ${name}"`) 35 | } 36 | }) 37 | .catch(() => ({})) 38 | } 39 | 40 | export default hook 41 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-prismic-nextjs", 3 | "version": "4.2.3", 4 | "main": "generators/app", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@prismicio/prismic-yeoman-generator": "4.2.3", 15 | "chalk": "^4.1.1", 16 | "inquirer": "^7.3.3", 17 | "is-valid-path": "^0.1.1", 18 | "lodash.camelcase": "^4.3.0", 19 | "sm-commons": "^0.0.23", 20 | "tslib": "^1", 21 | "yeoman-generator": "^4.12.0" 22 | }, 23 | "devDependencies": { 24 | "@types/chai": "^4", 25 | "@types/mocha": "^5", 26 | "@types/node": "^14.14.10", 27 | "chai": "^4", 28 | "del-cli": "^3.0.1", 29 | "fancy-test": "^1.4.10", 30 | "mocha": "^5", 31 | "nyc": "14", 32 | "typescript": "^3.3", 33 | "yeoman-assert": "^3.1.0", 34 | "yeoman-test": "^1.7.0" 35 | }, 36 | "scripts": { 37 | "clean": "del-cli generators/**/*.js generators/**/*.d.ts !generators/**/templates/**/*.js", 38 | "prepack": "del-cli generators/**/*.js generators/**/*.d.ts !generators/**/templates/**/*.js && tsc -b", 39 | "test": "echo \"Error: no test specified\" && exit 0" 40 | }, 41 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 42 | } 43 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-master/documents/en-us/Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Homepage","spans":[]}}],"link":{"id":"Xs5M1hEAACEAImP9","wioUrl":"wio://documents/Xs5M1hEAACEAImP9"}},{"label":[{"type":"paragraph","content":{"text":"About us","spans":[]}}],"link":{"id":"Xs5rBhEAACEAIueu","wioUrl":"wio://documents/Xs5rBhEAACEAIueu"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/sm-resolver.js: -------------------------------------------------------------------------------- 1 | import React, { Fragment } from 'react' 2 | 3 | import {libraries} from './sm.json' 4 | 5 | const __allSlices = libraries.reduce((acc, lib) => { 6 | const location = lib.replace(/^@\//, './') 7 | const slices = require(location) 8 | return {...acc, ...slices} 9 | },{}) 10 | 11 | const NotFound = ({ sliceName, slice, i }) => { 12 | console.error(`[sm-resolver] component "${sliceName}" not found at index ${i}.`) 13 | console.warn(`slice data: ${slice}`) 14 | return process.env.NODE_ENV !== 'production' ? ( 15 |
26 |

27 | Slice "{sliceName}" not found. 28 |

29 |

30 | Check that you registered this component in your slices library! 31 |

32 |
33 | ) : 34 | } 35 | 36 | export default function SliceResolver({ sliceName, ...rest }) { 37 | return __allSlices[sliceName] ? __allSlices[sliceName] : () => 38 | } 39 | 40 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-master/documents/fr-fr/Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Page accueil","spans":[]}}],"link":{"id":"Xs5SSREAACQAInz5","wioUrl":"wio://documents/Xs5SSREAACQAInz5"}},{"label":[{"type":"paragraph","content":{"text":"Propos nous","spans":[]}}],"link":{"id":"Xs5ushEAACQAIvjn","wioUrl":"wio://documents/Xs5ushEAACQAIvjn"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site Logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/documents/en-us/Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Homepage","spans":[]}}],"link":{"id":"Xs5M1hEAACEAImP9","wioUrl":"wio://documents/Xs5M1hEAACEAImP9"}},{"label":[{"type":"paragraph","content":{"text":"About us","spans":[]}}],"link":{"id":"Xs5rBhEAACEAIueu","wioUrl":"wio://documents/Xs5rBhEAACEAIueu"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-master/documents/en-us/Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Homepage","spans":[]}}],"link":{"id":"Xs5M1hEAACEAImP9","wioUrl":"wio://documents/Xs5M1hEAACEAImP9"}},{"label":[{"type":"paragraph","content":{"text":"About us","spans":[]}}],"link":{"id":"Xs5rBhEAACEAIueu","wioUrl":"wio://documents/Xs5rBhEAACEAIueu"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/fake-theme-with-config-master/documents/fr-fr/Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Page accueil","spans":[]}}],"link":{"id":"Xs5SSREAACQAInz5","wioUrl":"wio://documents/Xs5SSREAACQAInz5"}},{"label":[{"type":"paragraph","content":{"text":"Propos nous","spans":[]}}],"link":{"id":"Xs5ushEAACQAIvjn","wioUrl":"wio://documents/Xs5ushEAACQAIvjn"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site Logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-master/documents/fr-fr/Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Page accueil","spans":[]}}],"link":{"id":"Xs5SSREAACQAInz5","wioUrl":"wio://documents/Xs5SSREAACQAInz5"}},{"label":[{"type":"paragraph","content":{"text":"Propos nous","spans":[]}}],"link":{"id":"Xs5ushEAACQAIvjn","wioUrl":"wio://documents/Xs5ushEAACQAIvjn"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site Logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-new-custom-types/documents/en-us/Xs5vWREAACYAIvvr=#=Xs5vWREAACYAIvvs=#=top_menu=#=Xs5vWREAACYAIvvt=#=en-us=#=y.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Homepage","spans":[]}}],"link":{"id":"Xs5M1hEAACEAImP9","wioUrl":"wio://documents/Xs5M1hEAACEAImP9"}},{"label":[{"type":"paragraph","content":{"text":"About us","spans":[]}}],"link":{"id":"Xs5rBhEAACEAIueu","wioUrl":"wio://documents/Xs5rBhEAACEAIueu"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/test/__stubs__/fake-theme-new-custom-types/documents/fr-fr/Xs5vkREAAArQIvz4=#=Xs5vkREAAArQIvz5=#=top_menu=#=Xs5vWREAACYAIvvt=#=fr-fr=#=n.json: -------------------------------------------------------------------------------- 1 | {"menu_links":[{"label":[{"type":"paragraph","content":{"text":"Page accueil","spans":[]}}],"link":{"id":"Xs5SSREAACQAInz5","wioUrl":"wio://documents/Xs5SSREAACQAInz5"}},{"label":[{"type":"paragraph","content":{"text":"Propos nous","spans":[]}}],"link":{"id":"Xs5ushEAACQAIvjn","wioUrl":"wio://documents/Xs5ushEAACQAIvjn"}}],"display_title":[{"type":"heading1","content":{"text":"Top Menu","spans":[]}}],"site_logo":{"origin":{"id":"Xs5P3BEAACQAInHj","url":"https://prismic-io.s3.amazonaws.com/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png","width":143,"height":32},"provider":"imgix","url":"https://images.prismic.io/multi-language-example/bf4f5d18-5ea8-404c-9c4c-da7e0b0ada66_site-logo.png?auto=compress,format&rect=0,0,142,32&w=102&h=23","alt":"Site Logo","credits":null,"width":102,"height":23,"edit":{"zoom":0.71875,"crop":{"x":0,"y":0},"background":"transparent"},"thumbnails":{}},"display_title_TYPE":"StructuredText","display_title_POSITION":0,"site_logo_TYPE":"Image","site_logo_POSITION":1,"menu_links_TYPE":"Group","menu_links_POSITION":2,"menu_links.label_TYPE":"StructuredText","menu_links.label_POSITION":3,"menu_links.link_TYPE":"Link","menu_links.link_POSITION":4,"slugs_INTERNAL":["top-menu"],"uids_INTERNAL":[]} -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/whoami.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | import {fs} from '../../src/utils' 3 | 4 | describe('whoami', () => { 5 | const fakeBase = 'https://prismic.io' 6 | const fakeCookies = 'SESSION=tea; DOMAIN=.prismic.io; X_XSFR=biscuits; prismic-auth=xyz' 7 | 8 | test 9 | .stdout() 10 | .stub(fs, 'readFileSync', () => JSON.stringify({base: fakeBase, cookies: fakeCookies})) 11 | .stub(fs, 'writeFile', () => Promise.resolve()) 12 | .nock('https://auth.prismic.io', api => { 13 | api.get('/validate?token=xyz').reply(200, { 14 | email: 'fake.user@prismic.io', 15 | type: 'USER', 16 | repositories: {}, 17 | }) 18 | }) 19 | .command('whoami') 20 | .it('When logged in it should show the user their user name', ctx => { 21 | expect(ctx.stdout).to.contain('fake.user@prismic.io') 22 | }) 23 | 24 | test 25 | .stdout() 26 | .stub(fs, 'readFileSync', () => JSON.stringify({base: fakeBase, cookies: fakeCookies})) 27 | .stub(fs, 'writeFile', () => Promise.resolve()) 28 | .nock('https://auth.prismic.io', api => { 29 | api.get('/validate?token=xyz').reply(401, 'One or more parameter values are not valid. The AttributeValue for a key attribute cannot contain an empty string value. Key: token') 30 | }) 31 | .command('whoami') 32 | .it('Should tell the user they are not logged in', ctx => { 33 | expect(ctx.stdout).to.contain('Not logged in') 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/utils/index.test.ts: -------------------------------------------------------------------------------- 1 | import {test, expect} from '@oclif/test' 2 | import {LocalDB} from '../../src/prismic/communication' 3 | import * as sinon from 'sinon' 4 | 5 | import { 6 | parseJson, 7 | parseJsonSync, 8 | } from '../../src/utils' 9 | 10 | describe('utils', () => { 11 | describe('parseJson', () => { 12 | test.it('it should return a promise and the parsed json', async () => { 13 | const str = JSON.stringify({base: 'https://prismic.io', cookies: ''}) 14 | const result = await parseJson(str) 15 | expect(result.base).to.equal('https://prismic.io') 16 | expect(result.cookies).to.equal('') 17 | }) 18 | 19 | test.it('it should throw an error if failed', async () => { 20 | const str = 'https://prismic.io' 21 | const catchFn = sinon.fake() 22 | await parseJson(str).catch(catchFn) 23 | expect(catchFn.called).to.be.true 24 | }) 25 | }) 26 | describe('parseJsonSync', () => { 27 | test.it('when given json it should return an object', () => { 28 | const str = JSON.stringify({base: 'https://prismic.io', cookies: ''}) 29 | const result = parseJsonSync(str) 30 | expect(result.base).to.equal('https://prismic.io') 31 | expect(result.cookies).to.equal('') 32 | }) 33 | 34 | test.it('should throw an error if it can not parse', () => { 35 | const str = 'https://prismic.io' 36 | expect(() => parseJsonSync(str)).to.throw() 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/slicemachine/templates/prismic.js: -------------------------------------------------------------------------------- 1 | /** Example file */ 2 | 3 | import Prismic from '@prismicio/client' 4 | import Link from 'next/link' 5 | 6 | import smConfig from './<%= smFile %>' 7 | 8 | export const apiEndpoint = smConfig.apiEndpoint 9 | 10 | // -- Access Token if the repository is not public 11 | // Generate a token in your dashboard and configure it here if your repository is private 12 | export const accessToken = '' 13 | 14 | // -- Link resolution rules 15 | // Manages the url links to internal Prismic documents 16 | export const linkResolver = (doc) => { 17 | if (doc.type === 'post') { 18 | return `/blog/${doc.uid}` 19 | } 20 | return '/' 21 | } 22 | 23 | // Additional helper function for Next/Link components 24 | export const hrefResolver = (doc) => { 25 | if (doc.type === 'post') { 26 | return '/blog/[uid]' 27 | } 28 | return '/' 29 | } 30 | 31 | export const customLink = (type, element, content, children, index) => ( 32 | 37 | {content} 38 | 39 | ) 40 | 41 | export const Router = { 42 | routes: [{"type":"page","path":"/:uid"}], 43 | 44 | href: (type) => { 45 | const route = Router.routes.find(r => r.type === type); 46 | return route && route.href; 47 | } 48 | }; 49 | 50 | export const Client = (req = null, options = {}) => ( 51 | Prismic.client(apiEndpoint, Object.assign({ routes: Router.routes }, options)) 52 | ) -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-prismic-nuxt", 3 | "version": "4.2.3", 4 | "main": "generators/app", 5 | "license": "Apache-2.0", 6 | "private": false, 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "files": [ 11 | "generators" 12 | ], 13 | "dependencies": { 14 | "@babel/core": "^7.15.0", 15 | "@babel/generator": "^7.15.4", 16 | "@babel/parser": "^7.15.4", 17 | "@babel/template": "^7.14.5", 18 | "@babel/traverse": "^7.15.4", 19 | "@babel/types": "^7.15.4", 20 | "@prismicio/prismic-yeoman-generator": "4.2.3", 21 | "chalk": "^4.1.1", 22 | "create-nuxt-app": "^4.0.0", 23 | "inquirer": "^7.3.3", 24 | "is-valid-path": "^0.1.1", 25 | "lodash.camelcase": "^4.3.0", 26 | "sm-commons": "^0.0.23", 27 | "tslib": "^1" 28 | }, 29 | "devDependencies": { 30 | "@types/babel__core": "^7.1.15", 31 | "@types/babel__template": "^7.4.1", 32 | "@types/mocha": "^5", 33 | "@types/node": "^14.14.10", 34 | "chai": "^4", 35 | "del-cli": "^3.0.1", 36 | "fancy-test": "1.4.10", 37 | "mocha": "^5", 38 | "nyc": "^14", 39 | "typescript": "^3.3" 40 | }, 41 | "scripts": { 42 | "clean": "del-cli generators/**/*.js generators/**/*.d.ts !generators/**/templates/**/*.js", 43 | "prepack": "del-cli generators/**/*.js generators/**/*.d.ts !generators/**/templates/**/*.js && tsc -b", 44 | "test": "nyc --extension .ts mocha \"test/**/*.test.ts\"" 45 | }, 46 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 47 | } 48 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/utils/data-dog.test.ts: -------------------------------------------------------------------------------- 1 | import {fancy} from 'fancy-test' 2 | import datadog from '../../src/utils/data-dog' 3 | import PrismicCommand from '../../src/prismic/base-command' 4 | 5 | describe('data-dog', () => { 6 | const now = Date.now() 7 | 8 | fancy 9 | .stub(Date, 'now', () => now) 10 | .nock('https://ykz3r8yyd6.execute-api.us-east-1.amazonaws.com', api => { 11 | api.post('/stage', body => ( 12 | body.alert_type === 'error' && 13 | body.priority === 'normal' && 14 | body.source_type_name === 'NODE' && 15 | body.host === 'prismic-cli' && 16 | body.title === 'Test title' && 17 | JSON.stringify(body.text) === '{}' && 18 | body.date_happened === now 19 | )) 20 | }) 21 | .do(async () => { 22 | return datadog('Test title', {} as PrismicCommand) 23 | }) 24 | .it('When given a string it should send an error event to the error handling service') 25 | 26 | fancy 27 | .stub(Date, 'now', () => now) 28 | .nock('https://ykz3r8yyd6.execute-api.us-east-1.amazonaws.com', api => { 29 | api.post('/stage', body => ( 30 | body.alert_type === 'error' && 31 | body.priority === 'normal' && 32 | body.source_type_name === 'NODE' && 33 | body.host === 'prismic-cli' && 34 | body.title === 'Test title' && 35 | body.date_happened === now 36 | )) 37 | }) 38 | .do(async () => { 39 | return datadog(new Error('Test title'), {} as PrismicCommand) 40 | }) 41 | .it('When given a string it should send an error event to the error handling service') 42 | }) 43 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/pages/index.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 33 | 34 | 74 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/signup.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import {Command} from '../prismic' 3 | import cli from 'cli-ux' 4 | import {DEFAULT_PORT} from '../utils/server' 5 | import {LogDecorations, PRISMIC_LOG_HEADER} from '../utils/logDecoration' 6 | 7 | export default class Signup extends Command { 8 | static description = 'Create a Prismic account.' 9 | 10 | static flags = { 11 | help: flags.help({char: 'h'}), 12 | 13 | base: flags.string({ 14 | name: 'base', 15 | hidden: true, 16 | description: 'Base URL to sign up with.', 17 | default: 'https://prismic.io', 18 | }), 19 | 20 | port: flags.integer({ 21 | name: 'port', 22 | hidden: false, 23 | description: 'Port to start the local login server.', 24 | default: DEFAULT_PORT, 25 | }), 26 | 27 | 'auth-url': flags.string({ 28 | hidden: true, 29 | name: 'auth-url', 30 | description: 'URL to use when validating and refreshing sessions.', 31 | }), 32 | } 33 | 34 | async run() { 35 | const {flags} = this.parse(Signup) 36 | const {base, port, 'auth-url': authUrl} = flags 37 | 38 | // ask confirmation 39 | const confirmationMessage = PRISMIC_LOG_HEADER + 'Press any key to open up the browser to signup or ' + LogDecorations.FgRed + 'q' + LogDecorations.Reset + ' to exist' 40 | const confirmationKey: string = await cli.prompt(confirmationMessage, {type: 'single', required: false}) 41 | 42 | if (confirmationKey === 'q' || confirmationKey === '\u0003') return Promise.resolve() 43 | 44 | return this.prismic.signUp(port, base, authUrl) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/create-generator.ts: -------------------------------------------------------------------------------- 1 | import {Command, flags} from '@oclif/command' 2 | import {createEnv} from 'yeoman-environment' 3 | 4 | export default class CreateGenerator extends Command { 5 | static description = 'Create a new generator.' 6 | 7 | static hidden = true 8 | 9 | static flags = { 10 | help: flags.help({char: 'h'}), 11 | 12 | name: flags.string({char: 'n', description: 'Name for the generator.'}), 13 | 14 | force: flags.boolean({description: 'Overwrite local files.'}), 15 | 16 | 'skip-install': flags.boolean({description: 'prevent packages from being installed'}), 17 | 18 | pm: flags.string({ 19 | char: 'p', 20 | description: 'Package manager.', 21 | required: false, 22 | options: ['npm', 'yarn'], 23 | }), 24 | 25 | language: flags.string({ 26 | char: 'l', 27 | description: 'Language to write the generator in.', 28 | required: false, 29 | options: ['js', 'ts'], 30 | parse: value => { 31 | switch (value) { 32 | case 'js': return 'javascript' 33 | case 'ts': return 'typescript' 34 | default: return value 35 | } 36 | }, 37 | }), 38 | 39 | folder: flags.string({ 40 | char: 'f', 41 | description: 'Project where to create the generator.', 42 | }), 43 | } 44 | 45 | async run() { 46 | const {flags: {folder, ...flags}} = this.parse(CreateGenerator) 47 | 48 | const env = createEnv() 49 | env.register(require.resolve('@prismicio/prismic-generator-generator'), 'generator') 50 | 51 | // @ts-expect-error 52 | return env.run('generator', {...flags, path: folder}) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/__stubs__/nuxt-template/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | /logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | 10 | # Runtime data 11 | pids 12 | *.pid 13 | *.seed 14 | *.pid.lock 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # Bower dependency directory (https://bower.io/) 29 | bower_components 30 | 31 | # node-waf configuration 32 | .lock-wscript 33 | 34 | # Compiled binary addons (https://nodejs.org/api/addons.html) 35 | build/Release 36 | 37 | # Dependency directories 38 | node_modules/ 39 | jspm_packages/ 40 | 41 | # TypeScript v1 declaration files 42 | typings/ 43 | 44 | # Optional npm cache directory 45 | .npm 46 | 47 | # Optional eslint cache 48 | .eslintcache 49 | 50 | # Optional REPL history 51 | .node_repl_history 52 | 53 | # Output of 'npm pack' 54 | *.tgz 55 | 56 | # Yarn Integrity file 57 | .yarn-integrity 58 | 59 | # dotenv environment variables file 60 | .env 61 | 62 | # parcel-bundler cache (https://parceljs.org/) 63 | .cache 64 | 65 | # next.js build output 66 | .next 67 | 68 | # nuxt.js build output 69 | .nuxt 70 | 71 | # Nuxt generate 72 | dist 73 | 74 | # vuepress build output 75 | .vuepress/dist 76 | 77 | # Serverless directories 78 | .serverless 79 | 80 | # IDE / Editor 81 | .idea 82 | 83 | # Service worker 84 | sw.* 85 | 86 | # macOS 87 | .DS_Store 88 | 89 | # Vim swap files 90 | *.swp 91 | -------------------------------------------------------------------------------- /packages/generator-prismic-nodejs/generators/app/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator from '@prismicio/prismic-yeoman-generator' 2 | export default class PrismicNodeJS extends PrismicGenerator { 3 | /** 4 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 5 | * 6 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 7 | * 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * 10 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 11 | * 12 | * writing - Where you write the generator specific files (routes, controllers, etc) 13 | * 14 | * conflicts - Where conflicts are handled (used internally) 15 | * 16 | * install - Where installations are run (npm, bower) 17 | * 18 | * end - Called last, cleanup, say good bye, etc 19 | */ 20 | 21 | async initializing() { 22 | this.destinationRoot(this.path) 23 | return this.downloadAndExtractZipFrom('https://github.com/prismicio/nodejs-sdk/archive/master.zip', 'nodejs-sdk-master') 24 | } 25 | 26 | async configuring() { 27 | const customTypes = this.readCustomTypesFrom('custom_types') 28 | 29 | return this.maybeCreatePrismicRepository({domain: this.domain, framework: 'node', customTypes}, this.existingRepo) 30 | .then(res => { 31 | const oldConfig = this.readDestination('prismic-configuration.js') 32 | const newConfig = oldConfig.replace(/your-repo-name/g, res.data || this.domain) 33 | this.writeDestination('prismic-configuration.js', newConfig) 34 | }) 35 | } 36 | 37 | install() { 38 | return this.npmInstall() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | ``` 12 | 13 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 14 | 15 | You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. 16 | 17 | [API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`. 18 | 19 | The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. 20 | 21 | ## Learn More 22 | 23 | To learn more about Next.js, take a look at the following resources: 24 | 25 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 26 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 27 | 28 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 29 | 30 | ## Deploy on Vercel 31 | 32 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 33 | 34 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 35 | -------------------------------------------------------------------------------- /packages/generator-prismic-angular2/generators/app/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator from '@prismicio/prismic-yeoman-generator' 2 | import * as path from 'path' 3 | 4 | export default class extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * 8 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 9 | * 10 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 11 | * 12 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 13 | * 14 | * writing - Where you write the generator specific files (routes, controllers, etc) 15 | * 16 | * conflicts - Where conflicts are handled (used internally) 17 | * 18 | * install - Where installations are run (npm, bower) 19 | * 20 | * end - Called last, cleanup, say good bye, etc 21 | */ 22 | 23 | async initializing() { 24 | this.destinationRoot(this.path) 25 | return this.downloadAndExtractZipFrom('https://github.com/prismicio/angular2-starter/archive/master.zip', 'angular2-starter-master') 26 | } 27 | 28 | async configuring() { 29 | return this.maybeCreatePrismicRepository({ 30 | domain: this.domain, 31 | framework: 'angular2', 32 | }, this.existingRepo) 33 | .then(res => { 34 | const location = path.join('src', 'prismic-configuration.ts') 35 | const oldConfig = this.readDestination(location) 36 | const newConfig = oldConfig.replace(/your-repo-name/g, res.data || this.domain) 37 | this.writeDestination(location, newConfig) 38 | }) 39 | } 40 | 41 | async install() { 42 | return this.npmInstall() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/generator-prismic-vue/generators/app/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator from '@prismicio/prismic-yeoman-generator' 2 | import * as path from 'path' 3 | 4 | export default class extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * 8 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 9 | * 10 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 11 | * 12 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 13 | * 14 | * writing - Where you write the generator specific files (routes, controllers, etc) 15 | * 16 | * conflicts - Where conflicts are handled (used internally) 17 | * 18 | * install - Where installations are run (npm, bower) 19 | * 20 | * end - Called last, cleanup, say good bye, etc 21 | */ 22 | 23 | async initializing() { 24 | this.destinationRoot(this.path) 25 | return this.downloadAndExtractZipFrom('https://github.com/prismicio/vuejs-starter/archive/master.zip', 'vuejs-starter-master') 26 | } 27 | 28 | async configuring() { 29 | const customTypes = this.readCustomTypesFrom('custom_types') 30 | 31 | return this.maybeCreatePrismicRepository({ 32 | domain: this.domain, 33 | framework: 'vue.js', 34 | customTypes, 35 | }).then(res => { 36 | const location = path.join('public', 'index.html') 37 | const oldConfig = this.readDestination(location) 38 | const newConfig = oldConfig.replace(/your-repo-name/g, res.data || this.domain) 39 | this.writeDestination(location, newConfig) 40 | }) 41 | } 42 | 43 | async install() { 44 | return this.npmInstall() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/generator-prismic-react/generators/app/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator from '@prismicio/prismic-yeoman-generator' 2 | import * as path from 'path' 3 | 4 | export default class extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * 8 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 9 | * 10 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 11 | * 12 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 13 | * 14 | * writing - Where you write the generator specific files (routes, controllers, etc) 15 | * 16 | * conflicts - Where conflicts are handled (used internally) 17 | * 18 | * install - Where installations are run (npm, bower) 19 | * 20 | * end - Called last, cleanup, say good bye, etc 21 | */ 22 | 23 | async initializing() { 24 | this.destinationRoot(this.path) 25 | return this.downloadAndExtractZipFrom('https://github.com/prismicio/reactjs-starter/archive/master.zip', 'reactjs-starter-master') 26 | } 27 | 28 | async configuring() { 29 | this.log('Creating repository') 30 | 31 | const customTypes = this.readCustomTypesFrom('custom_types') 32 | 33 | return this.maybeCreatePrismicRepository({ 34 | domain: this.domain, 35 | framework: 'react', 36 | customTypes, 37 | }).then(res => { 38 | const location = path.join('src', 'prismic-configuration.js') 39 | const oldConfig = this.readDestination(location) 40 | const newConfig = oldConfig.replace(/your-repo-name/g, res.data || this.domain) 41 | this.writeDestination(location, newConfig) 42 | }) 43 | } 44 | 45 | async install() { 46 | return this.npmInstall() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/prismic-yeoman-generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@prismicio/prismic-yeoman-generator", 3 | "version": "4.2.3", 4 | "description": "custom yeoman generator for building projects with prismic", 5 | "main": "src", 6 | "repository": "https://github.com/prismicio/prismic-cli", 7 | "author": "prismic.io developers", 8 | "files": [ 9 | "src" 10 | ], 11 | "contributors": [ 12 | "Marc McIntosh " 13 | ], 14 | "engines": { 15 | "node": ">=14.0.0" 16 | }, 17 | "license": "Apache-2.0", 18 | "private": false, 19 | "devDependencies": { 20 | "@types/adm-zip": "^0.4.33", 21 | "@types/chai": "^4", 22 | "@types/mocha": "^5", 23 | "@types/node": "^14.14.10", 24 | "@types/tmp": "^0.2.0", 25 | "chai": "^4", 26 | "eslint": "^7", 27 | "eslint-config-oclif": "^3.1", 28 | "eslint-config-oclif-typescript": "^0.1", 29 | "fancy-test": "^1.4.10", 30 | "mocha": "^5", 31 | "nyc": "^14", 32 | "rimraf": "^3.0.2", 33 | "sinon": "^9.2.1", 34 | "stream-mock": "^2.0.5", 35 | "ts-node": "^8", 36 | "typescript": "^3.3" 37 | }, 38 | "dependencies": { 39 | "@types/yeoman-generator": "^5.2.7", 40 | "adm-zip": "^0.5.1", 41 | "axios": "^0.24.0", 42 | "cli-ux": "^5.5.1", 43 | "ejs": "^3.1.6", 44 | "lodash.camelcase": "^4.3.0", 45 | "lookpath": "^1.2.0", 46 | "prismic-cli": "4.2.3", 47 | "sm-commons": "^0.0.23", 48 | "tmp-promise": "^3.0.2", 49 | "tslib": "^1", 50 | "yeoman-generator": "^5.4.2" 51 | }, 52 | "scripts": { 53 | "clean": "rimraf src/**/*.js src/**/*.d.ts", 54 | "prepack": "rimraf src/**/*.js src/**/*.d.ts && tsc -b", 55 | "posttest": "eslint . --ext .ts --config .eslintrc", 56 | "test": "nyc --extension .ts mocha \"test/**/*.test.ts\"" 57 | }, 58 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 59 | } 60 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/framework/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path' 2 | import * as fs from 'fs' 3 | 4 | import {supportedProjects, Framework, findProjectType} from './project-types' 5 | 6 | export interface PkgJson { 7 | dependencies?: { [dependencyName: string]: string }; 8 | peerDependencies?: { [dependencyName: string]: string }; 9 | devDependencies?: { [dependencyName: string]: string }; 10 | } 11 | const hasDependency = (packageJson: PkgJson, name: string) => Boolean(packageJson.dependencies && packageJson.dependencies[name]) || Boolean(packageJson.devDependencies && packageJson.devDependencies[name]) 12 | 13 | const hasPeerDependency = (packageJson: PkgJson, name: string) => Boolean(packageJson.peerDependencies && packageJson.peerDependencies[name]) 14 | 15 | const getFrameworkPreset = ( 16 | packageJson: PkgJson, 17 | framework: Framework, 18 | ) /* ProjectType | null */ => { 19 | const matcher = { 20 | dependencies: [false], 21 | peerDependencies: [false], 22 | files: [false], 23 | } 24 | 25 | const { 26 | preset, files, dependencies, peerDependencies, matcherFunction, 27 | } = framework 28 | 29 | if (Array.isArray(dependencies) && dependencies.length > 0) { 30 | matcher.dependencies = dependencies.map(name => hasDependency(packageJson, name)) 31 | } 32 | 33 | if (Array.isArray(peerDependencies) && peerDependencies.length > 0) { 34 | matcher.peerDependencies = peerDependencies.map(name => hasPeerDependency(packageJson, name)) 35 | } 36 | 37 | if (Array.isArray(files) && files.length > 0) { 38 | matcher.files = files.map(name => fs.existsSync(path.join(process.cwd(), name))) 39 | } 40 | 41 | return matcherFunction(matcher) ? preset : null 42 | } 43 | 44 | export function detect(pkgJson: PkgJson) /* ProjectType */ { 45 | const result = supportedProjects.find((framework: Framework) => getFrameworkPreset(pkgJson, framework) !== null) 46 | 47 | return result ? result.preset : null 48 | } 49 | 50 | export const parse = findProjectType 51 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/create-generator.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | import * as os from 'os' 3 | import * as path from 'path' 4 | import * as fs from 'fs' 5 | import * as rimraf from 'rimraf' 6 | import * as inquirer from 'inquirer' 7 | import CreateGenerator from '../../src/commands/create-generator' 8 | 9 | describe('create-generator', () => { 10 | const tmpDir = os.tmpdir() 11 | const jsDir = path.join(tmpDir, 'js-generator-test') 12 | const tsDir = path.join(tmpDir, 'ts-generator-test') 13 | before(() => { 14 | rimraf.sync(jsDir) 15 | rimraf.sync(tsDir) 16 | }) 17 | 18 | test.it('flags', () => { 19 | expect(CreateGenerator.flags.folder).to.exist 20 | expect(CreateGenerator.flags.force).to.exist 21 | expect(CreateGenerator.flags.help).exist 22 | expect(CreateGenerator.flags.language).to.exist 23 | expect(CreateGenerator.flags.name).to.exist 24 | expect(CreateGenerator.flags.pm).to.exist 25 | expect(CreateGenerator.flags['skip-install']).to.exist 26 | expect(CreateGenerator.flags.language.parse('js', {})).to.equal('javascript') 27 | expect(CreateGenerator.flags.language.parse('ts', {})).to.equal('typescript') 28 | expect(CreateGenerator.flags.language.parse('jts', {})).to.equal('jts') // unlikely to happen 29 | }) 30 | 31 | test 32 | .stdout() 33 | .stderr() 34 | .stub(inquirer, 'prompt', () => Promise.resolve({slicemachine: true})) 35 | .command(['create-generator', '--pm', 'npm', '--language', 'js', '--name', 'js-test', '--folder', jsDir, '--skip-install', '--force']) 36 | .it('setups a JavaSript based generator', () => { 37 | const outDir = path.join(jsDir, 'generator-prismic-js-test') 38 | expect(fs.existsSync(path.join(outDir, 'package.json'))).to.be.true 39 | }) 40 | 41 | test 42 | .stdout() 43 | .stderr() 44 | .stub(inquirer, 'prompt', () => Promise.resolve({slicemachine: true})) 45 | .command(['create-generator', '--pm', 'npm', '--language', 'js', '--name', 'ts-test', '--folder', tsDir, '--skip-install', '--force']) 46 | .it('setups a TypeScript based generator', () => { 47 | const outDir = path.join(tsDir, 'generator-prismic-ts-test') 48 | expect(fs.existsSync(outDir)).to.be.true 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/updates.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | 3 | import * as semver from 'semver' 4 | 5 | const libnpmconfig = require('libnpmconfig') 6 | 7 | const pjson = require('../../package.json') 8 | 9 | describe('hooks', () => { 10 | test 11 | .stdout() 12 | .stderr() 13 | .stub(libnpmconfig, 'read', () => ({})) 14 | .nock('https://registry.npmjs.org/', api => { 15 | api.get('/prismic-cli').reply(200, {'dist-tags': {latest: pjson.version}}) 16 | }) 17 | .hook('postrun') 18 | .it('update hook: should not log anything if the user is using the most recent version', (ctx, done) => { 19 | expect(ctx.stdout).to.equal('') 20 | expect(ctx.stderr).to.equal('') 21 | done() 22 | }) 23 | 24 | test 25 | .stdout() 26 | .stderr() 27 | .stub(libnpmconfig, 'read', () => ({})) 28 | .nock('https://registry.npmjs.org/', api => { 29 | api.get('/prismic-cli').reply(200, {'dist-tags': {latest: semver.inc(pjson.version, 'patch')}}) 30 | }) 31 | .hook('postrun') 32 | .it('update hook: inform the user about a more recent version being available is using the most recent version', (ctx, done) => { 33 | expect(ctx.stdout).to.include('A new version of prismic-cli is available!') 34 | expect(ctx.stderr).to.equal('') 35 | done() 36 | }) 37 | 38 | test 39 | .stdout() 40 | .stderr() 41 | .stub(libnpmconfig, 'read', () => ({registry: 'https://registry.npmjs.org/'})) 42 | .nock('https://registry.npmjs.org/', api => { 43 | api.get('/prismic-cli').reply(200, {'dist-tags': {latest: pjson.version}}) 44 | }) 45 | .hook('postrun') 46 | .it('update hook: will use a configured npm-registry', (ctx, done) => { 47 | expect(ctx.stdout).to.include('') 48 | expect(ctx.stderr).to.equal('') 49 | done() 50 | }) 51 | 52 | test 53 | .skip() 54 | .stub(libnpmconfig, 'read', () => ({registry: 'https://registry.npmjs.org/'})) 55 | .nock('https://registry.npmjs.org/', api => { 56 | api.get('/prismic-cli-2').reply(200, {'dist-tags': {latest: pjson.version}}) 57 | }) 58 | .hook('postrun', {config: {pjson: {name: 'prismic-cli-2', version: semver.inc(pjson.version, 'patch')}}}) 59 | .it('update hook: uses package version and name provided in options option by oclif', (ctx, done) => done()) 60 | }) 61 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/pages/index.js: -------------------------------------------------------------------------------- 1 | import Head from 'next/head' 2 | import styles from '../styles/Home.module.css' 3 | 4 | export default function Home() { 5 | return ( 6 | 64 | ) 65 | } 66 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/storybook/index.ts: -------------------------------------------------------------------------------- 1 | import Generator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | const {SM_FILE} = require('sm-commons/consts') 3 | 4 | export default class StoryBookNext extends Generator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 10 | * writing - Where you write the generator specific files (routes, controllers, etc) 11 | * conflicts - Where conflicts are handled (used internally) 12 | * install - Where installations are run (npm, bower) 13 | * end - Called last, cleanup, say good bye, etc 14 | */ 15 | 16 | constructor(argv: string|string[], opts: TemplateOptions) { 17 | super(argv, opts) 18 | 19 | if (this.destinationRoot().endsWith(this.path) === false) { 20 | this.destinationRoot(this.path) 21 | } 22 | } 23 | 24 | async prompting() { 25 | if (!this.pm) await this.promptForPackageManager() 26 | } 27 | 28 | async writing() { 29 | const pkJson = { 30 | devDependencies: { 31 | '@storybook/react': '^6.2.8', 32 | 'babel-loader': '^8.2.2', 33 | 'babel-plugin-react-require': '^3.1.3', 34 | }, 35 | scripts: { 36 | storybook: 'start-storybook -p 8888', 37 | 'build-storybook': 'build-storybook', 38 | }, 39 | } 40 | 41 | this.fs.extendJSON(this.destinationPath('package.json'), pkJson) 42 | 43 | const babelrc = { 44 | presets: [ 45 | ['next/babel'], 46 | ], 47 | plugins: ['react-require'], 48 | } 49 | 50 | this.fs.extendJSON(this.destinationPath('.babelrc'), babelrc) 51 | 52 | const smJson = { 53 | storybook: 'http://localhost:8888', 54 | } 55 | 56 | this.fs.extendJSON(this.destinationPath(SM_FILE), smJson) 57 | 58 | this.fs.copy(this.templatePath(), this.destinationPath(), {globOptions: {dot: true}}) 59 | } 60 | 61 | async install() { 62 | if (this.pm === 'yarn') { 63 | return this.yarnInstall() 64 | } 65 | return this.npmInstall(undefined, {'legacy-peer-deps': true}) // TODO: remove once storybook installs with out peer-dep related errors 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/storybook/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | import addGetStoriesPaths from './add-get-stories-paths' 3 | const {SM_FILE} = require('sm-commons/consts') 4 | export default class StoryBookNuxt extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 10 | * writing - Where you write the generator specific files (routes, controllers, etc) 11 | * conflicts - Where conflicts are handled (used internally) 12 | * install - Where installations are run (npm, bower) 13 | * end - Called last, cleanup, say good bye, etc 14 | */ 15 | 16 | pm: 'npm' | 'yarn' | undefined; 17 | 18 | constructor(argv: string | string[], opts: TemplateOptions) { // TODO: options 19 | super(argv, opts) 20 | // this.pm = this.pm || 'npm' 21 | if (this.destinationRoot().endsWith(this.path) === false) { 22 | this.destinationRoot(this.path) 23 | } 24 | } 25 | 26 | async prompting() { 27 | if (!this.pm) await this.promptForPackageManager() 28 | } 29 | 30 | async writing() { 31 | const pkJson = { 32 | scripts: { 33 | storybook: 'nuxt storybook', 34 | 'build-storybook': 'nuxt storybook build', 35 | }, 36 | devDependencies: { 37 | sass: '^1.35.1', 38 | '@storybook/vue': '6.1.21', 39 | 'vue-loader': '15.9.6', 40 | '@nuxtjs/storybook': '3.3.1', 41 | 'sass-loader': '^10.1.1', 42 | 'slice-machine-ui': '^0.1.2', 43 | }, 44 | } 45 | 46 | this.fs.extendJSON(this.destinationPath('package.json'), pkJson) 47 | 48 | const smJson = { 49 | storybook: 'http://localhost:3003', 50 | } 51 | 52 | this.fs.extendJSON(this.destinationPath(SM_FILE), smJson) 53 | 54 | const config = this.readDestination('nuxt.config.js') 55 | 56 | const updatedConfig = addGetStoriesPaths(config) 57 | 58 | this.writeDestination('nuxt.config.js', updatedConfig) 59 | } 60 | 61 | async install() { 62 | if (this.pm === 'yarn') { 63 | return this.yarnInstall() 64 | } 65 | return this.npmInstall() 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/templates/styles/Home.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | min-height: 100vh; 3 | padding: 0 0.5rem; 4 | display: flex; 5 | flex-direction: column; 6 | justify-content: center; 7 | align-items: center; 8 | } 9 | 10 | .main { 11 | padding: 5rem 0; 12 | flex: 1; 13 | display: flex; 14 | flex-direction: column; 15 | justify-content: center; 16 | align-items: center; 17 | } 18 | 19 | .footer { 20 | width: 100%; 21 | height: 100px; 22 | border-top: 1px solid #eaeaea; 23 | display: flex; 24 | justify-content: center; 25 | align-items: center; 26 | } 27 | 28 | .footer img { 29 | margin-left: 0.5rem; 30 | } 31 | 32 | .footer a { 33 | display: flex; 34 | justify-content: center; 35 | align-items: center; 36 | } 37 | 38 | .title a { 39 | color: #0070f3; 40 | text-decoration: none; 41 | } 42 | 43 | .title a:hover, 44 | .title a:focus, 45 | .title a:active { 46 | text-decoration: underline; 47 | } 48 | 49 | .title { 50 | margin: 0; 51 | line-height: 1.15; 52 | font-size: 4rem; 53 | } 54 | 55 | .title, 56 | .description { 57 | text-align: center; 58 | } 59 | 60 | .description { 61 | line-height: 1.5; 62 | font-size: 1.5rem; 63 | } 64 | 65 | .code { 66 | background: #fafafa; 67 | border-radius: 5px; 68 | padding: 0.75rem; 69 | font-size: 1.1rem; 70 | font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, 71 | Bitstream Vera Sans Mono, Courier New, monospace; 72 | } 73 | 74 | .grid { 75 | display: flex; 76 | align-items: center; 77 | justify-content: center; 78 | flex-wrap: wrap; 79 | max-width: 800px; 80 | margin-top: 3rem; 81 | } 82 | 83 | .card { 84 | margin: 1rem; 85 | flex-basis: 45%; 86 | padding: 1.5rem; 87 | text-align: left; 88 | color: inherit; 89 | text-decoration: none; 90 | border: 1px solid #eaeaea; 91 | border-radius: 10px; 92 | transition: color 0.15s ease, border-color 0.15s ease; 93 | } 94 | 95 | .card:hover, 96 | .card:focus, 97 | .card:active { 98 | color: #0070f3; 99 | border-color: #0070f3; 100 | } 101 | 102 | .card h3 { 103 | margin: 0 0 1rem 0; 104 | font-size: 1.5rem; 105 | } 106 | 107 | .card p { 108 | margin: 0; 109 | font-size: 1.25rem; 110 | line-height: 1.5; 111 | } 112 | 113 | .logo { 114 | height: 1em; 115 | } 116 | 117 | @media (max-width: 600px) { 118 | .grid { 119 | width: 100%; 120 | flex-direction: column; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/signup.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | expect, 3 | test, 4 | } from '@oclif/test' 5 | import {fs} from '../../src/utils' 6 | import cli from 'cli-ux' 7 | import Signup from '../../src/commands/signup' 8 | import * as server from '../../src/utils/server' 9 | import * as sinon from 'sinon' 10 | 11 | describe('signup', () => { 12 | beforeEach(() => { 13 | sinon.reset() 14 | }) 15 | 16 | test.it('accepted flags', () => { 17 | expect(Signup.flags.port).exist 18 | expect(Signup.flags.base).to.exist 19 | expect(Signup.flags.base.hidden).to.be.true 20 | expect(Signup.flags['auth-url']).exist 21 | expect(Signup.flags['auth-url'].hidden).to.be.true 22 | }) 23 | 24 | const config = JSON.stringify({}) 25 | 26 | const fakeServer = sinon.fake.resolves(null) 27 | 28 | test 29 | .stdout() 30 | .stub(cli, 'prompt', () => async () => Promise.resolve('')) 31 | .stub(fs, 'readFileSync', () => config) 32 | .stub(fs, 'writeFile', () => Promise.resolve()) 33 | .stub(server, 'startServerAndOpenBrowser', fakeServer) 34 | .command(['signup']) 35 | .it('should call startServerAndOpenBrowser with default arguments', () => { 36 | expect(fakeServer.calledOnce).to.be.true 37 | expect(fakeServer.called).to.be.true 38 | const [url, base, port, logAction] = fakeServer.firstCall.args 39 | expect(url).to.be.equal(`${base}/dashboard/cli/signup?port=${server.DEFAULT_PORT}`) 40 | expect(base).to.equal(base) 41 | expect(port).to.equal(server.DEFAULT_PORT) 42 | expect(logAction).to.include('Signing in') 43 | }) 44 | 45 | test 46 | .stdout() 47 | .stub(cli, 'prompt', () => async () => Promise.resolve('q')) 48 | .stub(fs, 'readFileSync', () => config) 49 | .stub(fs, 'writeFile', () => Promise.resolve()) 50 | .stub(server, 'startServerAndOpenBrowser', fakeServer) 51 | .command(['signup']) 52 | .it('when user abourts it should not call startServerAndOpenBrowser', () => { 53 | expect(fakeServer.called).to.be.false 54 | }) 55 | 56 | test 57 | .stdout() 58 | .stub(cli, 'prompt', () => async () => Promise.resolve('')) 59 | .stub(fs, 'readFileSync', () => config) 60 | .stub(fs, 'writeFile', () => Promise.resolve()) 61 | .stub(server, 'startServerAndOpenBrowser', fakeServer) 62 | .command(['signup', '--port', '8080']) 63 | .it('should call startServerAndOpenBrowser with custom arguments', () => { 64 | expect(fakeServer.calledOnce).to.be.true 65 | expect(fakeServer.called).to.be.true 66 | const [url, base, port, logAction] = fakeServer.firstCall.args 67 | expect(url).to.be.equal(`${base}/dashboard/cli/signup?port=8080`) 68 | expect(base).to.equal(base) 69 | expect(Number(port)).to.equal(8080) 70 | expect(logAction).to.include('Signing in') 71 | }) 72 | }) 73 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/framework/project-types.ts: -------------------------------------------------------------------------------- 1 | export enum ProjectType { 2 | NUXT = 'nuxt', 3 | NEXT = 'next', 4 | VUE = 'vue.js', 5 | REACT = 'react', 6 | SVELTE = 'svelte', 7 | GATSBY = 'gatsby', 8 | NODE = 'node', 9 | } 10 | 11 | export function findProjectType(strFramework: string): ProjectType | null { 12 | switch (strFramework.toLowerCase()) { 13 | case ProjectType.NUXT: return ProjectType.NUXT 14 | case ProjectType.NEXT: return ProjectType.NEXT 15 | case ProjectType.VUE: return ProjectType.VUE 16 | case ProjectType.REACT: return ProjectType.REACT 17 | case ProjectType.SVELTE: return ProjectType.SVELTE 18 | case ProjectType.GATSBY: return ProjectType.GATSBY 19 | case ProjectType.NODE: return ProjectType.NODE 20 | default: return null 21 | } 22 | } 23 | 24 | export interface Framework { 25 | preset: ProjectType; 26 | dependencies?: ReadonlyArray; 27 | peerDependencies?: ReadonlyArray; 28 | files?: ReadonlyArray; 29 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => boolean; 30 | } 31 | /* 32 | * This has to be an array sorted in order of specificity/priority. 33 | * Reason: both REACT and WEBPACK_REACT have react as dependency, 34 | * therefore WEBPACK_REACT has to come first, as it's more specific. 35 | */ 36 | export const supportedProjects: ReadonlyArray = [ 37 | { 38 | preset: ProjectType.NUXT, 39 | dependencies: ['nuxt'], 40 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.some(Boolean), 41 | }, 42 | { 43 | preset: ProjectType.NEXT, 44 | dependencies: ['next'], 45 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.some(Boolean), 46 | }, 47 | { 48 | preset: ProjectType.VUE, 49 | dependencies: ['vue'], 50 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.some(Boolean), 51 | }, 52 | { 53 | preset: ProjectType.REACT, 54 | dependencies: ['react'], 55 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.every(Boolean), 56 | }, 57 | { 58 | preset: ProjectType.SVELTE, 59 | dependencies: ['svelte'], 60 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.every(Boolean), 61 | }, 62 | { 63 | preset: ProjectType.GATSBY, 64 | dependencies: ['gatsby'], 65 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.every(Boolean), 66 | }, 67 | { 68 | preset: ProjectType.NODE, 69 | dependencies: ['express', 'koa'], 70 | matcherFunction: ({dependencies}: { dependencies: ReadonlyArray }) => dependencies.every(Boolean), 71 | }, 72 | ] 73 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/storybook/index.js: -------------------------------------------------------------------------------- 1 | const Generator = require('@prismicio/prismic-yeoman-generator').default 2 | const {SM_FILE} = require('sm-commons/consts') 3 | 4 | class StoryBook extends Generator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 10 | * writing - Where you write the generator specific files (routes, controllers, etc) 11 | * conflicts - Where conflicts are handled (used internally) 12 | * install - Where installations are run (npm, bower) 13 | * end - Called last, cleanup, say good bye, etc 14 | */ 15 | 16 | constructor(argv, opts) { 17 | super(argv, opts) 18 | 19 | if (this.destinationRoot().endsWith(this.path) === false) { 20 | this.destinationRoot(this.path) 21 | } 22 | } 23 | 24 | async prompting() { 25 | if (!this.pm) await this.promptForPackageManager() 26 | } 27 | 28 | async writing() { 29 | const pkJson = { 30 | devDependencies: { 31 | }, 32 | scripts: { 33 | storybook: 'start-storybook -p 8888', // Or how ever story is to be started 34 | 'build-storybook': 'build-storybook', 35 | }, 36 | } 37 | 38 | this.fs.extendJSON(this.destinationPath('package.json'), pkJson) 39 | 40 | const smJson = { 41 | storybook: 'http://localhost:8888', // remember to change the port as needed 42 | } 43 | 44 | this.fs.extendJSON(this.destinationPath(SM_FILE), smJson) 45 | 46 | // TODO: this part maybe Redundant if .storybook/main.js can resolve "../.slicemachine/**/*.stories.@(js|jsx|ts|tsx|svelte)", 47 | 48 | const smfile = this.readDestinationJSON(SM_FILE) 49 | const libraries = smfile.libraries || [] 50 | 51 | // read sm file for local libraries. 52 | const localLibs = libraries.filter(lib => lib.startsWith('@/')).map(lib => lib.substring(2)) 53 | 54 | const stories = localLibs.reduce((acc, p) => { 55 | return acc.concat([ 56 | `../${p}/**/*.stories.[tj]s`, 57 | `../.slicemachine/assets/${p}/**/*.stories.[tj]s`, 58 | ]) 59 | }, []) 60 | 61 | const storiesString = JSON.stringify(stories) 62 | 63 | const storyBookEntry = ` 64 | module.exports = { 65 | stories: ${storiesString} 66 | } 67 | ` 68 | // Update storybook configuration 69 | // this.writeDestination('.storybook/main.js', storyBookEntry) 70 | } 71 | 72 | async install() { 73 | if (this.pm === 'yarn') { 74 | return this.yarnInstall() 75 | } 76 | return this.npmInstall() 77 | } 78 | } 79 | 80 | module.exports = StoryBook -------------------------------------------------------------------------------- /packages/prismic-cli/test/commands/login.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, test} from '@oclif/test' 2 | import * as sinon from 'sinon' 3 | import {fs} from '../../src/utils' 4 | import cli from 'cli-ux' 5 | import Login from '../../src/commands/login' 6 | import * as server from '../../src/utils/server' 7 | 8 | describe('login', () => { 9 | beforeEach(() => { 10 | sinon.reset() 11 | }) 12 | 13 | test 14 | .it('login flags', () => { 15 | expect(Login.flags.port).exist 16 | expect(Login.flags.base).exist 17 | expect(Login.flags.base.hidden).to.be.true 18 | expect(Login.flags['auth-url']).exist 19 | expect(Login.flags['auth-url'].hidden).to.be.true 20 | }) 21 | 22 | const prismicBase = 'https://prismic.io' 23 | const fakeErrorFileNotFound = new Error() 24 | Object.assign(fakeErrorFileNotFound, {code: 'ENOENT'}) 25 | const fakeReadFileSync = sinon.fake.returns(JSON.stringify({})) 26 | const fakeWriteFile = sinon.fake.resolves(null) 27 | 28 | const fakeServer = sinon.fake.resolves(null) 29 | 30 | test 31 | // .stdout() 32 | .stub(cli, 'prompt', () => async () => Promise.resolve('')) 33 | .stub(fs, 'readFileSync', fakeReadFileSync) 34 | .stub(fs, 'writeFile', fakeWriteFile) 35 | .stub(server, 'startServerAndOpenBrowser', fakeServer) 36 | .command(['login']) 37 | .it('login should call startServerAndOpenBrowser with default parameters', _ => { 38 | expect(fakeServer.called).to.be.true 39 | const [url, base, port, logAction] = fakeServer.firstCall.args 40 | expect(url).to.be.equal(`${prismicBase}/dashboard/cli/login?port=${server.DEFAULT_PORT}`) 41 | expect(base).to.equal(prismicBase) 42 | expect(port).to.equal(server.DEFAULT_PORT) 43 | expect(logAction).to.include('Logging in') 44 | }) 45 | 46 | const fakeBase = 'https://example.com' 47 | 48 | test 49 | .stderr() 50 | .stdout() 51 | .stub(cli, 'prompt', () => async () => Promise.resolve('')) 52 | .stub(fs, 'readFileSync', fakeReadFileSync) 53 | .stub(fs, 'writeFile', fakeWriteFile) 54 | .stub(server, 'startServerAndOpenBrowser', fakeServer) 55 | .command(['login', '--base', fakeBase, '--port', '8080']) 56 | .it('login with base and auth-url parameters', _ => { 57 | expect(fakeServer.called).to.be.true 58 | const [url, base, port, logAction] = fakeServer.firstCall.args 59 | expect(url).to.be.equal(`${fakeBase}/dashboard/cli/login?port=8080`) 60 | expect(base).to.equal(fakeBase) 61 | expect(port).to.equal(8080) 62 | expect(logAction).to.include('Logging in') 63 | }) 64 | 65 | test 66 | .stderr() 67 | .stdout() 68 | .stub(cli, 'prompt', () => async () => Promise.resolve('q')) 69 | .stub(fs, 'readFileSync', fakeReadFileSync) 70 | .stub(fs, 'writeFile', fakeWriteFile) 71 | .stub(server, 'startServerAndOpenBrowser', fakeServer) 72 | .command(['login']) 73 | .it('user can quit login process', _ => { 74 | expect(fakeServer.called).to.be.false 75 | }) 76 | }) 77 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/theme.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import {Command} from '../prismic' 3 | import generator from '../prismic/yeoman-env' 4 | 5 | export default class Theme extends Command { 6 | static description = 'Create a project from a ZIP file or a GitHub repository URL and a new Prismic repository.' 7 | 8 | static flags = { 9 | help: flags.help({char: 'h'}), 10 | 11 | domain: flags.string({ 12 | char: 'd', 13 | description: 'Name of the new Prismic repository. For example, repo-name becomes https://repo-name.prismic.io.', 14 | parse: input => input.toLowerCase().trim(), 15 | }), 16 | 17 | folder: flags.string({ 18 | char: 'f', 19 | description: 'Name of the project folder.', 20 | }), 21 | 22 | 'theme-url': flags.string({ 23 | char: 't', 24 | description: 'GitHub URL or path to the theme file.', 25 | }), 26 | 27 | conf: flags.string({ 28 | char: 'c', 29 | description: 'Path to Prismic configuration file.', 30 | default: 'prismic-configuration.js', 31 | }), 32 | 33 | documents: flags.string({ 34 | description: 'Path to the documents in the theme.', 35 | default: 'documents', 36 | }), 37 | 38 | customTypes: flags.string({ 39 | description: 'Path to the Custom Types directory in the theme.', 40 | default: 'custom_types', 41 | }), 42 | 43 | force: flags.boolean({description: 'Overwrite local files.'}), 44 | 45 | 'skip-install': flags.boolean({ 46 | description: 'Prevent running install command after generating project.', 47 | default: false, 48 | }), 49 | 50 | 'existing-repo': flags.boolean({ 51 | description: 'Connect to an existing Prismic repository.', 52 | default: false, 53 | }), 54 | 55 | } 56 | 57 | static args = [{ 58 | name: 'source', 59 | description: 'Path or URL to a ZIP file, or a GitHub repository for the theme.', 60 | required: false, 61 | }] 62 | 63 | async run() { 64 | const isAuthenticated = await this.prismic.isAuthenticated() 65 | if (!isAuthenticated) { 66 | await this.login() 67 | } 68 | 69 | const {flags, args} = this.parse(Theme) 70 | 71 | const existingRepo = flags['existing-repo'] || false 72 | const domain = await this.validateDomain(flags.domain, existingRepo) 73 | const folder = await this.validateFolder(flags.folder, domain, flags.force) 74 | const theme = await this.validateTheme(flags['theme-url'] || args.source) 75 | 76 | generator.register( 77 | require.resolve('../generators/theme'), 78 | 'Theme', 79 | ) 80 | 81 | const {conf: configPath, documents: documentsPath, customTypes: customTypesPath, ...rest} = flags 82 | 83 | // @ts-expect-error 84 | return generator.run('Theme', {domain, source: theme, path: folder, prismic: this.prismic, configPath, existingRepo, documentsPath, customTypesPath, ...rest}) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/storybook/index.ts: -------------------------------------------------------------------------------- 1 | import Generator, {SliceMachineJson, TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | const {SM_FILE} = require('sm-commons/consts') 3 | 4 | export default class StoryBookNext extends Generator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 10 | * writing - Where you write the generator specific files (routes, controllers, etc) 11 | * conflicts - Where conflicts are handled (used internally) 12 | * install - Where installations are run (npm, bower) 13 | * end - Called last, cleanup, say good bye, etc 14 | */ 15 | 16 | constructor(argv: string|string[], opts: TemplateOptions) { 17 | super(argv, opts) 18 | 19 | if (this.destinationRoot().endsWith(this.path) === false) { 20 | this.destinationRoot(this.path) 21 | } 22 | } 23 | 24 | async prompting() { 25 | if (!this.pm) await this.promptForPackageManager() 26 | } 27 | 28 | async writing() { 29 | const pkJson = { 30 | devDependencies: { 31 | }, 32 | scripts: { 33 | storybook: 'start-storybook -p 8888', // Or how ever story is to be started 34 | 'build-storybook': 'build-storybook', 35 | }, 36 | } 37 | 38 | this.fs.extendJSON(this.destinationPath('package.json'), pkJson) 39 | 40 | const smJson = { 41 | storybook: 'http://localhost:8888', // remember to change the port as needed 42 | } 43 | 44 | this.fs.extendJSON(this.destinationPath(SM_FILE), smJson) 45 | 46 | // TODO: this part maybe Redundant if .storybook/main.js can resolve "../.slicemachine/**/*.stories.@(js|jsx|ts|tsx|svelte)", 47 | 48 | 49 | const smfile = this.readDestinationJSON(SM_FILE) as unknown as SliceMachineJson 50 | 51 | const libraries = smfile.libraries || [] 52 | 53 | // read sm file for local libraries. 54 | const localLibs = libraries.filter(lib => lib.startsWith('@/')).map(lib => lib.substring(2)) 55 | 56 | const stories = localLibs.reduce>((acc, p) => { 57 | return acc.concat([ 58 | `../${p}/**/*.stories.[tj]s`, 59 | `../.slicemachine/assets/${p}/**/*.stories.[tj]s`, 60 | ]) 61 | }, []) 62 | 63 | const storiesString = JSON.stringify(stories) 64 | 65 | const storyBookEntry = ` 66 | module.exports = { 67 | stories: ${storiesString} 68 | } 69 | ` 70 | // Update storybook configuration 71 | // this.writeDestination('.storybook/main.js', storyBookEntry) 72 | } 73 | 74 | async install() { 75 | if (this.pm === 'yarn') { 76 | return this.yarnInstall() 77 | } 78 | return this.npmInstall() 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/commands/new.ts: -------------------------------------------------------------------------------- 1 | import {flags} from '@oclif/command' 2 | import * as inquirer from 'inquirer' 3 | import {Command} from '../prismic' 4 | import prismicGenerators, {names} from '../prismic/yeoman-env' 5 | 6 | export default class New extends Command { 7 | static description = 'Create a project with a new Prismic repository.' 8 | 9 | static flags = { 10 | help: flags.help({char: 'h'}), 11 | 12 | domain: flags.string({ 13 | char: 'd', 14 | description: 'Name of the Prismic repository. For example: repo-name, becomes https://repo-name.prismic.io.', 15 | parse: (input: string) => input.toLowerCase().trim(), 16 | }), 17 | 18 | folder: flags.string({ 19 | char: 'f', 20 | description: 'Name of the project folder.', 21 | }), 22 | 23 | template: flags.string({ 24 | char: 't', 25 | description: 'Prismic template for the project.', 26 | }), 27 | 28 | force: flags.boolean({description: 'Overwrite local files.'}), 29 | 30 | 'skip-install': flags.boolean({ 31 | description: 'Prevent running install command after generating project.', 32 | default: false, 33 | }), 34 | 35 | 'existing-repo': flags.boolean({ 36 | description: 'Connect to an existing Prismic repository.', 37 | default: false, 38 | }), 39 | } 40 | 41 | static args = [] 42 | 43 | async run() { 44 | const isAuthenticated = await this.prismic.isAuthenticated() 45 | 46 | if (!isAuthenticated) { 47 | await this.login() 48 | } 49 | 50 | const {flags} = this.parse(New) 51 | 52 | const existingRepo = flags['existing-repo'] || false 53 | const domain = await this.validateDomain(flags.domain, existingRepo) 54 | const folder = await this.validateFolder(flags.folder, domain, flags.force) 55 | 56 | const generators = names.map(value => { 57 | const nameWithOutPrefix = value.replace('prismic-', '').replace(/js$/i, 'JS') 58 | return { 59 | name: nameWithOutPrefix.charAt(0).toUpperCase() + nameWithOutPrefix.slice(1), 60 | value, 61 | } 62 | }) 63 | 64 | const isValidTemplate = flags.template && names.includes(`prismic-${flags.template.toLowerCase()}`) ? `prismic-${flags.template.toLowerCase()}` : '' 65 | 66 | const template: string = isValidTemplate || await inquirer.prompt({ 67 | type: 'list', 68 | name: 'template', 69 | message: 'Template to use', 70 | choices: generators, 71 | }).then(res => res.template) 72 | 73 | // @ts-expect-error 74 | return prismicGenerators.run(template, {...flags, domain, path: folder, prismic: this.prismic, existingRepo}) 75 | } 76 | 77 | async validateTemplate(template: string | undefined, options: Array): Promise { 78 | if (template && options.includes(template)) return Promise.resolve(template) 79 | return inquirer.prompt({ 80 | type: 'list', 81 | name: 'template', 82 | message: 'Template to use', 83 | choices: options, 84 | }).then(res => res.template) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /packages/prismic-cli/src/utils/server.ts: -------------------------------------------------------------------------------- 1 | import cli from 'cli-ux' 2 | import {LogDecorations} from './logDecoration' 3 | import * as hapi from '@hapi/hapi' 4 | 5 | export const DEFAULT_PORT = 5555 6 | 7 | type HandlerData = { email: unknown; cookies: ReadonlyArray } 8 | 9 | function validatePayload(payload: any): HandlerData | null { 10 | if (!payload) return null 11 | if (!payload.email || !payload.cookies) return null 12 | if (!(Array.isArray(payload.cookies))) return null 13 | if (payload.cookies.some((c: any) => typeof c !== 'string')) return null 14 | 15 | return payload as HandlerData 16 | } 17 | 18 | const authenticationHandler = (server: hapi.Server) => (cb: (data: HandlerData) => Promise) => { 19 | return async (request: hapi.Request, h: hapi.ResponseToolkit) => { 20 | try { 21 | const data: HandlerData | null = validatePayload(request.payload) 22 | 23 | if (!data) { 24 | cli.action.stop('It seems the server didn\'t respond properly, please contact us.') 25 | return h.response('Error with cookies').code(400) 26 | } 27 | await cb(data) 28 | return h.response(data).code(200) 29 | } finally { 30 | server.stop({timeout: 10000}) 31 | } 32 | } 33 | } 34 | 35 | export const Routes = { 36 | authentication: (server: hapi.Server) => (cb: (data: HandlerData) => Promise) => ({ 37 | method: 'POST', 38 | path: '/', 39 | handler: authenticationHandler(server)(cb), 40 | }), 41 | 42 | notFound: { 43 | method: ['GET', 'POST'], 44 | path: '/{any*}', 45 | handler: (request: hapi.Request, h: hapi.ResponseToolkit) => { 46 | return h.response(`not found: [${request.method}]: ${request.url.toString()}`).code(404) 47 | }, 48 | }, 49 | } 50 | 51 | export const Server = { 52 | build: (base: string, port: number, host: string) => { 53 | const server = hapi.server({ 54 | port, 55 | host, 56 | routes: { 57 | cors: { 58 | origin: [base], 59 | headers: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept'], 60 | }, 61 | }, 62 | }) 63 | return server 64 | }, 65 | } 66 | 67 | export async function startServerAndOpenBrowser( 68 | url: string, 69 | base: string, 70 | port: number, 71 | logAction: string, 72 | setCookies: (cookies: ReadonlyArray) => Promise, 73 | ): Promise { 74 | return new Promise(resolve => { 75 | async function callback(data: HandlerData) { 76 | await setCookies(data.cookies) 77 | cli.action.stop(`Logged in as ${data.email}`) 78 | resolve() 79 | } 80 | 81 | const server = Server.build(base, port, 'localhost') 82 | server.route([Routes.authentication(server)(callback), Routes.notFound]) 83 | 84 | server.start() 85 | .then(() => { 86 | cli.log('\nOpening browser to ' + LogDecorations.Underscore + url + LogDecorations.Reset) 87 | cli.action.start(logAction, 'Waiting for the browser response') 88 | cli.open(url) 89 | }) 90 | }) 91 | } 92 | 93 | export default startServerAndOpenBrowser 94 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/app/index.js: -------------------------------------------------------------------------------- 1 | const PrismicGenerator = require('@prismicio/prismic-yeoman-generator').default 2 | const path = require('path') 3 | 4 | class App extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * 8 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 9 | * 10 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 11 | * 12 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 13 | * 14 | * writing - Where you write the generator specific files (routes, controllers, etc) 15 | * 16 | * conflicts - Where conflicts are handled (used internally) 17 | * 18 | * install - Where installations are run (npm, bower) 19 | * 20 | * end - Called last, cleanup, say good bye, etc 21 | */ 22 | 23 | async initializing() { 24 | this.destinationRoot(this.path) 25 | } 26 | 27 | async configuring() { 28 | this.config.set('framework', '<%= name %>') 29 | } 30 | 31 | async prompting() { 32 | if (!this.pm) await this.promptForPackageManager() 33 | <% if (slicemachine) { %> 34 | if (this.options.slicemachine === undefined) { 35 | this.options.slicemachine = await this.prompt([{ 36 | name: 'slicemachine', 37 | type: 'confirm', 38 | default: true, 39 | message: 'Slice Machine', 40 | }]).then(res => res.slicemachine) 41 | } 42 | <% } %> 43 | } 44 | 45 | <% if (slicemachine) { %> 46 | async default() { 47 | const opts = {framework: '<%= name %>', force: this.force, domain: this.domain, prismic: this.prismic, path: this.destinationRoot(), pm: this.pm, ...this.options} 48 | 49 | if (this.options.slicemachine) { 50 | this.composeWith('prismic-<%= name %>:slicemachine', opts) 51 | this.composeWith('prismic-<%= name %>:create-slice', opts) 52 | this.composeWith('prismic-<%= name %>:storybook', opts) 53 | } else { 54 | const customTypes = this.readCustomTypesFrom('custom_types') 55 | return this.maybeCreatePrismicRepository({domain: this.domain, framework: '<%= name %>', customTypes}, this.existingRepo) 56 | } 57 | } 58 | <% } else { %> 59 | async writing() { 60 | const customTypes = this.readCustomTypesFrom('custom_types') 61 | return this.maybeCreatePrismicRepository({domain: this.domain, framework: '<%= name %>', customTypes}, this.existingRepo).then(res => { 62 | const location = path.join(this.path, 'prismic-configuration.js') 63 | const oldConfig = this.fs.read(location) 64 | const newConfig = oldConfig.replace(/your-repo-name/g, res.data || this.domain) 65 | this.fs.write(location, newConfig) 66 | }) 67 | } 68 | <% } %> 69 | 70 | async install() { 71 | if (this.pm === 'yarn') { 72 | this.yarnInstall() 73 | } else { 74 | this.npmInstall() 75 | } 76 | } 77 | } 78 | 79 | module.exports = App -------------------------------------------------------------------------------- /packages/prismic-generator-generator/README.md: -------------------------------------------------------------------------------- 1 | # Prismic Generator Generator. 2 | Used for generating prismic projects for use with the prismic-cli. It creates a customized [yeoman-generator](https://yeoman.io/authoring/) with some additional methods added by [prismic-yeoman-generator](../prismic-yeoman-generator/README.md). 3 | 4 | ## Usage 5 | First install the latest version of the prismic cli 6 | `npm install -g prismic-cli@alpha` then run the `create-generator` command. 7 | 8 | #### Prompts 9 | 10 | ##### Name 11 | Name of the generator, `generator-prismic-` will be prefixed to the input. This is prefixed so `prismic-cli` can determine which generators are compatible with the cli. 12 | 13 | ##### Language 14 | Both JavaScript and Typescript are supported as languages for writing a generator. 15 | 16 | ##### Package manager 17 | Use yarn or npm, yarn tends to work better with mono-repositories, but it's really down to personal preference. 18 | 19 | ##### Slicemachine 20 | This adds the file and folder structure for the sm commands. 21 | 22 | #### Folder structure 23 | After prompting the cli will generate a `yeoman-generator` following file and folder structure. 24 | 25 | ##### /generators/app 26 | When run this sub-generator should create a working sample project + prismic. 27 | there are three options to do this. 28 | 1. The standard yeoman way for writing generators where the files and folders are kept in app/tempmlates. These files can be interpreted as _ejs_ which allows variables like _domain_ to be passed to te templates. (example: `prismic-generator-nextjs`) 29 | 2. Download a project from a github repository. This is easier to get started with but less Flexible ini regards to modifying files. (example `prismic-generator-vue` or `prismic-cli/src/generatos/theme`) 30 | 3. Reverse engineer an existing generator, a lot of frameworks provided their own generators that can be reverse-engineered to run in yeoman. (example `prismic-generator-nuxt`) 31 | 32 | ##### /generators/slicemachine 33 | This sub-generator installs slicemachine-ui and configures the project to use slicemachine and installs dependacies like `slice-zone` 34 | 35 | ##### /generators/create-slice 36 | As the name suggests this sub-generator is run to add a new slice to the project. Only one file here needs to be modified and that's the templates/library/slice/index.js file. This file will be handed data from the user inputs during the prompts (sliceName) and create a generic slice in the language beiing used 37 | TODO: show example for svelt 38 | 39 | ##### /generators/storybook 40 | This installs and configures storybook. 41 | Storybook does have a cli to handle this, but I've not been able to reverse engineer it to be compatible with yeoman. yeoman's `this.spawnCommand` might be te easiest way to install storybook, but this won't work until after the files have been written out so try and put it in the `end` part of the yeoman life cycle. Or run it and find what modifications where done and emulate those. 42 | 43 | 44 | #### Running the generator locally. 45 | From the root of the generator run `npm link` this will allow te generator to be discovered by the `prismic new` and `prismic sm` commands. 46 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/app/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator from '@prismicio/prismic-yeoman-generator' 2 | import * as path from 'path' 3 | 4 | export default class extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * 8 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 9 | * 10 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 11 | * 12 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 13 | * 14 | * writing - Where you write the generator specific files (routes, controllers, etc) 15 | * 16 | * conflicts - Where conflicts are handled (used internally) 17 | * 18 | * install - Where installations are run (npm, bower) 19 | * 20 | * end - Called last, cleanup, say good bye, etc 21 | */ 22 | 23 | async initializing() { 24 | this.destinationRoot(this.path) 25 | } 26 | 27 | async configuring() { 28 | this.config.set('framework', '<%= name %>') 29 | } 30 | 31 | async prompting() { 32 | if (!this.pm) await this.promptForPackageManager() 33 | <% if (slicemachine) { %> 34 | if (this.options.slicemachine === undefined) { 35 | this.options.slicemachine = await this.prompt<{slicemachine: boolean}>([{ 36 | name: 'slicemachine', 37 | type: 'confirm', 38 | default: true, 39 | message: 'Slice Machine', 40 | }]).then(res => res.slicemachine) 41 | } 42 | <% } %> 43 | } 44 | 45 | <% if (slicemachine) { %> 46 | async default() { 47 | const opts = {framework: '<%= name %>', force: this.force, domain: this.domain, prismic: this.prismic, path: this.destinationRoot(), pm: this.pm, ...this.options} 48 | 49 | if (this.options.slicemachine) { 50 | this.composeWith('prismic-<%= name %>:slicemachine', opts) 51 | this.composeWith('prismic-<%= name %>:create-slice', opts) 52 | this.composeWith('prismic-<%= name %>:storybook', opts) 53 | } else { 54 | const customTypes = this.readCustomTypesFrom('custom_types') 55 | return this.maybeCreatePrismicRepository({ 56 | domain: this.domain, 57 | framework: '<%= name %>', 58 | customTypes, 59 | }, this.existingRepo) 60 | } 61 | } 62 | <% } else { %> 63 | async writing() { 64 | 65 | const customTypes = this.readCustomTypesFrom('custom_types') 66 | return this.maybeCreatePrismicRepository({ 67 | domain: this.domain, 68 | framework: '<%= name %>', 69 | customTypes, 70 | }, this.existingRepo).then(res => { 71 | const location = path.join(this.path, 'prismic-configuration.js') 72 | const oldConfig = this.fs.read(location) 73 | const newConfig = oldConfig.replace(/your-repo-name/g, res.data || this.domain) 74 | this.fs.write(location, newConfig) 75 | }) 76 | } 77 | <% } %> 78 | 79 | async install() { 80 | if (this.pm === 'yarn') { 81 | this.yarnInstall() 82 | } else { 83 | this.npmInstall() 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/test/slicemachine/modify-nuxt-config.test.ts: -------------------------------------------------------------------------------- 1 | import {expect} from 'chai' 2 | import modifyNuxtConfig from '../../generators/slicemachine/modify-nuxt-config' 3 | 4 | const input = `export default { 5 | // Global page headers: https://go.nuxtjs.dev/config-head 6 | head: { 7 | title: 'qwerty', 8 | htmlAttrs: { 9 | lang: 'en' 10 | }, 11 | meta: [ 12 | { charset: 'utf-8' }, 13 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 14 | { hid: 'description', name: 'description', content: '' } 15 | ], 16 | link: [ 17 | { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 18 | ] 19 | }, 20 | 21 | // Global CSS: https://go.nuxtjs.dev/config-css 22 | css: [ 23 | ], 24 | 25 | // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins 26 | plugins: [ 27 | ], 28 | 29 | // Auto import components: https://go.nuxtjs.dev/config-components 30 | components: true, 31 | 32 | // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules 33 | buildModules: [ 34 | ], 35 | 36 | // Modules: https://go.nuxtjs.dev/config-modules 37 | modules: [ 38 | ], 39 | 40 | // Build Configuration: https://go.nuxtjs.dev/config-build 41 | build: { 42 | } 43 | } 44 | ` 45 | 46 | const output = `export default { 47 | // Global page headers: https://go.nuxtjs.dev/config-head 48 | head: { 49 | title: 'qwerty', 50 | htmlAttrs: { 51 | lang: 'en' 52 | }, 53 | meta: [{ 54 | charset: 'utf-8' 55 | }, { 56 | name: 'viewport', 57 | content: 'width=device-width, initial-scale=1' 58 | }, { 59 | hid: 'description', 60 | name: 'description', 61 | content: '' 62 | }], 63 | link: [{ 64 | rel: 'icon', 65 | type: 'image/x-icon', 66 | href: '/favicon.ico' 67 | }], 68 | script: [{ 69 | src: "https://cdn.polyfill.io/v2/polyfill.min.js?features=Element.prototype.classList" 70 | }, { 71 | src: "https://cdn.jsdelivr.net/npm/focus-visible@5.0.2/dist/focus-visible.min.js" 72 | }] 73 | }, 74 | // Global CSS: https://go.nuxtjs.dev/config-css 75 | css: ["vue-essential-slices/src/styles/styles.scss"], 76 | // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins 77 | plugins: [], 78 | // Auto import components: https://go.nuxtjs.dev/config-components 79 | components: true, 80 | // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules 81 | buildModules: [], 82 | // Modules: https://go.nuxtjs.dev/config-modules 83 | modules: [["@nuxtjs/prismic", { 84 | endpoint: "https://qwerty.cdn.prismic.io/api/v2", 85 | apiOptions: { 86 | routes: [{ 87 | type: "page", 88 | path: "/:uid" 89 | }] 90 | } 91 | }]], 92 | // Build Configuration: https://go.nuxtjs.dev/config-build 93 | build: { 94 | transpile: ["vue-slicezone", "nuxt-sm"] 95 | } 96 | };` 97 | 98 | describe('modifyNuxtConfig', () => { 99 | it('should modify the nuxt-config.js file', () => { 100 | expect(modifyNuxtConfig(input, 'qwerty')).to.equal(output) 101 | }) 102 | }) 103 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/slicemachine/index.js: -------------------------------------------------------------------------------- 1 | const PrismicGenerator = require('@prismicio/prismic-yeoman-generator').default 2 | const {SM_FILE} = require('sm-commons/consts') 3 | 4 | class SliceMachine extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 10 | * writing - Where you write the generator specific files (routes, controllers, etc) 11 | * conflicts - Where conflicts are handled (used internally) 12 | * install - Where installations are run (npm, bower) 13 | * end - Called last, cleanup, say good bye, etc 14 | */ 15 | 16 | constructor(argv, opts) { 17 | super(argv, opts) 18 | this.pm = opts.pm 19 | this.domain = opts.domain 20 | if (this.destinationRoot().endsWith(this.path) === false) { 21 | this.destinationRoot(this.path) 22 | } 23 | } 24 | 25 | async prompting() { 26 | if (!this.pm) await this.promptForPackageManager() 27 | } 28 | 29 | async writing() { 30 | const pkgJson = { 31 | scripts: { 32 | slicemachine: 'start-slicemachine --port 9999', 33 | }, 34 | dependencies: {}, 35 | devDependencies: { 36 | 'slice-machine-ui': 'beta', 37 | }, 38 | } 39 | 40 | this.fs.extendJSON(this.destinationPath('package.json'), pkgJson) 41 | 42 | this.fs.copyTpl(this.templatePath(), this.destinationPath(), { 43 | defaultLibrary: '', 44 | domain: this.domain, 45 | }, undefined, { 46 | globOptions: {dot: true}, 47 | }) 48 | 49 | // maybe rename sm file 50 | if (this.existsDestination('sm.json') && SM_FILE !== 'sm.json') { 51 | this.moveDestination('sm.json', SM_FILE) 52 | } 53 | 54 | const customTypes = this.readCustomTypesFrom('custom_types') 55 | return this.maybeCreatePrismicRepository({domain: this.domain, framework: '<%= name %>', customTypes}, this.existingRepo) 56 | } 57 | 58 | async install() { 59 | if (this.pm === 'yarn') { 60 | this.yarnInstall() 61 | } else { 62 | this.npmInstall() 63 | } 64 | } 65 | 66 | async end() { 67 | const url = new URL(this.prismic.base) 68 | 69 | if (this.domain) { 70 | url.hostname = `${this.domain}.${url.hostname}` 71 | url.pathname = 'documents' 72 | } else { 73 | url.pathname = 'dashboard' 74 | } 75 | 76 | const writingRoomUrl = url.toString() 77 | 78 | this.log(` 79 | Your project is now configured to use SliceMachine! 80 | Follow these next steps to get going: 81 | 82 | - Add the SliceZone, anywhere in your code https://github.com/prismicio/slice-machine 83 | - Access your Prismic writing room here 84 | ${writingRoomUrl} 85 | 86 | - To add your own slice, run this command 87 | $> npx prismic-cli sm --create-slice 88 | 89 | - Run slicemachine 90 | $> npx prismic-cli sm --develop 91 | `) 92 | } 93 | } 94 | 95 | module.exports = SliceMachine -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/slicemachine/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | const {SM_FILE} = require('sm-commons/consts') 3 | 4 | export default class SliceMachine extends PrismicGenerator { 5 | /** 6 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 9 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 10 | * writing - Where you write the generator specific files (routes, controllers, etc) 11 | * conflicts - Where conflicts are handled (used internally) 12 | * install - Where installations are run (npm, bower) 13 | * end - Called last, cleanup, say good bye, etc 14 | */ 15 | framework: string; 16 | 17 | pm: 'npm' | 'yarn' | undefined 18 | 19 | constructor(argv: string | string[], opts: TemplateOptions) { 20 | super(argv, opts) 21 | 22 | if (this.destinationRoot().endsWith(this.path) === false) { 23 | this.destinationRoot(this.path) 24 | } 25 | } 26 | 27 | async prompting() { 28 | if (!this.pm) await this.promptForPackageManager() 29 | } 30 | 31 | async writing() { 32 | const pkgJson = { 33 | scripts: { 34 | slicemachine: 'start-slicemachine --port 9999', 35 | }, 36 | dependencies: {}, 37 | devDependencies: { 38 | 'slice-machine-ui': 'beta', 39 | }, 40 | } 41 | 42 | this.fs.extendJSON(this.destinationPath('package.json'), pkgJson) 43 | 44 | this.fs.copyTpl(this.templatePath(), this.destinationPath(), { 45 | defaultLibrary: '', 46 | domain: this.domain, 47 | }, undefined, { 48 | globOptions: {dot: true}, 49 | }) 50 | 51 | // maybe rename sm file 52 | if (this.existsDestination('sm.json') && SM_FILE !== 'sm.json') { 53 | this.moveDestination('sm.json', SM_FILE) 54 | } 55 | 56 | const customTypes = this.readCustomTypesFrom('custom_types') 57 | return this.maybeCreatePrismicRepository({domain: this.domain, framework: '<%= name %>', customTypes}, this.existingRepo) 58 | } 59 | 60 | async install() { 61 | if (this.pm === 'yarn') { 62 | this.yarnInstall() 63 | } else { 64 | this.npmInstall() 65 | } 66 | } 67 | 68 | async end() { 69 | const url = new URL(this.prismic.base) 70 | 71 | if (this.domain) { 72 | url.hostname = `${this.domain}.${url.hostname}` 73 | url.pathname = 'documents' 74 | } else { 75 | url.pathname = 'dashboard' 76 | } 77 | 78 | const writingRoomUrl = url.toString() 79 | 80 | this.log(` 81 | Your project is now configured to use SliceMachine! 82 | Follow these next steps to get going: 83 | 84 | - Add the SliceZone, anywhere in your code https://github.com/prismicio/slice-machine 85 | - Access your Prismic writing room here 86 | ${writingRoomUrl} 87 | 88 | - To add your own slice, run this command 89 | $> npx prismic-cli sm --create-slice 90 | 91 | - Run slicemachine 92 | $> npx prismic-cli sm --develop 93 | `) 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/app/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator from '@prismicio/prismic-yeoman-generator' 2 | import * as inquirer from 'inquirer' 3 | export default class extends PrismicGenerator { 4 | /** 5 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 6 | * 7 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 8 | * 9 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 10 | * 11 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 12 | * 13 | * writing - Where you write the generator specific files (routes, controllers, etc) 14 | * 15 | * conflicts - Where conflicts are handled (used internally) 16 | * 17 | * install - Where installations are run (npm, bower) 18 | * 19 | * end - Called last, cleanup, say good bye, etc 20 | */ 21 | 22 | // slicemachine: boolean | undefined; 23 | 24 | async initializing() { 25 | this.destinationRoot(this.path) 26 | } 27 | 28 | async configuring() { 29 | this.config.set('framework', 'nextjs') 30 | } 31 | 32 | async prompting() { 33 | if (!this.pm) await this.promptForPackageManager() 34 | if (this.options.slicemachine === undefined) { 35 | this.options.slicemachine = await inquirer.prompt<{slicemachine: boolean}>([{ 36 | 37 | name: 'slicemachine', 38 | type: 'confirm', 39 | default: true, 40 | message: 'Slice Machine', 41 | }]).then(res => res.slicemachine) 42 | } 43 | } 44 | 45 | async default() { 46 | const opts = { 47 | framework: 'nextjs', 48 | force: this.force, 49 | domain: this.domain, 50 | prismic: this.prismic, 51 | path: this.destinationRoot(), 52 | pm: this.pm, 53 | existingRepo: this.existingRepo, 54 | ...this.options, 55 | } 56 | 57 | if (this.options.slicemachine) { 58 | this.composeWith('prismic-nextjs:slicemachine', opts) 59 | this.composeWith('prismic-nextjs:create-slice', opts) 60 | this.composeWith('prismic-nextjs:storybook', opts) 61 | } 62 | } 63 | 64 | async writing() { 65 | this.fs.copyTpl( 66 | this.templatePath('**'), 67 | this.destinationPath(), 68 | {domain: this.domain}, 69 | undefined, 70 | {globOptions: {dot: true}}, 71 | ) 72 | 73 | const pkjJson = { 74 | name: this.domain, 75 | version: '0.1.0', 76 | private: true, 77 | scripts: { 78 | dev: 'next dev', 79 | build: 'next build', 80 | start: 'next start', 81 | export: 'next export', 82 | }, 83 | dependencies: { 84 | next: '^10.1.3', 85 | react: '^17.0.2', 86 | 'react-dom': '^17.0.2', 87 | '@prismicio/client': '^5', 88 | 'prismic-reactjs': '^1.3.3', 89 | }, 90 | } 91 | 92 | this.fs.extendJSON(this.destinationPath('package.json'), pkjJson) 93 | 94 | if (!this.options.slicemachine) { 95 | this.maybeCreatePrismicRepository({domain: this.domain, framework: 'next'}, this.existingRepo) 96 | } 97 | } 98 | 99 | async install() { 100 | if (this.pm === 'yarn') { 101 | this.yarnInstall() 102 | } else { 103 | this.npmInstall(undefined, {'legacy-peer-deps': true}) 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/index.ts: -------------------------------------------------------------------------------- 1 | import * as Generator from 'yeoman-generator' 2 | import * as path from 'path' 3 | import * as inquirer from 'inquirer' 4 | export default class extends Generator { 5 | name: string | undefined; 6 | 7 | pm: 'npm' | 'yarn' | undefined; 8 | 9 | language: 'javascript'| 'typescript' | undefined; 10 | 11 | path: string | undefined 12 | 13 | slicemachine: boolean | undefined 14 | 15 | constructor(argv: string | string[], opts: Generator.GeneratorOptions) { 16 | super(argv, opts) 17 | this.pm = opts.pm 18 | this.name = opts.name 19 | this.language = opts.language 20 | this.path = opts.path 21 | } 22 | 23 | async initializing() { 24 | if (this.path) this.destinationRoot(this.path) 25 | } 26 | 27 | async prompting() { 28 | if (!this.name) { 29 | this.name = await inquirer.prompt<{name: string}>([ 30 | { 31 | type: 'input', 32 | name: 'name', 33 | message: 'name of the generator', 34 | transformer: value => `generator-prismic-${value}`, 35 | validate: value => value ? true : 'required', 36 | }, 37 | ]).then(res => res.name.trim()) 38 | } 39 | 40 | if (!this.language) { 41 | this.language = await inquirer.prompt<{language: 'javascript' | 'typescript'}>([ 42 | { 43 | type: 'list', 44 | name: 'language', 45 | default: 'javascript', 46 | choices: [ 47 | {name: 'JavaScript', value: 'javascript'}, 48 | {name: 'TypeScript', value: 'typescript'}, 49 | ], 50 | message: 'Language', 51 | }, 52 | ]).then(res => res.language) 53 | } 54 | 55 | if (!this.pm) { 56 | this.pm = await inquirer.prompt<{pm: 'npm' | 'yarn'}>([ 57 | { 58 | type: 'list', 59 | name: 'pm', 60 | message: 'package manager', 61 | choices: [ 62 | { 63 | name: 'Yarn', 64 | value: 'yarn', 65 | }, 66 | { 67 | name: 'Npm', 68 | value: 'npm', 69 | }, 70 | ], 71 | }, 72 | ]).then(res => res.pm) 73 | } 74 | 75 | if (!this.slicemachine) { 76 | this.slicemachine = await inquirer.prompt<{slicemachine: boolean}>([{ 77 | type: 'confirm', 78 | name: 'slicemachine', 79 | message: 'Support SliceMachine', 80 | default: true, 81 | }]).then(res => res.slicemachine) 82 | } 83 | } 84 | 85 | async configuring() { 86 | this.destinationRoot(`generator-prismic-${this.name}`) 87 | } 88 | 89 | async writing() { 90 | const template = path.join(this.language || 'javascript', '**') 91 | const opts = { 92 | name: this.name, 93 | packageName: `generator-prismic-${this.name}`, 94 | slicemachine: this.slicemachine, 95 | } 96 | 97 | this.fs.copyTpl( 98 | this.templatePath(template), 99 | this.destinationPath(), 100 | opts, 101 | {}, 102 | {globOptions: {dot: true}}, 103 | ) 104 | 105 | if (!this.slicemachine) { 106 | this.deleteDestination(path.join('generators', 'slicemachine')) 107 | this.deleteDestination(path.join('generators', 'create-slice')) 108 | this.deleteDestination(path.join('generators', 'storybook')) 109 | } 110 | } 111 | 112 | async install() { 113 | if (this.pm === 'yarn') { 114 | return this.yarnInstall() 115 | } 116 | return this.npmInstall() 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/javascript/generators/create-slice/index.js: -------------------------------------------------------------------------------- 1 | const PrismicGenerator = require('@prismicio/prismic-yeoman-generator').default 2 | const isValidPath = require('is-valid-path') 3 | const path = require('path').posix 4 | 5 | const fs = require('fs') 6 | const inquirer = require('inquirer') // this is easier to mock 7 | 8 | const {SM_FILE} = require('sm-commons/consts') 9 | 10 | function validateSliceName(name) { 11 | // PascalCase 12 | const regexp = /^([A-Z][a-z]+){2,}$/ 13 | if (!name) return false 14 | return regexp.test(name) 15 | } 16 | 17 | class CreateSlice extends PrismicGenerator { 18 | /** 19 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 20 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 21 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 22 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 23 | * writing - Where you write the generator specific files (routes, controllers, etc) 24 | * conflicts - Where conflicts are handled (used internally) 25 | * install - Where installations are run (npm, bower) 26 | * end - Called last, cleanup, say good bye, etc 27 | */ 28 | 29 | constructor(argv, opts) { 30 | super(argv, opts) 31 | this.answers = {} 32 | if (this.destinationRoot().endsWith(this.path) === false) { 33 | this.destinationRoot(this.path) 34 | } 35 | } 36 | 37 | async prompting() { 38 | const {library} = isValidPath(this.options.library) ? this.options : await inquirer.prompt([{ 39 | type: 'text', 40 | name: 'library', 41 | default: 'slices', 42 | prefix: '🗂 ', 43 | message: 'Where should we create your new local library?', 44 | validate: (value) => { 45 | return (value && isValidPath(this.destinationPath(value))) || ('Invalid Path: ' + value) 46 | }, 47 | }]) 48 | 49 | const {sliceName} = validateSliceName(this.options.sliceName) ? this.options : await inquirer.prompt([{ 50 | type: 'text', 51 | name: 'sliceName', 52 | message: 'Enter the name of your slice (2 words, PascalCased)', 53 | default: this.options.sliceName || 'TestSlice', 54 | validate: value => { 55 | return validateSliceName(value) || 'Must be PascalCased' 56 | }, // change validation to check for the slice as well. 57 | }]) 58 | 59 | Object.assign(this.answers, {sliceName, library}) 60 | } 61 | 62 | async configuring() { 63 | this.copySliceTemplate(this.answers.library, this.answers.sliceName) 64 | } 65 | 66 | async writing() { 67 | // change to library and lbrary/slice rather that index, default and next 68 | const libIndex = this.destinationPath(path.join(this.answers.library, 'index.js')) 69 | const hasLibIndex = fs.existsSync(libIndex) 70 | 71 | if (hasLibIndex) { 72 | this.fs.copy(libIndex, libIndex) 73 | const content = `export { default as ${this.answers.sliceName} } from './${this.answers.sliceName}'` 74 | this.fs.append(libIndex, content) 75 | } else { 76 | this.fs.copyTpl( 77 | this.templatePath('library/index.js'), 78 | libIndex, 79 | {sliceName: this.answers.sliceName}, 80 | ) 81 | } 82 | 83 | const libName = path.join('@', this.answers.library) 84 | const {libraries} = this.readDestinationJSON(SM_FILE, {libraries: []}) 85 | 86 | if (libraries.includes(libName) === false) { 87 | this.fs.extendJSON(this.destinationPath(SM_FILE), {libraries: [...libraries, libName]}) 88 | } 89 | } 90 | } 91 | 92 | module.exports = CreateSlice -------------------------------------------------------------------------------- /packages/prismic-cli/src/generators/theme.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | import * as Framework from '../utils/framework' 3 | 4 | export interface ThemeOptions extends TemplateOptions { 5 | source: string; 6 | configPath: string; 7 | documentsPath: string; 8 | } 9 | 10 | /** 11 | * The contents of a `prismic-theme.json` file that a theme can include to 12 | * configure the `prismic theme` command. 13 | */ 14 | interface ThemeConfig { 15 | /** 16 | * The Prismic repository name in the theme's Prismic configuration file (e.g. 17 | * `prismic-configuration.js`) to replace with the new repository name. 18 | */ 19 | replaceRepositoryName?: string; 20 | } 21 | 22 | export default class PrismicTheme extends PrismicGenerator { 23 | source: string 24 | 25 | customTypesPath: string 26 | 27 | documentsPath: string 28 | 29 | configPath: string 30 | 31 | constructor(argv: string | string[], opts: ThemeOptions) { 32 | super(argv, opts) 33 | this.source = opts.source 34 | this.customTypesPath = opts.customTypesPath 35 | this.documentsPath = opts.documentsPath 36 | this.configPath = opts.configPath || 'prismic-configuration.js' 37 | } 38 | 39 | async initializing() { 40 | this.destinationRoot(this.path) 41 | const innerFolder = this.innerFolderFromGitRepo(this.source) 42 | return this.downloadAndExtractZipFrom(this.source, innerFolder) 43 | } 44 | 45 | async prompting() { 46 | this.pm = await this.promptForPackageManager() 47 | } 48 | 49 | async configuring() { 50 | const customTypes = this.readCustomTypesFrom(this.customTypesPath) 51 | const documents = this.readDocumentsFrom(this.documentsPath) 52 | 53 | const pkg: Framework.PkgJson | null = (() => { 54 | const pkgPath = this.destinationPath('package.json') 55 | if (this.fs.exists(pkgPath) === false) { 56 | return null 57 | } 58 | return this.fs.readJSON(pkgPath) as Framework.PkgJson 59 | })() 60 | 61 | if (!pkg) console.error('NO PKG FOUND') 62 | 63 | const maybeFramework = pkg && Framework.detect(pkg) 64 | 65 | this.maybeCreatePrismicRepository({ 66 | domain: this.domain, 67 | customTypes, 68 | signedDocuments: documents, 69 | framework: maybeFramework || 'other', 70 | }, this.existingRepo).then(res => { 71 | if (res.data) this.domain = res.data 72 | }) 73 | } 74 | 75 | async writing() { 76 | const location = this.destinationPath(this.configPath) 77 | 78 | let themeConfig: ThemeConfig = {} 79 | try { 80 | themeConfig = JSON.parse(this.readDestination('prismic-theme.json', {defaults: '{}'})) 81 | } catch { 82 | console.error("An invalid prismic-theme.json was found. The theme's configuration will be ignored.") 83 | } 84 | 85 | if (this.existsDestination(this.configPath)) { 86 | const oldConfig = this.readDestination(this.configPath) 87 | const oldRepoName = themeConfig.replaceRepositoryName || 'your-repo-name' 88 | const newConfig = oldConfig.replace(new RegExp(oldRepoName, 'g'), this.domain) 89 | this.writeDestination(this.configPath, newConfig) 90 | } else { 91 | const url = new URL(this.prismic.base) 92 | url.host = `${this.domain}.${url.host}` 93 | url.pathname = '/api/v2' 94 | this.fs.writeJSON(location, {apiEndpoint: url.toString()}) 95 | } 96 | 97 | if (this.existsDestination('prismic-theme.json')) { 98 | this.deleteDestination('prismic-theme.json') 99 | } 100 | } 101 | 102 | async install() { 103 | if (this.pm === 'yarn') { 104 | this.yarnInstall() 105 | } else { 106 | this.npmInstall() 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /packages/prismic-generator-generator/app/templates/typescript/generators/create-slice/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | const isValidPath = require('is-valid-path') 3 | import * as nodePath from 'path' 4 | import * as fs from 'fs' 5 | import * as inquirer from 'inquirer' // this is easier to mock 6 | 7 | const {SM_FILE} = require('sm-commons/consts') 8 | 9 | const path = nodePath.posix 10 | 11 | function validateSliceName(name: string): boolean { 12 | // PascalCase 13 | const regexp = /^([A-Z][a-z]+){2,}$/ 14 | if (!name) return false 15 | return regexp.test(name) 16 | } 17 | 18 | export default class CreateSlice extends PrismicGenerator { 19 | /** 20 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 21 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 22 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 23 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 24 | * writing - Where you write the generator specific files (routes, controllers, etc) 25 | * conflicts - Where conflicts are handled (used internally) 26 | * install - Where installations are run (npm, bower) 27 | * end - Called last, cleanup, say good bye, etc 28 | */ 29 | answers: Record = {} 30 | 31 | constructor(argv: string|string[], opts: TemplateOptions) { 32 | super(argv, opts) 33 | 34 | if (this.destinationRoot().endsWith(this.path) === false) { 35 | this.destinationRoot(this.path) 36 | } 37 | } 38 | 39 | async prompting() { 40 | const {library} = isValidPath(this.options.library) ? this.options : await inquirer.prompt<{library: string}>([{ 41 | type: 'text', 42 | name: 'library', 43 | default: 'slices', 44 | prefix: '🗂 ', 45 | message: 'Where should we create your new local library?', 46 | validate: (value: string) => { 47 | return (value && isValidPath(this.destinationPath(value))) || ('Invalid Path: ' + value) 48 | }, 49 | }]) 50 | 51 | const {sliceName} = validateSliceName(this.options.sliceName) ? this.options : await inquirer.prompt<{sliceName: string}>([{ 52 | type: 'text', 53 | name: 'sliceName', 54 | message: 'Enter the name of your slice (2 words, PascalCased)', 55 | default: this.options.sliceName || 'TestSlice', 56 | validate: value => { 57 | return validateSliceName(value) || 'Must be PascalCased' 58 | }, // change validation to check for the slice as well. 59 | }]) 60 | 61 | Object.assign(this.answers, {sliceName, library}) 62 | } 63 | 64 | async configuring() { 65 | this.copySliceTemplate(this.answers.library, this.answers.sliceName) 66 | } 67 | 68 | async writing() { 69 | // change to library and lbrary/slice rather that index, default and next 70 | const libIndex = this.destinationPath(path.join(this.answers.library, 'index.js')) 71 | const hasLibIndex = fs.existsSync(libIndex) 72 | 73 | if (hasLibIndex) { 74 | this.fs.copy(libIndex, libIndex) 75 | const content = `export { default as ${this.answers.sliceName} } from './${this.answers.sliceName}'` 76 | this.fs.append(libIndex, content) 77 | } else { 78 | this.fs.copyTpl( 79 | this.templatePath('library/index.js'), 80 | libIndex, 81 | {sliceName: this.answers.sliceName}, 82 | ) 83 | } 84 | 85 | const libName = path.join('@', this.answers.library) 86 | const {libraries} = this.readDestinationJSON(SM_FILE, {libraries: []}) as unknown as SliceMachineConfig 87 | 88 | if (libraries.includes(libName) === false) { 89 | this.fs.extendJSON(this.destinationPath(SM_FILE), {libraries: [...libraries, libName]}) 90 | } 91 | } 92 | } 93 | 94 | export interface SliceMachineConfig { 95 | libraries: Array; 96 | _latest: string; 97 | apiEndpoint: string; 98 | } 99 | -------------------------------------------------------------------------------- /packages/generator-prismic-nextjs/generators/create-slice/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | const isValidPath = require('is-valid-path') 3 | import * as nodePath from 'path' 4 | import * as fs from 'fs' 5 | import * as inquirer from 'inquirer' // this is easier to mock 6 | const path = nodePath.posix 7 | 8 | const {SM_FILE} = require('sm-commons/consts') 9 | 10 | function validateSliceName(name: string): boolean { 11 | // PascalCase 12 | const regexp = /^([A-Z][a-z]+){2,}$/ 13 | if (!name) return false 14 | return regexp.test(name) 15 | } 16 | export default class CreateSlice extends PrismicGenerator { 17 | /** 18 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 19 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 20 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 21 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 22 | * writing - Where you write the generator specific files (routes, controllers, etc) 23 | * conflicts - Where conflicts are handled (used internally) 24 | * install - Where installations are run (npm, bower) 25 | * end - Called last, cleanup, say good bye, etc 26 | */ 27 | answers: Record = {} 28 | 29 | constructor(argv: string|string[], opts: TemplateOptions) { 30 | super(argv, opts) 31 | 32 | if (this.destinationRoot().endsWith(this.path) === false) { 33 | this.destinationRoot(this.path) 34 | } 35 | } 36 | 37 | async prompting() { 38 | // TODO: case where a user may already have a slice library to add to 39 | const {library} = isValidPath(this.options.library) ? this.options : await inquirer.prompt<{library: string}>([{ 40 | type: 'text', 41 | name: 'library', 42 | default: 'slices', 43 | prefix: '🗂 ', 44 | message: 'Where should we create your new local library?', 45 | validate: (value: string) => { 46 | return (value && isValidPath(this.destinationPath(value))) || ('Invalid Path: ' + value) 47 | }, 48 | }]) 49 | 50 | const {sliceName} = validateSliceName(this.options.sliceName) ? this.options : await inquirer.prompt<{sliceName: string}>([{ 51 | type: 'text', 52 | name: 'sliceName', 53 | message: 'Enter the name of your slice (2 words, PascalCased)', 54 | default: this.options.sliceName || 'TestSlice', 55 | validate: value => { 56 | return validateSliceName(value) || 'Must be PascalCased' 57 | }, // change validation to check for the slice as well. 58 | }]) 59 | 60 | Object.assign(this.answers, {sliceName, library}) 61 | } 62 | 63 | async configuring() { 64 | this.copySliceTemplate(this.answers.library, this.answers.sliceName) 65 | } 66 | 67 | async writing() { 68 | // change to library and library/slice 69 | const libIndex = this.destinationPath(path.join(this.answers.library, 'index.js')) 70 | const hasLibIndex = fs.existsSync(libIndex) 71 | 72 | if (hasLibIndex) { 73 | this.fs.copy(libIndex, libIndex) 74 | const content = `export { default as ${this.answers.sliceName} } from './${this.answers.sliceName}'` 75 | this.fs.append(libIndex, content) 76 | } else { 77 | this.fs.copyTpl( 78 | this.templatePath('library/index.js'), 79 | libIndex, 80 | {sliceName: this.answers.sliceName}, 81 | ) 82 | } 83 | 84 | const libName = path.join('@', this.answers.library) 85 | const {libraries} = this.readDestinationJSON(SM_FILE, {libraries: []}) as unknown as SliceMachineConfig 86 | 87 | if (libraries.includes(libName) === false) { 88 | // update sm.json 89 | this.fs.extendJSON(this.destinationPath(SM_FILE), {libraries: [...libraries, libName]}) 90 | } 91 | } 92 | } 93 | 94 | export interface SliceMachineConfig { 95 | libraries: Array; 96 | _latest: string; 97 | apiEndpoint: string; 98 | } 99 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/create-slice/index.ts: -------------------------------------------------------------------------------- 1 | import PrismicGenerator, {TemplateOptions} from '@prismicio/prismic-yeoman-generator' 2 | const isValidPath = require('is-valid-path') 3 | import * as nodePath from 'path' 4 | import * as fs from 'fs' 5 | import * as inquirer from 'inquirer' // this is easier to mock 6 | const {SM_FILE} = require('sm-commons/consts') 7 | 8 | const path = nodePath.posix 9 | 10 | function validateSliceName(name: string): boolean { 11 | // PascalCase 12 | const regexp = /^([A-Z][a-z]+){2,}$/ 13 | if (!name) return false 14 | return regexp.test(name) 15 | } 16 | export default class CreateSlice extends PrismicGenerator { 17 | /** 18 | * initializing - Your initialization methods (checking current project state, getting configs, etc) 19 | * prompting - Where you prompt users for options (where you’d call this.prompt()) 20 | * configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) 21 | * default - If the method name doesn’t match a priority, it will be pushed to this group. 22 | * writing - Where you write the generator specific files (routes, controllers, etc) 23 | * conflicts - Where conflicts are handled (used internally) 24 | * install - Where installations are run (npm, bower) 25 | * end - Called last, cleanup, say good bye, etc 26 | */ 27 | answers: Record = {} 28 | 29 | constructor(argv: string|string[], opts: TemplateOptions) { 30 | super(argv, opts) 31 | 32 | if (this.destinationRoot().endsWith(this.path) === false) { 33 | this.destinationRoot(this.path) 34 | } 35 | 36 | const framework = this.config.get('framework') 37 | if (!framework) { 38 | this.config.set('framework', 'nuxt') 39 | } 40 | } 41 | 42 | async prompting() { 43 | const {library} = isValidPath(this.options.library) ? this.options : await inquirer.prompt([{ 44 | type: 'text', 45 | name: 'library', 46 | default: 'slices', 47 | prefix: '🗂 ', 48 | message: 'Where should we create your new local library?', 49 | validate: (value: string) => { 50 | return (value && isValidPath(this.destinationPath(value))) || ('Invalid Path: ' + value) 51 | }, 52 | }]) 53 | 54 | const {sliceName} = validateSliceName(this.options.sliceName) ? this.options : await inquirer.prompt([{ 55 | type: 'text', 56 | name: 'sliceName', 57 | message: 'Enter the name of your slice (2 words, PascalCased)', 58 | default: this.options.sliceName || 'TestSlice', 59 | validate: value => { 60 | return validateSliceName(value) || 'Must be PascalCased' 61 | }, // change validation to check for the slice as well. 62 | }]) 63 | 64 | Object.assign(this.answers, {sliceName, library}) 65 | } 66 | 67 | async configuring() { 68 | this.copySliceTemplate(this.answers.library, this.answers.sliceName) 69 | } 70 | 71 | async writing() { 72 | const libIndex = this.destinationPath(path.join(this.answers.library, 'index.js')) 73 | const hasLibIndex = fs.existsSync(libIndex) 74 | 75 | if (hasLibIndex) { 76 | this.fs.copy(libIndex, libIndex) 77 | const content = `export { default as ${this.answers.sliceName} } from './${this.answers.sliceName}'` 78 | this.fs.append(libIndex, content) 79 | } else { 80 | this.fs.copyTpl( 81 | this.templatePath('library/index.js'), 82 | libIndex, 83 | {sliceName: this.answers.sliceName}, 84 | ) 85 | } 86 | 87 | const libName = path.join('@', this.answers.library) 88 | const {libraries} = this.readDestinationJSON(SM_FILE, {libraries: []}) as unknown as SliceMachineConfig 89 | 90 | if (libraries.includes(libName) === false) { 91 | this.fs.extendJSON(this.destinationPath(SM_FILE), {libraries: [...libraries, libName]}) 92 | } 93 | } 94 | } 95 | 96 | export interface SliceMachineConfig { 97 | libraries: Array; 98 | apiEndpoint: string; 99 | } 100 | -------------------------------------------------------------------------------- /packages/prismic-cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prismic-cli", 3 | "description": "Command line to bootstrap prismic projects.", 4 | "version": "4.2.3", 5 | "author": "prismic.io developers", 6 | "bin": { 7 | "prismic": "bin/run" 8 | }, 9 | "bugs": "https://github.com/prismicio/prismic-cli/issues", 10 | "contributors": [ 11 | "Marc McIntosh " 12 | ], 13 | "dependencies": { 14 | "@babel/generator": "^7.12.11", 15 | "@babel/parser": "^7.12.11", 16 | "@babel/traverse": "^7.12.12", 17 | "@babel/types": "^7.12.12", 18 | "@hapi/hapi": "^20.1.5", 19 | "@oclif/command": "^1", 20 | "@oclif/config": "^1", 21 | "@oclif/plugin-help": "^3", 22 | "@prismicio/prismic-generator-generator": "4.2.1", 23 | "@prismicio/prismic-yeoman-generator": "4.2.3", 24 | "@types/adm-zip": "^0.4.33", 25 | "@types/inquirer": "^7.3.1", 26 | "@types/node": "^14.14.10", 27 | "@types/qs": "^6.9.5", 28 | "@types/yeoman-generator": "^5.2.7", 29 | "adm-zip": "^0.5.1", 30 | "axios": "^0.24.0", 31 | "chalk": "^4.1.1", 32 | "cli-ux": "^5.5.1", 33 | "cookie": "^0.4.1", 34 | "create-nuxt-app": "^4.0.0", 35 | "email-validator": "^2.0.4", 36 | "fast-glob": "^3.2.5", 37 | "fs-extra": "^9.1.0", 38 | "generator-prismic-angular2": "4.2.3", 39 | "generator-prismic-nextjs": "4.2.3", 40 | "generator-prismic-nodejs": "4.2.3", 41 | "generator-prismic-nuxt": "4.2.3", 42 | "generator-prismic-react": "4.2.3", 43 | "generator-prismic-vue": "4.2.3", 44 | "inquirer": "^7.3.3", 45 | "is-valid-path": "^0.1.1", 46 | "libnpmconfig": "^1.2.1", 47 | "lookpath": "^1.2.0", 48 | "mem-fs": "^2.2.1", 49 | "mem-fs-editor": "^9.4.0", 50 | "qs": "^6.9.4", 51 | "semver": "^7.3.5", 52 | "serialize-error": "^8.0.1", 53 | "sinon": "^9.2.1", 54 | "sm-commons": "^0.0.23", 55 | "tmp-promise": "^3.0.2", 56 | "tslib": "^1", 57 | "yeoman-environment": "^3.8.1", 58 | "yeoman-generator": "^5.4.2" 59 | }, 60 | "devDependencies": { 61 | "@oclif/dev-cli": "^1", 62 | "@oclif/test": "^1", 63 | "@types/babel__generator": "^7.6.2", 64 | "@types/babel__traverse": "^7.11.0", 65 | "@types/chai": "^4", 66 | "@types/cookie": "^0.4.0", 67 | "@types/fs-extra": "^9.0.7", 68 | "@types/hapi__hapi": "^20.0.9", 69 | "@types/is-valid-path": "^0.1.0", 70 | "@types/mocha": "^5", 71 | "@types/rimraf": "^3.0.0", 72 | "@types/semver": "^7.3.5", 73 | "@types/tmp": "^0.2.0", 74 | "chai": "^4", 75 | "eslint": "^7", 76 | "eslint-config-oclif": "^3.1", 77 | "eslint-config-oclif-typescript": "^0.1", 78 | "globby": "^10", 79 | "mocha": "^5", 80 | "nock": "^13.0.5", 81 | "nyc": "^14", 82 | "rimraf": "^3.0.2", 83 | "standard-changelog": "^2.0.27", 84 | "ts-node": "^8", 85 | "typescript": "^3.3" 86 | }, 87 | "engines": { 88 | "node": ">=14.0.0" 89 | }, 90 | "files": [ 91 | "/bin", 92 | "/lib", 93 | "/npm-shrinkwrap.json", 94 | "/oclif.manifest.json", 95 | "/src" 96 | ], 97 | "homepage": "https://github.com/prismicio/prismic-cli", 98 | "keywords": [ 99 | "oclif" 100 | ], 101 | "license": "Apache-2.0", 102 | "main": "lib/index.js", 103 | "oclif": { 104 | "commands": "./lib/commands", 105 | "bin": "prismic", 106 | "plugins": [ 107 | "@oclif/plugin-help" 108 | ], 109 | "hooks": { 110 | "postrun": "./lib/hooks/postrun/updates" 111 | } 112 | }, 113 | "repository": "prismicio/prismic-cli", 114 | "scripts": { 115 | "clean": "rimraf lib", 116 | "postpack": "rimraf oclif.manifest.json", 117 | "posttest": "eslint . --ext .ts --config .eslintrc", 118 | "prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme", 119 | "test": "nyc --extension .ts mocha \"test/**/*.test.ts\"", 120 | "version": "oclif-dev readme && git add README.md && standard-changelog && git add CHANGELOG.md" 121 | }, 122 | "types": "lib/index.d.ts", 123 | "gitHead": "a36c058ffb375807bed3d47981f699af42346aad" 124 | } 125 | -------------------------------------------------------------------------------- /packages/generator-prismic-nuxt/generators/slicemachine/modify-nuxt-config.ts: -------------------------------------------------------------------------------- 1 | import * as parser from '@babel/parser' 2 | import {default as traverse, NodePath} from '@babel/traverse' 3 | import * as t from '@babel/types' 4 | import generate from '@babel/generator' 5 | 6 | function getKeys(properties: Array): Array { 7 | return properties.reduce>((acc, curr) => { 8 | if (t.isObjectProperty(curr) && t.isIdentifier(curr.key)) { 9 | return [...acc, curr.key.name] 10 | } 11 | return acc 12 | }, []) 13 | } 14 | 15 | export default function modifyNuxtConfig(source: string, domain: string): string { 16 | const ast = parser.parse(source, {sourceType: 'module'}) 17 | 18 | const srcPollyFill = t.objectExpression([t.objectProperty(t.identifier('src'), t.stringLiteral('https://cdn.polyfill.io/v2/polyfill.min.js?features=Element.prototype.classList'))]) 19 | 20 | const srcFocusVisible = t.objectExpression([t.objectProperty(t.identifier('src'), t.stringLiteral('https://cdn.jsdelivr.net/npm/focus-visible@5.0.2/dist/focus-visible.min.js'))]) 21 | 22 | const css = t.stringLiteral('vue-essential-slices/src/styles/styles.scss') 23 | 24 | const modulesToTranspile = t.arrayExpression([ 25 | t.stringLiteral('vue-slicezone'), 26 | t.stringLiteral('nuxt-sm'), 27 | ]) 28 | 29 | const transpile = t.objectProperty(t.identifier('transpile'), modulesToTranspile) 30 | 31 | const modules = t.arrayExpression([ 32 | t.stringLiteral('@nuxtjs/prismic'), 33 | t.objectExpression([ 34 | t.objectProperty( 35 | t.identifier('endpoint'), 36 | t.stringLiteral(`https://${domain}.cdn.prismic.io/api/v2`)), 37 | t.objectProperty( 38 | t.identifier('apiOptions'), 39 | t.objectExpression([ 40 | t.objectProperty( 41 | t.identifier('routes'), 42 | t.arrayExpression([ 43 | t.objectExpression([ 44 | t.objectProperty( 45 | t.identifier('type'), 46 | t.stringLiteral('page'), 47 | ), 48 | t.objectProperty( 49 | t.identifier('path'), 50 | t.stringLiteral('/:uid'), 51 | ), 52 | ]), 53 | ]), 54 | ), 55 | ]), 56 | ), 57 | ]), 58 | ]) 59 | 60 | traverse(ast, { 61 | ObjectExpression(path: NodePath) { 62 | path.node.properties.forEach((prop: t.ObjectMethod | t.ObjectProperty | t.SpreadElement) => { 63 | if (t.isObjectProperty(prop) && t.isIdentifier(prop.key) && t.isObjectExpression(prop.value) && prop.key.name === 'head') { 64 | const keys = getKeys(prop.value.properties) 65 | const hasScript = keys.includes('script') 66 | 67 | if (hasScript === false) { 68 | return prop.value.properties.push(t.objectProperty(t.identifier('script'), t.arrayExpression([ 69 | srcPollyFill, 70 | srcFocusVisible, 71 | ]))) 72 | } 73 | return prop.value.properties.forEach(headProp => { 74 | if (t.isObjectProperty(headProp) && t.isIdentifier(headProp.key) && t.isArrayExpression(headProp.value) && headProp.key.name === 'script') { 75 | headProp.value.elements.push(srcPollyFill, srcFocusVisible) 76 | } 77 | }) 78 | } 79 | 80 | if (t.isObjectProperty(prop) && t.isIdentifier(prop.key) && t.isArrayExpression(prop.value) && prop.key.name === 'css') { 81 | return prop.value.elements.push(css) 82 | } 83 | 84 | if (t.isObjectProperty(prop) && t.isIdentifier(prop.key) && t.isArrayExpression(prop.value) && prop.key.name === 'modules') { 85 | return prop.value.elements.push(modules) 86 | } 87 | 88 | if (t.isObjectProperty(prop) && t.isIdentifier(prop.key) && t.isObjectExpression(prop.value) && prop.key.name === 'build') { 89 | const keys = getKeys(prop.value.properties) 90 | const hasTranspile = keys.includes('transpile') 91 | if (hasTranspile === false) { 92 | return prop.value.properties.push(transpile) 93 | } 94 | return prop.value.properties.forEach(buildProp => { 95 | if (t.isObjectProperty(buildProp) && t.isIdentifier(buildProp.key) && t.isArrayExpression(buildProp.value) && buildProp.key.name === 'transpile') { 96 | buildProp.value.elements.push(modulesToTranspile) 97 | } 98 | }) 99 | } 100 | }) 101 | }, 102 | }) 103 | 104 | const {code} = generate(ast, { /* config */ }, source) 105 | 106 | return code 107 | } 108 | --------------------------------------------------------------------------------