Skip to content

Commit dbb6b12

Browse files
committed
Merge branch 'release/1.7.0'
2 parents 190e30b + 6ce46cc commit dbb6b12

File tree

20 files changed

+568
-363
lines changed

20 files changed

+568
-363
lines changed

.github/main.workflow

Lines changed: 0 additions & 28 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
.dist
2+
dist

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ The [**build** command](https://github.com/8eecf0d2/netlify-local/wiki/Command-B
3535
netlify-local build <options>
3636
```
3737

38+
#### `bundle` command
39+
The [**bundle** command](https://github.com/8eecf0d2/netlify-local/wiki/Command-Bundle) will attempt to parse your `netlify.toml` and update your Webpack Configuration with the correct `entry` and `output` properties.
40+
```bash
41+
netlify-local bundle <options>
42+
```
43+
3844
#### Options
3945
You can view a detailed [list of options in the wiki](https://github.com/8eecf0d2/netlify-local/wiki/Options).
4046

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "netlify-local",
3-
"version": "1.6.7",
3+
"version": "1.7.0",
44
"description": "Local Netlify service emulation",
5-
"main": ".dist/index.js",
6-
"types": ".dist/index.d.ts",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
77
"bin": {
8-
"netlify-local": ".dist/cli.js"
8+
"netlify-local": "dist/cli.js"
99
},
1010
"repository": "https://github.com/8eecf0d2/netlify-local.git",
1111
"author": "8eecf0d2 <[email protected]>",
@@ -15,7 +15,7 @@
1515
"build": "tsc --project ./tsconfig.json",
1616
"pretest": "yarn run build",
1717
"test": "ts-mocha --project ./test/tsconfig.json test/**/*.ts",
18-
"test:now": "ts-mocha --project ./test/tsconfig.json test/**/*.ts"
18+
"lint": "tslint -c tslint.json src/**/*.ts"
1919
},
2020
"devDependencies": {
2121
"@types/assert": "^1.4.0",
@@ -32,6 +32,7 @@
3232
"assert": "^1.4.1",
3333
"mocha": "^5.2.0",
3434
"ts-mocha": "^2.0.0",
35+
"tslint": "^5.12.0",
3536
"typescript": "^3.1.3"
3637
},
3738
"dependencies": {
@@ -43,9 +44,9 @@
4344
"get-port": "^4.0.0",
4445
"git-branch": "^2.0.1",
4546
"jsonwebtoken": "^8.3.0",
47+
"serve-static": "^1.13.2",
4648
"toml": "^2.3.3",
4749
"url-pattern": "^1.0.3",
48-
"serve-static": "^1.13.2",
4950
"webpack": "^4.20.2"
5051
},
5152
"files": [

src/ts/cli.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import * as program from "commander";
66

77
import { Logger } from "./helper";
88
import { Netlify } from "./netlify";
9-
import { Server } from "./server";
10-
import { Build } from "./build";
11-
import { Webpack } from "./webpack";
12-
import { parseNetlifyConfig, parseNetlifyPluginLocalConfig, parseSslCertificates, parseWebpackConfig } from "./config";
9+
import { parseNetlifyConfig, parseNetlifyPluginLocalConfig, parseSslCertificates, parseWebpackConfig, Server, Webpack } from "./utility";
10+
import { Build, Bundle } from "./command";
1311

1412
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
1513

@@ -29,7 +27,7 @@ program
2927
.description("Locally emulate Netlify services")
3028
.action(() => {
3129
(async () => {
32-
if(program.context) {
30+
if (program.context) {
3331
process.env.NETLIFY_LOCAL_CONTEXT = program.context;
3432
}
3533

@@ -41,8 +39,8 @@ program
4139
static: program.static === undefined ? undefined : program.static === "false" ? false : true,
4240
lambda: program.lambda === undefined ? undefined : program.lambda === "false" ? false : true,
4341
certificates: program.certificates,
44-
port: program.hasOwnProperty("port") ? parseInt(program.port) : undefined,
45-
}
42+
port: program.hasOwnProperty("port") ? parseInt(program.port, 10) : undefined,
43+
},
4644
});
4745

4846
const server = new Server({
@@ -52,49 +50,73 @@ program
5250

5351
await server.listen();
5452

55-
if(netlifyConfig.plugins.local.webpack.config) {
53+
if (netlifyConfig.plugins.local.webpack.config) {
5654
const webpackConfig = parseWebpackConfig(netlifyConfig.plugins.local.webpack.config);
5755
const webpack = new Webpack(webpackConfig);
5856
webpack.watch();
5957
}
6058

6159
})()
62-
.catch(error => {
63-
Logger.error(error)
60+
.catch((error) => {
61+
Logger.error(error);
6462
process.exit(1);
65-
})
63+
});
6664
});
6765

6866
program
6967
.command("build")
7068
.description("Execute Netlify build")
7169
.action(() => {
7270
(async () => {
73-
if(program.context) {
71+
if (program.context) {
7472
process.env.NETLIFY_LOCAL_CONTEXT = program.context;
7573
}
7674

7775
const netlifyConfig = parseNetlifyConfig(program.netlify || "netlify.toml", {
7876
webpack: {
7977
config: program.webpack,
8078
},
81-
server: {
82-
static: false,
83-
lambda: false,
84-
certificates: undefined,
85-
port: 9000,
86-
}
8779
});
8880

8981
try {
90-
await Build.from(netlifyConfig);
91-
} catch(error) {}
82+
await Build.start(netlifyConfig);
83+
} catch (error) {
84+
Logger.error(error);
85+
}
9286

9387
})()
94-
.catch(error => {
95-
Logger.error(error)
88+
.catch((error) => {
89+
Logger.error(error);
9690
process.exit(1);
97-
})
91+
});
92+
});
93+
94+
program
95+
.command("bundle")
96+
.description("Bundle Netlify functions")
97+
.action(() => {
98+
(async () => {
99+
if (program.context) {
100+
process.env.NETLIFY_LOCAL_CONTEXT = program.context;
101+
}
102+
103+
const netlifyConfig = parseNetlifyConfig(program.netlify || "netlify.toml", {
104+
webpack: {
105+
config: program.webpack,
106+
},
107+
});
108+
109+
try {
110+
await Bundle.start(netlifyConfig);
111+
} catch (error) {
112+
Logger.error(error);
113+
}
114+
115+
})()
116+
.catch((error) => {
117+
Logger.error(error);
118+
process.exit(1);
119+
});
98120
});
99121

100122
program.parse(process.argv);

src/ts/build.ts renamed to src/ts/command/build.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import { exec } from "child_process";
22

3-
import { Logger } from "./helper";
4-
import { Netlify} from "./netlify";
3+
import { Logger } from "../helper";
4+
import { Netlify} from "../netlify";
55

66
export class Build {
7-
8-
public static async from (netlifyConfig: Netlify.Config): Promise<void> {
7+
public static async start(netlifyConfig: Netlify.Config): Promise<void> {
98
return new Promise<void>((resolve, reject) => {
109
Logger.info("build started");
11-
const buildCommand = Build.objectToEnvironmentVariables(netlifyConfig.build.environment) + netlifyConfig.build.command;
10+
const buildCommand = Build.objectToEnvironmentVariables(netlifyConfig.build.environment || {}) + netlifyConfig.build.command;
1211
const result = exec(buildCommand, (error, stdout, stderr) => {
13-
if(error) {
12+
if (error) {
1413
Logger.error("build failed");
15-
console.log(stderr);
14+
Logger.raw(stdout);
1615
return reject();
1716
} else {
1817
Logger.good("build complete");
19-
console.log(stdout);
18+
Logger.raw(stdout);
2019
return resolve();
2120
}
2221
});
23-
})
22+
});
2423
}
2524

2625
private static objectToEnvironmentVariables = (obj: { [key: string]: any }): string => {

src/ts/command/bundle.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Logger } from "../helper";
2+
import { Netlify } from "../netlify";
3+
import { composeWebpackEntry, composeWebpackOutput, parseWebpackConfig, Webpack } from "../utility";
4+
5+
export class Bundle {
6+
7+
public static async start(netlifyConfig: Netlify.Config): Promise<void> {
8+
return new Promise<void>((resolve, reject) => {
9+
Logger.info("bundle started");
10+
const baseWebpackConfig = parseWebpackConfig(netlifyConfig.plugins.local.webpack.config).find((config) => config.name === "functions");
11+
const updatedWebpackConfig = Bundle.generateFunctionsConfig(netlifyConfig, baseWebpackConfig);
12+
const webpack = new Webpack(updatedWebpackConfig);
13+
webpack.build();
14+
})
15+
}
16+
17+
public static generateFunctionsConfig(netlifyConfig: Netlify.Config, webpackConfig: Webpack.Config): Webpack.Config {
18+
return {
19+
...webpackConfig,
20+
entry: composeWebpackEntry(netlifyConfig),
21+
output: composeWebpackOutput(netlifyConfig),
22+
};
23+
}
24+
25+
}

src/ts/command/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./build";
2+
export * from "./bundle";

src/ts/helper/logger.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
import chalk from "chalk";
22

33
export class Logger {
4-
static active = () => !(process.env.SILENT === "true");
4+
public static active = () => !(process.env.SILENT === "true");
55

6-
public static info (...args: any[]): void {
7-
if(Logger.active()) {
6+
public static raw(...args: Array<any>): void {
7+
if (Logger.active()) {
8+
// tslint:disable-next-line
9+
console.log(...args);
10+
}
11+
}
12+
public static info(...args: Array<any>): void {
13+
if (Logger.active()) {
14+
// tslint:disable-next-line
815
console.log(chalk.white("[netlify-local]"), ...args);
916
}
1017
}
1118

12-
public static good (...args: any[]): void {
13-
if(Logger.active()) {
19+
public static good(...args: Array<any>): void {
20+
if (Logger.active()) {
21+
// tslint:disable-next-line
1422
console.log(chalk.green("[netlify-local]"), ...args);
1523
}
1624
}
1725

18-
public static error (...args: any[]): void {
19-
if(Logger.active()) {
26+
public static error(...args: Array<any>): void {
27+
if (Logger.active()) {
28+
// tslint:disable-next-line
2029
console.error(chalk.red("[netlify-local]"), ...args);
2130
}
2231
}

src/ts/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
export { parseNetlifyConfig, parseWebpackConfig } from "./config";
21
export { Netlify } from "./netlify";
3-
export { Server } from "./server";
4-
export { Webpack } from "./webpack";
2+
export { composeWebpackEntry, composeWebpackOutput, parseNetlifyConfig, parseWebpackConfig, Server, Webpack } from "./utility";

0 commit comments

Comments
 (0)