From ed5ebe9155ed8b9d7dc55fa1842bf7ac2655b45f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 29 Dec 2018 15:51:13 -0800 Subject: [PATCH] More progress, committing to get assistance with TS --- .../assets/scripts/api/{http.js => http.ts} | 14 ++++++---- ...oryContents.js => getDirectoryContents.ts} | 15 +++++------ resources/assets/scripts/api/server/types.ts | 5 ++++ .../assets/scripts/components/auth/Login.vue | 7 ++--- resources/assets/scripts/router.ts | 2 +- storage/framework/cache/data/.gitignore | 0 tsconfig.json | 27 +++++++++++++------ webpack.config.js | 2 +- 8 files changed, 45 insertions(+), 27 deletions(-) rename resources/assets/scripts/api/{http.js => http.ts} (65%) rename resources/assets/scripts/api/server/{getDirectoryContents.js => getDirectoryContents.ts} (79%) create mode 100644 resources/assets/scripts/api/server/types.ts mode change 100644 => 100755 storage/framework/cache/data/.gitignore diff --git a/resources/assets/scripts/api/http.js b/resources/assets/scripts/api/http.ts similarity index 65% rename from resources/assets/scripts/api/http.js rename to resources/assets/scripts/api/http.ts index 07d2cfe76..072268e56 100644 --- a/resources/assets/scripts/api/http.js +++ b/resources/assets/scripts/api/http.ts @@ -1,19 +1,23 @@ -import axios from 'axios'; +import axios, {AxiosInstance} from 'axios'; // This token is set in the bootstrap.js file at the beginning of the request // and is carried through from there. // const token: string = ''; -const http = axios.create({ - 'X-Requested-With': 'XMLHttpRequest', - 'Accept': 'application/json', - 'Content-Type': 'application/json', +const http: AxiosInstance = axios.create({ + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, }); // If we have a phpdebugbar instance registered at this point in time go // ahead and route the response data through to it so things show up. +// @ts-ignore if (typeof window.phpdebugbar !== 'undefined') { http.interceptors.response.use(response => { + // @ts-ignore window.phpdebugbar.ajaxHandler.handle(response.request); return response; diff --git a/resources/assets/scripts/api/server/getDirectoryContents.js b/resources/assets/scripts/api/server/getDirectoryContents.ts similarity index 79% rename from resources/assets/scripts/api/server/getDirectoryContents.js rename to resources/assets/scripts/api/server/getDirectoryContents.ts index c2d7b7336..3c9903b69 100644 --- a/resources/assets/scripts/api/server/getDirectoryContents.js +++ b/resources/assets/scripts/api/server/getDirectoryContents.ts @@ -1,16 +1,13 @@ -import http from './../http'; -import filter from 'lodash/filter'; -import isObject from 'lodash/isObject'; +import http from '../http'; +import { filter, isObject } from 'lodash'; +// @ts-ignore import route from '../../../../../vendor/tightenco/ziggy/src/js/route'; +import {DirectoryContents} from "./types"; /** * Get the contents of a specific directory for a given server. - * - * @param {String} server - * @param {String} directory - * @return {Promise} */ -export function getDirectoryContents (server, directory) { +export function getDirectoryContents (server: string, directory: string): Promise { return new Promise((resolve, reject) => { http.get(route('server.files', { server, directory })) .then((response) => { @@ -30,7 +27,7 @@ export function getDirectoryContents (server, directory) { } if (err.response.data && isObject(err.response.data.errors)) { - err.response.data.errors.forEach(error => { + err.response.data.errors.forEach((error: any) => { return reject(error.detail); }); } diff --git a/resources/assets/scripts/api/server/types.ts b/resources/assets/scripts/api/server/types.ts new file mode 100644 index 000000000..7b220c1ef --- /dev/null +++ b/resources/assets/scripts/api/server/types.ts @@ -0,0 +1,5 @@ +export type DirectoryContents = { + files: Array, + directories: Array, + editable: Array +} diff --git a/resources/assets/scripts/components/auth/Login.vue b/resources/assets/scripts/components/auth/Login.vue index a2fadfbba..7a8406f96 100644 --- a/resources/assets/scripts/components/auth/Login.vue +++ b/resources/assets/scripts/components/auth/Login.vue @@ -15,13 +15,14 @@ - diff --git a/resources/assets/scripts/router.ts b/resources/assets/scripts/router.ts index 86947d30b..ad1278659 100644 --- a/resources/assets/scripts/router.ts +++ b/resources/assets/scripts/router.ts @@ -4,7 +4,7 @@ import store from './store/index'; const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default; // Base Vuejs Templates -import Login from './components/auth/Login'; +import Login from './components/auth/Login.vue'; import Dashboard from './components/dashboard/Dashboard'; import Account from './components/dashboard/Account'; import ResetPassword from './components/auth/ResetPassword'; diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore old mode 100644 new mode 100755 diff --git a/tsconfig.json b/tsconfig.json index 36489af08..29c653ccc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,27 @@ { "compilerOptions": { - "target": "es6", - "lib": [ - "es2015", - "es2016", - "dom" - ], + "target": "esnext", + "module": "esnext", "strict": true, "moduleResolution": "node", - "module": "es2015" + "lib": [ + "esnext", + "dom", + "dom.iterable", + "scripthost" + ], + "baseUrl": ".", + "paths": { + "@/*": [ + "resources/*" + ] + } }, "include": [ - "./resources/assets/scripts/**/*" + "./resources/assets/**/*.ts", + "./resources/assets/**/*.vue" + ], + "exclude": [ + "node_modules" ] } diff --git a/webpack.config.js b/webpack.config.js index 046af9ff5..ddae52d6d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -88,7 +88,7 @@ module.exports = { loader: 'vue-loader', }, { - test: /\.tsx?$/, + test: /\.ts$/, loader: 'ts-loader', exclude: /node_modules/, options: {