Merge pull request #26 from Azure/feature-ignoremodules
Adds feature to ignore modules when packing
This commit is contained in:
Коммит
a40c57ddb2
|
@ -1,3 +1,7 @@
|
|||
coverage/
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
|
||||
lib
|
||||
|
||||
**/*.csv
|
12
README.md
12
README.md
|
@ -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
package.json
32
package.json
|
@ -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",
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"disabled": false,
|
||||
"bindings": [
|
||||
{
|
||||
"authLevel": "function",
|
||||
"type": "httpTrigger",
|
||||
"direction": "in",
|
||||
"name": "req"
|
||||
},
|
||||
{
|
||||
"type": "http",
|
||||
"direction": "out",
|
||||
"name": "$return"
|
||||
}
|
||||
],
|
||||
"scriptFile": "index.js"
|
||||
}
|
|
@ -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);
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"ignoredModules":[
|
||||
"chai"
|
||||
]
|
||||
}
|
|
@ -12,5 +12,8 @@
|
|||
"azure": "^1.2.0-preview",
|
||||
"lodash": "^4.17.4",
|
||||
"tedious": "^1.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai":"3.5.0"
|
||||
}
|
||||
}
|
||||
|
|
11
src/main.ts
11
src/main.ts
|
@ -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>")
|
||||
|
@ -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 = "*";
|
||||
}
|
||||
|
@ -121,6 +129,7 @@ async function pack(name: string, options: any) {
|
|||
projectRootPath,
|
||||
uglify,
|
||||
outputPath,
|
||||
ignoredModules: config.ignoredModules,
|
||||
});
|
||||
} catch (error) {
|
||||
winston.error(error);
|
||||
|
|
|
@ -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 +1,2 @@
|
|||
export * from "./fs-helper";
|
||||
export * from "./config-loader";
|
|
@ -11,6 +11,7 @@ export interface IWebpackRunner {
|
|||
indexFileName?: string;
|
||||
outputPath?: string;
|
||||
uglify?: boolean;
|
||||
ignoredModules?: string[];
|
||||
}
|
||||
|
||||
export class WebpackRunner {
|
||||
|
@ -18,6 +19,7 @@ export class WebpackRunner {
|
|||
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");
|
||||
|
@ -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,
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
testOk $testName 'simple'
|
||||
testOk $testName 'entryPoint'
|
||||
testOk $testName 'excluded'
|
||||
testOk $testName 'externalScriptFile'
|
||||
testOk $testName 'fs-ignoremeScriptFile'
|
||||
testOk $testName 'cs-ignoreme'
|
||||
|
|
Загрузка…
Ссылка в новой задаче