Skip to content

Commit 58a9179

Browse files
committed
feat: almost finalize serve cli
1 parent b4f5fab commit 58a9179

File tree

13 files changed

+716
-249
lines changed

13 files changed

+716
-249
lines changed

examples/plugin/src/app/mobile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('Hello Mobile');
1+
console.log('Hello Mobile!');

examples/plugin/wpackio.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
// Whether to show the "BrowserSync Connected"
2323
notify: false,
2424
// Open the dev server URL, set false to disable
25-
open: true,
25+
open: false,
2626
// BrowserSync ghostMode, set to false to completely disable
2727
ghostMode: {
2828
clicks: true,

packages/scripts/@types/boxen.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
declare module 'boxen' {
2+
type borderstyle = 'single' | 'double' | 'round' | 'single-double'
3+
| 'double-single' | 'classic' | {
4+
topLeft: string,
5+
topRight: string,
6+
bottomLeft: string,
7+
bottomRight: string,
8+
horizontal: string,
9+
vertical: string,
10+
}
11+
interface CssProperty {
12+
top: number;
13+
right: number;
14+
bottom: number;
15+
left: number;
16+
}
17+
type alignment = 'right' | 'center' | 'left';
18+
interface Options {
19+
borderColor?: string;
20+
borderStyle?: borderstyle;
21+
dimBorder?: boolean;
22+
padding?:number | CssProperty;
23+
margin?: number | CssProperty;
24+
float?: alignment;
25+
backgroundColor?: string;
26+
align?: alignment;
27+
}
28+
export default function boxen(input: string, options: Options): string;
29+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'react-dev-utils/clearConsole' {
2+
export default function clearConsole():void;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'terminal-link' {
2+
export default function terminalLink(txt:string, link:string):string;
3+
}

packages/scripts/package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,40 @@
2323
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
2424
"@babel/preset-typescript": "^7.1.0",
2525
"@types/browser-sync": "^0.0.42",
26+
"@types/figlet": "^1.2.0",
27+
"@types/figures": "^2.0.0",
28+
"@types/find-up": "^2.1.1",
29+
"@types/gradient-string": "^1.1.0",
30+
"@types/log-symbols": "^2.0.0",
2631
"@types/node": "^10.11.3",
27-
"@types/signale": "^1.2.0",
32+
"@types/ora": "^1.3.4",
2833
"@types/webpack": "^4.4.13",
2934
"@types/webpack-assets-manifest": "^3.0.0",
3035
"@types/webpack-dev-middleware": "^2.0.2",
3136
"@types/webpack-hot-middleware": "^2.16.4",
3237
"@wpackio/babel-preset-base": "0.0.1",
3338
"autoprefixer": "^9.1.5",
3439
"babel-loader": "^8.0.2",
40+
"boxen": "^2.0.0",
3541
"browser-sync": "^2.24.7",
42+
"chalk": "^2.4.1",
3643
"clean-webpack-plugin": "^0.1.19",
3744
"commander": "^2.18.0",
3845
"css-loader": "^1.0.0",
3946
"dev-ip": "^1.0.1",
47+
"figlet": "^1.2.0",
48+
"figures": "^2.0.0",
4049
"file-loader": "^2.0.0",
50+
"find-up": "^3.0.0",
51+
"gradient-string": "^1.2.0",
52+
"log-symbols": "^2.2.0",
4153
"mini-css-extract-plugin": "^0.4.3",
4254
"optimize-css-assets-webpack-plugin": "^5.0.1",
55+
"ora": "^3.0.0",
4356
"postcss-loader": "^3.0.0",
57+
"pretty-error": "^2.1.1",
4458
"react-dev-utils": "^6.0.4",
4559
"sass-loader": "^7.1.0",
46-
"signale": "^1.3.0",
4760
"slugify": "^1.3.1",
4861
"style-loader": "^0.23.0",
4962
"uglifyjs-webpack-plugin": "^2.0.1",

packages/scripts/src/bin/build.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Build } from '../scripts/Build';
2+
import { getProjectAndServerConfig } from './getProjectAndServerConfig';
3+
import { ProgramOptions } from './index';
4+
import { resolveCWD } from './utils';
5+
6+
/**
7+
* Start the `wpackio-scripts build` command.
8+
*
9+
* @param options Option as received from CLI.
10+
*/
11+
export function build(options: ProgramOptions | undefined): void {
12+
console.log('Creating production builds...');
13+
// Set process.env.NODE_ENV to production
14+
process.env.NODE_ENV = 'production';
15+
// Set process.env.BABEL_ENV to production
16+
process.env.BABEL_ENV = 'production';
17+
// Get project and server config JSONs.
18+
const cwd = resolveCWD(options);
19+
console.log(`Using startup path: ${cwd}`);
20+
try {
21+
const {
22+
projectConfig,
23+
serverConfig,
24+
projectConfigPath,
25+
serverConfigPath,
26+
} = getProjectAndServerConfig(cwd, options);
27+
console.log(`Using project config from ${projectConfigPath}`);
28+
console.log(`Using server config from ${serverConfigPath}`);
29+
// Start the webpack/browserSync server
30+
const builder: Build = new Build(projectConfig, serverConfig, cwd);
31+
builder
32+
.build()
33+
.then(log => {
34+
console.log('Build Successful. Please check the log below');
35+
console.log(log);
36+
process.exit(0);
37+
})
38+
.catch(err => {
39+
console.error(
40+
'Could not create production build. Please check the log below'
41+
);
42+
console.log(err);
43+
process.exit(1);
44+
});
45+
} catch (e) {
46+
console.error(
47+
'Could not start development server. Please check the log below.'
48+
);
49+
console.error(e);
50+
process.exit(1);
51+
}
52+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import path from 'path';
2+
import { ProjectConfig } from '../config/project.config.default';
3+
import { ServerConfig } from '../config/server.config.default';
4+
// tslint:disable: non-literal-require
5+
export function getProjectAndServerConfig(
6+
cwd: string,
7+
options:
8+
| {
9+
projectConfig?: string;
10+
serverConfig?: string;
11+
}
12+
| undefined
13+
): {
14+
projectConfig: ProjectConfig;
15+
serverConfig: ServerConfig;
16+
projectConfigPath: string;
17+
serverConfigPath: string;
18+
} {
19+
// Get the config file paths from options
20+
// If user is passing relative path, then it will be used along with cwd
21+
// If it is absolute path, then the absolute would be used instead
22+
// This is how path.resolve works.
23+
const projectConfigPath = path.resolve(
24+
cwd,
25+
options && options.projectConfig
26+
? options.projectConfig
27+
: 'wpackio.project.js'
28+
);
29+
const serverConfigPath = path.resolve(
30+
cwd,
31+
options && options.serverConfig
32+
? options.serverConfig
33+
: 'wpackio.server.js'
34+
);
35+
// Now create the configuration objects
36+
let projectConfig: ProjectConfig;
37+
let serverConfig: ServerConfig;
38+
// First check to see if the files are present
39+
try {
40+
projectConfig = require(projectConfigPath) as ProjectConfig;
41+
} catch (e) {
42+
throw new Error(
43+
`Could not find project configuration at:\n${projectConfigPath}\nPlease make sure the file exists or adjust your --context or --project-config parameters.`
44+
);
45+
}
46+
try {
47+
serverConfig = require(serverConfigPath) as ServerConfig;
48+
} catch (e) {
49+
throw new Error(
50+
`Could not find server configuration at:\n${serverConfigPath}\nPlease make sure the file exists or adjust your --context or --server-config parameters.`
51+
);
52+
}
53+
// Now validate them
54+
if (typeof projectConfig !== 'object') {
55+
throw new Error(
56+
`Project configuration must export an object literal. Right now it is ${typeof projectConfig}`
57+
);
58+
}
59+
if (typeof serverConfig !== 'object') {
60+
throw new Error(
61+
`Server configuration must export an object literal. Right now it is ${typeof serverConfig}`
62+
);
63+
}
64+
// @todo
65+
// Also validate the config, but let's leave it for now
66+
// Make sure to do it in future
67+
return { projectConfig, serverConfig, projectConfigPath, serverConfigPath };
68+
}

0 commit comments

Comments
 (0)