Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Convert scripts to nodejs so they work on Windows #4462

Merged
merged 11 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions build/clean-symlinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Clean any symlinks from a pre 4.0 Stratos
// These are no longer used for customization and need to be removed

// Implemented as a single script here so that it works on Windows, Linux and Mac

const path = require('path');
const fs = require('fs');

// __dirname is the folder where build.js is located
const STRATOS_DIR= path.resolve(__dirname, '..');

function processFile(filepath) {
if (fs.existsSync(filepath)) {
const stats = fs.lstatSync(filepath);
if (stats.isSymbolicLink()) {
console.log(`Removing symlink ${filepath}`);
fs.unlinkSync(filepath);
}
}
}

function processFolder(dir) {
if (!fs.existsSync(dir)) {
return
}
fs.readdirSync(dir).forEach( f => {
let dirPath = path.join(dir, f);
const realPath = fs.realpathSync(dirPath);
const stats = fs.lstatSync(realPath);
if (stats.isDirectory()) {
processFolder(dirPath);
} else {
processFile(dirPath);
}
});
};

processFolder(path.join(STRATOS_DIR, 'src', 'frontend', 'packages', 'core', 'sass'));
processFolder(path.join(STRATOS_DIR, 'src', 'frontend', 'packages', 'core', 'assets'));
processFile(path.join(STRATOS_DIR, 'src', 'frontend', 'packages', 'core', 'favicon.ico'));
28 changes: 0 additions & 28 deletions build/clean-symlinks.sh

This file was deleted.

30 changes: 30 additions & 0 deletions build/dev-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copy files required for developer quick start
// Implemented as a single script here so that it works on Windows, Linux and Mac

const path = require('path');
const fs = require('fs');

// __dirname is the folder where build.js is located
const STRATOS_DIR= path.resolve(__dirname, '..');

// Only copy files if they are not already there - just make sure initial versions are in place for developer

// Proxy config file
const PROXY_CONF = path.join(STRATOS_DIR, 'proxy.conf.js');
if (!fs.existsSync(PROXY_CONF)) {
let err = fs.copyFileSync(path.join(__dirname, 'proxy.conf.localdev.js'), PROXY_CONF);
if (err) {
console.log(err);
}
}

// config.properties
const BACKEND_DIR = path.join(STRATOS_DIR, 'src', 'jetstream');
const BACKEND_CONF = path.join(BACKEND_DIR, 'config.properties');
const BACKEND_CONF_DEV = path.join(BACKEND_DIR, 'config.dev');
if (!fs.existsSync(BACKEND_CONF)) {
let err = fs.copyFileSync(BACKEND_CONF_DEV, BACKEND_CONF);
if (err) {
console.log(err);
}
}
82 changes: 0 additions & 82 deletions build/fe-build.js

This file was deleted.

14 changes: 0 additions & 14 deletions build/gulp.config.js

This file was deleted.

16 changes: 16 additions & 0 deletions build/prebuild-zip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Zip the dist folder
// Implemented as a single script here so that it works on Windows, Linux and Mac

const path = require('path');
const fs = require('fs');
const AdmZip = require('adm-zip');

// __dirname is the folder where build.js is located
const STRATOS_DIR= path.resolve(__dirname, '..');
const DIST_DIR= path.join(STRATOS_DIR, 'dist');
const ZIP_FILE= path.join(STRATOS_DIR, 'stratos-frontend-prebuild.zip');

var zip = new AdmZip();

zip.addLocalFolder(DIST_DIR);
zip.writeZip(path.join(ZIP_FILE));
38 changes: 38 additions & 0 deletions build/store-git-metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Generate the git metadata file

// Implemented as a single script here so that it works on Windows, Linux and Mac

const path = require('path');
const fs = require('fs');
const execSync = require('child_process').execSync;

// __dirname is the folder where build.js is located
const STRATOS_DIR = path.resolve(__dirname, '..');
const GIT_FOLDER = path.join(STRATOS_DIR, '.git');
const GIT_METADATA = path.join(STRATOS_DIR, '.stratos-git-metadata.json');

function execGit(cmd) {
try {
var response = execSync(cmd);
return response.toString().trim();
} catch (e) {
console.log(e)
return '';
}
}

// We can only do this if we have a git repository checkout
// We'll store this in a file which we will then use - when in environments like Docker, we will run this
// in the host environment so that we can pick it up when we're running in the Docker world
// Do we have a git folder?
if (!fs.existsSync(GIT_FOLDER)) {
console.log(' + Unable to store git repository metadata - .git folder not found');
return;
}
var gitMetadata = {
project: execGit('git config --get remote.origin.url'),
branch: execGit('git rev-parse --abbrev-ref HEAD'),
commit: execGit('git rev-parse HEAD')
};

fs.writeFileSync(GIT_METADATA, JSON.stringify(gitMetadata, null, 2));
2 changes: 1 addition & 1 deletion deploy/stratos-ui-release/packages/backend/pre_packaging
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
# Build backend
npm install
export PATH=$PATH:$PWD/node_modules/.bin
npm run bosh-build-backend
npm run build-backend

