@ioffice/tc-builder
Advanced tools
Comparing version 1.0.0-beta.1803261620 to 1.0.0-beta.1803281537
import { TCBuilder, resolution } from './TCBuilder'; | ||
import { compile, compileProject } from './Compiler'; | ||
import { move, changePackageVersion, readJSON } from './Util'; | ||
import { move, replaceStrings, changePackageVersion, readJSON } from './Util'; | ||
import { formatResults } from './Formatter'; | ||
export { resolution, TCBuilder, compile, compileProject, move, changePackageVersion, readJSON, formatResults }; | ||
export { resolution, TCBuilder, compile, compileProject, move, replaceStrings, changePackageVersion, readJSON, formatResults }; |
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.move = Util_1.move; | ||
exports.replaceStrings = Util_1.replaceStrings; | ||
exports.changePackageVersion = Util_1.changePackageVersion; | ||
@@ -12,0 +13,0 @@ exports.readJSON = Util_1.readJSON; |
{ | ||
"name": "@ioffice/tc-builder", | ||
"version": "1.0.0-beta.1803261620", | ||
"version": "1.0.0-beta.1803281537", | ||
"description": "iOFFICE TeamCity Builder", | ||
@@ -41,2 +41,6 @@ "main": "index.js", | ||
}, | ||
"peerDependencies": { | ||
"tslib": "1.9.0", | ||
"tslint": "5.9.1" | ||
}, | ||
"publishConfig": { | ||
@@ -43,0 +47,0 @@ "registry": "https://registry.npmjs.com" |
@@ -1,2 +0,2 @@ | ||
declare function setupFiles(pkgName: string): void; | ||
declare function setupFiles(pkgName: string, fileName?: string): void; | ||
export { setupFiles }; |
77
Setup.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var utils_1 = require("tslint/lib/utils"); | ||
var fs = require("fs"); | ||
function setupFiles(pkgName) { | ||
var path = require("path"); | ||
var Util_1 = require("./Util"); | ||
var rel = function (x) { return path.resolve(__dirname, x); }; | ||
function safeMkDir(directory) { | ||
if (!fs.existsSync(directory)) { | ||
fs.mkdirSync(directory); | ||
} | ||
} | ||
function getFileContents(fileName, replacements) { | ||
var contents = fs.readFileSync(rel("./projectFiles/" + fileName), 'r'); | ||
return Util_1.replaceStrings(contents, replacements); | ||
} | ||
function verifySourceDirectory() { | ||
var files = ['src/main/index.ts', 'src/test/index.ts']; | ||
safeMkDir('src'); | ||
safeMkDir('src/main'); | ||
safeMkDir('src/test'); | ||
Object.keys(files).forEach(function (fileName) { | ||
if (fs.existsSync(fileName)) { | ||
console.log('[SKIP]: ', fileName); | ||
} | ||
else { | ||
console.log('[WRITING]: ', fileName); | ||
fs.writeFileSync(fileName, '\n'); | ||
} | ||
}); | ||
} | ||
function setupFiles(pkgName, fileName) { | ||
var _a = pkgName.split('/'), repoName = _a[1]; | ||
var files = { | ||
'CHANGELOG.md': utils_1.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n # Change Log\n\n ## [0.0.1] - Date of release\n\n Description\n\n [0.0.1]: https://github.com/ioffice/", "/compare/<hash/tag>...0.0.1\n "], ["\n # Change Log\n\n ## [0.0.1] - Date of release\n\n Description\n\n [0.0.1]: https://github.com/ioffice/", "/compare/<hash/tag>...0.0.1\n "])), repoName), | ||
'.editorconfig': utils_1.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n ## ", " EDITORCONFIG ##\n\n\n ### TOP MOST EDITORCONFIG FILE ###\n root = true\n\n\n ### DEFAULT GLOBAL SETTINGS FOR ALL FILES ###\n [*]\n charset = utf-8\n trim_trailing_whitespace = true\n insert_final_newline = true\n end_of_line = lf\n indent_style = space\n indent_size = 2\n\n\n ### MAKEFILE ###\n [Makefile]\n indent_style = tab\n "], ["\n ## ", " EDITORCONFIG ##\n\n\n ### TOP MOST EDITORCONFIG FILE ###\n root = true\n\n\n ### DEFAULT GLOBAL SETTINGS FOR ALL FILES ###\n [*]\n charset = utf-8\n trim_trailing_whitespace = true\n insert_final_newline = true\n end_of_line = lf\n indent_style = space\n indent_size = 2\n\n\n ### MAKEFILE ###\n [Makefile]\n indent_style = tab\n "])), pkgName.toLocaleUpperCase()), | ||
'.gitignore': utils_1.dedent(templateObject_3 || (templateObject_3 = tslib_1.__makeTemplateObject(["\n .idea\n build/\n docs/\n node_modules/\n src/**/*.js\n version.json\n "], ["\n .idea\n build/\n docs/\n node_modules/\n src/**/*.js\n version.json\n "]))), | ||
'.npmignore': utils_1.dedent(templateObject_4 || (templateObject_4 = tslib_1.__makeTemplateObject(["\n .idea\n build\n node_modules\n src\n .editorconfig\n .gitignore\n .npmignore\n Makefile\n tsconfig.json\n tslint.json\n CHANGELOG.md\n version.json\n *.build.cmd\n "], ["\n .idea\n build\n node_modules\n src\n .editorconfig\n .gitignore\n .npmignore\n Makefile\n tsconfig.json\n tslint.json\n CHANGELOG.md\n version.json\n *.build.cmd\n "]))), | ||
'Makefile': utils_1.dedent(templateObject_5 || (templateObject_5 = tslib_1.__makeTemplateObject(["\n ## Tasks\n\n test: tcBuild\n\n preRelease: build\n PRERELEASE=true tc-builder run\n\n tcBuild: info build\n tc-builder run\n\n docs: FORCE\n cd src; ../node_modules/.bin/typedoc --out ../docs main --target es6 --ignoreCompilerErrors --mode modules --module commonjs --hideGenerator --excludePrivate --name '", " $(VERSION)'\n\n serveDocs:\n cd docs; python -m SimpleHTTPServer 8000\n\n ## Dependencies\n\n build: FORCE\n tc-builder build\n\n clean:\n rm -rf build\n\n info:\n node --version\n npm --version\n tsc --version\n typedoc --version\n\n FORCE:\n "], ["\n ## Tasks\n\n test: tcBuild\n\n preRelease: build\n PRERELEASE=true tc-builder run\n\n tcBuild: info build\n tc-builder run\n\n docs: FORCE\n cd src; ../node_modules/.bin/typedoc --out ../docs main --target es6 --ignoreCompilerErrors --mode modules --module commonjs --hideGenerator --excludePrivate --name '", " $(VERSION)'\n\n serveDocs:\n cd docs; python -m SimpleHTTPServer 8000\n\n ## Dependencies\n\n build: FORCE\n tc-builder build\n\n clean:\n rm -rf build\n\n info:\n node --version\n npm --version\n tsc --version\n typedoc --version\n\n FORCE:\n "])), pkgName), | ||
'tsconfig.json': utils_1.dedent(templateObject_6 || (templateObject_6 = tslib_1.__makeTemplateObject(["\n {\n \"compilerOptions\": {\n \"skipDefaultLibCheck\": true,\n \"skipLibCheck\": true,\n \"noImplicitAny\": true,\n \"suppressImplicitAnyIndexErrors\": true,\n \"strictNullChecks\": true,\n \"strictPropertyInitialization\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"emitDecoratorMetadata\": true,\n \"experimentalDecorators\": true,\n \"noEmitHelpers\": true,\n \"importHelpers\": true,\n \"target\": \"es5\",\n \"declaration\": true,\n \"noEmit\": false,\n \"outDir\": \"./build\"\n },\n \"files\": [\n \"src/main/index.ts\",\n \"src/test/index.ts\",\n ],\n \"exclude\": [\n \"build\",\n \"node_modules\"\n ]\n }\n "], ["\n {\n \"compilerOptions\": {\n \"skipDefaultLibCheck\": true,\n \"skipLibCheck\": true,\n \"noImplicitAny\": true,\n \"suppressImplicitAnyIndexErrors\": true,\n \"strictNullChecks\": true,\n \"strictPropertyInitialization\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"emitDecoratorMetadata\": true,\n \"experimentalDecorators\": true,\n \"noEmitHelpers\": true,\n \"importHelpers\": true,\n \"target\": \"es5\",\n \"declaration\": true,\n \"noEmit\": false,\n \"outDir\": \"./build\"\n },\n \"files\": [\n \"src/main/index.ts\",\n \"src/test/index.ts\",\n ],\n \"exclude\": [\n \"build\",\n \"node_modules\"\n ]\n }\n "]))), | ||
'tslint.json': utils_1.dedent(templateObject_7 || (templateObject_7 = tslib_1.__makeTemplateObject(["\n {\n \"rulesDirectory\": [\n \"node_modules/tslint-eslint-rules/dist/rules\"\n ],\n \"rules\": {\n \"array-bracket-spacing\": [\n true,\n \"never\"\n ],\n \"no-trailing-whitespace\": true,\n \"class-name\": true,\n \"brace-style\": [true, \"1tbs\", {\n \"allowSingleLine\": false\n }],\n \"block-spacing\": [true],\n \"ter-prefer-arrow-callback\": [true, {\n \"allowNamedFunctions\": true,\n \"allowUnboundThis\": false\n }],\n \"object-curly-spacing\": [\n true,\n \"always\"\n ]\n }\n }\n "], ["\n {\n \"rulesDirectory\": [\n \"node_modules/tslint-eslint-rules/dist/rules\"\n ],\n \"rules\": {\n \"array-bracket-spacing\": [\n true,\n \"never\"\n ],\n \"no-trailing-whitespace\": true,\n \"class-name\": true,\n \"brace-style\": [true, \"1tbs\", {\n \"allowSingleLine\": false\n }],\n \"block-spacing\": [true],\n \"ter-prefer-arrow-callback\": [true, {\n \"allowNamedFunctions\": true,\n \"allowUnboundThis\": false\n }],\n \"object-curly-spacing\": [\n true,\n \"always\"\n ]\n }\n }\n "]))), | ||
'src/main/index.ts': '\n', | ||
'src/test/index.ts': '\n', | ||
var replacements = { | ||
pkgName: pkgName, | ||
repoName: repoName, | ||
upperCasePkgName: pkgName.toLocaleUpperCase(), | ||
}; | ||
if (!fs.existsSync('src')) { | ||
fs.mkdirSync('src'); | ||
var projectFiles = [ | ||
'CONTRIBUTING.md', | ||
'CHANGELOG.md', | ||
'.editorconfig', | ||
'gitignore', | ||
'.npmignore', | ||
'Makefile', | ||
'tsconfig.json', | ||
'tslint.json', | ||
]; | ||
if (fileName) { | ||
if (projectFiles.indexOf(fileName) === -1) { | ||
console.log('[ERROR]: invalid file ', fileName); | ||
} | ||
else { | ||
console.log(getFileContents(fileName, replacements)); | ||
} | ||
return; | ||
} | ||
if (!fs.existsSync('src/main')) { | ||
fs.mkdirSync('src/main'); | ||
} | ||
if (!fs.existsSync('src/test')) { | ||
fs.mkdirSync('src/test'); | ||
} | ||
Object.keys(files).forEach(function (fileName) { | ||
var contents = files[fileName].split('\n').slice(1).join('\n'); | ||
Object.keys(projectFiles).forEach(function (fileName) { | ||
var contents = getFileContents(fileName, replacements); | ||
if (fs.existsSync(fileName)) { | ||
@@ -38,4 +67,4 @@ console.log('[SKIP]: ', fileName); | ||
}); | ||
verifySourceDirectory(); | ||
} | ||
exports.setupFiles = setupFiles; | ||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7; |
@@ -8,3 +8,3 @@ #!/usr/bin/env node | ||
var commands = ['setup', 'compile', 'run']; | ||
var options = ['--no-lint', '--verbose', '--help', '-h', '--version', '-v']; | ||
var options = ['--no-lint', '--verbose', '--help', '-h', '--version', '-v', '-f']; | ||
var _a = commands.map(function (x) { return process.argv.indexOf(x) > -1; }), setup = _a[0], compile = _a[1], run = _a[2]; | ||
@@ -14,3 +14,3 @@ var _b = options.map(function (x) { return process.argv.indexOf(x) > -1; }), noLint = _b[0], verbose = _b[1], help = _b[2], h = _b[3], version = _b[4], v = _b[5]; | ||
var pkgVersion = pkg['version']; | ||
var usage = "usage: tc-builder <command> [--options]\n\nThe following commands are supported:\n\n - setup: Installs all the same dependencies as the ones in the tc-builder and creates\n configuration files if they do not exists. This command should be run when starting\n a new project or updating tc-builder.\n - compile: Looks at the 'tsconfig.json' file to compile the project. By default it will also\n lint the files unless we use the '--no-lint' option.\n - run: Main command to be run in team city. It will make sure to run all the tests and publish\n to npm if necessary.\n\nOptions:\n\n --no-lint: Skip linting.\n --verbose: Print messages of the steps for the 'compile' command.\n --help, -h: Print this message.\n --version, -v: Print the version.\n\ntc-builder@" + pkgVersion + "\n"; | ||
var usage = "usage: tc-builder <command> [--options]\n\nThe following commands are supported:\n\n - setup: Installs all the same dependencies as the ones in the tc-builder and creates\n configuration files if they do not exists. This command should be run when starting\n a new project or updating tc-builder.\n\n If there are any new updates to the configuration files and you wish to see them you\n can provide the name of the file right after the command.\n - compile: Looks at the 'tsconfig.json' file to compile the project. By default it will also\n lint the files unless we use the '--no-lint' option.\n - run: Main command to be run in team city. It will make sure to run all the tests and publish\n to npm if necessary.\n\nOptions:\n\n --no-lint: Skip linting.\n --verbose: Print messages of the steps for the 'compile' command.\n --help, -h: Print this message.\n --version, -v: Print the version.\n\ntc-builder@" + pkgVersion + "\n"; | ||
var exitNumber = 0; | ||
@@ -30,8 +30,14 @@ if (help || h) { | ||
if (projectPkg) { | ||
var devDeps_1 = pkg['devDependencies']; | ||
var depsArray = Object.keys(devDeps_1).map(function (x) { return x + "@" + devDeps_1[x]; }); | ||
var cmd = "npm i -D " + depsArray.join(' '); | ||
console.log('Running: ', cmd); | ||
child_process_1.execSync(cmd); | ||
Setup_1.setupFiles(projectPkg['name']); | ||
var fileName = process.argv[process.argv.indexOf('setup') + 1]; | ||
if (fileName) { | ||
Setup_1.setupFiles(projectPkg['name'], fileName); | ||
} | ||
else { | ||
var devDeps_1 = pkg['devDependencies']; | ||
var depsArray = Object.keys(devDeps_1).map(function (x) { return x + "@" + devDeps_1[x]; }); | ||
var cmd = "npm i -D " + depsArray.join(' '); | ||
console.log('Running: ', cmd); | ||
child_process_1.execSync(cmd); | ||
Setup_1.setupFiles(projectPkg['name']); | ||
} | ||
} | ||
@@ -38,0 +44,0 @@ else { |
@@ -12,2 +12,6 @@ declare function changePackageVersion(version: string): void; | ||
declare function readJSON(name: string, path?: string): object | null; | ||
export { move, changePackageVersion, readJSON }; | ||
/** | ||
* Quick dirty function to replace strings with a certain format. | ||
*/ | ||
declare function replaceStrings(template: string, properties: object): string; | ||
export { move, changePackageVersion, readJSON, replaceStrings }; |
12
Util.js
@@ -84,1 +84,13 @@ "use strict"; | ||
exports.readJSON = readJSON; | ||
/** | ||
* Quick dirty function to replace strings with a certain format. | ||
*/ | ||
function replaceStrings(template, properties) { | ||
var result = template; | ||
Object.keys(properties).forEach(function (key) { | ||
var reg = new RegExp("%{" + key + "}", 'g'); | ||
result = result.replace(reg, properties[key]); | ||
}); | ||
return result; | ||
} | ||
exports.replaceStrings = replaceStrings; |
19
1234
49276
2