generator-folklore 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/lib/generators/intl/index.js +93 -0
  2. package/lib/generators/laravel-mediatheque/index.js +133 -0
  3. package/lib/generators/laravel-mediatheque/templates/app/Models/Media.php +9 -0
  4. package/lib/generators/laravel-mediatheque/templates/app/Models/MediaFile.php +9 -0
  5. package/lib/generators/laravel-panneau/index.js +49 -28
  6. package/lib/generators/laravel-panneau/templates/app/Contracts/Repositories/Pages.php +19 -0
  7. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Blocks/Text.php +10 -0
  8. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Page.php +10 -0
  9. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Pages/Home.php +9 -0
  10. package/lib/generators/laravel-panneau/templates/app/Http/Resources/BlockResource.php +37 -0
  11. package/lib/generators/laravel-panneau/templates/app/Http/Resources/BlocksCollection.php +8 -0
  12. package/lib/generators/laravel-panneau/templates/app/Http/Resources/PageResource.php +47 -0
  13. package/lib/generators/laravel-panneau/templates/app/Http/Resources/PagesCollection.php +10 -0
  14. package/lib/generators/laravel-panneau/templates/app/Models/Block.php +3 -13
  15. package/lib/generators/laravel-panneau/templates/app/Models/Page.php +3 -60
  16. package/lib/generators/laravel-panneau/templates/app/Panneau/Composers/AppComposer.php +50 -0
  17. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Block.php +22 -0
  18. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Blocks.php +87 -0
  19. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Page.php +51 -0
  20. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlug.php +34 -0
  21. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlugLocalized.php +18 -0
  22. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/AccountController.php +41 -0
  23. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/Controller.php +19 -0
  24. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/HomeController.php +16 -0
  25. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/PagesController.php +24 -0
  26. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/UploadController.php +27 -0
  27. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/UsersController.php +32 -0
  28. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Requests/AccountUpdateRequest.php +29 -0
  29. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Requests/UploadRequest.php +29 -0
  30. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlockResource.php +39 -0
  31. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlocksCollection.php +8 -0
  32. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/PageResource.php +56 -0
  33. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/PagesCollection.php +10 -0
  34. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/UserResource.php +24 -0
  35. package/lib/generators/laravel-panneau/templates/app/Panneau/PanneauServiceProvider.php +48 -0
  36. package/lib/generators/laravel-panneau/templates/app/Panneau/Policies/PanneauPolicy.php +32 -0
  37. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/BlockWithBlocks.php +110 -0
  38. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/TextBlock.php +27 -0
  39. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks.php +42 -0
  40. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages/Page.php +28 -0
  41. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages.php +92 -0
  42. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Users.php +57 -0
  43. package/lib/generators/laravel-panneau/templates/app/Repositories/Pages.php +42 -0
  44. package/lib/generators/laravel-panneau/templates/app/Resources/Blocks/TextBlock.php +14 -0
  45. package/lib/generators/laravel-panneau/templates/app/Resources/Page.php +10 -0
  46. package/lib/generators/laravel-panneau/templates/app/Resources/Pages/HomePage.php +10 -0
  47. package/lib/generators/laravel-panneau/templates/app.blade.php +8 -0
  48. package/lib/generators/laravel-panneau/templates/index.js +32 -0
  49. package/lib/generators/laravel-panneau/templates/lang/en/panneau.php +62 -0
  50. package/lib/generators/laravel-panneau/templates/lang/fr/panneau.php +62 -0
  51. package/lib/generators/laravel-panneau/templates/layout.blade.php +17 -48
  52. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/Panneau.jsx +68 -0
  53. package/lib/generators/laravel-panneau/templates/{app/Schemas/Fields/.gitkeep → resources/assets/js/components/panneau/fields/PageSlug.jsx} +0 -0
  54. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/PageSlugLocalized.jsx +43 -0
  55. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/index.js +2 -0
  56. package/lib/generators/laravel-panneau/templates/resources/assets/styles/panneau.scss +2 -0
  57. package/lib/generators/laravel-panneau/templates/routes.php +30 -0
  58. package/lib/generators/laravel-project/index.js +504 -0
  59. package/lib/generators/laravel-project/templates/env +41 -0
  60. package/lib/generators/laravel-project/templates/laravel/app/Composers/AppComposer.php +48 -0
  61. package/lib/generators/laravel-project/templates/laravel/app/Composers/IntlComposer.php +10 -0
  62. package/lib/generators/laravel-project/templates/laravel/app/Composers/MetaComposer.php +48 -0
  63. package/lib/generators/laravel-project/templates/laravel/app/Composers/RoutesComposer.php +19 -0
  64. package/lib/generators/laravel-project/templates/laravel/app/Contracts/Resources/User.php +10 -0
  65. package/lib/generators/laravel-project/templates/laravel/app/Http/Controllers/HomeController.php +18 -0
  66. package/lib/generators/laravel-project/templates/laravel/app/Http/Middleware/TrustProxies.php +28 -0
  67. package/lib/generators/laravel-project/templates/laravel/app/Http/Resources/UserResource.php +21 -0
  68. package/lib/generators/laravel-project/templates/laravel/app/Models/User.php +50 -0
  69. package/lib/generators/laravel-project/templates/laravel/app/Providers/AppServiceProvider.php +45 -0
  70. package/lib/generators/laravel-project/templates/laravel/app/Providers/RouteServiceProvider.php +64 -0
  71. package/lib/generators/laravel-project/templates/laravel/app/Providers/ViewServiceProvider.php +33 -0
  72. package/lib/generators/laravel-project/templates/laravel/app/Repositories/Users.php +36 -0
  73. package/lib/generators/laravel-project/templates/laravel/app/Resources/User.php +11 -0
  74. package/lib/generators/laravel-project/templates/laravel/config/app.php +216 -0
  75. package/lib/generators/laravel-project/templates/laravel/config/auth.php +116 -0
  76. package/lib/generators/laravel-project/templates/laravel/config/services.php +39 -0
  77. package/lib/generators/laravel-project/templates/laravel/lang/en/content.php +5 -0
  78. package/lib/generators/laravel-project/templates/laravel/lang/en/errors.php +17 -0
  79. package/lib/generators/laravel-project/templates/laravel/lang/en/meta.php +11 -0
  80. package/lib/generators/laravel-project/templates/laravel/lang/en/routes.php +4 -0
  81. package/lib/generators/laravel-project/templates/laravel/lang/fr/auth.php +19 -0
  82. package/lib/generators/laravel-project/templates/laravel/lang/fr/content.php +5 -0
  83. package/lib/generators/laravel-project/templates/laravel/lang/fr/errors.php +17 -0
  84. package/lib/generators/laravel-project/templates/laravel/lang/fr/meta.php +11 -0
  85. package/lib/generators/laravel-project/templates/laravel/lang/fr/pagination.php +19 -0
  86. package/lib/generators/laravel-project/templates/laravel/lang/fr/passwords.php +22 -0
  87. package/lib/generators/laravel-project/templates/laravel/lang/fr/routes.php +12 -0
  88. package/lib/generators/laravel-project/templates/laravel/lang/fr/validation.php +146 -0
  89. package/lib/generators/laravel-project/templates/laravel/resources/assets/fonts/.gitkeep +0 -0
  90. package/lib/generators/laravel-project/templates/laravel/resources/assets/img/.gitkeep +0 -0
  91. package/lib/generators/laravel-project/templates/laravel/resources/assets/img/folklore.png +0 -0
  92. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/body.blade.php +3 -0
  93. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/gpt.blade.php +16 -0
  94. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/head.blade.php +1 -0
  95. package/lib/generators/laravel-project/templates/laravel/resources/views/app.blade.php +8 -0
  96. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/401.blade.php +8 -0
  97. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/403.blade.php +8 -0
  98. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/404.blade.php +8 -0
  99. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/500.blade.php +8 -0
  100. package/lib/generators/laravel-project/templates/laravel/resources/views/layout.blade.php +33 -0
  101. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/all.blade.php +4 -0
  102. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/base.blade.php +11 -0
  103. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/facebook.blade.php +4 -0
  104. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/opengraph.blade.php +9 -0
  105. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/twitter.blade.php +5 -0
  106. package/lib/generators/laravel-project/templates/laravel/routes/web.php +12 -0
  107. package/lib/generators/react-app/templates/src/components/App.jsx +3 -2
  108. package/lib/generators/react-app/templates/src/components/pages/Error.jsx +2 -2
  109. package/lib/lib/generator.js +9 -0
  110. package/package.json +2 -2
  111. package/lib/generators/laravel-panneau/templates/_composer.json +0 -6
  112. package/lib/generators/laravel-panneau/templates/_package.json +0 -11
  113. package/lib/generators/laravel-panneau/templates/app/Http/Controllers/Panneau/HomeController.php +0 -14
  114. package/lib/generators/laravel-panneau/templates/app/Http/Controllers/Panneau/PagesController.php +0 -11
  115. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/File.php +0 -13
  116. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/Picture.php +0 -13
  117. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/Video.php +0 -34
  118. package/lib/generators/laravel-panneau/templates/app/Providers/PanneauServiceProvider.php +0 -23
  119. package/lib/generators/laravel-panneau/templates/app/Reducers/SlugExtractReducer.php +0 -18
  120. package/lib/generators/laravel-panneau/templates/app/Resources/Pages.php +0 -54
  121. package/lib/generators/laravel-panneau/templates/app/Schemas/Blocks/Base.php +0 -22
  122. package/lib/generators/laravel-panneau/templates/app/Schemas/Bubbles/Base.php +0 -22
  123. package/lib/generators/laravel-panneau/templates/app/Schemas/Pages/Base.php +0 -36
  124. package/lib/generators/laravel-panneau/templates/resources/lang/en/panneau.php +0 -12
  125. package/lib/generators/laravel-panneau/templates/resources/lang/fr/panneau.php +0 -12
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ var _chalk = _interopRequireDefault(require("chalk"));
4
+
5
+ var _path = _interopRequireDefault(require("path"));
6
+
7
+ var _generator = _interopRequireDefault(require("../../lib/generator"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ module.exports = class IntlGenerator extends _generator.default {
12
+ constructor(...args) {
13
+ super(...args);
14
+ this.option('translations-path', {
15
+ type: String,
16
+ desc: 'Path for to search for translations',
17
+ defaults: './src/**/*.{js,jsx}'
18
+ });
19
+ this.option('locales', {
20
+ type: String,
21
+ desc: 'Supported locales',
22
+ defaults: 'fr,en'
23
+ });
24
+ this.option('output-path', {
25
+ type: String,
26
+ desc: 'Path to output locale files',
27
+ defaults: './locale'
28
+ });
29
+ this.option('json-path', {
30
+ type: String,
31
+ desc: 'Path to copy json files'
32
+ });
33
+ this.option('without-id-only', {
34
+ type: String,
35
+ desc: 'Extract only messages without id',
36
+ defaults: false
37
+ });
38
+ }
39
+
40
+ get prompting() {
41
+ return {
42
+ welcome() {
43
+ if (this.options.quiet) {
44
+ return;
45
+ }
46
+
47
+ console.log(_chalk.default.yellow('\n----------------------'));
48
+ console.log('Intl Generator');
49
+ console.log(_chalk.default.yellow('----------------------\n'));
50
+ }
51
+
52
+ };
53
+ }
54
+
55
+ get writing() {
56
+ return {
57
+ packageJSON() {
58
+ const {
59
+ 'translations-path': translationsPath = null,
60
+ 'output-path': outputPath = null,
61
+ 'json-path': jsonPath = null,
62
+ 'without-id-only': withoutIdOnly = false,
63
+ locales
64
+ } = this.options;
65
+ const intlCommand = `flklr intl --po${withoutIdOnly ? ' --without-id-only' : ''} --output-path$ '${outputPath}' '${translationsPath}'`;
66
+ this.packageJson.merge({
67
+ scripts: jsonPath !== null ? {
68
+ intl: 'npm run intl:build && npm run intl:copy',
69
+ 'intl:build': intlCommand,
70
+ 'intl:copy': `cp ${_path.default.join(outputPath, '*.json')} ${jsonPath}`
71
+ } : {
72
+ intl: intlCommand
73
+ },
74
+ supportedLocales: locales.split(',')
75
+ });
76
+ },
77
+
78
+ dependencies() {
79
+ this.addDevDependencies(['@folklore/cli']);
80
+ }
81
+
82
+ };
83
+ }
84
+
85
+ async install() {
86
+ if (this.options['skip-install']) {
87
+ return;
88
+ }
89
+
90
+ await this.spawnCommand('npm', ['install']);
91
+ }
92
+
93
+ };
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ var _chalk = _interopRequireDefault(require("chalk"));
4
+
5
+ var _glob = _interopRequireDefault(require("glob"));
6
+
7
+ var _lodash = _interopRequireDefault(require("lodash"));
8
+
9
+ var _path = _interopRequireDefault(require("path"));
10
+
11
+ var _generator = _interopRequireDefault(require("../../lib/generator"));
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ module.exports = class LaravelMediathequeGenerator extends _generator.default {
16
+ constructor(...args) {
17
+ super(...args);
18
+ this.argument('project-name', {
19
+ type: String,
20
+ required: false
21
+ });
22
+ this.argument('overrides', {
23
+ type: Boolean,
24
+ required: false,
25
+ default: false
26
+ });
27
+ this.argument('skip-publish', {
28
+ type: Boolean,
29
+ required: false,
30
+ default: false
31
+ });
32
+ }
33
+
34
+ get prompting() {
35
+ return {
36
+ welcome() {
37
+ if (this.options.quiet) {
38
+ return;
39
+ }
40
+
41
+ console.log(_chalk.default.yellow('\n----------------------'));
42
+ console.log('Laravel Mediatheque Generator');
43
+ console.log(_chalk.default.yellow('----------------------\n'));
44
+ },
45
+
46
+ prompts() {
47
+ const prompts = [];
48
+
49
+ if (!this.options['project-name']) {
50
+ prompts.push(_generator.default.prompts.project_name);
51
+ }
52
+
53
+ if (!prompts.length) {
54
+ return null;
55
+ }
56
+
57
+ return this.prompt(prompts).then(answers => {
58
+ if (answers['project-name']) {
59
+ this.options['project-name'] = answers['project-name'];
60
+ }
61
+ });
62
+ }
63
+
64
+ };
65
+ }
66
+
67
+ get writing() {
68
+ return {
69
+ composerJSON() {
70
+ this.composerJson.merge({
71
+ require: {
72
+ 'folklore/laravel-folklore': 'v1.x-dev',
73
+ 'folklore/laravel-mediatheque': 'v1.1.x-dev'
74
+ }
75
+ });
76
+ },
77
+
78
+ files() {
79
+ if (!this.options.overrides) {
80
+ return;
81
+ }
82
+
83
+ const folders = ['app'];
84
+ folders.forEach(folder => {
85
+ const templatePath = this.templatePath(folder);
86
+ const destinationPath = this.destinationPath(folder);
87
+
88
+ _glob.default.sync('**', {
89
+ dot: true,
90
+ nodir: true,
91
+ cwd: templatePath
92
+ }).forEach(file => {
93
+ const source = _path.default.join(templatePath, file);
94
+
95
+ const destination = _path.default.join(destinationPath, file);
96
+
97
+ if (file.match(/\.(jpg|jpeg|gif|png)$/i)) {
98
+ this.fs.copy(source, destination);
99
+ } else {
100
+ this.fs.copyTpl(source, destination, {
101
+ project_name: this.options['project-name']
102
+ });
103
+ }
104
+ });
105
+ });
106
+ }
107
+
108
+ };
109
+ }
110
+
111
+ get install() {
112
+ return {
113
+ composer() {
114
+ if (this.options['skip-install']) {
115
+ return;
116
+ }
117
+
118
+ const done = this.async();
119
+ this.spawnCommand('composer', ['install']).on('close', done);
120
+ },
121
+
122
+ async vendorPublish() {
123
+ if (this.options['skip-publish']) {
124
+ return;
125
+ }
126
+
127
+ await this.spawnCommand('php', ['artisan', 'vendor:publish', '--provider=Folklore\\Mediatheque\\ServiceProvider']);
128
+ }
129
+
130
+ };
131
+ }
132
+
133
+ };
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ namespace App\Models;
4
+
5
+ use Folklore\Models\Media as BaseMedia;
6
+
7
+ class Media extends BaseMedia
8
+ {
9
+ }
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ namespace App\Models;
4
+
5
+ use Folklore\Models\MediaFile as BaseMediaFile;
6
+
7
+ class MediaFile extends BaseMediaFile
8
+ {
9
+ }
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _lodash = _interopRequireDefault(require("lodash"));
4
-
5
3
  var _chalk = _interopRequireDefault(require("chalk"));
6
4
 
7
5
  var _glob = _interopRequireDefault(require("glob"));
8
6
 
7
+ var _lodash = _interopRequireDefault(require("lodash"));
8
+
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
 
11
11
  var _generator = _interopRequireDefault(require("../../lib/generator"));
@@ -19,11 +19,6 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
19
19
  type: String,
20
20
  required: false
21
21
  });