find ../stratos/deploy -type d ! -path '../stratos/deploy' ! -path '*/db' -maxdepth 1 | xargs rm -rf

Expand Down
4 changes: 2 additions & 2 deletions docs/developers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ db provider this can be done by deleting `src/jetstream/console-database.db`

#### Configure by Environment Variables and/or Config File

By default, the configuration in file `src/jetstream/default.config.properties` will be used. These can be changed by environment variables
By default, the configuration in file `src/jetstream/config.properties` will be used. These can be changed by environment variables
or an overrides file.

##### Environment variable
Expand All @@ -238,7 +238,7 @@ If you have a custom uaa, ensure you have set the following environment variable

##### Config File

To easily persist configuration settings copy `src/jetstream/default.config.properties` to `src/jetstream/config.properties`. The backend will load its
To easily persist configuration settings copy `src/jetstream/config.example` to `src/jetstream/config.properties`. The backend will load its
configuration from this file in preference to the default config file, if it exists. You can also modify individual configuration settings
by setting the corresponding environment variable.

Expand Down
4 changes: 0 additions & 4 deletions gulpfile.js

This file was deleted.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"build-backend": "./build/bk-build.sh",
"full-build-dev": "npm run build-dev; npm run build-backend",
"fetch-backend-deps": "./build/bk-fetch-deps.sh",
"bosh-build-backend": "gulp bosh-build-backend",
"test-backend": "./build/bk-build.sh test",
"update-webdriver": "webdriver-manager update",
"build": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod",
"build-cf": "node --max_old_space_size=1500 --gc_interval=100 node_modules/@angular/cli/bin/ng build --prod",
"build-dev": "ng build --dev",
"prebuild-ui": "npm run build && gulp package-prebuild",
"prebuild-ui": "npm run build && npm run prebuild-zip",
"prebuild-zip": "node build/prebuild-zip.js",
"ng": "ng",
"start": "ng serve",
"start-high-mem": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve",
Expand All @@ -37,10 +37,11 @@
"headless-e2e": "xvfb-run --server-args='-screen 0 1920x1080x24' protractor ./protractor.conf.js",
"climate": "codeclimate analyze $(git diff --name-only master)",
"gate-check": "npm run lint && npm run test-headless",
"store-git-metadata": "gulp store-git-metadata",
"postinstall": "gulp dev-setup && npm run build-devkit && npm run clean-symlinks",
"store-git-metadata": "node build/store-git-metadata.js",
"postinstall": "npm run dev-setup && npm run build-devkit && npm run clean-symlinks && npm run store-git-metadata",
"build-devkit": "cd src/frontend/packages/devkit && npm run build",
"clean-symlinks": "./build/clean-symlinks.sh"
"clean-symlinks": "node build/clean-symlinks.js",
"dev-setup": "node build/dev-setup.js"
},
"author": "",
"license": "Apache-2.0",
Expand Down Expand Up @@ -109,15 +110,14 @@
"@types/node": "^13.11.1",
"@types/request": "^2.48.4",
"acorn": "^7.1.1",
"adm-zip": "^0.4.16",
"browserstack-local": "^1.4.5",
"codecov": "^3.7.1",
"codelyzer": "^5.1.2",
"copy-webpack-plugin": "5.1.1",
"delete": "^1.1.0",
"fs-extra": "^9.0.0",
"globby": "^11.0.0",
"gulp": "^4.0.2",
"gulp-zip": "^5.0.1",
"istanbul": "^0.4.5",
"istanbul-api": "2.1.6",
"istanbul-reports": "3.0.2",
Expand All @@ -143,7 +143,6 @@
"protractor": "^5.4.3",
"ps-node": "^0.1.6",
"q": "^1.4.1",
"replace-in-file": "^5.0.2",
"request": "^2.88.2",
"request-promise-native": "^1.0.8",
"rxjs-tslint": "^0.1.8",
Expand Down
27 changes: 27 additions & 0 deletions src/frontend/packages/devkit/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copy extra files needed as part of the devkit build
// Implemented as a single script here so that it works on Windows, Linux and Mac

const path = require('path');
const fs = require('fs-extra');

console.log('Copying devkit files');

// __dirname is the folder where build.js is located
const STRATOS_DIR= path.resolve(__dirname, '..', '..', '..', '..');
const DEVKIT_DIST_DIR= path.join(STRATOS_DIR, 'dist-devkit');

let err = fs.copySync(path.join(__dirname, 'package.json'), path.join(DEVKIT_DIST_DIR, 'package.json'));
if (err) {
console.log(err);
}
err =fs.copySync(path.join(__dirname, 'src'), path.join(DEVKIT_DIST_DIR), {
overwrite: true,
dereference: true,
preserveTimestamps: true,
filter: function(file) {
return !file.endsWith('.ts');
}
});
if (err) {
console.log(err);
}
Loading