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

Commit 3566628

Browse files
author
Christopher Anderson
authored
0.1.1 (#9)
* 0.1.0 pack/unpack Adds pack/unpack options Add unpack functionality Adds uglify option Adds changing directory name option Adds lots more test cases (still manual testing) Changes "original" settings to have underscores LOTS of fixes * Roll cli version to 0.1.0 * use any type (lint issue) * update readme * add uglify config * fix options parsing * add libs that should be inlcuded... * Use temporary webpack version which supports es6 * Add note on uglify * Bump version to 0.1.1
1 parent 257944d commit 3566628

File tree

7 files changed

+112
-26
lines changed

7 files changed

+112
-26
lines changed

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@
9393
"sourceMaps": true,
9494
"stopOnEntry": false,
9595
"type": "node"
96+
},
97+
{
98+
"args": [
99+
"pack","./sample2","-u"
100+
],
101+
"cwd": "${workspaceRoot}",
102+
"env": {
103+
},
104+
"name": "Pack uglify",
105+
"outFiles": [
106+
"${workspaceRoot}/lib/**"
107+
],
108+
"program": "${workspaceRoot}/src/main.ts",
109+
"request": "launch",
110+
"runtimeArgs": [
111+
"--nolazy"
112+
],
113+
"runtimeExecutable": null,
114+
"sourceMaps": true,
115+
"stopOnEntry": false,
116+
"type": "node"
96117
}
97118
]
98119
}

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,65 @@ This is a tool to make it easy to package your Azure Functions Node.js Functions
44

55
:construction: This project is experimental; use with caution and be prepared for breaking changes :construction:
66

7-
WARNING: This requires host version `1.0.10726.0` or higher.
8-
97
## How to run
108

119
```
1210
npm install -g azure-functions-pack
13-
funcpack
11+
funcpack pack ./
1412
```
1513

1614
You can then test locally using the CLI tool: `func run <myfunc>`
1715

16+
When uploading your files, you need to include your `package.json`, but you don't need your `node_modules` directory.
17+
1818
## API
1919

2020
```
21-
Usage: funcpack [options]
21+
Usage: main [options] [command]
22+
23+
24+
Commands:
25+
26+
unpack [options] <path> Will remove all traces of packing tool at the specified path or the current directory if none is specified
27+
pack [options] <path> Will pack the specified path or the current directory if none is specified
2228
2329
Options:
2430
25-
-h, --help output usage information
26-
-V, --version output the version number
27-
-d, --debug Emits debug messages
28-
-p, --path <path> Path to root of Function App
31+
-h, --help output usage information
32+
-V, --version output the version number
33+
-d, --debug Emits debug messages
2934
```
3035

31-
You can pass the path to the root of your project via:
36+
### unpack
3237

33-
0. Using the `-p` command: `funcpack -p ./pathToFunctionApp`
34-
1. Just a normal argument: `funcpack ./pathToFunctionApp`
35-
2. Run in the same directory: `cd ./pathToFunctionApp && funcpack`
38+
```
39+
Usage: unpack [options] <path>
40+
41+
Will remove all traces of packing tool at the specified path or the current directory if none is specified
42+
43+
Options:
44+
45+
-h, --help output usage information
46+
-o, --output <path> Path for output directory
47+
```
48+
49+
Note: the uglify feature only supports some small amount of es6, so I recommend that if you get errors either don't uglify or drop your code down to es5.
50+
51+
Uglify will minimize the sample project that's included from 27 MB to 9 MB.
52+
53+
### pack
54+
55+
```
56+
Usage: pack [options] <path>
57+
58+
Will pack the specified path or the current directory if none is specified
59+
60+
Options:
61+
62+
-h, --help output usage information
63+
-u, --uglify Uglify the project when webpacking
64+
-o, --output <path> Path for output directory
65+
```
3666

