graphcool-yml
Advanced tools
Comparing version 0.0.2 to 0.0.4
@@ -17,2 +17,3 @@ import { Args } from './types/common'; | ||
load(args: Args): Promise<void>; | ||
migrateOldCli(globalRCPath: string): void; | ||
clusterByName(name: string, throws?: boolean): Cluster | undefined; | ||
@@ -19,0 +20,0 @@ setToken(token: string | undefined): void; |
@@ -52,6 +52,8 @@ "use strict"; | ||
var Output_1 = require("./Output"); | ||
var path = require("path"); | ||
var os = require("os"); | ||
var Environment = /** @class */ (function () { | ||
function Environment(globalRCPath, out) { | ||
if (out === void 0) { out = new Output_1.Output(); } | ||
this.sharedClusters = ['shared-eu-west-1']; | ||
this.sharedClusters = ['shared-public-demo']; | ||
this.sharedEndpoint = 'https://database-beta.graph.cool'; | ||
@@ -61,2 +63,3 @@ this.globalRC = {}; | ||
this.out = out; | ||
this.migrateOldCli(globalRCPath); | ||
} | ||
@@ -75,2 +78,18 @@ Environment.prototype.load = function (args) { | ||
}; | ||
Environment.prototype.migrateOldCli = function (globalRCPath) { | ||
if (fs.pathExistsSync(globalRCPath)) { | ||
try { | ||
var rc = fs.readFileSync(globalRCPath, 'utf-8'); | ||
var json = JSON.parse(rc); | ||
if (json && typeof json === 'object') { | ||
var newPath = path.join(os.homedir(), '.old.graphcool'); | ||
fs.moveSync(globalRCPath, newPath); | ||
this.out.log("Old .graphcool file detected. We just moved it to " + newPath); | ||
} | ||
} | ||
catch (e) { | ||
// | ||
} | ||
} | ||
}; | ||
Environment.prototype.clusterByName = function (name, throws) { | ||
@@ -98,3 +117,4 @@ if (throws === void 0) { throws = false; } | ||
}; | ||
var rcString = yaml.safeDump(rc); | ||
// parse & stringify to rm undefined for yaml parser | ||
var rcString = yaml.safeDump(JSON.parse(JSON.stringify(rc))); | ||
fs.writeFileSync(this.globalRCPath, rcString); | ||
@@ -101,0 +121,0 @@ }; |
@@ -133,2 +133,28 @@ "use strict"; | ||
}); }); | ||
test('load yml with secret and env var in args', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var yml, datamodel, definitionDir, definitionPath, modelPath, env, definition; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
yml = "service: jj\n\ndatamodel:\n- datamodel.graphql\n\nschema: schemas/database.graphql\nstages: \n default: dev\n dev: shared-eu-west-1\n "; | ||
datamodel = "\ntype User @model {\n id: ID! @isUnique\n name: String!\n lol: Int\n what: String\n}\n"; | ||
definitionDir = getTmpDir_1.getTmpDir(); | ||
definitionPath = path.join(definitionDir, 'graphcool.yml'); | ||
modelPath = path.join(definitionDir, 'datamodel.graphql'); | ||
env = Environment_test_1.makeEnv(defaultGlobalRC); | ||
definition = new GraphcoolDefinition_1.GraphcoolDefinitionClass(env, definitionPath, { GRAPHCOOL_SECRET: 'this-is-secret' }); | ||
fs.writeFileSync(modelPath, datamodel); | ||
fs.writeFileSync(definitionPath, yml); | ||
return [4 /*yield*/, env.load({})]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, definition.load({})]; | ||
case 2: | ||
_a.sent(); | ||
expect(definition.definition).toMatchSnapshot(); | ||
expect(definition.secrets).toMatchSnapshot(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test('load yml with disableAuth: true', function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -135,0 +161,0 @@ var secret, yml, datamodel, _a, definition, env, envPath; |
export declare class Output { | ||
log(...args: any[]): void; | ||
warn(...args: any[]): void; | ||
@@ -7,3 +8,4 @@ getErrorPrefix(fileName: string, type?: 'error' | 'warning'): string; | ||
warn: (...args) => void; | ||
log: (...args) => void; | ||
getErrorPrefix: (fileName: string, type?: 'error' | 'warning') => string; | ||
} |
@@ -6,2 +6,9 @@ "use strict"; | ||
} | ||
Output.prototype.log = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
console.log(args); | ||
}; | ||
Output.prototype.warn = function () { | ||
@@ -8,0 +15,0 @@ var args = []; |
{ | ||
"name": "graphcool-yml", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"main": "dist/index.js", | ||
@@ -39,3 +39,3 @@ "types": "dist/index.d.ts", | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "../node_modules/ts-jest/preprocessor.js" | ||
"^.+\\.(ts|tsx)$": "../../../node_modules/ts-jest/preprocessor.js" | ||
}, | ||
@@ -42,0 +42,0 @@ "testMatch": ["**/*.test.(ts|js)"], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103781
1521