@microsoft.azure/autorest-core
Advanced tools
Comparing version 2.0.3 to 2.0.5
@@ -40,7 +40,3 @@ import { IEvent, EventEmitter } from "./events"; | ||
readonly view: Promise<ConfigurationView>; | ||
/** | ||
* @param fileSystem The implementation of the filesystem to load and save files from the host application. | ||
* @param configFileOrFolderUri The URI of the configuration file or folder containing the configuration file. Is null if no configuration file should be looked for. | ||
*/ | ||
constructor(fileSystem?: IFileSystem | undefined, configFileOrFolderUri?: string | undefined); | ||
static create(fileSystem?: IFileSystem, configFileOrFolderUri?: string): AutoRest; | ||
RegenerateView(includeDefault?: boolean): Promise<ConfigurationView>; | ||
@@ -47,0 +43,0 @@ Invalidate(): void; |
@@ -25,2 +25,3 @@ "use strict"; | ||
/** | ||
* @internal | ||
* @param fileSystem The implementation of the filesystem to load and save files from the host application. | ||
@@ -62,13 +63,13 @@ * @param configFileOrFolderUri The URI of the configuration file or folder containing the configuration file. Is null if no configuration file should be looked for. | ||
static async LiterateToJson(content) { | ||
let autorest = new AutoRest({ | ||
EnumerateFileUris: async function (folderUri) { return []; }, | ||
ReadFile: async (f) => f == "mem:///foo.md" ? content : "" | ||
}); | ||
let result = ""; | ||
autorest.AddConfiguration({ "input-file": "mem:///foo.md", "output-artifact": ["swagger-document"] }); | ||
autorest.GeneratedFile.Subscribe((source, artifact) => { | ||
result = artifact.content; | ||
}); | ||
// run autorest and wait. | ||
try { | ||
let autorest = new AutoRest({ | ||
EnumerateFileUris: async function (folderUri) { return []; }, | ||
ReadFile: async (f) => f == "none:///empty-file.md" ? content || "# empty file" : "# empty file" | ||
}); | ||
let result = ""; | ||
autorest.AddConfiguration({ "input-file": "none:///empty-file.md", "output-artifact": ["swagger-document"] }); | ||
autorest.GeneratedFile.Subscribe((source, artifact) => { | ||
result = artifact.content; | ||
}); | ||
// run autorest and wait. | ||
await (await autorest.Process()).finish; | ||
@@ -112,2 +113,5 @@ return result; | ||
} | ||
static create(fileSystem, configFileOrFolderUri) { | ||
return new AutoRest(fileSystem, configFileOrFolderUri); | ||
} | ||
async RegenerateView(includeDefault = false) { | ||
@@ -114,0 +118,0 @@ this.Invalidate(); |
@@ -367,2 +367,22 @@ "use strict"; | ||
} | ||
// fix the source names | ||
for (const source of mx.Source || []) { | ||
if (source.Position) { | ||
try { | ||
source.document = this.DataStore.ReadStrictSync(source.document).Description; | ||
} | ||
catch (e) { | ||
} | ||
} | ||
} | ||
// fix the source names in Ranges too | ||
for (const range of mx.Range || []) { | ||
if (range.document) { | ||
try { | ||
range.document = this.DataStore.ReadStrictSync(range.document).Description; | ||
} | ||
catch (e) { | ||
} | ||
} | ||
} | ||
this.messageEmitter.Message.Dispatch(mx); | ||
@@ -385,3 +405,3 @@ } | ||
// load config | ||
const hConfig = await literate_yaml_1.ParseCodeBlocks(contextConfig, configFile, contextConfig.DataStore.DataSink); | ||
const hConfig = await literate_yaml_1.ParseCodeBlocks(contextConfig, configFile, contextConfig.DataStore.getDataSink()); | ||
const blocks = hConfig.map(each => { | ||
@@ -406,2 +426,6 @@ const block = each.data.ReadObject(); | ||
configs["use-extension"] = Object.assign({}, configs["use-extension"]); | ||
if (configs.hasOwnProperty('licence-header')) { | ||
configs['license-header'] = configs['licence-header']; | ||
delete configs['licence-header']; | ||
} | ||
// use => use-extension | ||
@@ -408,0 +432,0 @@ let use = configs.use; |
@@ -12,2 +12,3 @@ import { CancellationToken } from "../ref/cancellation"; | ||
export interface Metadata { | ||
artifact: string | null; | ||
inputSourceMap: Lazy<RawSourceMap>; | ||
@@ -53,5 +54,5 @@ sourceMap: Lazy<RawSourceMap>; | ||
private WriteDataInternal(uri, data, metadata); | ||
WriteData(description: string, data: string, sourceMapFactory?: (self: DataHandle) => RawSourceMap): Promise<DataHandle>; | ||
WriteData(description: string, data: string, artifact: string | null, sourceMapFactory?: (self: DataHandle) => RawSourceMap): Promise<DataHandle>; | ||
private createUri(description); | ||
readonly DataSink: DataSink; | ||
getDataSink(artifact?: string | null): DataSink; | ||
ReadStrictSync(absoluteUri: string): DataHandle; | ||
@@ -84,2 +85,3 @@ Read(uri: string): Promise<DataHandle>; | ||
ReadYamlAst(): YAMLNode; | ||
GetArtifact(): string | null; | ||
readonly Description: string; | ||
@@ -86,0 +88,0 @@ IsObject(): boolean; |
@@ -89,3 +89,3 @@ "use strict"; | ||
} | ||
const readHandle = await this.store.WriteData(uri, data); | ||
const readHandle = await this.store.WriteData(uri, data, "input-file"); | ||
this.uris.push(uri); | ||
@@ -130,3 +130,3 @@ return readHandle; | ||
} | ||
async WriteData(description, data, sourceMapFactory) { | ||
async WriteData(description, data, artifact, sourceMapFactory) { | ||
const uri = this.createUri(description); | ||
@@ -136,2 +136,3 @@ // metadata | ||
const result = await this.WriteDataInternal(uri, data, metadata); | ||
metadata.artifact = artifact; | ||
metadata.sourceMap = new lazy_1.Lazy(() => { | ||
@@ -174,4 +175,4 @@ if (!sourceMapFactory) { | ||
} | ||
get DataSink() { | ||
return new DataSink((description, data, sourceMapFactory) => this.WriteData(description, data, sourceMapFactory), async (description, input) => { | ||
getDataSink(artifact = null) { | ||
return new DataSink((description, data, sourceMapFactory) => this.WriteData(description, data, artifact, sourceMapFactory), async (description, input) => { | ||
const uri = this.createUri(description); | ||
@@ -280,2 +281,5 @@ this.store[uri] = this.store[input.key]; | ||
} | ||
GetArtifact() { | ||
return this.ReadMetadata().artifact; | ||
} | ||
get Description() { | ||
@@ -282,0 +286,0 @@ return decodeURIComponent(this.key.split('?').reverse()[0]); |
@@ -17,7 +17,10 @@ "use strict"; | ||
if (config.IsOutputArtifactRequested(artifactType)) { | ||
config.GeneratedFile.Dispatch({ | ||
type: artifactType, | ||
uri: uri, | ||
content: handle.ReadData() | ||
}); | ||
const content = handle.ReadData(); | ||
if (content !== "") { | ||
config.GeneratedFile.Dispatch({ | ||
type: artifactType, | ||
uri: uri, | ||
content: content | ||
}); | ||
} | ||
} | ||
@@ -36,3 +39,3 @@ if (config.IsOutputArtifactRequested(artifactType + ".map")) { | ||
if (isObject) { | ||
const sink = config.DataStore.DataSink; | ||
const sink = config.DataStore.getDataSink(); | ||
const object = new lazy_1.Lazy(() => handle.ReadObject()); | ||
@@ -39,0 +42,0 @@ const ast = new lazy_1.Lazy(() => handle.ReadYamlAst()); |
@@ -8,5 +8,5 @@ import { DataHandle, DataSink } from '../data-store/data-store'; | ||
constructor(config: ConfigurationView); | ||
private MatchesSourceFilter(document, transform); | ||
private MatchesSourceFilter(document, transform, artifact); | ||
private ProcessInternal(data, sink, documentId?); | ||
Process(data: DataHandle, sink: DataSink, isObject: boolean, documentId?: string): Promise<DataHandle>; | ||
} |
@@ -18,10 +18,10 @@ "use strict"; | ||
} | ||
MatchesSourceFilter(document, transform) { | ||
MatchesSourceFilter(document, transform, artifact) { | ||
document = "/" + document; | ||
// console.log(document, [...transform.from]); | ||
// from | ||
const from = linq_1.From(transform.from); | ||
const matchesFrom = !from.Any() || from | ||
.Any(d => document.endsWith("/" + d) || | ||
document.indexOf("/" + d + "/") !== -1); | ||
.Any(d => artifact === d || | ||
document.endsWith("/" + d)); | ||
// console.log(matchesFrom, document, artifact, [...transform.from]); | ||
return matchesFrom; | ||
@@ -32,3 +32,3 @@ } | ||
// matches filter? | ||
if (this.MatchesSourceFilter(documentId || data.key, trans)) { | ||
if (this.MatchesSourceFilter(documentId || data.key, trans, data.GetArtifact())) { | ||
for (const w of trans.where) { | ||
@@ -35,0 +35,0 @@ // transform |
@@ -157,3 +157,3 @@ "use strict"; | ||
const plugin = cfg.plugin || stageName.split("/").reverse()[0]; | ||
const outputArtifact = cfg.outputArtifact; | ||
const outputArtifact = cfg["output-artifact"]; | ||
const scope = cfg.scope; | ||
@@ -245,4 +245,4 @@ const inputs = (!cfg.input ? [] : (Array.isArray(cfg.input) ? cfg.input : [cfg.input])).map((x) => resolvePipelineStageName(stageName, x)); | ||
"emitter": CreateArtifactEmitter(), | ||
"pipeline-emitter": CreateArtifactEmitter(async () => new data_store_1.QuickDataSource([await configView.DataStore.DataSink.WriteObject("pipeline", pipeline.pipeline)])), | ||
"configuration-emitter": CreateArtifactEmitter(async () => new data_store_1.QuickDataSource([await configView.DataStore.DataSink.WriteObject("configuration", configView.Raw)])) | ||
"pipeline-emitter": CreateArtifactEmitter(async () => new data_store_1.QuickDataSource([await configView.DataStore.getDataSink().WriteObject("pipeline", pipeline.pipeline)])), | ||
"configuration-emitter": CreateArtifactEmitter(async () => new data_store_1.QuickDataSource([await configView.DataStore.getDataSink().WriteObject("configuration", configView.Raw)])) | ||
}; | ||
@@ -265,5 +265,6 @@ // dynamically loaded, auto-discovered plugins | ||
// get input | ||
let inputScopes = await Promise.all(node.inputs.map(getTask)); | ||
const inputScopes = await Promise.all(node.inputs.map(getTask)); | ||
let inputScope; | ||
if (inputScopes.length === 0) { | ||
inputScopes = [fsInput]; | ||
inputScope = fsInput; | ||
} | ||
@@ -278,5 +279,4 @@ else { | ||
} | ||
inputScopes = [new data_store_1.QuickDataSource(handles)]; | ||
inputScope = new data_store_1.QuickDataSource(handles); | ||
} | ||
const inputScope = inputScopes[0]; | ||
const config = pipeline.configs[jsonpath_1.stringify(node.configScope)]; | ||
@@ -290,3 +290,3 @@ const pluginName = node.pluginName; | ||
config.Message({ Channel: message_1.Channel.Debug, Text: `${nodeName} - START` }); | ||
const scopeResult = await plugin(config, inputScope, config.DataStore.DataSink); | ||
const scopeResult = await plugin(config, inputScope, config.DataStore.getDataSink(node.outputArtifact)); | ||
config.Message({ Channel: message_1.Channel.Debug, Text: `${nodeName} - END` }); | ||
@@ -293,0 +293,0 @@ return scopeResult; |
@@ -1,4 +0,11 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// enable static modules for autorest-core | ||
if (global.StaticVolumeSet) { | ||
global.StaticVolumeSet.addFileSystem(`${__dirname}/static_modules.fs`); | ||
} | ||
var message_1 = require("./lib/message"); | ||
@@ -5,0 +12,0 @@ exports.Channel = message_1.Channel; |
{ | ||
"name": "@microsoft.azure/autorest-core", | ||
"version": "2.0.3", | ||
"version": "2.0.5", | ||
"description": "AutoRest core module", | ||
@@ -24,3 +24,3 @@ "engines": { | ||
"test": "./node_modules/.bin/mocha ./dist/test", | ||
"prepare": "shx rm -rf ./dist/ && tsc && cd ./static_modules && npm install", | ||
"prepare": "shx rm -rf ./dist/ && shx mkdir -p ./dist/ && tsc && cd ./static_modules && npm install", | ||
"prepublishonly": "gulp build" | ||
@@ -78,2 +78,2 @@ }, | ||
"dependencies": {} | ||
} | ||
} |
@@ -44,3 +44,3 @@ # Default Configuration | ||
use-extension: | ||
"@microsoft.azure/autorest.nodejs": "1.9.3" | ||
"@microsoft.azure/autorest.nodejs": "1.9.4" | ||
``` | ||
@@ -65,6 +65,11 @@ | ||
use-extension: | ||
"@microsoft.azure/classic-openapi-validator": "1.0.3" | ||
"@microsoft.azure/openapi-validator": "0.1.2-preview" | ||
``` | ||
"@microsoft.azure/classic-openapi-validator": "~1.0.3" | ||
"@microsoft.azure/openapi-validator": "~1.0.0" | ||
``` | ||
``` yaml $(typescript) | ||
use-extension: | ||
"@microsoft.azure/autorest.typescript": "0.1.0" | ||
``` | ||
### Graph | ||
@@ -71,0 +76,0 @@ |
30706197
5527