Skip to content

Commit

Permalink
Windows support (except for starship folder)
Browse files Browse the repository at this point in the history
  • Loading branch information
NorOldBurden committed Aug 27, 2024
1 parent 9e053b7 commit db53d12
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/ast/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getTestProtoStore = (options?: TelescopeOptions) => {
}

export const getMiscTestProtoStore = (options?: TelescopeOptions) => {
const store = new ProtoStore([__dirname + '/../../../__fixtures__/misc/proto'], options ? deepmerge(defaultTelescopeOptions, options) : deepmerge(defaultTelescopeOptions, {}));
const store = new ProtoStore([__dirname.replace(/\\/g,'/') + '/../../../__fixtures__/misc/proto'], options ? deepmerge(defaultTelescopeOptions, options) : deepmerge(defaultTelescopeOptions, {}));
return store;
}

Expand Down
10 changes: 6 additions & 4 deletions packages/parser/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sync as glob } from 'glob';
import { glob } from './utils';
import { parse } from '@cosmology/protobufjs';
import { readFileSync } from 'fs';
import { join, resolve as pathResolve } from 'path';
Expand Down Expand Up @@ -69,7 +69,9 @@ export class ProtoStore implements IProtoStore {
}> = {};

constructor(protoDirs: string[] = [], options: TelescopeOptions = defaultTelescopeOptions) {
this.protoDirs = protoDirs.map(protoDir => pathResolve(protoDir));
this.protoDirs = protoDirs.map((protoDir) => {
return pathResolve(protoDir).replace(/\\/g,'/')
});
this.options = options;
}

