generated from T99/ts-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 08422ae
Showing
20 changed files
with
1,319 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This folder contains definition files for this project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.