|
11 | 11 | class DownloadAssetsCommand extends Command
|
12 | 12 | {
|
13 | 13 | public const REACT_PATH_LOCAL = 'vendor/graphiql/react.production.min.js';
|
14 |
| - public const REACT_PATH_CDN = '//unpkg.com/react@17/umd/react.production.min.js'; |
| 14 | + public const REACT_PATH_CDN = '//cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js'; |
15 | 15 |
|
16 | 16 | public const REACT_DOM_PATH_LOCAL = 'vendor/graphiql/react-dom.production.min.js';
|
17 |
| - public const REACT_DOM_PATH_CDN = '//unpkg.com/react-dom@17/umd/react-dom.production.min.js'; |
| 17 | + public const REACT_DOM_PATH_CDN = '//cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js'; |
18 | 18 |
|
19 | 19 | public const JS_PATH_LOCAL = 'vendor/graphiql/graphiql.min.js';
|
20 |
| - public const JS_PATH_CDN = '//unpkg.com/graphiql/graphiql.min.js'; |
| 20 | + public const JS_PATH_CDN = '//cdn.jsdelivr.net/npm/graphiql/graphiql.min.js'; |
21 | 21 |
|
22 | 22 | public const PLUGIN_EXPLORER_PATH_LOCAL = 'vendor/graphiql/graphiql-plugin-explorer.umd.js';
|
23 | 23 | /** Pinned because the latest version broke, see https://github.com/mll-lab/laravel-graphiql/issues/25. */
|
24 |
| - public const PLUGIN_EXPLORER_PATH_CDN = '//unpkg.com/@graphiql/[email protected]/dist/index.umd.js'; |
| 24 | + public const PLUGIN_EXPLORER_PATH_CDN = '//cdn.jsdelivr.net/npm/@graphiql/[email protected]/dist/index.umd.js'; |
25 | 25 |
|
26 | 26 | public const CSS_PATH_LOCAL = 'vendor/graphiql/graphiql.min.css';
|
27 |
| - public const CSS_PATH_CDN = '//unpkg.com/graphiql/graphiql.min.css'; |
| 27 | + public const CSS_PATH_CDN = '//cdn.jsdelivr.net/npm/graphiql/graphiql.min.css'; |
28 | 28 |
|
29 | 29 | public const FAVICON_PATH_LOCAL = 'vendor/graphiql/favicon.ico';
|
30 | 30 | public const FAVICON_PATH_CDN = '//raw.githubusercontent.com/graphql/graphql.github.io/source/public/favicon.ico';
|
@@ -64,53 +64,58 @@ protected function downloadFileFromCDN(string $localPath, string $cdnPath): void
|
64 | 64 |
|
65 | 65 | public static function reactPath(): string
|
66 | 66 | {
|
67 |
| - return self::assetPath(self::REACT_PATH_LOCAL, self::REACT_PATH_CDN); |
| 67 | + return self::availablePath(self::REACT_PATH_LOCAL, self::REACT_PATH_CDN); |
68 | 68 | }
|
69 | 69 |
|
70 | 70 | public static function reactDOMPath(): string
|
71 | 71 | {
|
72 |
| - return self::assetPath(self::REACT_DOM_PATH_LOCAL, self::REACT_DOM_PATH_CDN); |
| 72 | + return self::availablePath(self::REACT_DOM_PATH_LOCAL, self::REACT_DOM_PATH_CDN); |
73 | 73 | }
|
74 | 74 |
|
75 | 75 | public static function jsPath(): string
|
76 | 76 | {
|
77 |
| - return self::assetPath(self::JS_PATH_LOCAL, self::JS_PATH_CDN); |
| 77 | + return self::availablePath(self::JS_PATH_LOCAL, self::JS_PATH_CDN); |
78 | 78 | }
|
79 | 79 |
|
80 | 80 | public static function pluginExplorerPath(): string
|
81 | 81 | {
|
82 |
| - return self::assetPath(self::PLUGIN_EXPLORER_PATH_LOCAL, self::PLUGIN_EXPLORER_PATH_CDN); |
| 82 | + return self::availablePath(self::PLUGIN_EXPLORER_PATH_LOCAL, self::PLUGIN_EXPLORER_PATH_CDN); |
83 | 83 | }
|
84 | 84 |
|
85 | 85 | public static function cssPath(): string
|
86 | 86 | {
|
87 |
| - return self::assetPath(self::CSS_PATH_LOCAL, self::CSS_PATH_CDN); |
| 87 | + return self::availablePath(self::CSS_PATH_LOCAL, self::CSS_PATH_CDN); |
88 | 88 | }
|
89 | 89 |
|
90 | 90 | public static function faviconPath(): string
|
91 | 91 | {
|
92 |
| - return self::assetPath(self::FAVICON_PATH_LOCAL, self::FAVICON_PATH_CDN); |
| 92 | + return self::availablePath(self::FAVICON_PATH_LOCAL, self::FAVICON_PATH_CDN); |
93 | 93 | }
|
94 | 94 |
|
95 |
| - protected static function assetPath(string $local, string $cdn): string |
| 95 | + public static function availablePath(string $local, string $cdn): string |
96 | 96 | {
|
97 | 97 | return file_exists(self::publicPath($local))
|
98 |
| - ? self::asset($local) |
99 |
| - : $cdn; |
| 98 | + ? self::localAssetURL($local) |
| 99 | + : self::cdnURL($cdn); |
100 | 100 | }
|
101 | 101 |
|
102 |
| - protected static function asset(string $path): string |
| 102 | + public static function publicPath(string $path): string |
| 103 | + { |
| 104 | + $container = Container::getInstance(); |
| 105 | + assert($container instanceof LaravelApplication || $container instanceof LumenApplication); |
| 106 | + |
| 107 | + return $container->basePath("public/{$path}"); |
| 108 | + } |
| 109 | + |
| 110 | + public static function localAssetURL(string $path): string |
103 | 111 | {
|
104 | 112 | $url = Container::getInstance()->make(UrlGenerator::class);
|
105 | 113 |
|
106 | 114 | return $url->asset($path);
|
107 | 115 | }
|
108 | 116 |
|
109 |
| - protected static function publicPath(string $path): string |
| 117 | + public static function cdnURL(string $path): string |
110 | 118 | {
|
111 |
| - $container = Container::getInstance(); |
112 |
| - assert($container instanceof LaravelApplication || $container instanceof LumenApplication); |
113 |
| - |
114 |
| - return $container->basePath("public/{$path}"); |
| 119 | + return str_replace('//', '/', $path); |
115 | 120 | }
|
116 | 121 | }
|
0 commit comments