Skip to content

Commit

Permalink
add back client/build
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Apr 17, 2024
1 parent f0193d4 commit 005d792
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ node_modules
/server_manager/install_scripts/do_install_script.ts
/server_manager/install_scripts/gcp_install_script.ts
/output
/build
59 changes: 59 additions & 0 deletions client/build/get_build_parameters.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2022 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import minimist from 'minimist';

const VALID_PLATFORMS = ['linux', 'windows', 'ios', 'macos', 'maccatalyst', 'android', 'browser'];
const VALID_BUILD_MODES = ['debug', 'release'];

const MS_PER_HOUR = 1000 * 60 * 60;

/*
Inputs:
=> cliParameters: the list of action arguments passed in
Outputs:
=> an object containing the specificed platform and buildMode.
*/
export function getBuildParameters(cliArguments) {
const {
_: [platform = 'browser'],
buildMode = 'debug',
verbose = false,
versionName = '0.0.0',
sentryDsn = process.env.SENTRY_DSN,
} = minimist(cliArguments);

if (platform && !VALID_PLATFORMS.includes(platform)) {
throw new TypeError(
`Platform "${platform}" is not a valid target for Outline Client. Must be one of ${VALID_PLATFORMS.join(', ')}`
);
}

if (buildMode && !VALID_BUILD_MODES.includes(buildMode)) {
throw new TypeError(
`Build mode "${buildMode}" is not a valid build mode for Outline Client. Must be one of ${VALID_BUILD_MODES.join(
', '
)}`
);
}

return {
platform,
buildMode,
verbose,
versionName: buildMode === 'release' ? versionName : `${versionName}-${buildMode}`,
sentryDsn,
buildNumber: Math.floor(Date.now() / MS_PER_HOUR),
};
}
30 changes: 30 additions & 0 deletions client/build/get_webpack_build_mode.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2022 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
Inputs:
=> buildMode: the outline build mode
Outputs:
=> the appropriate webpack mode for this type of build
*/
export function getWebpackBuildMode(buildMode) {
switch (buildMode) {
case 'debug':
return 'development';
case 'release':
return 'production';
default:
throw new TypeError('get_webpack_mode requires a buildMode argument of debug or release');
}
}
36 changes: 36 additions & 0 deletions client/build/run_webpack.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2022 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import webpack from 'webpack';

export const runWebpack = webpackConfig =>
new Promise((resolve, reject) => {
webpack(webpackConfig, (error, stats) => {
if (error || stats.hasErrors()) {
reject(
error ||
stats
.toJson()
?.errors.reduce(
(errorMessages, {message}) => (message ? `${errorMessages}\n${message}` : errorMessages),
''
) ||
'Unknown Webpack error.'
);
}

resolve(stats);
});
});

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"action:help": "npm run action list",
"action:list": "npm run action list",
"action": "node ./src/build/run_action.mjs",
"clean": "rimraf client/build client/output node_modules client/node_modules client/www client/platforms client/plugins third_party/jsign/*.jar && go run github.com/go-task/task/v3/cmd/task clean",
"clean": "rimraf client/output node_modules client/node_modules client/www client/platforms client/plugins third_party/jsign/*.jar && go run github.com/go-task/task/v3/cmd/task clean",
"format:all": "prettier --write \"**/*.{cjs,mjs,html,js,json,md,ts}\"",
"format": "pretty-quick --staged --pattern \"**/*.{cjs,mjs,html,js,json,md,ts}\"",
"lint:ts": "eslint --ext ts,mjs client",
Expand Down

0 comments on commit 005d792

Please sign in to comment.