Expand Down Expand Up @@ -135,11 +137,11 @@ export class ProtoStore implements IProtoStore {
getProtos(): ProtoRef[] {
if (this.protos) return this.protos;
const contents = this.protoDirs.reduce((m, protoDir) => {
const protoSplat = join(protoDir, '/**/*.proto');
const protoSplat = join(protoDir, '/**/*.proto').replace(/\\/g,'/');
const protoFiles = glob(protoSplat);
const contents = protoFiles.map(filename => ({
absolute: filename,
filename: filename.split(protoDir)[1].replace(/^\//, ''),
filename: filename.split(protoDir.replace(/\\/g,'/'))[1].replace(/^\//, ''),
content: readFileSync(filename, 'utf-8')
}));
return [...m, ...contents];
Expand Down
7 changes: 6 additions & 1 deletion packages/parser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ProtoStore } from './store';
import { getTypeUrl, getAminoTypeNameByRef, getTypeNameFromFieldName } from '@cosmology/utils';
import { getNestedProto } from '.';
export { isRefExcluded, isRefIncluded, getObjectName } from '@cosmology/utils'
import { sync as globSync } from 'glob';

// https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.cc#L3798-L3812
// NOTE: sometimes you need to pass in `.Dummy` for the first call,
Expand Down Expand Up @@ -221,4 +222,8 @@ export const createEmptyProtoRef = (pkg?: string, filename?: string): ProtoRef =
symbols: null
}
}
};
};

export const glob = (input:string, options?:object) => {
return globSync(input.replace(/\\/g,'/'), options);
}
2 changes: 1 addition & 1 deletion packages/telescope/__tests__/telescope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ const options: TelescopeOptions = {

const input: TelescopeInput = {
outPath,
protoDirs: [__dirname + '/../../../__fixtures__/chain1'],
protoDirs: [__dirname.replace(/\\/g,'/') + '/../../../__fixtures__/chain1'],
options
};

Expand Down
18 changes: 14 additions & 4 deletions packages/telescope/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ import { plugin as createRpcOpsBundle } from './generators/create-rpc-ops-bundle
const sanitizeOptions = (options: TelescopeOptions): TelescopeOptions => {
// If an element at the same key is present for both x and y, the value from y will appear in the result.
options = deepmerge(defaultTelescopeOptions, options ?? {});

// correct the path for windows
if(options.cosmwasm){
options.cosmwasm.outPath = options.cosmwasm.outPath.replace(/\\/g,'/')
options.cosmwasm.contracts = options.cosmwasm.contracts.map((item:{name:string, dir:string})=>{
item.dir = item.dir.replace(/\\/g,'/')
return item
})
}
// strip off leading slashes
options.tsDisable.files = options.tsDisable.files.map((file) =>
file.startsWith('/') ? file : file.replace(/^\//, '')
Expand Down Expand Up @@ -67,10 +74,13 @@ export class TelescopeBuilder {
store,
options
}: TelescopeInput & { store?: ProtoStore }) {
this.protoDirs = protoDirs;
this.outPath = resolve(outPath);
const fixedDirs = protoDirs.map((directory)=>{
return directory.replace(/\\/g,'/')
});
this.protoDirs = fixedDirs
this.outPath = resolve(outPath.replace(/\\/g,'/'));
this.options = sanitizeOptions(options);
this.store = store ?? new ProtoStore(protoDirs, this.options);
this.store = store ?? new ProtoStore(fixedDirs, this.options);
this.store.traverseAll();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/telescope/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const bundlePackages = (store: ProtoStore) => {
return Object.keys(allPackages).map(base => {
const pkgs = allPackages[base];
const bundleVariables = {};
const bundleFile = join(base, 'bundle.ts');
const bundleFile = join(base, 'bundle.ts').replace(/\\/g,'/');
const importPaths = [];
parsePackage(store.options, pkgs, bundleFile, importPaths, bundleVariables);
return {
Expand Down Expand Up @@ -153,7 +153,7 @@ export const createFileBundle = (
let rel = relative(dirname(bundleFile), filename);
if (!rel.startsWith('.')) rel = `./${rel}`;
const variable = `_${counter++}`;
importPaths.push(importNamespace(variable, rel));
importPaths.push(importNamespace(variable, rel.replace(/\\/g,'/')));
dotty.put(bundleVariables, pkg + '.__export', true);
dotty.put(bundleVariables, pkg + '.' + variable, true);
}
2 changes: 1 addition & 1 deletion packages/telescope/src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as shell from 'shelljs';
import { prompt } from '../prompt';
import dargs from 'dargs';
import { glob } from '../utils/index';

const glob = require('glob').sync;
const fs = require('fs');
const path = require('path');
const repo = 'https://github.com/cosmology-tech/telescope-module-boilerplate.git';
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/src/commands/install.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve, join, dirname, basename, extname } from 'path';
import { mkdirp } from 'mkdirp';
import { sync as glob } from 'glob';
import { glob } from '../utils/index';
import { rimrafSync as rimraf } from 'rimraf';
import { exec } from 'shelljs';
import { prompt } from '../prompt';
Expand Down
2 changes: 1 addition & 1 deletion packages/telescope/src/contracts/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve, join, dirname, basename, extname } from 'path';
import { sync as glob } from 'glob';
import { glob } from '../utils/index';
import { mkdirp } from 'mkdirp';
import { rimrafSync as rimraf } from 'rimraf';
import { exec } from 'shelljs';
Expand Down
6 changes: 3 additions & 3 deletions packages/telescope/src/protod/bufbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "fs";
import { Repo } from "./types";
import YAML from "yaml";
import { isPathExist } from "./utils";
import { sync as globSync } from "glob";
import { glob } from '../utils/index';

export function parseBufLockFile(filePath: string): Repo[] {
if (!isPathExist(filePath)) {
Expand Down Expand Up @@ -47,13 +47,13 @@ export function parseBufYamlFile(filePath: string): Repo[] {
}

export function findAllBufYamlFiles(dir: string): string[] {
return globSync(`${dir}/**/buf.yaml`, {
return glob(`${dir}/**/buf.yaml`, {
ignore: `${dir}/node_modules/**`,
});
}

export function findAllBufLockFiles(dir: string): string[] {
return globSync(`${dir}/**/buf.lock`, {
return glob(`${dir}/**/buf.lock`, {
ignore: `${dir}/node_modules/**`,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/telescope/src/protod/recursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { join, dirname, resolve } from "path";
import { getCorrespondingGit, makeDir, parseProtoFile } from "./utils";
import fs from "fs";
import { sync as globSync } from "glob";
import { glob } from '../utils/index';

export async function cloneAll({
repos,
Expand Down Expand Up @@ -131,7 +131,7 @@ function extractProtoFromDirs({

for (const target of targets) {
for (const source of Object.values(sources)) {
const files = globSync(join(source.protoPath, target));
const files = glob(join(source.protoPath, target));

extractProtoFiles.push(
...files
Expand Down
4 changes: 2 additions & 2 deletions packages/telescope/src/protod/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { exec as _exec } from "shelljs";
import fs from "fs";
import { bufInfo } from "./config";
import { Repo } from "./types";
import { sync as globSync } from "glob";
import { glob } from '../utils/index';

export function exec(command: string, verbose = false) {
const { code, stdout, stderr } = _exec(command);
Expand Down Expand Up @@ -76,7 +76,7 @@ export function isPathExist(path: string): boolean {
}

export function findAllProtoFiles(dir: string): string[] {
return globSync(`${dir}/**/*.proto`, {
return glob(`${dir}/**/*.proto`, {
ignore: `${dir}/node_modules/**`,
});
}
Expand Down
5 changes: 5 additions & 0 deletions packages/telescope/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ProtoRoot, ProtoRef } from '@cosmology/types';
import { relative, dirname, extname } from 'path';
import { ImportObj } from '../types';
import { restoreExtension } from '@cosmology/utils';
import { sync as globSync } from 'glob';

export const getRoot = (ref: ProtoRef): ProtoRoot => {
if (ref.traversed) return ref.traversed;
Expand Down Expand Up @@ -123,4 +124,8 @@ export const getRelativePath = (f1: string, f2: string, ext?: string) => {
return restoreExtension(importPath, ext);
}

export const glob = (input:string, options?:object) => {
return globSync(input.replace(/\\/g,'/'), options);
}

export * from './common-create-bundle';
4 changes: 2 additions & 2 deletions packages/telescope/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ const defaultTelescopeOptionsForTesting = {
const defaultTelescopeOptions = deepmerge(teleDefaults, defaultTelescopeOptionsForTesting);

export const getTestProtoStore = (options?: TelescopeOptions) => {
const store = new ProtoStore([__dirname + '/../../../__fixtures__/chain1'], options ? deepmerge(defaultTelescopeOptions, options) : deepmerge(defaultTelescopeOptions, {}));
const store = new ProtoStore([__dirname.replace(/\\/g,'/') + '/../../../__fixtures__/chain1'], options ? deepmerge(defaultTelescopeOptions, options) : deepmerge(defaultTelescopeOptions, {}));
return store;
}

export const getTestProtoStore2 = (options?: TelescopeOptions) => {
const store = new ProtoStore([__dirname + '/../../../__fixtures__/chain2'], options ? deepmerge(defaultTelescopeOptions, options) : deepmerge(defaultTelescopeOptions, {}));
const store = new ProtoStore([__dirname.replace(/\\/g,'/') + '/../../../__fixtures__/chain2'], options ? deepmerge(defaultTelescopeOptions, options) : deepmerge(defaultTelescopeOptions, {}));
return store;
}

Expand Down

0 comments on commit db53d12

Please sign in to comment.