bobril-build
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "bobril-build", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Builds Bobril Applications or Libraries", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import * as b from './node_modules/bobril/index'; | ||
import * as g from './node_modules/bobril-g11n/index'; | ||
import { t, initGlobalization as initG } from './node_modules/bobril-g11n/index'; | ||
g.initGlobalization({ | ||
initG({ | ||
defaultLocale: 'cs-CZ', | ||
@@ -48,5 +48,5 @@ pathToTranslation: (locale: string) => { return locale+'.js'; } | ||
b.init(() => [ | ||
header({ fontSize: 20 }, g.t('Hello')), | ||
header({ fontSize: 20 }, t('Hello')), | ||
warnHeader({ fontSize: 25, isWarning: true }, 'World'), | ||
header({ fontSize: 15 }, g.t('Right now is {now, date, LLLL}', { now: b.now() })) | ||
header({ fontSize: 15 }, t('Right now is {now, date, LLLL}', { now: b.now() })) | ||
]); |
var b = require('./node_modules/bobril/index'); | ||
var g = require('./node_modules/bobril-g11n/index'); | ||
g.initGlobalization({ | ||
var index_1 = require('./node_modules/bobril-g11n/index'); | ||
index_1.initGlobalization({ | ||
defaultLocale: 'cs-CZ', | ||
@@ -24,5 +24,5 @@ pathToTranslation: function (locale) { return locale + '.js'; } | ||
b.init(function () { return [ | ||
header({ fontSize: 20 }, g.t(0)), | ||
header({ fontSize: 20 }, index_1.t(0)), | ||
warnHeader({ fontSize: 25, isWarning: true }, 'World'), | ||
header({ fontSize: 15 }, g.t(1, { now: b.now() })) | ||
header({ fontSize: 15 }, index_1.t(1, { now: b.now() })) | ||
]; }); |
@@ -5,7 +5,22 @@ var ts = require("typescript"); | ||
function isBobrilFunction(name, callExpression, sourceInfo) { | ||
return callExpression.expression.getText() === sourceInfo.bobrilNamespace + '.' + name; | ||
var text = callExpression.expression.getText(); | ||
return text === sourceInfo.bobrilNamespace + '.' + name || text === sourceInfo.bobrilImports[name]; | ||
} | ||
function isBobrilG11NFunction(name, callExpression, sourceInfo) { | ||
return callExpression.expression.getText() === sourceInfo.bobrilG11NNamespace + '.' + name; | ||
var text = callExpression.expression.getText(); | ||
return text === sourceInfo.bobrilG11NNamespace + '.' + name || text === sourceInfo.bobrilG11NImports[name]; | ||
} | ||
function extractBindings(bindings, ns, ims) { | ||
if (bindings.kind === 223 /* NamedImports */) { | ||
var namedBindings = bindings; | ||
for (var i = 0; i < namedBindings.elements.length; i++) { | ||
var binding = namedBindings.elements[i]; | ||
ims[(binding.propertyName || binding.name).text] = binding.name.text; | ||
} | ||
} | ||
else if (ns == null && bindings.kind === 222 /* NamespaceImport */) { | ||
return bindings.name.text; | ||
} | ||
return ns; | ||
} | ||
function gatherSourceInfo(source, tc, resolvePathStringLiteral) { | ||
@@ -27,13 +42,9 @@ var result = { | ||
var moduleSymbol = tc.getSymbolAtLocation(id.moduleSpecifier); | ||
var sf = moduleSymbol.valueDeclaration.getSourceFile(); | ||
var fn = sf.fileName; | ||
var fn = moduleSymbol.valueDeclaration.getSourceFile().fileName; | ||
var bindings = id.importClause.namedBindings; | ||
if (/bobril\/index\.ts/i.test(fn)) { | ||
if (result.bobrilNamespace == null && id.importClause.namedBindings.kind === 222 /* NamespaceImport */) { | ||
result.bobrilNamespace = id.importClause.namedBindings.name.text; | ||
} | ||
result.bobrilNamespace = extractBindings(bindings, result.bobrilNamespace, result.bobrilImports); | ||
} | ||
else if (/bobril-g11n\/index\.ts/i.test(fn)) { | ||
if (result.bobrilG11NNamespace == null && id.importClause.namedBindings.kind === 222 /* NamespaceImport */) { | ||
result.bobrilG11NNamespace = id.importClause.namedBindings.name.text; | ||
} | ||
result.bobrilG11NNamespace = extractBindings(bindings, result.bobrilG11NNamespace, result.bobrilG11NImports); | ||
} | ||
@@ -40,0 +51,0 @@ result.sourceDeps.push(fn); |
@@ -48,9 +48,24 @@ import * as ts from "typescript"; | ||
function isBobrilFunction(name: string, callExpression: ts.CallExpression, sourceInfo: SourceInfo): boolean { | ||
return callExpression.expression.getText() === sourceInfo.bobrilNamespace + '.' + name; | ||
let text = callExpression.expression.getText(); | ||
return text === sourceInfo.bobrilNamespace + '.' + name || text === sourceInfo.bobrilImports[name]; | ||
} | ||
function isBobrilG11NFunction(name: string, callExpression: ts.CallExpression, sourceInfo: SourceInfo): boolean { | ||
return callExpression.expression.getText() === sourceInfo.bobrilG11NNamespace + '.' + name; | ||
let text = callExpression.expression.getText(); | ||
return text === sourceInfo.bobrilG11NNamespace + '.' + name || text === sourceInfo.bobrilG11NImports[name]; | ||
} | ||
function extractBindings(bindings: ts.NamespaceImport|ts.NamedImports, ns: string, ims: Object): string { | ||
if (bindings.kind === ts.SyntaxKind.NamedImports) { | ||
let namedBindings = <ts.NamedImports>bindings; | ||
for (let i = 0; i < namedBindings.elements.length; i++) { | ||
let binding = namedBindings.elements[i]; | ||
ims[(binding.propertyName || binding.name).text] = binding.name.text; | ||
} | ||
} else if (ns == null && bindings.kind === ts.SyntaxKind.NamespaceImport) { | ||
return (<ts.NamespaceImport>bindings).name.text; | ||
} | ||
return ns; | ||
} | ||
export function gatherSourceInfo(source: ts.SourceFile, tc: ts.TypeChecker, resolvePathStringLiteral: (sl: ts.StringLiteral) => string): SourceInfo { | ||
@@ -72,12 +87,8 @@ let result: SourceInfo = { | ||
let moduleSymbol = tc.getSymbolAtLocation(id.moduleSpecifier); | ||
let sf = moduleSymbol.valueDeclaration.getSourceFile(); | ||
let fn = sf.fileName; | ||
let fn = moduleSymbol.valueDeclaration.getSourceFile().fileName; | ||
let bindings = id.importClause.namedBindings; | ||
if (/bobril\/index\.ts/i.test(fn)) { | ||
if (result.bobrilNamespace == null && id.importClause.namedBindings.kind === ts.SyntaxKind.NamespaceImport) { | ||
result.bobrilNamespace = (<ts.NamespaceImport>id.importClause.namedBindings).name.text; | ||
} | ||
result.bobrilNamespace = extractBindings(bindings, result.bobrilNamespace, result.bobrilImports); | ||
} else if (/bobril-g11n\/index\.ts/i.test(fn)) { | ||
if (result.bobrilG11NNamespace == null && id.importClause.namedBindings.kind === ts.SyntaxKind.NamespaceImport) { | ||
result.bobrilG11NNamespace = (<ts.NamespaceImport>id.importClause.namedBindings).name.text; | ||
} | ||
result.bobrilG11NNamespace = extractBindings(bindings, result.bobrilG11NNamespace, result.bobrilG11NImports); | ||
} | ||
@@ -84,0 +95,0 @@ result.sourceDeps.push(fn); |
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
29807
1193722
128