Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
T99 committed Oct 2, 2019
0 parents commit 08422ae
Show file tree
Hide file tree
Showing 20 changed files with 1,319 additions and 0 deletions.
Empty file added .d.ts/main.d.ts
Empty file.
1 change: 1 addition & 0 deletions .d.ts/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder contains definition files for this project.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
js/* linguist-vendored
ts/tests/coverage/* linguist-vendored
gulpfile.js linguist-vendored
jest.config.js linguist-vendored
package.json linguist-vendored
package-lock.json linguist-vendored
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
node_modules/
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea
.d.ts/tests
js/tests
ts/tests
ts/tsconfig.json
ts/tslint.json
.gitattributes
.gitignore
.npmignore
gulpfile.js
jest.config.js
134 changes: 134 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Created by Trevor Sears <[email protected]>.
* 8:48 PM -- June 16th, 2019.
* Project: <name>
*/

const gulp = require("gulp");
const typescript = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const uglify = require("gulp-uglify-es").default;
const del = require("del");

const paths = {

typescript: {

dir: "ts/",
allFiles: "ts/**/*.ts",
tsconfig: "ts/tsconfig.json"

},

javascript: {

dir: "js/",
allFiles: "js/**/*.js",
entryPoint: "js/main.js",
entryPointFileName: "main.js"

},

typedefs: {

dir: ".d.ts/",
allFiles: ".d.ts/**/*.d.ts"

}

};

let typescriptProject = typescript.createProject(paths.typescript.tsconfig);

// The default Gulp task.
gulp.task("default", defaultTask);

// Cleans (deletes) all generated/compiled files.
gulp.task("clean", clean);

// Builds the entire project.
gulp.task("build", build);

// Cleans and builds the entire project.
gulp.task("rebuild", rebuild);

// Watch for changes to relevant files and compile-on-change.
gulp.task("watch", watch);

function defaultTask(done) {

return rebuild(done);

}

function clean(done) {

return del([
paths.javascript.dir,
paths.typedefs.dir
]);

}

function build(done) {

return buildJavaScriptPipeline(done);

}

function rebuild(done) {

gulp.series(clean, build)(done);

}

function buildJavaScriptPipeline(done) {

return gulp.series(
compileTypeScript,
uglifyJavaScript
)(done);

}

function compileTypeScript(done) {

let proj =
typescriptProject.src()
.pipe(sourcemaps.init())
.pipe(typescriptProject());

let compileJS = (done) => {

return proj.js
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(paths.javascript.dir));

};

let compileDTS = (done) => {

return proj.dts
.pipe(gulp.dest(paths.typedefs.dir));

};

return gulp.parallel(compileJS, compileDTS)(done);

}

function uglifyJavaScript(done) {

return gulp.src(paths.javascript.allFiles)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(paths.javascript.dir));

}

function watch(done) {

gulp.watch([paths.typescript.allFiles], buildJavaScriptPipeline);

}
83 changes: 83 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

# Print start message.
echo "Running js-module-template initialization script..."

# Prompt for relevant package information to find-and-replace template placeholder strings.
read -p " Package name: " packageName
read -p " Package description: " packageDesc
read -p " GitHub org: " gitHubOrg
read -p " NPM org: " npmOrg
read -p " readme title: " readmeTitle

# Print a spacer line.
echo ""

# If the GitHub organization name was left blank, assume the package belongs to T99.
if [[ -z $gitHubOrg ]]; then

gitHubOrg="T99"

fi

# Derive the full package name from the NPM organization and base package name.
if [[ -z $npmOrg ]]; then

fullPackageName="${packageName}"

else

fullPackageName=$(echo -n "@${npmOrg}/${packageName}")

fi

# If there was no readme title provided, use the package name.
if [[ -z $readmeTitle ]]; then

readmeTitle="${packageName}"

fi

# Delete the template repository's readme file and move the templatized one to the proper location.
echo -n " Deleting placeholder readme and moving templatized readme into place... "
rm readme.md
mv readme.md.template readme.md
echo "DONE"

# Modify template files to use correct package information.
echo -n " Modifying template files to use correct package information... "

files=("ts/main.ts" "gulpfile.js" "license.md" "package.json" "readme.md")

for file in "${files[*]}"; do

sed -i "s_<name>_${fullPackageName}_g" ${file} > /dev/null 2>&1
sed -i "s/<desc>/$packageDesc/g" ${file} > /dev/null 2>&1
sed -i "s/<title>/$readmeTitle/g" ${file} > /dev/null 2>&1
sed -i "s/<base_name>/$packageName/g" ${file} > /dev/null 2>&1
sed -i "s/<github_org>/$gitHubOrg/g" ${file} > /dev/null 2>&1

done

echo "DONE"

# Delete the readmes that were used to track otherwise-empty dirs.
echo -n " Removing placeholder readme files... "
rm ./.d.ts/readme.md ./js/readme.md ./ts/readme.md ./ts/tests/readme.md > /dev/null 2>&1
echo "DONE"

# Install the missing packages from our package.json file.
echo -n " Installing packages from package.json... "
npm install > /dev/null 2>&1
echo "DONE"

# Print an 'exiting' statement.
echo ""
echo " Exiting..."
echo ""

# Make the script remove itself.
rm -- "$0"

# Exit from the script.
exit 0
Loading

0 comments on commit 08422ae

Please sign in to comment.