Skip to content

Commit

Permalink
fix: cleaup types
Browse files Browse the repository at this point in the history
  • Loading branch information
PopGoesTheWza committed Mar 21, 2021
1 parent 309603b commit 65c1726
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/commands/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {ERROR} from '../messages';
import {URL} from '../urls';
import {checkIfOnlineOrDie, getProjectId} from '../utils';

import type {GaxiosResponse} from 'gaxios';
import type {ReadonlyDeep} from 'type-fest';

type DirectoryItem = Unpacked<discoveryV1.Schema$DirectoryList['items']>;
Expand Down Expand Up @@ -47,7 +46,7 @@ export default async (options: CommandOption): Promise<void> => {
console.log('\n# Currently enabled APIs:');
const projectId = await getProjectId(); // Will prompt user to set up if required
const MAX_PAGE_SIZE = 200; // This is the max page size according to the docs.
const list: GaxiosResponse<serviceUsageV1.Schema$ListServicesResponse> = await serviceUsage.services.list({
const list = await serviceUsage.services.list({
parent: `projects/${projectId}`,
filter: 'state:ENABLED',
pageSize: MAX_PAGE_SIZE,
Expand Down
14 changes: 8 additions & 6 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import multimatch from 'multimatch';
import path from 'path';
import recursive from 'recursive-readdir';
import ts2gas from 'ts2gas';
import ts from 'typescript';
import {parseConfigFileTextToJson} from 'typescript';

import {loadAPICredentials, script} from './auth';
import {ClaspError} from './clasp-error';
Expand All @@ -14,6 +14,8 @@ import {DOTFILE} from './dotfile';
import {ERROR, LOG} from './messages';
import {checkIfOnlineOrDie, getApiFileType, getErrorMessage, getProjectSettings, spinner, stopSpinner} from './utils';

import type {TranspileOptions} from 'typescript';

const {project} = Conf.get();

// An Apps Script API File
Expand All @@ -30,7 +32,7 @@ interface ProjectFile {
readonly type: string;
}

const projectFileWithContent = (file: ProjectFile, transpileOptions: ts.TranspileOptions): ProjectFile => {
const projectFileWithContent = (file: ProjectFile, transpileOptions: TranspileOptions): ProjectFile => {
const source = fs.readFileSync(file.name).toString();
const type = getApiFileType(file.name);

Expand All @@ -39,7 +41,7 @@ const projectFileWithContent = (file: ProjectFile, transpileOptions: ts.Transpil
// @see github.com/grant/ts2gas
{
...file,
source: ts2gas(source, transpileOptions as any),
source: ts2gas(source, transpileOptions),
type: 'SERVER_JS',
}
: {...file, source, type};
Expand Down Expand Up @@ -201,14 +203,14 @@ export const hasProject = (): boolean => fs.existsSync(project.resolve());

/**
* Returns in tsconfig.json.
* @returns {ts.TranspileOptions} if tsconfig.json not exists, return an empty object.
* @returns {TranspileOptions} if tsconfig.json not exists, return an empty object.
*/
const getTranspileOptions = (): ts.TranspileOptions => {
const getTranspileOptions = (): TranspileOptions => {
const tsconfigPath = path.join(project.resolvedDir, 'tsconfig.json');

return fs.existsSync(tsconfigPath)
? {
compilerOptions: ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, FS_OPTIONS)).config
compilerOptions: parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, FS_OPTIONS)).config
.compilerOptions,
}
: {};
Expand Down
3 changes: 2 additions & 1 deletion test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {OAuth2ClientOptions} from 'google-auth-library';
import os from 'os';
import path from 'path';

import {ClaspToken} from '../src/dotfile';
import {randomString} from './functions';

import type {OAuth2ClientOptions} from 'google-auth-library';

// Sample files
export const TEST_CODE_JS = "function test() { Logger.log('test'); }";
export const TEST_PAGE_HTML = '<html><body><p>hello there</p></body</html>';
Expand Down

0 comments on commit 65c1726

Please sign in to comment.