@progress/kendo-schematics
Advanced tools
Comparing version 0.1.2-dev.201805041307 to 0.2.0-dev.201805041516
@@ -6,3 +6,3 @@ { | ||
"license": "SEE LICENSE in LICENSE.md", | ||
"version": "0.1.2-dev.201805041307", | ||
"version": "0.2.0-dev.201805041516", | ||
"scripts": { | ||
@@ -9,0 +9,0 @@ "build-package": "npm run build", |
@@ -51,2 +51,17 @@ "use strict"; | ||
} | ||
function importHammerjs(options) { | ||
return (host) => { | ||
const moduleToUpdate = options.module; | ||
if (!moduleToUpdate || !options.importHammerjs) | ||
return host; | ||
const read = readSource(moduleToUpdate); | ||
const changes = utils_1.addImportToModule({ | ||
source: read(host), | ||
symbolName: '', | ||
modulePath: 'hammerjs' | ||
}); | ||
rules_1.applyChanges(host, moduleToUpdate, changes); | ||
return host; | ||
}; | ||
} | ||
function npmInstall(options) { | ||
@@ -59,5 +74,9 @@ return (host, context) => { | ||
} | ||
const progressDependencies = json => Object.entries(json.peerDependencies) | ||
.filter(([k, v]) => k.startsWith("@progress")) | ||
.reduce((s, [k, v]) => (s[k] = v, s), {}); | ||
const progressDependencies = (json, importHammerjs) => { | ||
const hammerRegEx = importHammerjs ? '|hammerjs' : ''; | ||
const validator = new RegExp(`^(@progress.*${hammerRegEx})$`); | ||
return Object.entries(json.peerDependencies) | ||
.filter(([k, v]) => validator.test(k)) | ||
.reduce((s, [k, v]) => (s[k] = v, s), {}); | ||
}; | ||
function registerInPackageJson(options) { | ||
@@ -67,3 +86,3 @@ return (tree, context) => { | ||
const content = utils_1.fileContent(tree, `node_modules/@progress/${fullPackageName}/package.json`); | ||
const dependencies = progressDependencies(JSON.parse(content)); | ||
const dependencies = progressDependencies(JSON.parse(content), options.importHammerjs); | ||
return rules_1.addToPackageJson({ dependencies })(tree, context); | ||
@@ -84,2 +103,3 @@ }; | ||
importKendoModules(options), | ||
importHammerjs(options), | ||
importAnimationModule(options), | ||
@@ -86,0 +106,0 @@ toInstall |
@@ -31,2 +31,6 @@ export interface Schema { | ||
/** | ||
* Import Hammer.js in the main module. | ||
*/ | ||
importHammerjs?: boolean; | ||
/** | ||
* Register Kendo theme. | ||
@@ -33,0 +37,0 @@ */ |
@@ -43,5 +43,10 @@ { | ||
}, | ||
"theme": { "description": "Register Kendo theme.", | ||
"theme": { | ||
"description": "Register Kendo theme.", | ||
"enum": ["default", "bootstrap", "material"], | ||
"type": "string" | ||
}, | ||
"importHammerjs": { | ||
"description": "Import Hammer.js in the main module.", | ||
"type": "boolean" | ||
} | ||
@@ -48,0 +53,0 @@ }, |
@@ -135,2 +135,3 @@ "use strict"; | ||
exports.insertImport = (source, symbolName, importFrom) => { | ||
const isSideEffectsImport = !symbolName; | ||
const allImports = exports.nodesByKind(source, ts.SyntaxKind.ImportDeclaration); | ||
@@ -159,5 +160,8 @@ const imports = allImports | ||
// missing module declaration | ||
const toAdd = isSideEffectsImport ? | ||
`${prefix}import '${importFrom}';\n` : | ||
`${prefix}import { ${symbolName} } from '${importFrom}';\n`; | ||
return [{ | ||
position, | ||
toAdd: `${prefix}import { ${symbolName} } from '${importFrom}';\n` | ||
toAdd | ||
}]; | ||
@@ -180,2 +184,6 @@ }; | ||
const namedImport = exports.nodesByKind(imports[0], ts.SyntaxKind.NamedImports)[0]; | ||
if (!namedImport) { | ||
// it should be import 'some-package'; | ||
return []; | ||
} | ||
if (!namedImport.elements.length) { | ||
@@ -182,0 +190,0 @@ return [ |
@@ -6,3 +6,4 @@ "use strict"; | ||
"peerDependencies": { | ||
"@progress/kendo-dependency": "^1.0.0" | ||
"@progress/kendo-dependency": "^1.0.0", | ||
"hammerjs": "^2.0.0" | ||
} | ||
@@ -9,0 +10,0 @@ }; |
55660
1428