3767
## License
3868

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-functions-pack",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "azure-functions-pack",
55
"license": "MIT",
66
"repository": "https://github.com/christopheranderson/azure-functions-pack",
@@ -29,7 +29,7 @@
2929
"commander": "^2.9.0",
3030
"debug": "^2.6.1",
3131
"rimraf": "^2.5.4",
32-
"webpack": "^2.2.1",
32+
"webpack": "fulls1z3/webpack#v2.2.1-harmony",
3333
"winston": "^2.3.1"
3434
},
3535
"devDependencies": {

sample/lib/externalScriptFile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function (context, req) {
2+
context.log('"./lib/externalScriptFile" function called');
3+
const res = {
4+
body: {
5+
"success":true
6+
}
7+
}
8+
context.done(null, res);
9+
};

sample/lib/model.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let sql = require('tedious');
2+
3+
class Model {
4+
getAll() {
5+
const request = new sql.Request("select 'hello'", function(err, rowCount) {
6+
// no op
7+
});
8+
return Promise.resolve([]);
9+
}
10+
11+
add() {
12+
return Promise.resolve({});
13+
}
14+
}
15+
16+
module.exports = {
17+
Model: Model
18+
}

src/main.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function runCli() {
1212

1313
p.command("unpack <path>")
1414
.description("Will remove all traces of packing tool at the specified "
15-
+ "path or the current directory if none is specified")
15+
+ "path or the current directory if none is specified")
1616
.option("-o, --output <path>", "Path for output directory")
1717
.action(unpack);
1818

@@ -22,14 +22,23 @@ async function runCli() {
2222
.option("-o, --output <path>", "Path for output directory")
2323
.action(pack);
2424

25+
p.command("*", null, { noHelp: true, isDefault: true })
26+
.action(() => {
27+
p.help();
28+
});
29+
2530
p.parse(process.argv);
2631

32+
if (!process.argv.slice(2).length) {
33+
p.help();
34+
}
35+
2736
}
2837

29-
async function unpack(name: string) {
30-
if (program.opts().debug) {
31-
process.env.DEBUG = "*";
32-
}
38+
async function unpack(name: string, options: any) {
39+
if (options.debug) {
40+
process.env.DEBUG = "*";
41+
}
3342

3443
// Grab the route either from the option, the argument (if there is only 1)
3544
let projectRootPath = "";
@@ -43,7 +52,7 @@ async function unpack(name: string) {
4352

4453
let outputPath = ".funcpack";
4554
try {
46-
if (program.opts().path) {
55+
if (options.path) {
4756
outputPath = program.opts().path;
4857
}
4958
} catch (e) {
@@ -54,11 +63,10 @@ async function unpack(name: string) {
5463
winston.info("Unpacking project at: " + projectRootPath);
5564
await Unpacker.unpack({ projectRootPath, outputPath });
5665
winston.info("Complete!");
57-
//process.exit(0);
5866
}
5967

60-
async function pack(name: string) {
61-
if (program.opts().debug) {
68+
async function pack(name: string, options: any) {
69+
if (options.debug) {
6270
process.env.DEBUG = "*";
6371
}
6472

@@ -74,7 +82,7 @@ async function pack(name: string) {
7482

7583
let uglify = false;
7684
try {
77-
if (program.opts().uglify) {
85+
if (options.uglify) {
7886
uglify = true;
7987
}
8088
} catch (e) {
@@ -84,7 +92,7 @@ async function pack(name: string) {
8492

8593
let outputPath = ".funcpack";
8694
try {
87-
if (program.opts().path) {
95+
if (options.path) {
8896
outputPath = program.opts().path;
8997
}
9098
} catch (e) {

src/utils/fs-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class FileHelper {
4444
}
4545

4646
public static readFileAsJSON(path: string): Promise<any> {
47-
return new Promise<Object>(async (resolve, reject) => {
47+
return new Promise<any>(async (resolve, reject) => {
4848
try {
4949
const content = await FileHelper.readFileUtf8(path);
5050
resolve(JSON.parse(content));

0 commit comments

Comments
 (0)