diff --git a/.prettierrc.json b/.prettierrc.json index 12884a7..8d3dfb0 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -5,4 +5,4 @@ "tabWidth": 2, "semi": true, "bracketSpacing": true -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 90258fe..734dd38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "schematics-utilities", - "version": "0.0.1", + "version": "0.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -27,22 +27,14 @@ "@types/jasmine": { "version": "2.8.8", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.8.8.tgz", - "integrity": "sha512-OJSUxLaxXsjjhob2DBzqzgrkLmukM3+JMpRp0r0E4HTdT1nwDCWhaswjYxazPij6uOdzHCJfNbDjmQ1/rnNbCg==" + "integrity": "sha512-OJSUxLaxXsjjhob2DBzqzgrkLmukM3+JMpRp0r0E4HTdT1nwDCWhaswjYxazPij6uOdzHCJfNbDjmQ1/rnNbCg==", + "dev": true }, "@types/node": { "version": "8.10.21", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.21.tgz", - "integrity": "sha512-87XkD9qDXm8fIax+5y7drx84cXsu34ZZqfB7Cial3Q/2lxSoJ/+DRaWckkCbxP41wFSIrrb939VhzaNxj4eY1w==" - }, - "@types/parse5": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@types/parse5/-/parse5-5.0.0.tgz", - "integrity": "sha512-J5D3z703XTDIGQFYXsnU9uRCW9e9mMEFO0Kpe6kykyiboqziru/RlZ0hM2P+PKTG4NHG1SjLrqae/NrV2iJApQ==" - }, - "@types/semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==" + "integrity": "sha512-87XkD9qDXm8fIax+5y7drx84cXsu34ZZqfB7Cial3Q/2lxSoJ/+DRaWckkCbxP41wFSIrrb939VhzaNxj4eY1w==", + "dev": true }, "ajv": { "version": "6.4.0", @@ -60,6 +52,15 @@ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "1.9.2" + } + }, "anymatch": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", @@ -286,6 +287,17 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "dev": true, + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.4.0" + } + }, "chokidar": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.0.4.tgz", @@ -306,6 +318,12 @@ "upath": "1.1.0" } }, + "ci-info": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.1.3.tgz", + "integrity": "sha512-SK/846h/Rcy8q9Z9CAwGBLfCJ6EkjJWdpelWDufQpqVDYq2Wnnv8zlSO6AMQap02jvhVruKKpEtQOufo3pFhLg==", + "dev": true + }, "class-utils": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", @@ -346,6 +364,21 @@ "object-visit": "1.0.1" } }, + "color-convert": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.2.tgz", + "integrity": "sha512-3NUJZdhMhcdPn8vJ9v2UQJoH0qqoGUkYTgFEPZaPjEtwmmKUfNV46zZmgB2M5M4DCEQHMaCfWHCxiBflLm04Tg==", + "dev": true, + "requires": { + "color-name": "1.1.1" + } + }, + "color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha1-SxQVMEz1ACjqgWQ2Q72C6gWANok=", + "dev": true + }, "combined-stream": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", @@ -390,6 +423,17 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, + "requires": { + "lru-cache": "4.1.3", + "shebang-command": "1.2.0", + "which": "1.3.1" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -468,10 +512,32 @@ "jsbn": "0.1.1" } }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "execa": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.8.0.tgz", + "integrity": "sha1-2NdrvBtVIX7RkP1t1J08d07PyNo=", + "dev": true, + "requires": { + "cross-spawn": "5.1.0", + "get-stream": "3.0.0", + "is-stream": "1.1.0", + "npm-run-path": "2.0.2", + "p-finally": "1.0.0", + "signal-exit": "3.0.2", + "strip-eof": "1.0.0" + } + }, "exit": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", - "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true }, "expand-brackets": { "version": "2.1.4", @@ -624,6 +690,15 @@ } } }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "2.0.0" + } + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -655,7 +730,8 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true }, "fsevents": { "version": "1.2.4", @@ -1135,6 +1211,12 @@ "wide-align": "1.1.3" } }, + "get-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", + "dev": true + }, "get-value": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", @@ -1152,6 +1234,7 @@ "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, "requires": { "fs.realpath": "1.0.0", "inflight": "1.0.6", @@ -1212,6 +1295,12 @@ } } }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, "has-unicode": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", @@ -1262,10 +1351,36 @@ "sshpk": "1.14.2" } }, + "husky": { + "version": "0.14.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-0.14.3.tgz", + "integrity": "sha512-e21wivqHpstpoiWA/Yi8eFti8E+sQDSS53cpJsPptPs295QTOQR0ZwnHo2TXy1XOpZFD9rPOd3NpmqTK6uMLJA==", + "dev": true, + "requires": { + "is-ci": "1.1.0", + "normalize-path": "1.0.0", + "strip-indent": "2.0.0" + }, + "dependencies": { + "normalize-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-1.0.0.tgz", + "integrity": "sha1-MtDkcvkf80VwHBWoMRAY07CpA3k=", + "dev": true + } + } + }, + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, "requires": { "once": "1.4.0", "wrappy": "1.0.2" @@ -1315,6 +1430,15 @@ "builtin-modules": "1.1.1" } }, + "is-ci": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.1.0.tgz", + "integrity": "sha512-c7TnwxLePuqIlxHgr7xtxzycJPegNHFuIrBkwbf8hc58//+Op1CqFkyS+xnIMkwn9UsJIwc174BIjkyBmSpjKg==", + "dev": true, + "requires": { + "ci-info": "1.1.3" + } + }, "is-data-descriptor": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz", @@ -1402,6 +1526,12 @@ "isobject": "3.0.1" } }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", + "dev": true + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -1417,6 +1547,12 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, "isobject": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", @@ -1431,6 +1567,7 @@ "version": "2.99.0", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.99.0.tgz", "integrity": "sha1-jKctEC5jm4Z8ZImFbg4YqceqQrc=", + "dev": true, "requires": { "exit": "0.1.2", "glob": "7.1.2", @@ -1440,7 +1577,8 @@ "jasmine-core": { "version": "2.99.1", "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", - "integrity": "sha1-5kAN8ea1bhMLYcS80JPap/boyhU=" + "integrity": "sha1-5kAN8ea1bhMLYcS80JPap/boyhU=", + "dev": true }, "jsbn": { "version": "0.1.1", @@ -1479,11 +1617,31 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==" }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", + "dev": true, + "requires": { + "p-locate": "2.0.0", + "path-exists": "3.0.0" + } + }, "lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" }, + "lru-cache": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", + "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", + "dev": true, + "requires": { + "pseudomap": "1.0.2", + "yallist": "2.1.2" + } + }, "map-cache": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", @@ -1557,6 +1715,12 @@ } } }, + "mri": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.1.1.tgz", + "integrity": "sha1-haom09ru7t+A3FmEr5XMXKXK2fE=", + "dev": true + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -1635,6 +1799,15 @@ "ssri": "5.3.0" } }, + "npm-run-path": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", + "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", + "dev": true, + "requires": { + "path-key": "2.0.1" + } + }, "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", @@ -1734,6 +1907,36 @@ "os-tmpdir": "1.0.2" } }, + "p-finally": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", + "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", + "dev": true + }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", + "dev": true, + "requires": { + "p-limit": "1.3.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, "parse5": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.0.0.tgz", @@ -1749,11 +1952,23 @@ "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=" }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "dev": true + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -1764,11 +1979,36 @@ "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, + "prettier": { + "version": "1.13.7", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.13.7.tgz", + "integrity": "sha512-KIU72UmYPGk4MujZGYMFwinB7lOf2LsDNGSOC8ufevsrPLISrZbNJlWstRi3m0AMuszbH+EFSQ/r6w56RSPK6w==", + "dev": true + }, + "pretty-quick": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/pretty-quick/-/pretty-quick-1.6.0.tgz", + "integrity": "sha512-bnCmsPy98ERD7VWBO+0y1OGWLfx/DPUjNFN2ZRVyxuGBiic1BXAGgjHsTKgBIbPISdqpP6KBEmRV0Lir4xu/BA==", + "dev": true, + "requires": { + "chalk": "2.4.1", + "execa": "0.8.0", + "find-up": "2.1.0", + "ignore": "3.3.10", + "mri": "1.1.1" + } + }, "process-nextick-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "dev": true + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -1941,11 +2181,25 @@ } } }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, + "requires": { + "shebang-regex": "1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "optional": true + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, "slide": { "version": "1.1.6", @@ -2176,6 +2430,27 @@ "ansi-regex": "2.1.1" } }, + "strip-eof": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", + "dev": true + }, + "strip-indent": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-2.0.0.tgz", + "integrity": "sha1-XvjbKV0B5u1sv3qrlpmNeCJSe2g=", + "dev": true + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "3.0.0" + } + }, "to-object-path": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", @@ -2386,6 +2661,15 @@ "extsprintf": "1.3.0" } }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "requires": { + "isexe": "2.0.0" + } + }, "wide-align": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", @@ -2399,6 +2683,12 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "dev": true } } } diff --git a/src/angular/ast-utils.ts b/src/angular/ast-utils.ts index f18d732..89cd7ad 100755 --- a/src/angular/ast-utils.ts +++ b/src/angular/ast-utils.ts @@ -8,7 +8,6 @@ import * as ts from 'typescript'; import { Change, InsertChange, NoopChange } from './change'; - /** * Add Import `import { symbolName } from fileName` if the import doesn't exit * already. Assumes fileToEdit can be resolved and accessed. @@ -18,15 +17,21 @@ import { Change, InsertChange, NoopChange } from './change'; * @param isDefault (if true, import follows style for importing default exports) * @return Change */ -export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string, - fileName: string, isDefault = false): Change { +export function insertImport( + source: ts.SourceFile, + fileToEdit: string, + symbolName: string, + fileName: string, + isDefault = false +): Change { const rootNode = source; const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration); // get nodes that map to import statements from the file fileName const relevantImports = allImports.filter(node => { // StringLiteral of the ImportDeclaration is the import file (fileName in this case). - const importFiles = node.getChildren() + const importFiles = node + .getChildren() .filter(child => child.kind === ts.SyntaxKind.StringLiteral) .map(n => (n as ts.StringLiteral).text); @@ -64,8 +69,9 @@ export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolNa } // no such import declaration exists - const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral) - .filter((n: ts.StringLiteral) => n.text === 'use strict'); + const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter( + (n: ts.StringLiteral) => n.text === 'use strict' + ); let fallbackPos = 0; if (useStrict.length > 0) { fallbackPos = useStrict[0].end; @@ -75,18 +81,11 @@ export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolNa // if there are no imports or 'use strict' statement, insert import at beginning of file const insertAtBeginning = allImports.length === 0 && useStrict.length === 0; const separator = insertAtBeginning ? '' : ';\n'; - const toInsert = `${separator}import ${open}${symbolName}${close}` + - ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`; - - return insertAfterLastOccurrence( - allImports, - toInsert, - fileToEdit, - fallbackPos, - ts.SyntaxKind.StringLiteral, - ); -} + const toInsert = + `${separator}import ${open}${symbolName}${close}` + ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`; + return insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral); +} /** * Find all nodes from the AST in the subtree of node of SyntaxKind kind. @@ -123,7 +122,6 @@ export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): t return arr; } - /** * Get all the nodes from a source. * @param sourceFile The source file object. @@ -161,7 +159,6 @@ export function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.N return foundNode; } - /** * Helper for sorting nodes. * @return function to sort nodes in increasing order of position in sourceFile @@ -170,7 +167,6 @@ function nodesByPosition(first: ts.Node, second: ts.Node): number { return first.getStart() - second.getStart(); } - /** * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]` * or after the last of occurence of `syntaxKind` if the last occurence is a sub child @@ -184,18 +180,22 @@ function nodesByPosition(first: ts.Node, second: ts.Node): number { * @return Change instance * @throw Error if toInsert is first occurence but fall back is not set */ -export function insertAfterLastOccurrence(nodes: ts.Node[], - toInsert: string, - file: string, - fallbackPos: number, - syntaxKind?: ts.SyntaxKind): Change { +export function insertAfterLastOccurrence( + nodes: ts.Node[], + toInsert: string, + file: string, + fallbackPos: number, + syntaxKind?: ts.SyntaxKind +): Change { // sort() has a side effect, so make a copy so that we won't overwrite the parent's object. let lastItem = [...nodes].sort(nodesByPosition).pop(); if (!lastItem) { throw new Error(); } if (syntaxKind) { - lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop(); + lastItem = findNodes(lastItem, syntaxKind) + .sort(nodesByPosition) + .pop(); } if (!lastItem && fallbackPos == undefined) { throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`); @@ -205,7 +205,6 @@ export function insertAfterLastOccurrence(nodes: ts.Node[], return new InsertChange(file, lastItemPosition, toInsert); } - export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null { if (node.kind == ts.SyntaxKind.Identifier) { return (node as ts.Identifier).text; @@ -216,9 +215,7 @@ export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): s } } - -function _angularImportsFromNode(node: ts.ImportDeclaration, - _sourceFile: ts.SourceFile): {[name: string]: string} { +function _angularImportsFromNode(node: ts.ImportDeclaration, _sourceFile: ts.SourceFile): { [name: string]: string } { const ms = node.moduleSpecifier; let modulePath: string; switch (ms.kind) { @@ -242,15 +239,15 @@ function _angularImportsFromNode(node: ts.ImportDeclaration, if (nb.kind == ts.SyntaxKind.NamespaceImport) { // This is of the form `import * as name from 'path'`. Return `name.`. return { - [(nb as ts.NamespaceImport).name.text + '.']: modulePath, + [(nb as ts.NamespaceImport).name.text + '.']: modulePath }; } else { // This is of the form `import {a,b,c} from 'path'` const namedImports = nb as ts.NamedImports; return namedImports.elements - .map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text) - .reduce((acc: {[name: string]: string}, curr: string) => { + .map((is: ts.ImportSpecifier) => (is.propertyName ? is.propertyName.text : is.name.text)) + .reduce((acc: { [name: string]: string }, curr: string) => { acc[curr] = modulePath; return acc; @@ -265,13 +262,10 @@ function _angularImportsFromNode(node: ts.ImportDeclaration, } } - -export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, - module: string): ts.Node[] { - const angularImports: {[name: string]: string} - = findNodes(source, ts.SyntaxKind.ImportDeclaration) +export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[] { + const angularImports: { [name: string]: string } = findNodes(source, ts.SyntaxKind.ImportDeclaration) .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source)) - .reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => { + .reduce((acc: { [name: string]: string }, current: { [name: string]: string }) => { for (const key of Object.keys(current)) { acc[key] = current[key]; } @@ -281,16 +275,16 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, return getSourceNodes(source) .filter(node => { - return node.kind == ts.SyntaxKind.Decorator - && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression; + return ( + node.kind == ts.SyntaxKind.Decorator && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression + ); }) .map(node => (node as ts.Decorator).expression as ts.CallExpression) .filter(expr => { if (expr.expression.kind == ts.SyntaxKind.Identifier) { const id = expr.expression as ts.Identifier; - return id.getFullText(source) == identifier - && angularImports[id.getFullText(source)] === module; + return id.getFullText(source) == identifier && angularImports[id.getFullText(source)] === module; } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) { // This covers foo.NgModule when importing * as foo. const paExpr = expr.expression as ts.PropertyAccessExpression; @@ -302,17 +296,16 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, const id = paExpr.name.text; const moduleId = (paExpr.expression as ts.Identifier).getText(source); - return id === identifier && (angularImports[moduleId + '.'] === module); + return id === identifier && angularImports[moduleId + '.'] === module; } return false; }) - .filter(expr => expr.arguments[0] - && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression) + .filter(expr => expr.arguments[0] && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression) .map(expr => expr.arguments[0] as ts.ObjectLiteralExpression); } -function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefined { +function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration | undefined { if (ts.isClassDeclaration(node)) { return node; } @@ -326,7 +319,7 @@ function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefine * @param source source file containing one or more @NgModule * @returns the name of the first @NgModule, or `undefined` if none is found */ -export function getFirstNgModuleName(source: ts.SourceFile): string|undefined { +export function getFirstNgModuleName(source: ts.SourceFile): string | undefined { // First, find the @NgModule decorators. const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core'); if (ngModulesMetadata.length === 0) { @@ -349,10 +342,10 @@ export function addSymbolToNgModuleMetadata( ngModulePath: string, metadataField: string, symbolName: string, - importPath: string | null = null, + importPath: string | null = null ): Change[] { const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core'); - let node: any = nodes[0]; // tslint:disable-line:no-any + let node: any = nodes[0]; // tslint:disable-line:no-any // Find the decorator declaration. if (!node) { @@ -360,8 +353,7 @@ export function addSymbolToNgModuleMetadata( } // Get all the children property assignment of object literals. - const matchingProperties: ts.ObjectLiteralElement[] = - (node as ts.ObjectLiteralExpression).properties + const matchingProperties: ts.ObjectLiteralElement[] = (node as ts.ObjectLiteralExpression).properties .filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment) // Filter out every fields that's not "metadataField". Also handles string literals // (but not expressions). @@ -404,7 +396,7 @@ export function addSymbolToNgModuleMetadata( if (importPath !== null) { return [ new InsertChange(ngModulePath, position, toInsert), - insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath), + insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath) ]; } else { return [new InsertChange(ngModulePath, position, toInsert)]; @@ -432,7 +424,7 @@ export function addSymbolToNgModuleMetadata( } if (Array.isArray(node)) { - const nodeArray = node as {} as Array; + const nodeArray = (node as {}) as Array; const symbolsArray = nodeArray.map(node => node.getText()); if (symbolsArray.includes(symbolName)) { return []; @@ -477,7 +469,7 @@ export function addSymbolToNgModuleMetadata( if (importPath !== null) { return [ new InsertChange(ngModulePath, position, toInsert), - insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath), + insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath) ]; } @@ -488,81 +480,93 @@ export function addSymbolToNgModuleMetadata( * Custom function to insert a declaration (component, pipe, directive) * into NgModule declarations. It also imports the component. */ -export function addDeclarationToModule(source: ts.SourceFile, - modulePath: string, classifiedName: string, - importPath: string): Change[] { - return addSymbolToNgModuleMetadata( - source, modulePath, 'declarations', classifiedName, importPath); +export function addDeclarationToModule( + source: ts.SourceFile, + modulePath: string, + classifiedName: string, + importPath: string +): Change[] { + return addSymbolToNgModuleMetadata(source, modulePath, 'declarations', classifiedName, importPath); } /** * Custom function to insert an NgModule into NgModule imports. It also imports the module. */ -export function addImportToModule(source: ts.SourceFile, - modulePath: string, classifiedName: string, - importPath: string): Change[] { - +export function addImportToModule( + source: ts.SourceFile, + modulePath: string, + classifiedName: string, + importPath: string +): Change[] { return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath); } /** * Custom function to insert a provider into NgModule. It also imports it. */ -export function addProviderToModule(source: ts.SourceFile, - modulePath: string, classifiedName: string, - importPath: string): Change[] { +export function addProviderToModule( + source: ts.SourceFile, + modulePath: string, + classifiedName: string, + importPath: string +): Change[] { return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath); } /** * Custom function to insert an export into NgModule. It also imports it. */ -export function addExportToModule(source: ts.SourceFile, - modulePath: string, classifiedName: string, - importPath: string): Change[] { +export function addExportToModule( + source: ts.SourceFile, + modulePath: string, + classifiedName: string, + importPath: string +): Change[] { return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath); } /** * Custom function to insert an export into NgModule. It also imports it. */ -export function addBootstrapToModule(source: ts.SourceFile, - modulePath: string, classifiedName: string, - importPath: string): Change[] { +export function addBootstrapToModule( + source: ts.SourceFile, + modulePath: string, + classifiedName: string, + importPath: string +): Change[] { return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath); } /** * Custom function to insert an entryComponent into NgModule. It also imports it. */ -export function addEntryComponentToModule(source: ts.SourceFile, - modulePath: string, classifiedName: string, - importPath: string): Change[] { - return addSymbolToNgModuleMetadata( - source, modulePath, - 'entryComponents', classifiedName, importPath, - ); +export function addEntryComponentToModule( + source: ts.SourceFile, + modulePath: string, + classifiedName: string, + importPath: string +): Change[] { + return addSymbolToNgModuleMetadata(source, modulePath, 'entryComponents', classifiedName, importPath); } /** * Determine if an import already exists. */ -export function isImported(source: ts.SourceFile, - classifiedName: string, - importPath: string): boolean { +export function isImported(source: ts.SourceFile, classifiedName: string, importPath: string): boolean { const allNodes = getSourceNodes(source); const matchingNodes = allNodes .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration) .filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral) .filter((imp: ts.ImportDeclaration) => { - return ( imp.moduleSpecifier).text === importPath; + return (imp.moduleSpecifier).text === importPath; }) .filter((imp: ts.ImportDeclaration) => { if (!imp.importClause) { return false; } - const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier) - .filter(n => n.getText() === classifiedName); + const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier).filter( + n => n.getText() === classifiedName + ); return nodes.length > 0; }); diff --git a/src/angular/change.ts b/src/angular/change.ts index 1255635..0154d1d 100755 --- a/src/angular/change.ts +++ b/src/angular/change.ts @@ -10,7 +10,6 @@ export interface Host { read(path: string): Promise; } - export interface Change { apply(host: Host): Promise; @@ -26,7 +25,6 @@ export interface Change { readonly description: string; } - /** * An operation that does nothing. */ @@ -34,15 +32,15 @@ export class NoopChange implements Change { description = 'No operation.'; order = Infinity; path = null; - apply() { return Promise.resolve(); } + apply() { + return Promise.resolve(); + } } - /** * Will add text to the source code. */ export class InsertChange implements Change { - order: number; description: string; @@ -71,7 +69,6 @@ export class InsertChange implements Change { * Will remove text from the source code. */ export class RemoveChange implements Change { - order: number; description: string; @@ -101,8 +98,7 @@ export class ReplaceChange implements Change { order: number; description: string; - constructor(public path: string, private pos: number, private oldText: string, - private newText: string) { + constructor(public path: string, private pos: number, private oldText: string, private newText: string) { if (pos < 0) { throw new Error('Negative positions are invalid'); } diff --git a/src/angular/config.ts b/src/angular/config.ts index 9915f8a..873d6d4 100755 --- a/src/angular/config.ts +++ b/src/angular/config.ts @@ -8,7 +8,6 @@ import { JsonParseMode, experimental, parseJson } from '@angular-devkit/core'; import { Rule, SchematicsException, Tree } from '@angular-devkit/schematics'; - // The interfaces below are generated from the Angular CLI configuration schema // https://github.com/angular/angular-cli/blob/master/packages/@angular/cli/lib/config/schema.json export interface AppConfig { @@ -31,20 +30,22 @@ export interface AppConfig { /** * List of application assets. */ - assets?: (string | { - /** - * The pattern to match. - */ - glob?: string; - /** - * The dir to search within. - */ - input?: string; - /** - * The output path (relative to the outDir). - */ - output?: string; - })[]; + assets?: ( + | string + | { + /** + * The pattern to match. + */ + glob?: string; + /** + * The dir to search within. + */ + input?: string; + /** + * The output path (relative to the outDir). + */ + output?: string; + })[]; /** * URL where files will be deployed. */ @@ -56,7 +57,7 @@ export interface AppConfig { /** * The runtime platform of the app. */ - platform?: ('browser' | 'server'); + platform?: 'browser' | 'server'; /** * The name of the start HTML file. */ @@ -92,26 +93,30 @@ export interface AppConfig { /** * Global styles to be included in the build. */ - styles?: (string | { - input?: string; - [name: string]: any; // tslint:disable-line:no-any - })[]; + styles?: ( + | string + | { + input?: string; + [name: string]: any; // tslint:disable-line:no-any + })[]; /** * Options to pass to style preprocessors */ stylePreprocessorOptions?: { - /** - * Paths to include. Paths will be resolved to project root. - */ - includePaths?: string[]; + /** + * Paths to include. Paths will be resolved to project root. + */ + includePaths?: string[]; }; /** * Global scripts to be included in the build. */ - scripts?: (string | { - input: string; - [name: string]: any; // tslint:disable-line:no-any - })[]; + scripts?: ( + | string + | { + input: string; + [name: string]: any; // tslint:disable-line:no-any + })[]; /** * Source file for environment config. */ @@ -120,7 +125,7 @@ export interface AppConfig { * Name and corresponding file for environment config. */ environments?: { - [name: string]: any; // tslint:disable-line:no-any + [name: string]: any; // tslint:disable-line:no-any }; appShell?: { app: string; @@ -130,7 +135,7 @@ export interface AppConfig { /** * The type of budget */ - type?: ('bundle' | 'initial' | 'allScript' | 'all' | 'anyScript' | 'any'); + type?: 'bundle' | 'initial' | 'allScript' | 'all' | 'anyScript' | 'any'; /** * The name of the bundle */ @@ -172,14 +177,14 @@ export interface CliConfig { * The global configuration of the project. */ project?: { - /** - * The name of the project. - */ - name?: string; - /** - * Whether or not this project was ejected. - */ - ejected?: boolean; + /** + * The name of the project. + */ + name?: string; + /** + * Whether or not this project was ejected. + */ + ejected?: boolean; }; /** * Properties of the different applications in this project. @@ -189,301 +194,300 @@ export interface CliConfig { * Configuration for end-to-end tests. */ e2e?: { - protractor?: { - /** - * Path to the config file. - */ - config?: string; - }; + protractor?: { + /** + * Path to the config file. + */ + config?: string; + }; }; /** * Properties to be passed to TSLint. */ lint?: { - /** - * File glob(s) to lint. - */ - files?: (string | string[]); - /** - * Location of the tsconfig.json project file. - * Will also use as files to lint if 'files' property not present. - */ - project: string; - /** - * Location of the tslint.json configuration. - */ - tslintConfig?: string; - /** - * File glob(s) to ignore. - */ - exclude?: (string | string[]); + /** + * File glob(s) to lint. + */ + files?: string | string[]; + /** + * Location of the tsconfig.json project file. + * Will also use as files to lint if 'files' property not present. + */ + project: string; + /** + * Location of the tslint.json configuration. + */ + tslintConfig?: string; + /** + * File glob(s) to ignore. + */ + exclude?: string | string[]; }[]; /** * Configuration for unit tests. */ test?: { - karma?: { - /** - * Path to the karma config file. - */ - config?: string; - }; - codeCoverage?: { - /** - * Globs to exclude from code coverage. - */ - exclude?: string[]; - }; + karma?: { + /** + * Path to the karma config file. + */ + config?: string; + }; + codeCoverage?: { + /** + * Globs to exclude from code coverage. + */ + exclude?: string[]; + }; }; /** * Specify the default values for generating. */ defaults?: { + /** + * The file extension to be used for style files. + */ + styleExt?: string; + /** + * How often to check for file updates. + */ + poll?: number; + /** + * Use lint to fix files after generation + */ + lintFix?: boolean; + /** + * Options for generating a class. + */ + class?: { + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; + }; + /** + * Options for generating a component. + */ + component?: { + /** + * Flag to indicate if a dir is created. + */ + flat?: boolean; + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; /** - * The file extension to be used for style files. + * Specifies if the style will be in the ts file. */ - styleExt?: string; + inlineStyle?: boolean; /** - * How often to check for file updates. + * Specifies if the template will be in the ts file. + */ + inlineTemplate?: boolean; + /** + * Specifies the view encapsulation strategy. + */ + viewEncapsulation?: 'Emulated' | 'Native' | 'None'; + /** + * Specifies the change detection strategy. + */ + changeDetection?: 'Default' | 'OnPush'; + }; + /** + * Options for generating a directive. + */ + directive?: { + /** + * Flag to indicate if a dir is created. + */ + flat?: boolean; + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; + }; + /** + * Options for generating a guard. + */ + guard?: { + /** + * Flag to indicate if a dir is created. + */ + flat?: boolean; + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; + }; + /** + * Options for generating an interface. + */ + interface?: { + /** + * Prefix to apply to interface names. (i.e. I) + */ + prefix?: string; + }; + /** + * Options for generating a module. + */ + module?: { + /** + * Flag to indicate if a dir is created. + */ + flat?: boolean; + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; + }; + /** + * Options for generating a pipe. + */ + pipe?: { + /** + * Flag to indicate if a dir is created. + */ + flat?: boolean; + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; + }; + /** + * Options for generating a service. + */ + service?: { + /** + * Flag to indicate if a dir is created. + */ + flat?: boolean; + /** + * Specifies if a spec file is generated. + */ + spec?: boolean; + }; + /** + * Properties to be passed to the build command. + */ + build?: { + /** + * Output sourcemaps. + */ + sourcemaps?: boolean; + /** + * Base url for the application being built. + */ + baseHref?: string; + /** + * The ssl key used by the server. + */ + progress?: boolean; + /** + * Enable and define the file watching poll time period (milliseconds). */ poll?: number; /** - * Use lint to fix files after generation - */ - lintFix?: boolean; - /** - * Options for generating a class. - */ - class?: { - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - }; - /** - * Options for generating a component. - */ - component?: { - /** - * Flag to indicate if a dir is created. - */ - flat?: boolean; - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - /** - * Specifies if the style will be in the ts file. - */ - inlineStyle?: boolean; - /** - * Specifies if the template will be in the ts file. - */ - inlineTemplate?: boolean; - /** - * Specifies the view encapsulation strategy. - */ - viewEncapsulation?: ('Emulated' | 'Native' | 'None'); - /** - * Specifies the change detection strategy. - */ - changeDetection?: ('Default' | 'OnPush'); - }; - /** - * Options for generating a directive. - */ - directive?: { - /** - * Flag to indicate if a dir is created. - */ - flat?: boolean; - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - }; - /** - * Options for generating a guard. - */ - guard?: { - /** - * Flag to indicate if a dir is created. - */ - flat?: boolean; - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - }; - /** - * Options for generating an interface. - */ - interface?: { - /** - * Prefix to apply to interface names. (i.e. I) - */ - prefix?: string; - }; - /** - * Options for generating a module. - */ - module?: { - /** - * Flag to indicate if a dir is created. - */ - flat?: boolean; - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - }; - /** - * Options for generating a pipe. - */ - pipe?: { - /** - * Flag to indicate if a dir is created. - */ - flat?: boolean; - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - }; - /** - * Options for generating a service. - */ - service?: { - /** - * Flag to indicate if a dir is created. - */ - flat?: boolean; - /** - * Specifies if a spec file is generated. - */ - spec?: boolean; - }; - /** - * Properties to be passed to the build command. - */ - build?: { - /** - * Output sourcemaps. - */ - sourcemaps?: boolean; - /** - * Base url for the application being built. - */ - baseHref?: string; - /** - * The ssl key used by the server. - */ - progress?: boolean; - /** - * Enable and define the file watching poll time period (milliseconds). - */ - poll?: number; - /** - * Delete output path before build. - */ - deleteOutputPath?: boolean; - /** - * Do not use the real path when resolving modules. - */ - preserveSymlinks?: boolean; - /** - * Show circular dependency warnings on builds. - */ - showCircularDependencies?: boolean; - /** - * Use a separate bundle containing code used across multiple bundles. - */ - commonChunk?: boolean; - /** - * Use file name for lazy loaded chunks. - */ - namedChunks?: boolean; - }; - /** - * Properties to be passed to the serve command. - */ - serve?: { - /** - * The port the application will be served on. - */ - port?: number; - /** - * The host the application will be served on. - */ - host?: string; - /** - * Enables ssl for the application. - */ - ssl?: boolean; - /** - * The ssl key used by the server. - */ - sslKey?: string; - /** - * The ssl certificate used by the server. - */ - sslCert?: string; - /** - * Proxy configuration file. - */ - proxyConfig?: string; - }; - /** - * Properties about schematics. - */ - schematics?: { - /** - * The schematics collection to use. - */ - collection?: string; - /** - * The new app schematic. - */ - newApp?: string; - }; - }; - /** - * Specify which package manager tool to use. - */ - packageManager?: ('npm' | 'cnpm' | 'yarn' | 'default'); - /** - * Allow people to disable console warnings. - */ - warnings?: { + * Delete output path before build. + */ + deleteOutputPath?: boolean; /** - * Show a warning when the user enabled the --hmr option. + * Do not use the real path when resolving modules. */ - hmrWarning?: boolean; + preserveSymlinks?: boolean; /** - * Show a warning when the node version is incompatible. + * Show circular dependency warnings on builds. */ - nodeDeprecation?: boolean; + showCircularDependencies?: boolean; /** - * Show a warning when the user installed angular-cli. + * Use a separate bundle containing code used across multiple bundles. */ - packageDeprecation?: boolean; + commonChunk?: boolean; /** - * Show a warning when the global version is newer than the local one. + * Use file name for lazy loaded chunks. */ - versionMismatch?: boolean; + namedChunks?: boolean; + }; + /** + * Properties to be passed to the serve command. + */ + serve?: { + /** + * The port the application will be served on. + */ + port?: number; + /** + * The host the application will be served on. + */ + host?: string; + /** + * Enables ssl for the application. + */ + ssl?: boolean; + /** + * The ssl key used by the server. + */ + sslKey?: string; /** - * Show a warning when the TypeScript version is incompatible + * The ssl certificate used by the server. */ - typescriptMismatch?: boolean; + sslCert?: string; + /** + * Proxy configuration file. + */ + proxyConfig?: string; + }; + /** + * Properties about schematics. + */ + schematics?: { + /** + * The schematics collection to use. + */ + collection?: string; + /** + * The new app schematic. + */ + newApp?: string; + }; + }; + /** + * Specify which package manager tool to use. + */ + packageManager?: 'npm' | 'cnpm' | 'yarn' | 'default'; + /** + * Allow people to disable console warnings. + */ + warnings?: { + /** + * Show a warning when the user enabled the --hmr option. + */ + hmrWarning?: boolean; + /** + * Show a warning when the node version is incompatible. + */ + nodeDeprecation?: boolean; + /** + * Show a warning when the user installed angular-cli. + */ + packageDeprecation?: boolean; + /** + * Show a warning when the global version is newer than the local one. + */ + versionMismatch?: boolean; + /** + * Show a warning when the TypeScript version is incompatible + */ + typescriptMismatch?: boolean; }; } export type WorkspaceSchema = experimental.workspace.WorkspaceSchema; export type WorkspaceProject = experimental.workspace.WorkspaceProject; - export function getWorkspacePath(host: Tree): string { - const possibleFiles = [ '/angular.json', '/.angular.json' ]; + const possibleFiles = ['/angular.json', '/.angular.json']; const path = possibleFiles.filter(path => host.exists(path))[0]; return path; @@ -497,16 +501,11 @@ export function getWorkspace(host: Tree): WorkspaceSchema { } const content = configBuffer.toString(); - return parseJson(content, JsonParseMode.Loose) as {} as WorkspaceSchema; + return (parseJson(content, JsonParseMode.Loose) as {}) as WorkspaceSchema; } -export function addProjectToWorkspace( - workspace: WorkspaceSchema, - name: string, - project: WorkspaceProject, -): Rule { +export function addProjectToWorkspace(workspace: WorkspaceSchema, name: string, project: WorkspaceProject): Rule { return (host: Tree) => { - if (workspace.projects[name]) { throw new Error(`Project '${name}' already exists in workspace.`); } @@ -531,7 +530,7 @@ export function getConfig(host: Tree): CliConfig { throw new SchematicsException('Could not find .angular-cli.json'); } - const config = parseJson(configBuffer.toString(), JsonParseMode.Loose) as {} as CliConfig; + const config = (parseJson(configBuffer.toString(), JsonParseMode.Loose) as {}) as CliConfig; return config; } @@ -545,5 +544,5 @@ export function getAppFromConfig(config: CliConfig, appIndexOrName: string): App return config.apps[parseInt(appIndexOrName)]; } - return config.apps.filter((app) => app.name === appIndexOrName)[0]; + return config.apps.filter(app => app.name === appIndexOrName)[0]; } diff --git a/src/angular/dependencies.ts b/src/angular/dependencies.ts index 92d8271..1a909bc 100755 --- a/src/angular/dependencies.ts +++ b/src/angular/dependencies.ts @@ -7,19 +7,14 @@ */ import { JsonAstObject, JsonParseMode, parseJsonAst } from '@angular-devkit/core'; import { SchematicsException, Tree } from '@angular-devkit/schematics'; -import { - appendPropertyInAstObject, - findPropertyInAstObject, - insertPropertyInAstObjectInOrder, - } from './json-utils'; - +import { appendPropertyInAstObject, findPropertyInAstObject, insertPropertyInAstObjectInOrder } from './json-utils'; const pkgJsonPath = '/package.json'; export enum NodeDependencyType { Default = 'dependencies', Dev = 'devDependencies', Peer = 'peerDependencies', - Optional = 'optionalDependencies', + Optional = 'optionalDependencies' } export interface NodeDependency { @@ -35,22 +30,22 @@ export function addPackageJsonDependency(tree: Tree, dependency: NodeDependency) const recorder = tree.beginUpdate(pkgJsonPath); if (!depsNode) { // Haven't found the dependencies key, add it to the root of the package.json. - appendPropertyInAstObject(recorder, packageJsonAst, dependency.type, { - [dependency.name]: dependency.version, - }, 2); + appendPropertyInAstObject( + recorder, + packageJsonAst, + dependency.type, + { + [dependency.name]: dependency.version + }, + 2 + ); } else if (depsNode.kind === 'object') { // check if package already added const depNode = findPropertyInAstObject(depsNode, dependency.name); if (!depNode) { // Package not found, add it. - insertPropertyInAstObjectInOrder( - recorder, - depsNode, - dependency.name, - dependency.version, - 4, - ); + insertPropertyInAstObjectInOrder(recorder, depsNode, dependency.name, dependency.version, 4); } else if (dependency.overwrite) { // Package found, update version if overwrite. const { end, start } = depNode; @@ -65,28 +60,25 @@ export function addPackageJsonDependency(tree: Tree, dependency: NodeDependency) export function getPackageJsonDependency(tree: Tree, name: string): NodeDependency | null { const packageJson = _readPackageJson(tree); let dep: NodeDependency | null = null; - [ - NodeDependencyType.Default, - NodeDependencyType.Dev, - NodeDependencyType.Optional, - NodeDependencyType.Peer, - ].forEach(depType => { - if (dep !== null) { - return; - } - const depsNode = findPropertyInAstObject(packageJson, depType); - if (depsNode !== null && depsNode.kind === 'object') { - const depNode = findPropertyInAstObject(depsNode, name); - if (depNode !== null && depNode.kind === 'string') { - const version = depNode.value; - dep = { - type: depType, - name: name, - version: version, - }; + [NodeDependencyType.Default, NodeDependencyType.Dev, NodeDependencyType.Optional, NodeDependencyType.Peer].forEach( + depType => { + if (dep !== null) { + return; + } + const depsNode = findPropertyInAstObject(packageJson, depType); + if (depsNode !== null && depsNode.kind === 'object') { + const depNode = findPropertyInAstObject(depsNode, name); + if (depNode !== null && depNode.kind === 'string') { + const version = depNode.value; + dep = { + type: depType, + name: name, + version: version + }; + } } } - }); + ); return dep; } diff --git a/src/angular/find-module.ts b/src/angular/find-module.ts index cf55bbd..aa32645 100755 --- a/src/angular/find-module.ts +++ b/src/angular/find-module.ts @@ -8,7 +8,6 @@ import { Path, join, normalize, relative, strings } from '@angular-devkit/core'; import { DirEntry, Tree } from '@angular-devkit/schematics'; - export interface ModuleOptions { module?: string; name: string; @@ -17,7 +16,6 @@ export interface ModuleOptions { skipImport?: boolean; } - /** * Find the module referred by a set of options passed to the schematics. */ @@ -27,14 +25,14 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path } if (!options.module) { - const pathToCheck = (options.path || '') - + (options.flat ? '' : '/' + strings.dasherize(options.name)); + const pathToCheck = (options.path || '') + (options.flat ? '' : '/' + strings.dasherize(options.name)); return normalize(findModule(host, pathToCheck)); } else { - const modulePath = normalize( - '/' + (options.path) + '/' + options.module); - const moduleBaseName = normalize(modulePath).split('/').pop(); + const modulePath = normalize('/' + options.path + '/' + options.module); + const moduleBaseName = normalize(modulePath) + .split('/') + .pop(); if (host.exists(modulePath)) { return normalize(modulePath); @@ -65,15 +63,16 @@ export function findModule(host: Tree, generateDir: string): Path { if (matches.length == 1) { return join(dir.path, matches[0]); } else if (matches.length > 1) { - throw new Error('More than one module matches. Use skip-import option to skip importing ' - + 'the component into the closest module.'); + throw new Error( + 'More than one module matches. Use skip-import option to skip importing ' + + 'the component into the closest module.' + ); } dir = dir.parent; } - throw new Error('Could not find an NgModule. Use the skip-import ' - + 'option to skip importing in NgModule.'); + throw new Error('Could not find an NgModule. Use the skip-import ' + 'option to skip importing in NgModule.'); } /** diff --git a/src/angular/index.ts b/src/angular/index.ts index f1fa8d9..bf1e8ff 100644 --- a/src/angular/index.ts +++ b/src/angular/index.ts @@ -8,4 +8,4 @@ export * from './latest-versions'; export * from './ng-ast-utils'; export * from './parse-name'; export * from './project'; -export * from './validation'; \ No newline at end of file +export * from './validation'; diff --git a/src/angular/json-utils.ts b/src/angular/json-utils.ts index 6a509ca..02e14bf 100755 --- a/src/angular/json-utils.ts +++ b/src/angular/json-utils.ts @@ -5,13 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import { - JsonAstArray, - JsonAstKeyValue, - JsonAstNode, - JsonAstObject, - JsonValue, -} from '@angular-devkit/core'; +import { JsonAstArray, JsonAstKeyValue, JsonAstNode, JsonAstObject, JsonValue } from '@angular-devkit/core'; import { UpdateRecorder } from '@angular-devkit/schematics'; export function appendPropertyInAstObject( @@ -19,7 +13,7 @@ export function appendPropertyInAstObject( node: JsonAstObject, propertyName: string, value: JsonValue, - indent: number, + indent: number ) { const indentStr = _buildIndent(indent); @@ -31,9 +25,7 @@ export function appendPropertyInAstObject( recorder.insertLeft( node.end.offset - 1, - ' ' - + `"${propertyName}": ${JSON.stringify(value, null, 2).replace(/\n/g, indentStr)}` - + indentStr.slice(0, -2), + ' ' + `"${propertyName}": ${JSON.stringify(value, null, 2).replace(/\n/g, indentStr)}` + indentStr.slice(0, -2) ); } @@ -42,9 +34,8 @@ export function insertPropertyInAstObjectInOrder( node: JsonAstObject, propertyName: string, value: JsonValue, - indent: number, + indent: number ) { - if (node.properties.length === 0) { appendPropertyInAstObject(recorder, node, propertyName, value, indent); @@ -78,25 +69,15 @@ export function insertPropertyInAstObjectInOrder( const indentStr = _buildIndent(indent); - const insertIndex = insertAfterProp === null - ? node.start.offset + 1 - : insertAfterProp.end.offset + 1; + const insertIndex = insertAfterProp === null ? node.start.offset + 1 : insertAfterProp.end.offset + 1; recorder.insertRight( insertIndex, - indentStr - + `"${propertyName}": ${JSON.stringify(value, null, 2).replace(/\n/g, indentStr)}` - + ',', + indentStr + `"${propertyName}": ${JSON.stringify(value, null, 2).replace(/\n/g, indentStr)}` + ',' ); } - -export function appendValueInAstArray( - recorder: UpdateRecorder, - node: JsonAstArray, - value: JsonValue, - indent = 4, -) { +export function appendValueInAstArray(recorder: UpdateRecorder, node: JsonAstArray, value: JsonValue, indent = 4) { const indentStr = _buildIndent(indent); if (node.elements.length > 0) { @@ -107,17 +88,11 @@ export function appendValueInAstArray( recorder.insertLeft( node.end.offset - 1, - ' ' - + JSON.stringify(value, null, 2).replace(/\n/g, indentStr) - + indentStr.slice(0, -2), + ' ' + JSON.stringify(value, null, 2).replace(/\n/g, indentStr) + indentStr.slice(0, -2) ); } - -export function findPropertyInAstObject( - node: JsonAstObject, - propertyName: string, -): JsonAstNode | null { +export function findPropertyInAstObject(node: JsonAstObject, propertyName: string): JsonAstNode | null { let maybeNode: JsonAstNode | null = null; for (const property of node.properties) { if (property.key.value == propertyName) { diff --git a/src/angular/latest-versions.ts b/src/angular/latest-versions.ts index 30c77d1..7cb14a0 100755 --- a/src/angular/latest-versions.ts +++ b/src/angular/latest-versions.ts @@ -14,5 +14,5 @@ export const latestVersions = { TypeScript: '~2.7.2', // The versions below must be manually updated when making a new devkit release. DevkitBuildAngular: '~0.7.0-beta.1', - DevkitBuildNgPackagr: '~0.7.0-beta.1', + DevkitBuildNgPackagr: '~0.7.0-beta.1' }; diff --git a/src/angular/ng-ast-utils.ts b/src/angular/ng-ast-utils.ts index 37aa512..ae6daaf 100755 --- a/src/angular/ng-ast-utils.ts +++ b/src/angular/ng-ast-utils.ts @@ -24,20 +24,23 @@ export function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallEx let bootstrapCall: ts.CallExpression | null = null; for (const node of allNodes) { - let bootstrapCallNode: ts.Node | null = null; bootstrapCallNode = findNode(node, ts.SyntaxKind.Identifier, 'bootstrapModule'); // Walk up the parent until CallExpression is found. - while (bootstrapCallNode && bootstrapCallNode.parent - && bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) { - + while ( + bootstrapCallNode && + bootstrapCallNode.parent && + bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression + ) { bootstrapCallNode = bootstrapCallNode.parent; } - if (bootstrapCallNode !== null && + if ( + bootstrapCallNode !== null && bootstrapCallNode.parent !== undefined && - bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression) { + bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression + ) { bootstrapCall = bootstrapCallNode.parent as ts.CallExpression; break; } @@ -67,7 +70,7 @@ export function findBootstrapModulePath(host: Tree, mainPath: string): string { return findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText()); }) .map((imp: ts.ImportDeclaration) => { - const modulePathStringLiteral = imp.moduleSpecifier; + const modulePathStringLiteral = imp.moduleSpecifier; return modulePathStringLiteral.text; })[0]; diff --git a/src/angular/parse-name.ts b/src/angular/parse-name.ts index e30c13d..f7ae311 100755 --- a/src/angular/parse-name.ts +++ b/src/angular/parse-name.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright Google Inc. All Rights Reserved. @@ -20,6 +19,6 @@ export function parseName(path: string, name: string): Location { return { name: nameWithoutPath, - path: normalize('/' + namePath), + path: normalize('/' + namePath) }; } diff --git a/src/angular/project.ts b/src/angular/project.ts index e67272c..78d41d8 100755 --- a/src/angular/project.ts +++ b/src/angular/project.ts @@ -7,15 +7,12 @@ */ import { WorkspaceProject } from './config'; - /** * Build a default project path for generating. * @param project The project to build the path for. */ export function buildDefaultPath(project: WorkspaceProject): string { - const root = project.sourceRoot - ? `/${project.sourceRoot}/` - : `/${project.root}/src/`; + const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`; const projectDirName = project.projectType === 'application' ? 'app' : 'lib'; diff --git a/src/angular/validation.ts b/src/angular/validation.ts index 1161483..f921469 100755 --- a/src/angular/validation.ts +++ b/src/angular/validation.ts @@ -26,7 +26,6 @@ export function validateHtmlSelector(selector: string): void { } } - export function validateProjectName(projectName: string) { const errorIndex = getRegExpFailPosition(projectName); const unsupportedProjectNames = ['test', 'ember', 'ember-cli', 'vendor', 'app']; @@ -44,8 +43,7 @@ export function validateProjectName(projectName: string) { `; throw new SchematicsException(msg); } else if (unsupportedProjectNames.indexOf(projectName) !== -1) { - throw new SchematicsException( - `Project name ${JSON.stringify(projectName)} is not a supported name.`); + throw new SchematicsException(`Project name ${JSON.stringify(projectName)} is not a supported name.`); } else if (!packageNameRegex.test(projectName)) { throw new SchematicsException(`Project name ${JSON.stringify(projectName)} is invalid.`); } @@ -73,5 +71,5 @@ function getRegExpFailPosition(str: string): number | null { const compare = matched.join('-'); - return (str !== compare) ? compare.length : null; + return str !== compare ? compare.length : null; } diff --git a/src/index.ts b/src/index.ts index 0d45dba..f805539 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ export * from './angular/index'; export * from './material/index'; -export * from './package_update/index'; \ No newline at end of file +export * from './package_update/index'; diff --git a/src/material/ast.ts b/src/material/ast.ts index 76c4078..093f751 100644 --- a/src/material/ast.ts +++ b/src/material/ast.ts @@ -33,8 +33,7 @@ export function addModuleImportToRootModule(host: Tree, moduleName: string, src: * @param moduleName name of module to import * @param src src location to import */ -export function addModuleImportToModule( - host: Tree, modulePath: string, moduleName: string, src: string) { +export function addModuleImportToModule(host: Tree, modulePath: string, moduleName: string, src: string) { const moduleSource = getSourceFile(host, modulePath); if (!moduleSource) { @@ -44,7 +43,7 @@ export function addModuleImportToModule( const changes = addImportToModule(moduleSource, modulePath, moduleName, src); const recorder = host.beginUpdate(modulePath); - changes.forEach((change) => { + changes.forEach(change => { if (change instanceof InsertChange) { recorder.insertLeft(change.pos, change.toAdd); } @@ -69,7 +68,7 @@ export function getStylesPath(host: Tree, project: Project): string { const buildTarget = project.architect['build']; if (buildTarget.options && buildTarget.options.styles && buildTarget.options.styles.length) { - const styles = buildTarget.options.styles.map(s => typeof s === 'string' ? s : s.input); + const styles = buildTarget.options.styles.map(s => (typeof s === 'string' ? s : s.input)); // First, see if any of the assets is called "styles.(le|sc|c)ss", which is the default // "main" style sheet. @@ -102,4 +101,4 @@ export function findModuleFromOptionsWithPathHandling(host: Tree, options: any) } return internalFindModule(host, options); -} \ No newline at end of file +} diff --git a/src/material/config.ts b/src/material/config.ts index f3af442..2f7363e 100644 --- a/src/material/config.ts +++ b/src/material/config.ts @@ -5,11 +5,10 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {SchematicsException, Tree} from '@angular-devkit/schematics'; +import { SchematicsException, Tree } from '@angular-devkit/schematics'; export const ANGULAR_CLI_WORKSPACE_PATH = '/angular.json'; - /** An Angular CLI Workspacer config (angular.json) */ export interface Workspace { /** Link to schema. */ @@ -91,7 +90,10 @@ export function getProjectFromWorkspace(config: Workspace, projectName?: string) throw new SchematicsException(`No project named "${projectName}" exists.`); } - Object.defineProperty(project, 'name', {enumerable: false, value: projectName}); + Object.defineProperty(project, 'name', { + enumerable: false, + value: projectName + }); return project; } @@ -102,7 +104,10 @@ export function getProjectFromWorkspace(config: Workspace, projectName?: string) const project = config.projects[allProjectNames[0]]; // Set a non-enumerable project name to the project. We need the name for schematics // later on, but don't want to write it back out to the config file. - Object.defineProperty(project, 'name', {enumerable: false, value: projectName}); + Object.defineProperty(project, 'name', { + enumerable: false, + value: projectName + }); return project; } else { throw new SchematicsException('Multiple projects are defined; please specify a project name'); @@ -110,4 +115,4 @@ export function getProjectFromWorkspace(config: Workspace, projectName?: string) } throw new SchematicsException('No projects are defined'); -} \ No newline at end of file +} diff --git a/src/material/html.ts b/src/material/html.ts index 29cf575..7828ec1 100644 --- a/src/material/html.ts +++ b/src/material/html.ts @@ -9,8 +9,9 @@ import { InsertChange } from '../angular'; * @param src the src path of the html file to parse */ export function getHeadTag(host: Tree, src: string) { - const document = parse5.parse(src, - { sourceCodeLocationInfo: true }) as parse5.AST.Default.Document; + const document = parse5.parse(src, { + sourceCodeLocationInfo: true + }) as parse5.AST.Default.Document; let head; const visit = (nodes: parse5.AST.Default.Node[]) => { @@ -59,4 +60,4 @@ export function addHeadLink(host: Tree, project: any, link: string) { recorder.insertLeft(insertion.pos, insertion.toAdd); host.commitUpdate(recorder); } -} \ No newline at end of file +} diff --git a/src/material/index.ts b/src/material/index.ts index 0b4f7b8..38016a4 100644 --- a/src/material/index.ts +++ b/src/material/index.ts @@ -1,4 +1,4 @@ export * from './ast'; export * from './config'; export * from './html'; -export * from './package'; \ No newline at end of file +export * from './package'; diff --git a/src/material/package.ts b/src/material/package.ts index 7e49027..5853a42 100644 --- a/src/material/package.ts +++ b/src/material/package.ts @@ -3,8 +3,7 @@ import { Tree } from '@angular-devkit/schematics'; /** * Adds a package to the package.json */ -export function addPackageToPackageJson( - host: Tree, type: string, pkg: string, version: string): Tree { +export function addPackageToPackageJson(host: Tree, type: string, pkg: string, version: string): Tree { if (host.exists('package.json')) { const sourceText = host.read('package.json')!.toString('utf-8'); const json = JSON.parse(sourceText); @@ -20,4 +19,4 @@ export function addPackageToPackageJson( } return host; -} \ No newline at end of file +} diff --git a/src/package_update/index.ts b/src/package_update/index.ts index d4074bc..96237e8 100644 --- a/src/package_update/index.ts +++ b/src/package_update/index.ts @@ -1 +1 @@ -export * from './npm'; \ No newline at end of file +export * from './npm'; diff --git a/src/package_update/npm.ts b/src/package_update/npm.ts index 6e00d21..7757f21 100755 --- a/src/package_update/npm.ts +++ b/src/package_update/npm.ts @@ -6,42 +6,23 @@ * found in the LICENSE file at https://angular.io/license */ import { JsonObject, JsonParseMode, logging, parseJson } from '@angular-devkit/core'; -import { - Rule, - SchematicContext, - SchematicsException, - Tree, - chain, -} from '@angular-devkit/schematics'; +import { Rule, SchematicContext, SchematicsException, Tree, chain } from '@angular-devkit/schematics'; import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; import * as https from 'https'; -import { - EMPTY, - Observable, - ReplaySubject, - concat, - from as observableFrom, - of as observableOf, -} from 'rxjs'; +import { EMPTY, Observable, ReplaySubject, concat, from as observableFrom, of as observableOf } from 'rxjs'; import { ignoreElements, map, mergeMap } from 'rxjs/operators'; import * as semver from 'semver'; const semverIntersect = require('semver-intersect'); -const kPackageJsonDependencyFields = [ - 'dependencies', - 'devDependencies', - 'peerDependencies', - 'optionalDependencies', -]; - +const kPackageJsonDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']; const npmPackageJsonCache = new Map>(); function _getVersionFromNpmPackage(json: JsonObject, version: string, loose: boolean): string { const distTags = json['dist-tags'] as JsonObject; if (distTags && distTags[version]) { - return (loose ? '~' : '') + distTags[version] as string; + return ((loose ? '~' : '') + distTags[version]) as string; } else { if (!semver.validRange(version)) { throw new SchematicsException(`Invalid range or version: "${version}".`); @@ -54,9 +35,7 @@ function _getVersionFromNpmPackage(json: JsonObject, version: string, loose: boo const maybeMatch = semver.maxSatisfying(packageVersions, version); if (!maybeMatch) { - throw new SchematicsException( - `Version "${version}" has no satisfying version for package ${json['name']}`, - ); + throw new SchematicsException(`Version "${version}" has no satisfying version for package ${json['name']}`); } const maybeOperator = version.match(/^[~^]/); @@ -77,10 +56,7 @@ function _getVersionFromNpmPackage(json: JsonObject, version: string, loose: boo * @returns {Observable} An observable that will put the pacakge.json content. * @private */ -function _getNpmPackageJson( - packageName: string, - logger: logging.LoggerApi, -): Observable { +function _getNpmPackageJson(packageName: string, logger: logging.LoggerApi): Observable { const url = `https://registry.npmjs.org/${packageName.replace(/\//g, '%2F')}`; logger.debug(`Getting package.json from ${JSON.stringify(packageName)}...`); @@ -90,7 +66,7 @@ function _getNpmPackageJson( const request = https.request(url, response => { let data = ''; - response.on('data', chunk => data += chunk); + response.on('data', chunk => (data += chunk)); response.on('end', () => { try { const json = parseJson(data, JsonParseMode.Strict); @@ -127,7 +103,7 @@ function _getRecursiveVersions( packages: { [name: string]: string }, allVersions: { [name: string]: string }, logger: logging.LoggerApi, - loose: boolean, + loose: boolean ): Observable { return observableFrom(kPackageJsonDependencyFields).pipe( mergeMap(field => { @@ -135,8 +111,8 @@ function _getRecursiveVersions( if (deps) { return observableFrom( Object.keys(deps) - .map(depName => depName in deps ? [depName, deps[depName]] : null) - .filter(x => !!x), + .map(depName => (depName in deps ? [depName, deps[depName]] : null)) + .filter(x => !!x) ); } else { return EMPTY; @@ -153,22 +129,26 @@ function _getRecursiveVersions( } return _getNpmPackageJson(depName, logger).pipe( - map(json => ({ version: packages[depName], depName, depVersion, npmPackageJson: json })), + map(json => ({ + version: packages[depName], + depName, + depVersion, + npmPackageJson: json + })) ); }), - mergeMap(({version, depName, depVersion, npmPackageJson}) => { + mergeMap(({ version, depName, depVersion, npmPackageJson }) => { const updateVersion = _getVersionFromNpmPackage(npmPackageJson, version, loose); const npmPackageVersions = Object.keys(npmPackageJson['versions'] as JsonObject); const match = semver.maxSatisfying(npmPackageVersions, updateVersion); if (!match) { return EMPTY; } - if (semver.lt( - semverIntersect.parseRange(updateVersion).version, - semverIntersect.parseRange(depVersion).version) + if ( + semver.lt(semverIntersect.parseRange(updateVersion).version, semverIntersect.parseRange(depVersion).version) ) { - throw new SchematicsException(`Cannot downgrade package ${ - JSON.stringify(depName)} from version "${depVersion}" to "${updateVersion}".`, + throw new SchematicsException( + `Cannot downgrade package ${JSON.stringify(depName)} from version "${depVersion}" to "${updateVersion}".` ); } @@ -187,9 +167,9 @@ function _getRecursiveVersions( if (allVersions[depName]) { if (!semver.intersects(allVersions[depName], updateVersion)) { throw new SchematicsException( - 'Cannot update safely because packages have conflicting dependencies. Package ' - + `${depName} would need to match both versions "${updateVersion}" and ` - + `"${allVersions[depName]}, which are not compatible.`, + 'Cannot update safely because packages have conflicting dependencies. Package ' + + `${depName} would need to match both versions "${updateVersion}" and ` + + `"${allVersions[depName]}, which are not compatible.` ); } @@ -198,14 +178,8 @@ function _getRecursiveVersions( allVersions[depName] = updateVersion; } - return _getRecursiveVersions( - packageJson, - dependencies, - allVersions, - logger, - loose, - ); - }), + return _getRecursiveVersions(packageJson, dependencies, allVersions, logger, loose); + }) ); } @@ -218,14 +192,10 @@ function _getRecursiveVersions( * @param loose Whether to use loose version operators (instead of specific versions). * @private */ -export function updatePackageJson( - supportedPackages: string[], - maybeVersion = 'latest', - loose = false, -): Rule { +export function updatePackageJson(supportedPackages: string[], maybeVersion = 'latest', loose = false): Rule { const version = maybeVersion ? maybeVersion : 'latest'; // This will be updated as we read the NPM repository. - const allVersions: { [name: string]: string} = {}; + const allVersions: { [name: string]: string } = {}; return chain([ (tree: Tree, context: SchematicContext): Observable => { @@ -243,10 +213,8 @@ export function updatePackageJson( } return concat( - _getRecursiveVersions(packageJson, packages, allVersions, context.logger, loose).pipe( - ignoreElements(), - ), - observableOf(tree), + _getRecursiveVersions(packageJson, packages, allVersions, context.logger, loose).pipe(ignoreElements()), + observableOf(tree) ); }, (tree: Tree) => { @@ -278,6 +246,6 @@ export function updatePackageJson( }, (_tree: Tree, context: SchematicContext) => { context.addTask(new NodePackageInstallTask()); - }, + } ]); } diff --git a/tsconfig.json b/tsconfig.json index 5feb672..16f3274 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,7 @@ "main": "index.js", "compilerOptions": { "baseUrl": "tsconfig", - "lib": [ - "es2017", - "dom" - ], + "lib": ["es2017", "dom"], "declaration": true, "module": "commonjs", "rootDir": "./src", @@ -15,15 +12,8 @@ "strictNullChecks": false, "skipLibCheck": true, "target": "es6", - "types": [ - "jasmine", - "node" - ] + "types": ["jasmine", "node"] }, - "include": [ - "src/**/*" - ], - "exclude": [ - "src/*/files/**/*" - ] + "include": ["src/**/*"], + "exclude": ["src/*/files/**/*"] }