<commit_before>#!/usr/bin/env sh

# ------------------------------------------------------
#
#   Creates a basic NPM module with the UIHarness
#   and startup script installed.
#
#   A great starting point for an isolated set of React
#   components either for your application or published
#   as a library on NPM.
#
#   Are you looking at this in your web browser and would
#   like to create a module with a UIHarness?
#
#   Open your terminal and run:
#
#       curl -L http://j.mp/ui-harness | sh
#
# ------------------------------------------------------

# Get the current version of Node.
NODE_VERSION=$(node --version)
NODE_VERSION=${NODE_VERSION:1} # Remove the "v" prefix (eg. "v0.0.1" => "0.0.1").

GREEN='\033[0;32m'
CYAN='\033[0;36m'
RED='\033[0;31m'
LIGHT_GREY='\033[0;37m'
PURPLE='\033[0;35m'
NC='\033[0m' # No Color.


#
#   NOTE: This is run within a function to ensure the entire
#   script is fully downloaded before execution starts.
#
function createModule() {

#
# Ensure the correct version of node is installed.
#
semverGT "4.0.0" $NODE_VERSION
if [ $? -eq 0 ]; then
  echo ""
  echo "Please ensure you have Node (version >= 4.0.0) installed."
  echo ""
  exit -1
fi


# Prompt for name of the module:
echo "${PURPLE}Please enter the name of your module/directory:${NC}"
read MODULE_NAME < /dev/tty
if [ -z "$MODULE_NAME" ]; then
  echo "${RED}Sorry, a module name is required.${NC}"
  echo ""
  exit -1
fi
if [ ! -d "$MODULE_NAME" ]; then
  mkdir $MODULE_NAME
fi
cd $MODULE_NAME


#
# Module already exists.
#
if [ -f ./package.json ]; then
  echo ""
  echo "Ooops, the folder '${MODULE_NAME}' is already an NPM module."
  echo "Instead run:"
  echo ""
  echo "     ${CYAN}npm start${NC}"
  echo ""
  exit -1
fi

echo ""
echo "Creating a new UI component module named '${MODULE_NAME}'."


#
# Create [package.json] file.
#
cat > "package.json" <<- EOM
{
  "name": "${MODULE_NAME}",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node ./node_modules/ui-harness/server --entry ./src/specs"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
EOM

cat > ".gitignore" <<- EOM
.DS_Store
lib
node_modules
npm-debug.log
EOM



#
# Install the `ui-harness` module.
#
echo "${LIGHT_GREY}Running NPM install... (this may take a moment as Babel gets built)${NC}"
npm install ui-harness --saveDev --loglevel error >&-



echo ""
echo "+|-------------------------------------------------------"
echo "   Module created and initialized successfully."
echo "   Automaticaly starting the server now using:"
echo ""
echo "      ${CYAN}npm start${NC}"
echo ""
echo "   Open your browser at ${GREEN}http://localhost:3030${NC}"
echo "-|-------------------------------------------------------"

#
# Start the server.
#
npm start
}







# ---------------------------------------------------------------------------------
# Semantic version checking:
# Source: https://github.com/cloudflare/semver_bash
# ---------------------------------------------------------------------------------
# Copyright (c) 2013, <NAME><commit_msg>--save-dev<commit_after>#!/usr/bin/env sh

# ------------------------------------------------------
#
#   Creates a basic NPM module with the UIHarness
#   and startup script installed.
#
#   A great starting point for an isolated set of React
#   components either for your application or published
#   as a library on NPM.
#
#   Are you looking at this in your web browser and would
#   like to create a module with a UIHarness?
#
#   Open your terminal and run:
#
#       curl -L http://j.mp/ui-harness | sh
#
# ------------------------------------------------------

# Get the current version of Node.
NODE_VERSION=$(node --version)
NODE_VERSION=${NODE_VERSION:1} # Remove the "v" prefix (eg. "v0.0.1" => "0.0.1").

GREEN='\033[0;32m'
CYAN='\033[0;36m'
RED='\033[0;31m'
LIGHT_GREY='\033[0;37m'
PURPLE='\033[0;35m'
NC='\033[0m' # No Color.


#
#   NOTE: This is run within a function to ensure the entire
#   script is fully downloaded before execution starts.
#
function createModule() {

#
# Ensure the correct version of node is installed.
#
semverGT "4.0.0" $NODE_VERSION
if [ $? -eq 0 ]; then
  echo ""
  echo "Please ensure you have Node (version >= 4.0.0) installed."
  echo ""
  exit -1
fi


# Prompt for name of the module:
echo "${PURPLE}Please enter the name of your module/directory:${NC}"
read MODULE_NAME < /dev/tty
if [ -z "$MODULE_NAME" ]; then
  echo "${RED}Sorry, a module name is required.${NC}"
  echo ""
  exit -1
fi
if [ ! -d "$MODULE_NAME" ]; then
  mkdir $MODULE_NAME
fi
cd $MODULE_NAME


#
# Module already exists.
#
if [ -f ./package.json ]; then
  echo ""
  echo "Ooops, the folder '${MODULE_NAME}' is already an NPM module."
  echo "Instead run:"
  echo ""
  echo "     ${CYAN}npm start${NC}"
  echo ""
  exit -1
fi

echo ""
echo "Creating a new UI component module named '${MODULE_NAME}'."


#
# Create [package.json] file.
#
cat > "package.json" <<- EOM
{
  "name": "${MODULE_NAME}",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node ./node_modules/ui-harness/server --entry ./src/specs"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
EOM

cat > ".gitignore" <<- EOM
.DS_Store
lib
node_modules
npm-debug.log
EOM



#
# Install the `ui-harness` module.
#
echo "${LIGHT_GREY}Running NPM install... (this may take a moment as Babel gets built)${NC}"
npm install ui-harness --save-dev --loglevel error >&-



echo ""
echo "+|-------------------------------------------------------"
echo "   Module created and initialized successfully."
echo "   Automaticaly starting the server now using:"
echo ""
echo "      ${CYAN}npm start${NC}"
echo ""
echo "   Open your browser at ${GREEN}http://localhost:3030${NC}"
echo "-|-------------------------------------------------------"

#
# Start the server.
#
npm start
}







# ---------------------------------------------------------------------------------
# Semantic version checking:
# Source: https://github.com/cloudflare/semver_bash
# ---------------------------------------------------------------------------------
# Copyright (c) 2013, <NAME>
{'fraction_non_alphanumeric': 0.25988334413480235, 'fraction_numerical': 0.020090732339598186, 'mean_word_length': 2.075734927752865, 'pattern_counts': {'":': 18, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1399245', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1935, 'n_words': 625}