22
- this.option('install-npm', {
23
- type: Boolean,
24
- desc: 'Install NPM dependencies',
25
- defaults: false
26
- });
27
22
  }
28
23
 
29
24
  get prompting() {
@@ -62,24 +57,31 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
62
57
  get writing() {
63
58
  return {
64
59
  composerJSON() {
65
- const srcPath = this.templatePath('_composer.json');
66
- const destPath = this.destinationPath('composer.json');
67
- const newJson = this.fs.readJSON(srcPath);
68
- const currentJson = this.fs.exists(destPath) ? this.fs.readJSON(destPath) : {};
69
- this.fs.writeJSON(destPath, _lodash.default.merge(currentJson, newJson));
60
+ this.composerJson.merge({
61
+ require: {
62
+ 'folklore/laravel-panneau': 'v1.2.x-dev'
63
+ }
64
+ });
70
65
  },
71
66
 
72
67
  packageJSON() {
73
- const srcPath = this.templatePath('_package.json');
74
- const destPath = this.destinationPath('package.json');
75
- const newJson = this.fs.readJSON(srcPath);
76
- const currentJson = this.fs.exists(destPath) ? this.fs.readJSON(destPath) : {};
77
- this.fs.writeJSON(destPath, _lodash.default.merge(currentJson, newJson));
68
+ this.addDependencies(['@panneau/app@^1.0.0-alpha.193', '@panneau/core@^1.0.0-alpha.193']);
69
+ },
70
+
71
+ routes() {
72
+ const source = this.templatePath('routes.php');
73
+ const destination = this.destinationPath('routes/panneau.php');
74
+
75
+ if (this.fs.exists(destination)) {
76
+ this.fs.delete(destination);
77
+ }
78
+
79
+ this.fs.copyTpl(source, destination, {});
78
80
  },
79
81
 
80
82
  layout() {
81
83
  const source = this.templatePath('layout.blade.php');
82
- const destination = this.destinationPath('resources/views/vendor/panneau/index.blade.php');
84
+ const destination = this.destinationPath('resources/views/vendor/panneau/layout.blade.php');
83
85
 
84
86
  if (this.fs.exists(destination)) {
85
87
  this.fs.delete(destination);
@@ -88,8 +90,29 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
88
90
  this.fs.copyTpl(source, destination, {});
89
91
  },
90
92
 
93
+ app() {
94
+ const source = this.templatePath('app.blade.php');
95
+ const destination = this.destinationPath('resources/views/vendor/panneau/app.blade.php');
96
+
97
+ if (this.fs.exists(destination)) {
98
+ this.fs.delete(destination);
99
+ }
100
+
101
+ this.fs.copyTpl(source, destination, {});
102
+ },
103
+
104
+ indexJs() {
105
+ const source = this.templatePath('index.js');
106
+ const destination = this.destinationPath('resources/assets/js/index.js');
107
+ this.fs.copyTpl(source, destination, {});
108
+ },
109
+
110
+ npmDependencies() {
111
+ this.addDependencies(['@panneau/app@^1.0.0-alpha.193', '@panneau/core@^1.0.0-alpha.193', '@panneau/data@^1.0.0-alpha.193', '@panneau/field-text@^1.0.0-alpha.193', '@panneau/field-localized@^1.0.0-alpha.193']);
112
+ },
113
+
91
114
  files() {
92
- const folders = ['app', 'resources'];
115
+ const folders = ['app', 'resources', 'lang'];
93
116
  folders.forEach(folder => {
94
117
  const templatePath = this.templatePath(folder);
95
118
  const destinationPath = this.destinationPath(folder);
@@ -119,30 +142,28 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
119
142
 
120
143
  get install() {
121
144
  return {
122
- composer() {
145
+ async npm() {
123
146
  if (this.options['skip-install']) {
124
147
  return;
125
148
  }
126
149
 
127
- const done = this.async();
128
- this.spawnCommand('composer', ['install']).on('close', done);
150
+ await this.spawnCommand('npm', ['install']);
129
151
  },
130
152
 
131
- vendorPublish() {
153
+ async composer() {
132
154
  if (this.options['skip-install']) {
133
155
  return;
134
156
  }
135
157
 
136
- const done = this.async();
137
- this.spawnCommand('php', ['artisan', 'vendor:publish', '--all']).on('close', done);
158
+ await this.spawnCommand('composer', ['install']);
138
159
  },
139
160
 
140
- panneau() {
141
- if (this.options['skip-install'] && !this.options['install-npm']) {
161
+ async vendorPublish() {
162
+ if (this.options['skip-install']) {
142
163
  return;
143
164
  }
144
165
 
145
- this.addDependencies(['panneau@^0.6.53']);
166
+ await this.spawnCommand('php', ['artisan', 'vendor:publish', '--provider=Panneau\\ServiceProvider']);
146
167
  }
147
168
 
148
169
  };
@@ -0,0 +1,19 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Repositories;
4
+
5
+ use Folklore\Contracts\Repositories\Pages as BasePages;
6
+ use App\Contracts\Resources\Page as PageResource;
7
+
8
+ interface Pages extends BasePages
9
+ {
10
+ public function findById(string $id): ?PageResource;
11
+
12
+ public function findByHandle(string $handle): ?PageResource;
13
+
14
+ public function findBySlug(string $slug, string $locale = null): ?PageResource;
15
+
16
+ public function create(array $data): PageResource;
17
+
18
+ public function update(string $id, array $data): ?PageResource;
19
+ }
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Resources\Blocks;
4
+
5
+ use App\Contracts\Resources\Block as BaseBlock;
6
+
7
+ interface Text extends BaseBlock
8
+ {
9
+ public function body(string $locale): ?string;
10
+ }
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Resources;
4
+
5
+ use Folklore\Contracts\Resources\Page as BasePage;
6
+
7
+ interface Page extends BasePage
8
+ {
9
+
10
+ }
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Resources\Pages;
4
+
5
+ use App\Contracts\Resources\Page as BasePage;
6
+
7
+ interface Home extends BasePage
8
+ {
9
+ }
@@ -0,0 +1,37 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+ use App\Contracts\Resources\HasBlocks;
7
+ use Folklore\Http\Resources\LocalizedResource;
8
+ use App\Contracts\Resources\Blocks\Text as TextBlock;
9
+
10
+ class BlockResource extends JsonResource
11
+ {
12
+ /**
13
+ * Transform the resource into an array.
14
+ *
15
+ * @param \Illuminate\Http\Request $request
16
+ * @return array
17
+ */
18
+ public function toArray($request)
19
+ {
20
+ $type = $this->type();
21
+ $locale = $request->locale();
22
+ return [
23
+ 'id' => $this->id(),
24
+ 'type' => $type,
25
+ 'blocks' => $this->when($this->resource instanceof HasBlocks, function () {
26
+ $blocks = $this->blocks();
27
+ return !is_null($blocks) ? new BlocksCollection($blocks) : [];
28
+ }),
29
+
30
+ $this->mergeWhen($this->resource instanceof TextBlock, function () use ($locale) {
31
+ return [
32
+ 'body' => $this->body($locale),
33
+ ];
34
+ }),
35
+ ];
36
+ }
37
+ }
@@ -0,0 +1,8 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ class BlocksCollection extends Collection
6
+ {
7
+ public $collects = BlockResource::class;
8
+ }
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+ use App\Http\Resources\Medias\ImageResource;
7
+ use App\Contracts\Resources\Page;
8
+ use App\Contracts\Resources\HasBlocks;
9
+ use App\Contracts\Resources\Pages\Home as HomePage;
10
+
11
+ class PageResource extends JsonResource
12
+ {
13
+ /**
14
+ * Transform the resource into an array.
15
+ *
16
+ * @param \Illuminate\Http\Request $request
17
+ * @return array
18
+ */
19
+ public function toArray($request)
20
+ {
21
+ $locale = $request->locale();
22
+ return [
23
+ 'id' => $this->id(),
24
+ 'type' => $this->type(),
25
+ 'published' => $this->published(),
26
+ 'title' => $this->title($locale),
27
+ 'description' => $this->description($locale),
28
+ 'slug' => $this->slug($locale),
29
+ 'image' => !is_null($image) ? new ImageResource($image) : null,
30
+ 'parent' =>
31
+ !is_null($parent) && $parent instanceof Page
32
+ ? new ParentPageResource($parent)
33
+ : null,
34
+
35
+ $this->mergeWhen($this->resource instanceof HasBlocks, function () {
36
+ $blocks = $this->blocks();
37
+ return [
38
+ 'blocks' => !is_null($blocks) ? new BlocksCollection($blocks) : [],
39
+ ];
40
+ }),
41
+
42
+ $this->mergeWhen($this->resource instanceof HomePage, function () {
43
+ return [];
44
+ }),
45
+ ];
46
+ }
47
+ }
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Http\Resources;
4
+
5
+ use Folklore\Http\Resources\Collection;
6
+
7
+ class PagesCollection extends Collection
8
+ {
9
+ public $collects = PageResource::class;
10
+ }
@@ -2,21 +2,11 @@
2
2
 
3
3
  namespace App\Models;
4
4
 
5
- use Folklore\Panneau\Models\Block as BaseBlock;
5
+ use Folklore\Models\Block as BaseBlock;
6
6
 
7
7
  class Block extends BaseBlock
8
8
  {
9
- protected $hidden = [
10
- 'pictures',
11
- 'audios',
12
- 'videos',
13
- 'pivot',
14
- 'deleted_at'
15
- ];
16
-
17
- protected $jsonSchemasReducers = [
18
- \Folklore\Panneau\Reducers\BlocksReducer::class,
19
- \Folklore\Panneau\Reducers\PagesReducer::class,
20
- \Folklore\Panneau\Reducers\MediasReducer::class,
9
+ protected $typeResources = [
10
+ 'text' => \App\Resources\Blocks\TextBlock::class,
21
11
  ];
22
12
  }
@@ -2,68 +2,11 @@
2
2
 
3
3
  namespace App\Models;
4
4
 
5
- use Folklore\Panneau\Models\Page as BasePage;
6
- use Folklore\Panneau\Contracts\Page as PageContract;
5
+ use Folklore\Models\Page as BasePage;
7
6
 
8
7
  class Page extends BasePage
9
8
  {
10
- protected $hidden = [
11
- 'slug_fr',
12
- 'slug_en',
13
- 'blocks',
14
- 'pages',
15
- 'pictures',
16
- 'audios',
17
- 'videos',
18
- 'order',
19
- 'deleted_at'
9
+ protected $typeResources = [
10
+ 'text' => \App\Resources\Pages\HomePage::class,
20
11
  ];
21
-
22
- protected $appends = [
23
- 'url',
24
- 'urls',
25
- ];
26
-
27
- protected $jsonSchemasReducers = [
28
- \Folklore\Panneau\Reducers\BlocksReducer::class,
29
- \Folklore\Panneau\Reducers\PagesReducer::class,
30
- \Folklore\Panneau\Reducers\MediasReducer::class,
31
- \Folklore\Panneau\Reducers\SlugReducer::class,
32
- \App\Reducers\SlugExtractReducer::class,
33
- ];
34
-
35
- protected function getUrlAttribute()
36
- {
37
- return $this->getUrl();
38
- }
39
-
40
- protected function getUrlsAttribute()
41
- {
42
- $urls = [];
43
- $locales = config('locale.locales', []);
44
- foreach ($locales as $locale) {
45
- $urls[$locale] = $this->getUrl($locale);
46
- }
47
- return $urls;
48
- }
49
-
50
- protected function getUrl($locale = null)
51
- {
52
- if (is_null($locale)) {
53
- $locale = app()->getLocale();
54
- }
55
- return '';
56
- // return route('pages.show.'.$locale, [array_get($this->attributes, 'slug_'.$locale)]);
57
- }
58
-
59
- /**
60
- * Get the route key for the model.
61
- *
62
- * @return string
63
- */
64
- public function getRouteKeyName()
65
- {
66
- $locale = app()->getLocale();
67
- return 'slug_'.$locale;
68
- }
69
12
  }
@@ -0,0 +1,50 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Composers;
4
+
5
+ use Illuminate\Http\Request;
6
+ use Illuminate\View\View;
7
+ use App\Panneau\Http\Resources\UserResource;
8
+
9
+ class AppComposer
10
+ {
11
+ /**
12
+ * The request
13
+ *
14
+ * @var \Illuminate\Http\Request
15
+ */
16
+ protected $request;
17
+
18
+ protected $panneau;
19
+
20
+ /**
21
+ * Create a new profile composer.
22
+ *
23
+ * @param \Illuminate\Http\Request $request
24
+ * @return void
25
+ */
26
+ public function __construct(Request $request)
27
+ {
28
+ $this->request = $request;
29
+ }
30
+
31
+ /**
32
+ * Bind data to the view.
33
+ *
34
+ * @param View $view
35
+ * @return void
36
+ */
37
+ public function compose(View $view)
38
+ {
39
+ $user = $this->request->user();
40
+
41
+ $view->props = array_merge(isset($view->props) ? $view->props : [], [
42
+ 'user' => !is_null($user) ? new UserResource($user) : null,
43
+ 'isPanneau' => true,
44
+ 'statusCode' => $view->statusCode,
45
+ 'pubnubNamespace' => config('services.pubnub.namespace'),
46
+ 'pubnubPublishKey' => config('services.pubnub.publish_key'),
47
+ 'pubnubSubscribeKey' => config('services.pubnub.subscribe_key'),
48
+ ]);
49
+ }
50
+ }