Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from Azure/dev
Browse files Browse the repository at this point in the history
Add Ignore module support
  • Loading branch information
Christopher Anderson authored Jun 30, 2017
2 parents 0a0386b + a40c57d commit 3579ad5
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
coverage/
node_modules/
npm-debug.log

lib

**/*.csv
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ Usage: pack [options] <path>
-o, --output <path> Path for output directory
```

### funcpack.config.json

Pack will optionally take in a config file that will let you further customize the behavior. The config file must be in the directory you run the command from and named `funcpack.config.json`.

Here are all the supported options:

```
{
"ignoredModules":["chai"]
}
```

## License

[MIT](LICENSE)
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-functions-pack",
"version": "0.1.2",
"version": "0.2.2",
"description": "azure-functions-pack",
"license": "MIT",
"repository": "https://github.com/christopheranderson/azure-functions-pack",
Expand All @@ -26,28 +26,28 @@
"e2etst": "npm run "
},
"dependencies": {
"commander": "^2.9.0",
"debug": "^2.6.1",
"rimraf": "^2.5.4",
"commander": "~2.9.0",
"debug": "~2.6.1",
"rimraf": "~2.5.4",
"webpack": "fulls1z3/webpack#v2.2.1-harmony",
"winston": "^2.3.1"
"winston": "~2.3.1"
},
"devDependencies": {
"@types/chai": "^3.0.0",
"@types/commander": "^2.3.31",
"@types/chai": "3.5.0",
"@types/commander": "~2.3.31",
"@types/debug": "0.0.29",
"@types/mocha": "^2.0.0",
"@types/mocha": "2.2.41",
"@types/node": "6.0.31",
"@types/rimraf": "0.0.28",
"@types/webpack": "^2.2.5",
"@types/winston": "^2.2.0",
"chai": "^3.0.0",
"mocha": "^3.0.0",
"ts-node": "^1.0.0",
"tslint": "^4.0.0",
"typescript": "^2.0.0"
"@types/webpack": "~2.2.5",
"@types/winston": "~2.2.0",
"chai": "~3.5.0",
"mocha": "~3.0.0",
"ts-node": "~1.0.0",
"tslint": "~4.0.0",
"typescript": "~2.2.0"
},
"engines": {
"node": ">=4.0.0"
"node": ">=6.5.0"
}
}
17 changes: 17 additions & 0 deletions sample/excluded/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"disabled": false,
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
],
"scriptFile": "index.js"
}
13 changes: 13 additions & 0 deletions sample/excluded/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if(false) { // never called
require('chai');
}

module.exports = function (context, req) {
context.log('"simple" function called');
const res = {
body: {
"success":true
}
}
context.done(null, res);
};
5 changes: 5 additions & 0 deletions sample/funcpack.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ignoredModules":[
"chai"
]
}
3 changes: 3 additions & 0 deletions sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"azure": "^1.2.0-preview",
"lodash": "^4.17.4",
"tedious": "^1.14.0"
},
"devDependencies": {
"chai":"3.5.0"
}
}
11 changes: 10 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import * as program from "commander";
import * as path from "path";
import * as winston from "winston";
import { PackhostGenerator, Unpacker, WebpackRunner } from "./";
import { ConfigLoader, IFuncpackConfig } from "./utils";

async function runCli() {
const p = program
.version("0.1.2")
.version("0.2.2")
.option("-d, --debug", "Emits debug messages");

p.command("unpack <path>")
Expand Down Expand Up @@ -66,6 +67,13 @@ async function unpack(name: string, options: any) {
}

async function pack(name: string, options: any) {
// TBD - allow loadConfig to get a filename from options
let config: IFuncpackConfig = await ConfigLoader.loadConfig();

config = config || {
ignoredModules: [],
};

if (options.debug) {
process.env.DEBUG = "*";
}
Expand Down Expand Up @@ -121,6 +129,7 @@ async function pack(name: string, options: any) {
projectRootPath,
uglify,
outputPath,
ignoredModules: config.ignoredModules,
});
} catch (error) {
winston.error(error);
Expand Down
18 changes: 18 additions & 0 deletions src/utils/config-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
FileHelper,
} from "./index";

import * as path from "path";

export class ConfigLoader {
public static async loadConfig(filename?: string): Promise<IFuncpackConfig> {
const pathToFile = path.join(process.cwd(), (filename || "funcpack.config.json"));
if (await FileHelper.exists(pathToFile)) {
return await FileHelper.readFileAsJSON(pathToFile);
}
}
}

export interface IFuncpackConfig {
ignoredModules?: string[];
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./fs-helper";
export * from "./config-loader";
9 changes: 9 additions & 0 deletions src/webpack-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export interface IWebpackRunner {
indexFileName?: string;
outputPath?: string;
uglify?: boolean;
ignoredModules?: string[];
}

export class WebpackRunner {
public static run(options: IWebpackRunner): Promise<any> {
options.indexFileName = options.indexFileName || "index.js";
options.outputPath = options.outputPath || ".funcpack";
options.uglify = options.uglify || false;
options.ignoredModules = options.ignoredModules || [];

return new Promise(async (resolve, reject) => {
debug("Setting up paths");
Expand All @@ -27,9 +29,16 @@ export class WebpackRunner {

const outputPath = path.join(options.projectRootPath, options.outputPath, "output.js");

const ignoredModules: { [key: string]: string } = {};

for (const mod of options.ignoredModules) {
ignoredModules[mod.toLowerCase()] = mod;
}

debug("Creating Webpack Configuration");
const config: webpack.Configuration = {
entry: oldPath,
externals: ignoredModules,
node: {
__dirname: false,
__filename: false,
Expand Down
1 change: 1 addition & 0 deletions test/runTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

testOk $testName 'simple'
testOk $testName 'entryPoint'
testOk $testName 'excluded'
testOk $testName 'externalScriptFile'
testOk $testName 'fs-ignoremeScriptFile'
testOk $testName 'cs-ignoreme'
Expand Down

0 comments on commit 3579ad5

Please sign in to comment.