├── .circleci └── config.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── after_prepare └── ionic-minify.ts ├── lib ├── IonicMinifyConfigurations.d.ts ├── ionicMinify.d.ts └── minifier.ts ├── minify-conf.json ├── package.json ├── scripts ├── install.ts └── uninstall.ts ├── tsconfig.json ├── typings.json └── typings └── shelljs └── shelljs.d.ts /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Javascript Node CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-javascript/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | # specify the version you desire here 10 | - image: circleci/node:7.10 11 | 12 | # Specify service dependencies here if necessary 13 | # CircleCI maintains a library of pre-built images 14 | # documented at https://circleci.com/docs/2.0/circleci-images/ 15 | # - image: circleci/mongo:3.4.4 16 | 17 | working_directory: ~/repo 18 | 19 | steps: 20 | - checkout 21 | 22 | # Download and cache dependencies 23 | - restore_cache: 24 | keys: 25 | - v1-dependencies-{{ checksum "package.json" }} 26 | # fallback to using the latest cache if no exact match is found 27 | - v1-dependencies- 28 | 29 | - run: yarn install 30 | 31 | - save_cache: 32 | paths: 33 | - node_modules 34 | key: v1-dependencies-{{ checksum "package.json" }} 35 | 36 | # run tests! 37 | - run: npm run prepublish 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | typings/* 3 | !typings/shelljs/ 4 | *.js -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | typings/ 3 | tsd.json 4 | tsconfig.json 5 | *.ts -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Luis Rogelio Hernández López 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ionic-minify 2 | [![npm version](https://badge.fury.io/js/ionic-minify.svg)](http://badge.fury.io/js/ionic-minify) 3 | 4 | #### Ionic-minify is a derived work of [Ross Martin's original cordova-uglify](https://github.com/rossmartin/cordova-uglify). 5 | 6 | # Important note 7 | 8 | The use of the `--release` flag is deprecated, use `--minify` instead. 9 | 10 | ## Changelog 11 | [Here](https://github.com/Kurtz1993/ionic-minify/releases) you can find the changelog. 12 | 13 | ionic-minify is a Cordova hook that minifes Javascript and CSS files, and it compress JPG and PNG images from your Cordova/Phonegap, Ionic or other Hybrid Cordova-based project. 14 | 15 | ## Install 16 | Just run the following command inside your project's root folder: 17 | ``` 18 | npm install ionic-minify --save-dev 19 | ``` 20 | 21 | ## Installation Quirks 22 | Sometimes on UNIX systems, installation can result in an error due to permisions and ownership of the files and folders. 23 | 24 | When installing on UNIX systems please make sure that the ownership of the files and folders of your project is your user and to run the comand using `sudo`. 25 | 26 | ## Usage 27 | Just run `ionic prepare ` or `ionic build ` with the `--minify` flag or set the `alwaysRun` attribute inside the configuration file to true. 28 | 29 | ## Configuration 30 | You can find this file inside your hooks/ folder with the name minify-conf.json 31 | 32 | 33 | ```javascript 34 | { 35 | // Folders that are going to be processed. 36 | "foldersToProcess": [ 37 | "js", 38 | "css", 39 | "img" 40 | ], 41 | "jpgOptions":{ 42 | "quality": 50 43 | }, 44 | "jsOptions": { 45 | "compress": { 46 | "drop_console": true 47 | } 48 | }, 49 | "cssOptions": { 50 | "keepSpecialComments": 0 51 | }, 52 | "alwaysRun": false, // Set to true if you want the hook to always run. 53 | "showErrStack": false // Set to true to show the error stack when a file fails to minify/compress. 54 | } 55 | ``` 56 | You can find valid UglifyJS options for Ionic Minify [here.](https://github.com/Kurtz1993/ionic-minify/blob/master/lib/IonicMinifyConfigurations.d.ts#L92) 57 | 58 | You can find valid CleanCSS options for Ionic Minify [here.](https://github.com/Kurtz1993/ionic-minify/blob/master/lib/IonicMinifyConfigurations.d.ts#L105) 59 | 60 | ## License 61 | #### MIT 62 | The MIT License (MIT) 63 | 64 | 65 | Copyright (c) 2015 Luis Rogelio Hernández López 66 | 67 | 68 | Permission is hereby granted, free of charge, to any person obtaining a copy 69 | of this software and associated documentation files (the "Software"), to deal 70 | in the Software without restriction, including without limitation the rights 71 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 72 | copies of the Software, and to permit persons to whom the Software is 73 | furnished to do so, subject to the following conditions: 74 | 75 | 76 | The above copyright notice and this permission notice shall be included in all 77 | copies or substantial portions of the Software. 78 | 79 | 80 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 81 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 82 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 83 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 84 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 85 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 86 | SOFTWARE. -------------------------------------------------------------------------------- /after_prepare/ionic-minify.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import * as path from "path"; 4 | import {Minifier} from "ionic-minify"; 5 | 6 | let config: IMConfig = require("../minify-conf.json"); 7 | let minify: boolean = config.alwaysRun; 8 | let cmd: string = process.env.CORDOVA_CMDLINE; 9 | let rootDir: string = process.argv[2]; 10 | let platforms: string[] = process.env.CORDOVA_PLATFORMS.split(','); 11 | let platformPath: string= path.join(rootDir, "platforms"); 12 | 13 | if(cmd.indexOf("--release") > -1 || cmd.indexOf("--minify") > -1) { 14 | if(cmd.indexOf("--release") > -1) { 15 | console.log("WARN: The use of the --release flag is deprecated!! Use --minify instead!"); 16 | } 17 | minify = true; 18 | } 19 | 20 | config.showErrStack = (config.showErrStack || false); 21 | config.jsOptions.fromString = true; 22 | 23 | if (minify === true) { 24 | let ionicMinify: Minifier = new Minifier(config, platforms, platformPath); 25 | console.log("Starting minifying your files..."); 26 | ionicMinify.run(); 27 | } -------------------------------------------------------------------------------- /lib/IonicMinifyConfigurations.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IMConfig{ 2 | /** 3 | * An array that contains the names of the folders to compress. 4 | */ 5 | foldersToProcess: string[], 6 | /** 7 | * Specify the output quality of the jpg compressed image. 8 | */ 9 | jpgOptions: {quality: number}, 10 | /** 11 | * Specify the options of UglifyJS. 12 | */ 13 | jsOptions: UJSConfig, 14 | /** 15 | * Specify the options of CleanCSS. 16 | */ 17 | cssOptions: CleanCSSConfig, 18 | /** 19 | * If true, the hook will always run. 20 | */ 21 | alwaysRun: boolean, 22 | /** 23 | * If true, will show the error stack if errors occur. 24 | */ 25 | showErrStack: boolean 26 | } 27 | 28 | declare interface UJSCompressorOptions { 29 | /** 30 | * Join consecutive simple statements using the comma operator. 31 | */ 32 | sequences?: boolean, 33 | /** 34 | * Rewrite property access using the dot notation. 35 | */ 36 | properties?: boolean, 37 | /** 38 | * Remove unreachable code. 39 | */ 40 | dead_code?: boolean, 41 | /** 42 | * Remove debugger; statements. 43 | */ 44 | drop_debugger?: boolean, 45 | /** 46 | * Apply optimizations for if's and conditional expressions. 47 | */ 48 | conditionals?: boolean, 49 | /** 50 | * Attempt to evaluate constant expressions. 51 | */ 52 | evaluate?: boolean, 53 | /** 54 | * Various optimizations for boolean context. 55 | */ 56 | booleans?: boolean, 57 | /** 58 | * Optimizations for do, while and for loops when we can statically determine the condition. 59 | */ 60 | loops?: boolean, 61 | /** 62 | * Drop unreferenced functions and variables. 63 | */ 64 | unused?: boolean, 65 | /** 66 | * Hoist function declarations. 67 | */ 68 | hoist_funs?: boolean, 69 | /** 70 | * Optimizations for if/return and if/continue. 71 | */ 72 | if_return?: boolean, 73 | /** 74 | * Join consecutive var statements. 75 | */ 76 | join_vars?: boolean, 77 | /** 78 | * Small optimization for sequences. 79 | */ 80 | cascade?: boolean, 81 | /** 82 | * Negate Immediately-Invoked Function Expressions where the return value is 83 | * discarded, to avoid the parens that the code generator would insert. 84 | */ 85 | negate_iife?: boolean, 86 | /** 87 | * Discard calls to console.* functions. 88 | */ 89 | drop_console?: boolean 90 | } 91 | 92 | declare interface UJSConfig { 93 | /** 94 | * As default behaviour of Ionic Minify, this property will always be true. 95 | */ 96 | fromString: boolean, 97 | /** 98 | * Display compressor warnings. 99 | * @default false 100 | */ 101 | warnings?: string, 102 | /** 103 | * UglifyJS custom compressor options. 104 | * @default {} 105 | */ 106 | compress?: UJSCompressorOptions 107 | } 108 | 109 | declare interface CleanCSSConfig { 110 | /** 111 | * Enable advanced optimizations. 112 | * @default true 113 | */ 114 | advanced?: boolean, 115 | /** 116 | * Enable aggressive merging of properties. 117 | * @default true 118 | */ 119 | aggressiveMerging?: boolean, 120 | /** 121 | * Keep line breaks. 122 | * @default false| 123 | */ 124 | keepBreaks?: boolean, 125 | /** 126 | * Use '*' to keep all, 1 to keep first one only and 0 to remove all. 127 | * @default '*' 128 | */ 129 | keepSpecialComments?: any, 130 | /** 131 | * Merge @media-at rules. 132 | * @default true 133 | */ 134 | mediaMerging?: boolean, 135 | /** 136 | * Process @import rules. 137 | */ 138 | processImport?: boolean, 139 | /** 140 | * Rebase URL. 141 | * @default true 142 | */ 143 | rebase?: boolean, 144 | /** 145 | * Path to resolve relative @import rules and URLs. 146 | */ 147 | relativeTo?: string, 148 | /** 149 | * Enable restructuring in advanced optimizations. 150 | */ 151 | restructuring?: boolean, 152 | /** 153 | * Path to resolve absolute @import rules and URLs. 154 | */ 155 | root?: string, 156 | /** 157 | * Rounding precission. You can disable it by passing -1. 158 | * @default 2 159 | */ 160 | roundingPrecision?: number, 161 | /** 162 | * Enable shorthand compacting. 163 | * @default true 164 | */ 165 | shorthandCompacting?: boolean 166 | } -------------------------------------------------------------------------------- /lib/ionicMinify.d.ts: -------------------------------------------------------------------------------- 1 | declare module "ionic-minify"{ 2 | export class Minifier { 3 | /** 4 | * Creates a new ionicMinify compressor. 5 | * @param {HookConf} hookConf - Ionic Minify configuration object. 6 | * @param {String[]} platforms - An array of the platforms to compress. 7 | * @param {String} basePath - The platforms base path. 8 | */ 9 | constructor(hookConf: IMConfig, platforms: string[], basePath: string); 10 | /** 11 | * Runs the compressor to minify files. 12 | */ 13 | public run(): void; 14 | } 15 | } -------------------------------------------------------------------------------- /lib/minifier.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs"; 2 | import * as path from "path"; 3 | import {execFile} from "child_process"; 4 | let ngAnnotate: any = require("ng-annotate"); 5 | let UglifyJS: any = require("uglify-js"); 6 | let CleanCss: any = require("clean-css"); 7 | let mozjpeg: any = require("mozjpeg-stream"); 8 | let optipng: string = require("pngout-bin").path; 9 | 10 | export class Minifier { 11 | private config: IMConfig; 12 | private platforms: string[]; 13 | private basePath: string; 14 | private platformPaths: string[] = []; 15 | private cssMinifer: any; 16 | 17 | /** 18 | * Creates a new ionicMinify compressor. 19 | * @param {HookConf} hookConf - Ionic Minify configuration object. 20 | * @param {String[]} platforms - An array of the platforms to compress. 21 | * @param {String} basePath - The platforms base path. 22 | */ 23 | public constructor(hookConf: IMConfig, platforms: string[], basePath: string) { 24 | this.config = hookConf; 25 | this.platforms = platforms; 26 | this.basePath = basePath; 27 | this.cssMinifer = new CleanCss(this.config.cssOptions); 28 | this.setPlatformPaths(); 29 | } 30 | 31 | /** 32 | * Checks whether a path starts with or contains a hidden file or a folder. 33 | * @param {string} source - The path of the file that needs to be validated. 34 | * returns {boolean} - `true` if the source is blacklisted and otherwise `false`. 35 | * Note: code is from http://stackoverflow.com/questions/8905680/nodejs-check-for-hidden-files/ 36 | */ 37 | private isHiddenFile(source: string): boolean { 38 | return (/(^|\/)\.[^\/\.]/g).test(source); 39 | } 40 | 41 | /** 42 | * Runs the compressor to minify files. 43 | */ 44 | public run(): void { 45 | this.platformPaths.forEach((platform) => { 46 | this.config.foldersToProcess.forEach((folder) => { 47 | this.processFiles(path.join(platform, folder)); 48 | }); 49 | }); 50 | } 51 | 52 | /** 53 | * Set the paths for all the platforms that are going to be minified. 54 | */ 55 | private setPlatformPaths(): void { 56 | this.platforms.forEach((platform) => { 57 | switch (platform) { 58 | case "android": 59 | this.platformPaths.push(path.join(this.basePath, platform, "assets", "www")); 60 | break; 61 | case "ios": 62 | case "wp8": 63 | case "browser": 64 | this.platformPaths.push(path.join(this.basePath, platform, "www")); 65 | break; 66 | default: 67 | console.log("Ionic minify supports Android, iOS, Windows Phone 8 and Browser only."); 68 | break; 69 | } 70 | }); 71 | } 72 | 73 | /** 74 | * Process all the files in a directory. 75 | * @param {string} dir - The directory that conttains the files to be processed. 76 | */ 77 | private processFiles(dir: string): void { 78 | fs.readdir(dir, (error, list) => { 79 | if (error) { 80 | console.log(`An error ocurred while reading directories: \n ${error}`); 81 | return; 82 | } else { 83 | list.forEach((file) => { 84 | file = path.join(dir, file); 85 | fs.stat(file, (err, stat) => { 86 | if (stat.isDirectory()){ 87 | this.processFiles(file); 88 | } else { 89 | if(this.isHiddenFile(file)){ 90 | console.log(`Not processing hidden file: ${file}`); 91 | } else { 92 | this.compress(file); 93 | } 94 | } 95 | }); 96 | }); 97 | } 98 | }); 99 | } 100 | 101 | /** 102 | * Compress the specified file. 103 | * @param {string} file - The file path. 104 | */ 105 | private compress (file: string): void { 106 | let extension: string = path.extname(file); 107 | let fileName: string = path.basename(file); 108 | 109 | if (fileName.indexOf(".min.") > -1){ 110 | extension = `.min${extension}`; 111 | } 112 | 113 | try { 114 | let ext = extension.split('.')[1].toUpperCase(); 115 | console.log(`Compressing ${ext} file: ${fileName}`); 116 | switch (extension){ 117 | case ".js": 118 | this.compressJS(file, fileName); 119 | break; 120 | case ".css": 121 | this.compressCSS(file, fileName); 122 | break; 123 | case ".jpg": 124 | case ".jpeg": 125 | this.compressJPG(file, fileName); 126 | break; 127 | case ".png": 128 | this.compressPNG(file, fileName); 129 | break; 130 | default: 131 | break; 132 | } 133 | } 134 | catch(err) { 135 | console.log(`Compressing/Minifying ${fileName} resulted in an error and won't be compressed/minified.`); 136 | if (this.config.showErrStack) { 137 | console.log(err.stack); 138 | } 139 | } 140 | } 141 | 142 | /** 143 | * Compress a JavaScript file. 144 | * @param {String} file - The path of the file to compress. 145 | * @param {String} fileName - The name of the file. 146 | */ 147 | private compressJS(file: string, fileName: string): void { 148 | let src: string = fs.readFileSync(file, "utf8"); 149 | let ngSafeFile: any = ngAnnotate(src, {add: true}); 150 | let result: any = UglifyJS.minify(ngSafeFile.src, this.config.jsOptions); 151 | fs.writeFileSync(file, result.code, "utf8"); 152 | console.log(`JS file: ${fileName} has been minified!`); 153 | } 154 | 155 | /** 156 | * Compress a CSS file. 157 | * @param {String} file - The path of the file to compress. 158 | * @param {String} fileName - The name of the file. 159 | */ 160 | private compressCSS(file: string, fileName: string): void { 161 | let src: string = fs.readFileSync(file, "utf8"); 162 | let css: any = this.cssMinifer.minify(src); 163 | css = (css.styles) ? css.styles : css; 164 | fs.writeFileSync(file, css, "utf8"); 165 | console.log(`CSS file: ${fileName} has been minified!`); 166 | } 167 | 168 | /** 169 | * Compress a JPG image. 170 | * @param {String} file - The path of the file to compress. 171 | * @param {String} fileName - The name of the file. 172 | */ 173 | private compressJPG(file: string, fileName: string): void { 174 | let ws: fs.WriteStream; 175 | fs.createReadStream(file) 176 | .pipe(mozjpeg(this.config.jpgOptions)) 177 | .pipe(ws = fs.createWriteStream(`${file}.jpg`)); 178 | 179 | ws.on("error", (err: any) => { 180 | console.log(`Compressing ${fileName} resulted in an error and won't be compressed.`); 181 | }); 182 | 183 | ws.on("finish", () => { 184 | fs.unlinkSync(file); 185 | fs.renameSync(`${file}.jpg`, file); 186 | console.log(`JPG image: ${fileName} has been compressed!`); 187 | }); 188 | } 189 | 190 | /** 191 | * Compress a PNG image. 192 | * @param {String} file - The path of the file to compress. 193 | * @param {String} fileName - The name of the file. 194 | */ 195 | private compressPNG(file: string, fileName: string): void { 196 | execFile(optipng, [file, `${file}.png`, "-s0", "-k0", "-f0"], (err) => { 197 | if (err) { 198 | console.log(`Compressing ${fileName} resulted in an error and won't be compressed.`); 199 | if(this.config.showErrStack) { 200 | console.log(`An error has ocurred: ${err}`); 201 | } 202 | } else { 203 | fs.unlinkSync(file); 204 | fs.renameSync(`${file}.png`, file); 205 | console.log(`PNG image: ${fileName} has been compressed!`); 206 | } 207 | }); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /minify-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "foldersToProcess": [ 3 | "js", 4 | "css", 5 | "img" 6 | ], 7 | "jpgOptions":{ 8 | "quality": 50 9 | }, 10 | "jsOptions": { 11 | "compress": { 12 | "drop_console": true 13 | } 14 | }, 15 | "cssOptions": { 16 | "keepSpecialComments": 0 17 | }, 18 | "alwaysRun": false, 19 | "showErrStack": false 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-minify", 3 | "version": "2.0.10", 4 | "description": "Cordova hook that minifies your JavaScript and CSS files, and compresses your JPG and PNG images.", 5 | "homepage": "https://github.com/Kurtz1993/ionic-minify", 6 | "engines": { 7 | "node": ">=0.10.36" 8 | }, 9 | "main": "lib/minifier.js", 10 | "keywords": [ 11 | "cordova", 12 | "uglify", 13 | "minify", 14 | "hook", 15 | "hooks", 16 | "compress", 17 | "ionic-minify", 18 | "ionic", 19 | "phonegap" 20 | ], 21 | "dependencies": { 22 | "chalk": "^1.1.1", 23 | "clean-css": "3.4.8", 24 | "mozjpeg-stream": "1.0.2", 25 | "ng-annotate": "0.15.4", 26 | "pngout-bin": "2.0.1", 27 | "shelljs": "0.5.3", 28 | "uglify-js": "2.6.1" 29 | }, 30 | "author": "Luis Rogelio Hernández López", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/Kurtz1993/ionic-minify/issues" 34 | }, 35 | "readmeFilename": "README.md", 36 | "repository": { 37 | "type": "git", 38 | "url": "https://github.com/Kurtz1993/ionic-minify.git" 39 | }, 40 | "scripts": { 41 | "prepublish": "tsc", 42 | "postinstall": "node scripts/install.js", 43 | "postuninstall": "node scripts/uninstall.js" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /scripts/install.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import * as fs from "fs"; 4 | import * as path from "path"; 5 | import * as chalk from "chalk"; 6 | import * as shell from "shelljs"; 7 | 8 | let packageDependencies: string[] = require("../package.json").dependencies; 9 | let cwd: string = process.cwd(); 10 | let scriptPath: string = __dirname; 11 | let paths: string[] = [path.join(cwd, "..", "..", "hooks"), path.join(cwd, "..", "..", "hooks", "after_prepare")]; 12 | let dependencies: string[] = []; 13 | let stat: fs.Stats = null; 14 | 15 | // Detect dependencies. 16 | for (let dependency in packageDependencies) { 17 | dependencies.push(dependency); 18 | } 19 | 20 | // If paths do not exist, make them. 21 | paths.forEach((folder) => { 22 | try { 23 | stat = fs.statSync(folder); 24 | } catch (err) { 25 | if (err.code === "ENOENT") { 26 | console.log(chalk.yellow.bold(`Creating directory: ${folder}`)); 27 | fs.mkdirSync(folder); 28 | } 29 | } 30 | }); 31 | 32 | // Absolute location for ionic-minify.js and configuration files. 33 | let minifyFilePath: string = path.join(cwd, "after_prepare", "ionic-minify.js"); 34 | let configFilePath: string = path.join(cwd, "minify-conf.json"); 35 | 36 | // Copy ionic-minify file to hooks folder. 37 | let minifyFile: string = fs.readFileSync(minifyFilePath, "utf8"); 38 | let configFile: string = fs.readFileSync(configFilePath, "utf8"); 39 | let minifyFileNewPath: string = path.join(paths[1], "ionic-minify.js"); 40 | let configFileNewPath: string = path.join(paths[0], "minify-conf.json"); 41 | 42 | console.log(chalk.cyan("Copying minifier file to project's hooks/after_prepare...")); 43 | fs.writeFileSync(minifyFileNewPath, minifyFile); 44 | 45 | // Create configuration file only if it doesn't exist 46 | try{ 47 | stat = fs.statSync(configFileNewPath); 48 | console.log(chalk.yellow("You already have a minify-conf.json file...")); 49 | } 50 | catch(err){ 51 | if(err.code === "ENOENT"){ 52 | console.log(chalk.cyan("Copying configuration file to project's hooks/ folder...")); 53 | fs.writeFileSync(configFileNewPath, configFile); 54 | } 55 | } 56 | 57 | console.log(chalk.cyan("Updating hooks directory to have execution permissions...")); 58 | shell.chmod("-R", 755, paths[0]); 59 | 60 | // Move dependencies to the parent node_modules folder. 61 | dependencies.forEach((dependency) => { 62 | // Moves dependencies to node_modules folder. 63 | try { 64 | stat = fs.statSync(path.join(cwd, "..", dependency)); 65 | console.log(chalk.yellow(`It appears that you have already installed ${dependency}...`)); 66 | } catch (err) { 67 | if ((dependency !== "chalk" && dependency !== "shelljs") && err.code === "ENOENT") { 68 | console.log(chalk.blue(`Copying ${dependency} to your node_modules/ folder...`)); 69 | fs.renameSync(path.join(cwd, "node_modules", dependency), path.join(cwd, "..", dependency)); 70 | } 71 | } 72 | }); 73 | console.log(chalk.green.bold("Ionic minify has been installed successfully! :)")); 74 | -------------------------------------------------------------------------------- /scripts/uninstall.ts: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | // Modules 4 | import * as fs from "fs"; 5 | import * as path from "path"; 6 | import * as readline from "readline"; 7 | import * as chalk from "chalk"; 8 | 9 | let rl = readline.createInterface({ 10 | input: process.stdin, 11 | output: process.stdout 12 | }); 13 | // Directories 14 | let cwd: string = process.cwd(); 15 | let minifyJsPath: string = path.join(cwd, "..", "..", "hooks", "after_prepare", "ionic-minify.js"); 16 | let configFilePath: string = path.join(cwd, "..", "..", "hooks", "minify-conf.json"); 17 | 18 | // Delete ionic-minify.js 19 | fs.unlink(minifyJsPath, (error) => { 20 | if (error === undefined) { 21 | console.log(chalk.red(`Cannot find hook to remove at ${minifyJsPath}. It may already have been removed!`)); 22 | } 23 | }); 24 | 25 | // Delete minify-conf.json 26 | 27 | rl.question("Do you want to keep your configuration file (Y/N)?[Y] ", (answer: string) => { 28 | if(answer.toUpperCase() === "N"){ 29 | fs.unlinkSync(configFilePath); 30 | console.log(chalk.red("Configuration file was deleted...")); 31 | } 32 | console.log(chalk.green("ionic-minify was uninstalled successfuly!")); 33 | process.exit(0); 34 | }); 35 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "removeComments": true, 6 | "noImplicitAny": true, 7 | "listFiles": true, 8 | "newLine": "LF" 9 | } 10 | } -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "globalDependencies": { 3 | "chalk": "registry:dt/chalk#0.4.0+20160317120654", 4 | "node": "registry:dt/node#6.0.0+20160928143418" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /typings/shelljs/shelljs.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for ShellJS v0.3.0 2 | // Project: http://shelljs.org 3 | // Definitions by: Niklas Mollenhauer 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | 7 | /// 8 | 9 | declare module "shelljs" 10 | { 11 | import child = require("child_process"); 12 | 13 | /** 14 | * Changes to directory dir for the duration of the script 15 | * @param {string} dir Directory to change in. 16 | */ 17 | export function cd(dir: string): void; 18 | 19 | /** 20 | * Returns the current directory. 21 | * @return {string} The current directory. 22 | */ 23 | export function pwd(): string; 24 | 25 | /** 26 | * Returns array of files in the given path, or in current directory if no path provided. 27 | * @param {string[]} ...paths Paths to search. 28 | * @return {string[]} An array of files in the given path(s). 29 | */ 30 | export function ls(...paths: string[]): string[]; 31 | 32 | /** 33 | * Returns array of files in the given path, or in current directory if no path provided. 34 | * @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..) 35 | * @param {string[]} ...paths Paths to search. 36 | * @return {string[]} An array of files in the given path(s). 37 | */ 38 | export function ls(options: string, ...paths: string[]): string[]; 39 | 40 | /** 41 | * Returns array of files in the given path, or in current directory if no path provided. 42 | * @param {string[]} paths Paths to search. 43 | * @return {string[]} An array of files in the given path(s). 44 | */ 45 | export function ls(paths: string[]): string[]; 46 | 47 | /** 48 | * Returns array of files in the given path, or in current directory if no path provided. 49 | * @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..) 50 | * @param {string[]} paths Paths to search. 51 | * @return {string[]} An array of files in the given path(s). 52 | */ 53 | export function ls(options: string, paths: string[]): string[]; 54 | 55 | /** 56 | * Returns array of all files (however deep) in the given paths. 57 | * @param {string[]} ...path The path(s) to search. 58 | * @return {string[]} An array of all files (however deep) in the given path(s). 59 | */ 60 | export function find(...path: string[]): string[]; 61 | 62 | /** 63 | * Returns array of all files (however deep) in the given paths. 64 | * @param {string[]} path The path(s) to search. 65 | * @return {string[]} An array of all files (however deep) in the given path(s). 66 | */ 67 | export function find(path: string[]): string[]; 68 | 69 | /** 70 | * Copies files. The wildcard * is accepted. 71 | * @param {string} source The source. 72 | * @param {string} dest The destination. 73 | */ 74 | export function cp(source: string, dest: string): void; 75 | 76 | /** 77 | * Copies files. The wildcard * is accepted. 78 | * @param {string[]} source The source. 79 | * @param {string} dest The destination. 80 | */ 81 | export function cp(source: string[], dest: string): void; 82 | 83 | /** 84 | * Copies files. The wildcard * is accepted. 85 | * @param {string} options Available options: -f (force), -r, -R (recursive) 86 | * @param {strin]} source The source. 87 | * @param {string} dest The destination. 88 | */ 89 | export function cp(options: string, source: string, dest: string): void; 90 | 91 | /** 92 | * Copies files. The wildcard * is accepted. 93 | * @param {string} options Available options: -f (force), -r, -R (recursive) 94 | * @param {string[]} source The source. 95 | * @param {string} dest The destination. 96 | */ 97 | export function cp(options: string, source: string[], dest: string): void; 98 | 99 | /** 100 | * Removes files. The wildcard * is accepted. 101 | * @param {string[]} ...files Files to remove. 102 | */ 103 | export function rm(...files: string[]): void; 104 | 105 | /** 106 | * Removes files. The wildcard * is accepted. 107 | * @param {string[]} files Files to remove. 108 | */ 109 | export function rm(files: string[]): void; 110 | 111 | /** 112 | * Removes files. The wildcard * is accepted. 113 | * @param {string} options Available options: -f (force), -r, -R (recursive) 114 | * @param {string[]} ...files Files to remove. 115 | */ 116 | export function rm(options: string, ...files: string[]): void; 117 | 118 | /** 119 | * Removes files. The wildcard * is accepted. 120 | * @param {string} options Available options: -f (force), -r, -R (recursive) 121 | * @param {string[]} ...files Files to remove. 122 | */ 123 | export function rm(options: string, files: string[]): void; 124 | 125 | /** 126 | * Moves files. The wildcard * is accepted. 127 | * @param {string} source The source. 128 | * @param {string} dest The destination. 129 | */ 130 | export function mv(source: string, dest: string): void; 131 | 132 | /** 133 | * Moves files. The wildcard * is accepted. 134 | * @param {string[]} source The source. 135 | * @param {string} dest The destination. 136 | */ 137 | export function mv(source: string[], dest: string): void; 138 | 139 | /** 140 | * Creates directories. 141 | * @param {string[]} ...dir Directories to create. 142 | */ 143 | export function mkdir(...dir: string[]): void; 144 | 145 | /** 146 | * Creates directories. 147 | * @param {string[]} dir Directories to create. 148 | */ 149 | export function mkdir(dir: string[]): void; 150 | 151 | /** 152 | * Creates directories. 153 | * @param {string} options Available options: p (full paths, will create intermediate dirs if necessary) 154 | * @param {string[]} ...dir The directories to create. 155 | */ 156 | export function mkdir(options: string, ...dir: string[]): void; 157 | 158 | /** 159 | * Creates directories. 160 | * @param {string} options Available options: p (full paths, will create intermediate dirs if necessary) 161 | * @param {string[]} dir The directories to create. 162 | */ 163 | export function mkdir(options: string, dir: string[]): void; 164 | 165 | /** 166 | * Evaluates expression using the available primaries and returns corresponding value. 167 | * @param {string} option '-b': true if path is a block device; '-c': true if path is a character device; '-d': true if path is a directory; '-e': true if path exists; '-f': true if path is a regular file; '-L': true if path is a symboilc link; '-p': true if path is a pipe (FIFO); '-S': true if path is a socket 168 | * @param {string} path The path. 169 | * @return {boolean} See option parameter. 170 | */ 171 | export function test(option: string, path: string): boolean; 172 | 173 | /** 174 | * Returns a string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). Wildcard * accepted. 175 | * @param {string[]} ...files Files to use. 176 | * @return {string} A string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). 177 | */ 178 | export function cat(...files: string[]): string; 179 | 180 | /** 181 | * Returns a string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). Wildcard * accepted. 182 | * @param {string[]} files Files to use. 183 | * @return {string} A string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). 184 | */ 185 | export function cat(files: string[]): string; 186 | 187 | 188 | // Does not work yet. 189 | export interface String 190 | { 191 | /** 192 | * Analogous to the redirection operator > in Unix, but works with JavaScript strings (such as those returned by cat, grep, etc). Like Unix redirections, to() will overwrite any existing file! 193 | * @param {string} file The file to use. 194 | */ 195 | to(file: string): void; 196 | 197 | /** 198 | * Analogous to the redirect-and-append operator >> in Unix, but works with JavaScript strings (such as those returned by cat, grep, etc). 199 | * @param {string} file The file to append to. 200 | */ 201 | toEnd(file: string): void; 202 | } 203 | 204 | /** 205 | * Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement. 206 | * @param {RegExp} searchRegex The regular expression to use for search. 207 | * @param {string} replacement The replacement. 208 | * @param {string} file The file to process. 209 | * @return {string} The new string after replacement. 210 | */ 211 | export function sed(searchRegex: RegExp, replacement: string, file: string): string; 212 | 213 | /** 214 | * Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement. 215 | * @param {string} searchRegex The regular expression to use for search. 216 | * @param {string} replacement The replacement. 217 | * @param {string} file The file to process. 218 | * @return {string} The new string after replacement. 219 | */ 220 | export function sed(searchRegex: string, replacement: string, file: string): string; 221 | 222 | /** 223 | * Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement. 224 | * @param {string} options Available options: -i (Replace contents of 'file' in-place. Note that no backups will be created!) 225 | * @param {RegExp} searchRegex The regular expression to use for search. 226 | * @param {string} replacement The replacement. 227 | * @param {string} file The file to process. 228 | * @return {string} The new string after replacement. 229 | */ 230 | export function sed(options: string, searchRegex: RegExp, replacement: string, file: string): string; 231 | 232 | /** 233 | * Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement. 234 | * @param {string} options Available options: -i (Replace contents of 'file' in-place. Note that no backups will be created!) 235 | * @param {string} searchRegex The regular expression to use for search. 236 | * @param {string} replacement The replacement. 237 | * @param {string} file The file to process. 238 | * @return {string} The new string after replacement. 239 | */ 240 | export function sed(options: string, searchRegex: string, replacement: string, file: string): string; 241 | 242 | /** 243 | * Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted. 244 | * @param {RegExp} regex_filter The regular expression to use. 245 | * @param {string[]} ...files The files to process. 246 | * @return {string} Returns a string containing all lines of the file that match the given regex_filter. 247 | */ 248 | export function grep(regex_filter: RegExp, ...files: string[]): string; 249 | 250 | /** 251 | * Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted. 252 | * @param {RegExp} regex_filter The regular expression to use. 253 | * @param {string[]} ...files The files to process. 254 | * @return {string} Returns a string containing all lines of the file that match the given regex_filter. 255 | */ 256 | export function grep(regex_filter: RegExp, files: string[]): string; 257 | 258 | /** 259 | * Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted. 260 | * @param {string} options Available options: -v (Inverse the sense of the regex and print the lines not matching the criteria.) 261 | * @param {string} regex_filter The regular expression to use. 262 | * @param {string[]} ...files The files to process. 263 | * @return {string} Returns a string containing all lines of the file that match the given regex_filter. 264 | */ 265 | export function grep(options: string, regex_filter: string, ...files: string[]): string; 266 | 267 | /** 268 | * Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted. 269 | * @param {string} options Available options: -v (Inverse the sense of the regex and print the lines not matching the criteria.) 270 | * @param {string} regex_filter The regular expression to use. 271 | * @param {string[]} files The files to process. 272 | * @return {string} Returns a string containing all lines of the file that match the given regex_filter. 273 | */ 274 | export function grep(options: string, regex_filter: string, files: string[]): string; 275 | 276 | /** 277 | * Searches for command in the system's PATH. On Windows looks for .exe, .cmd, and .bat extensions. 278 | * @param {string} command The command to search for. 279 | * @return {string} Returns string containing the absolute path to the command. 280 | */ 281 | export function which(command: string): string; 282 | 283 | /** 284 | * Prints string to stdout, and returns string with additional utility methods like .to(). 285 | * @param {string[]} ...text The text to print. 286 | * @return {string} Returns the string that was passed as argument. 287 | */ 288 | export function echo(...text: string[]): string; 289 | 290 | /** 291 | * Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. 292 | * @param {"+N"} dir Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. 293 | * @return {string[]} Returns an array of paths in the stack. 294 | */ 295 | export function pushd(dir: "+N"): string[]; 296 | 297 | /** 298 | * Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. 299 | * @param {"-N"} dir Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. 300 | * @return {string[]} Returns an array of paths in the stack. 301 | */ 302 | export function pushd(dir: "-N"): string[]; 303 | 304 | /** 305 | * Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. 306 | * @param {string} dir Makes the current working directory be the top of the stack, and then executes the equivalent of cd dir. 307 | * @return {string[]} Returns an array of paths in the stack. 308 | */ 309 | export function pushd(dir: string): string[]; 310 | 311 | /** 312 | * Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. 313 | * @param {string} options Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated) 314 | * @param {"+N"} dir Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. 315 | * @return {string[]} Returns an array of paths in the stack. 316 | */ 317 | export function pushd(options: string, dir: "+N"): string[]; 318 | 319 | /** 320 | * Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. 321 | * @param {string} options Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated) 322 | * @param {"-N"} dir Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. 323 | * @return {string[]} Returns an array of paths in the stack. 324 | */ 325 | export function pushd(options: string, dir: "-N"): string[]; 326 | 327 | /** 328 | * Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. 329 | * @param {string} options Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated) 330 | * @param {string} dir Makes the current working directory be the top of the stack, and then executes the equivalent of cd dir. 331 | * @return {string[]} Returns an array of paths in the stack. 332 | */ 333 | export function pushd(options: string, dir: string): string[]; 334 | 335 | /** 336 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 337 | * @param {"+N"} dir Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero. 338 | * @return {string[]} Returns an array of paths in the stack. 339 | */ 340 | export function popd(dir: "+N"): string[]; 341 | 342 | /** 343 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 344 | * @return {string[]} Returns an array of paths in the stack. 345 | */ 346 | export function popd(): string[]; 347 | 348 | /** 349 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 350 | * @param {"-N"} dir Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero. 351 | * @return {string[]} Returns an array of paths in the stack. 352 | */ 353 | export function popd(dir: "-N"): string[]; 354 | 355 | /** 356 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 357 | * @param {string} dir You can only use -N and +N. 358 | * @return {string[]} Returns an array of paths in the stack. 359 | */ 360 | export function popd(dir: string): string[]; 361 | 362 | /** 363 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 364 | * @param {string} options Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated) 365 | * @param {"+N"} dir Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero. 366 | * @return {string[]} Returns an array of paths in the stack. 367 | */ 368 | export function popd(options: string, dir: "+N"): string[]; 369 | 370 | /** 371 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 372 | * @param {string} options Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated) 373 | * @param {"-N"} dir Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero. 374 | * @return {string[]} Returns an array of paths in the stack. 375 | */ 376 | export function popd(options: string, dir: "-N"): string[]; 377 | 378 | /** 379 | * When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. 380 | * @param {string} options Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated) 381 | * @param {string} dir You can only use -N and +N. 382 | * @return {string[]} Returns an array of paths in the stack. 383 | */ 384 | export function popd(options: string, dir: string): string[]; 385 | 386 | /** 387 | * Clears the directory stack by deleting all of the elements. 388 | * @param {"-c"} options Clears the directory stack by deleting all of the elements. 389 | * @return {string[]} Returns an array of paths in the stack, or a single path if +N or -N was specified. 390 | */ 391 | export function dirs(options: "-c"): string[]; 392 | 393 | /** 394 | * Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified. 395 | * @param {"+N"} options Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero. 396 | * @return {string[]} Returns an array of paths in the stack, or a single path if +N or -N was specified. 397 | */ 398 | export function dirs(options: "+N"): string; 399 | 400 | /** 401 | * Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified. 402 | * @param {"-N"} options Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero. 403 | * @return {string[]} Returns an array of paths in the stack, or a single path if +N or -N was specified. 404 | */ 405 | export function dirs(options: "-N"): string; 406 | 407 | /** 408 | * Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified. 409 | * @param {string} options Available options: -c, -N, +N. You can only use those. 410 | * @return {any} Returns an array of paths in the stack, or a single path if +N or -N was specified. 411 | */ 412 | export function dirs(options: string): any; 413 | 414 | /** 415 | * Links source to dest. Use -f to force the link, should dest already exist. 416 | * @param {string} source The source. 417 | * @param {string} dest The destination. 418 | */ 419 | export function ln(source: string, dest: string): void; 420 | 421 | /** 422 | * Links source to dest. Use -f to force the link, should dest already exist. 423 | * @param {string} options Available options: s (symlink), f (force) 424 | * @param {string} source The source. 425 | * @param {string} dest The destination. 426 | */ 427 | export function ln(options: string, source: string, dest: string): void; 428 | 429 | /** 430 | * Exits the current process with the given exit code. 431 | * @param {number} code The exit code. 432 | */ 433 | export function exit(code: number): void; 434 | 435 | /** 436 | * Object containing environment variables (both getter and setter). Shortcut to process.env. 437 | */ 438 | export var env: { [key: string]: string }; 439 | 440 | /** 441 | * Executes the given command synchronously. 442 | * @param {string} command The command to execute. 443 | * @return {ExecOutputReturnValue} Returns an object containing the return code and output as string. 444 | */ 445 | export function exec(command: string): ExecOutputReturnValue; 446 | /** 447 | * Executes the given command synchronously. 448 | * @param {string} command The command to execute. 449 | * @param {ExecOptions} options Silence and synchronous options. 450 | * @return {ExecOutputReturnValue | child.ChildProcess} Returns an object containing the return code and output as string, or if {async:true} was passed, a ChildProcess. 451 | */ 452 | export function exec(command: string, options: ExecOptions): ExecOutputReturnValue | child.ChildProcess; 453 | /** 454 | * Executes the given command synchronously. 455 | * @param {string} command The command to execute. 456 | * @param {ExecOptions} options Silence and synchronous options. 457 | * @param {ExecCallback} callback Receives code and output asynchronously. 458 | */ 459 | export function exec(command: string, options: ExecOptions, callback: ExecCallback): child.ChildProcess; 460 | /** 461 | * Executes the given command synchronously. 462 | * @param {string} command The command to execute. 463 | * @param {ExecCallback} callback Receives code and output asynchronously. 464 | */ 465 | export function exec(command: string, callback: ExecCallback): child.ChildProcess; 466 | 467 | export interface ExecCallback { 468 | (code: number, output: string): any; 469 | } 470 | 471 | export interface ExecOptions { 472 | silent?: boolean; 473 | async?: boolean; 474 | } 475 | 476 | export interface ExecOutputReturnValue 477 | { 478 | code: number; 479 | output: string; 480 | } 481 | 482 | /** 483 | * Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions: 484 | * - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask. 485 | * - There is no "quiet" option since default behavior is to run silent 486 | * @param {string} options The options to pass to the command (-R recursive). 487 | * @param {number} octalMode The access mode. Octal. 488 | * @param {string} file The file to use. 489 | */ 490 | export function chmod(options: string, octalMode: number, file: string): void; 491 | 492 | /** 493 | * Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions: 494 | * - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask. 495 | * - There is no "quiet" option since default behavior is to run silent. 496 | * @param {number} octalMode The access mode. Octal. 497 | * @param {string} file The file to use. 498 | */ 499 | export function chmod(octalMode: number, file: string): void; 500 | 501 | /** 502 | * Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions: 503 | * - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask. 504 | * - There is no "quiet" option since default behavior is to run silent. 505 | * @param {string} mode The access mode. Can be an octal string or a symbolic mode string. 506 | * @param {string} file The file to use. 507 | */ 508 | export function chmod(mode: string, file: string): void; 509 | 510 | // Non-Unix commands 511 | 512 | /** 513 | * Searches and returns string containing a writeable, platform-dependent temporary directory. Follows Python's tempfile algorithm. 514 | * @return {string} The temp file path. 515 | */ 516 | export function tempdir(): string; 517 | 518 | /** 519 | * Tests if error occurred in the last command. 520 | * @return {string} Returns null if no error occurred, otherwise returns string explaining the error 521 | */ 522 | export function error(): string; 523 | 524 | // Configuration 525 | 526 | interface ShellConfig 527 | { 528 | /** 529 | * Suppresses all command output if true, except for echo() calls. Default is false. 530 | * @type {boolean} 531 | */ 532 | silent: boolean; 533 | 534 | /** 535 | * If true the script will die on errors. Default is false. 536 | * @type {boolean} 537 | */ 538 | fatal: boolean; 539 | } 540 | 541 | /** 542 | * The shelljs configuration. 543 | * @type {ShellConfig} 544 | */ 545 | export var config: ShellConfig; 546 | } 547 | --------------------------------------------------------------------------------