Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Clean up workspace on deploy #835

Merged
merged 2 commits into from
Sep 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[config]
command = deploy.cmd
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
149 changes: 149 additions & 0 deletions deploy.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.17
:: ----------------------

:: Prerequisites
:: -------------

:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)

:: Setup
:: -----

setlocal enabledelayedexpansion

SET ARTIFACTS=%~dp0%..\artifacts

IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%.
)

IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)

IF NOT DEFINED NEXT_MANIFEST_PATH (
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest

IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
)
)

IF NOT DEFINED KUDU_SYNC_CMD (
:: Install kudu sync
echo Installing Kudu Sync
call npm install kudusync -g --silent
IF !ERRORLEVEL! NEQ 0 goto error

:: Locally just running "kuduSync" would also work
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)
goto Deployment

:: Utility Functions
:: -----------------

:SelectNodeVersion

IF DEFINED KUDU_SELECT_NODE_VERSION_CMD (
:: The following are done only on Windows Azure Websites environment
call %KUDU_SELECT_NODE_VERSION_CMD% "%DEPLOYMENT_SOURCE%" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%"
IF !ERRORLEVEL! NEQ 0 goto error

IF EXIST "%DEPLOYMENT_TEMP%\__nodeVersion.tmp" (
SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp"
IF !ERRORLEVEL! NEQ 0 goto error
)

IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" (
SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp"
IF !ERRORLEVEL! NEQ 0 goto error
)

IF NOT DEFINED NODE_EXE (
SET NODE_EXE=node
)

SET NPM_CMD="!NODE_EXE!" "!NPM_JS_PATH!"
) ELSE (
SET NPM_CMD=npm
SET NODE_EXE=node
)

goto :EOF

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------

:Deployment
echo Handling node.js deployment.

:: 1. KuduSync
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
IF !ERRORLEVEL! NEQ 0 goto error
)

:: 2. Select node version
call :SelectNodeVersion

:: 3. Clean up previous deployments
IF EXIST "%DEPLOYMENT_TARGET%\node_modules\" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd RD /S /Q "node_modules"
IF !ERRORLEVEL! NEQ 0 goto error
popd
)

IF EXIST "%DEPLOYMENT_TARGET%\package-lock.json" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd DEL "package-lock.json"
IF !ERRORLEVEL! NEQ 0 goto error
popd
)


:: 4. Install npm packages
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd !NPM_CMD! install --production
IF !ERRORLEVEL! NEQ 0 goto error
popd
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end

:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%

:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul

:exitSetErrorLevel
exit /b 1

:exitFromFunction
()

:end
endlocal
echo Finished successfully.
40 changes: 22 additions & 18 deletions helpers/postinstall.js
Original file line number Diff line number Diff line change
@@ -2,26 +2,30 @@
* Post Install Script
* Copies a set of files from the `@hint/artwork` asset repository into this one
*/
const shell = require('shelljs');
const mkdirp = require('mkdirp');
try {
const shell = require('shelljs');
const mkdirp = require('mkdirp');

const baseSrcPath = 'node_modules/@hint/artwork/src/';
const baseTargetPath = 'src/webhint-theme/source/images/';
const baseSrcPath = 'node_modules/@hint/artwork/src/';
const baseTargetPath = 'src/webhint-theme/source/images/';

const fileSrcAndTargets = {
'other/confused/confused.svg': 'nellie-confused.svg',
'other/developing/developing.svg': 'developer-nellie.svg',
'other/octocat/octocat_1.svg': 'nellie-octocat.svg',
'other/searching/searching.svg': 'nellie-searching.svg',
'other/sunglasses/sunglasses.svg': 'nellie-customizable.svg',
'other/working/working.svg': 'nellie-construction.svg'
};
const fileSrcAndTargets = {
'other/confused/confused.svg': 'nellie-confused.svg',
'other/developing/developing.svg': 'developer-nellie.svg',
'other/octocat/octocat_1.svg': 'nellie-octocat.svg',
'other/searching/searching.svg': 'nellie-searching.svg',
'other/sunglasses/sunglasses.svg': 'nellie-customizable.svg',
'other/working/working.svg': 'nellie-construction.svg'
};

mkdirp.sync(baseTargetPath);
mkdirp.sync(baseTargetPath);

Object.entries(fileSrcAndTargets).forEach((entry) => {
const srcPath = entry[0];
const targetPath = entry[1];
Object.entries(fileSrcAndTargets).forEach((entry) => {
const srcPath = entry[0];
const targetPath = entry[1];

shell.cp(`${baseSrcPath}${srcPath}`, `${baseTargetPath}${targetPath}`);
});
shell.cp(`${baseSrcPath}${srcPath}`, `${baseTargetPath}${targetPath}`);
});
} catch (e) {
console.log(`Couldn't copy images, probably install in "--production" mode`);
}
8 changes: 7 additions & 1 deletion helpers/update-site.sh
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ prepare_site_dist_dir() {
helpers
dist
package.json
package-lock.json
src
web.config
)
@@ -69,6 +68,13 @@ main () {
prepare_site_dist_dir \
&& update_website

if [ $? -eq 0 ]
then
echo "Successfully deployed website"
else
echo "Could not deploy site" >&2
fi

rm -rf "$TMP_DIR"
}

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -7,14 +7,10 @@
"express": "^4.17.1",
"globby": "^10.0.1",
"highlight.js": "^9.15.10",
"hint": "^5.2.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to install hint somewhere to test staging or we could use npx hint https://staging

"js-yaml": "^3.13.1",
"klaw": "^3.0.0",
"lodash": "^4.17.15",
"mkdirp": "^0.5.1",
"moment": "^2.24.0",
"request": "^2.88.0",
"shelljs": "^0.8.3",
"strip-indent": "^3.0.0",
"xss-filters": "^1.2.7"
},
@@ -53,14 +49,17 @@
"hexo-renderer-handlebars": "^2.0.2",
"hexo-server": "^1.0.0",
"hexo-util": "^1.2.0",
"hint": "^5.3.0",
"json2yaml": "^1.1.0",
"markdownlint-cli": "^0.18.0",
"marked": "^0.7.0",
"md-2-json": "^1.0.6",
"mkdirp": "^0.5.1",
"mktemp": "^1.0.0",
"normalize-path": "^3.0.0",
"npm-run-all": "^4.1.3",
"remove-markdown": "^0.3.0",
"shelljs": "^0.8.3",
"stylelint": "^11.0.0",
"sw-precache": "^5.2.1",
"typescript": "^3.6.3",
@@ -90,7 +89,7 @@
"watch": "gulp watch",
"test": "npm run lint && npm run build",
"test-local": "hint http://localhost:8080 --tracking=off",
"test-staging": "hint https://sonarwhal-staging.azurewebsites.net --tracking=on",
"test-staging": "npx hint https://sonarwhal-staging.azurewebsites.net --tracking=on",
"update-site": "node helpers/update-site.js",
"postinstall": "node helpers/postinstall.js"
}