Skip to content
Open
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 4
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ Yes, that´s it, really!


Say bye bye to the relative path hell!

#### Options

| Arg | Type | Description | Default |
|--------|------|-------------|---------|
| `-f` | `boolean` | `optional` - skip the confirmation prompt displayed before `tspath` parses the project (e.g. `tspath -f`) | `false` |
| `-c` | `boolean` | `optional` - do not include superfluous whitespace characters and line terminators (e.g. `tspath -c`) | `false` |

#### Skipping files

To skip any file in your project, include the following comment anywhere in the file to skip:

// tspath:skip-file
23 changes: 16 additions & 7 deletions dist/src/parser-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const json_comment_stripper_1 = require("./json-comment-stripper");
const project_options_1 = require("./project-options");
const type_definitions_1 = require("./type-definitions");
const type_definitions_2 = require("./type-definitions");
const tspath_1 = require("./tspath");
const log = console.log;
class ParserEngine {
constructor() {
Expand Down Expand Up @@ -95,19 +96,21 @@ class ParserEngine {
else {
log(chalk.yellow.bold("Parsing project at: ") + '"' + this.projectPath + '"');
}
this.appRoot = path.resolve(this.projectPath, this.projectOptions.baseUrl);
this.appRoot = path.resolve(this.appRoot, this.projectOptions.outDir);
this.appRoot = path.resolve(this.projectPath, this.projectOptions.outDir);
let fileList = new Array();
this.walkSync(this.appRoot, fileList, ".js");
for (var i = 0; i < fileList.length; i++) {
let filename = fileList[i];
this.processFile(filename);
}
for (var i = 0; i < fileList.length; i++)
if (!this.shouldSkipFile(fileList[i]))
this.processFile(fileList[i]);
log(chalk.bold("Total files processed:"), this.nrFilesProcessed);
log(chalk.bold("Total paths processed:"), this.nrPathsProcessed);
console.timeEnd(PROCESS_TIME);
log(chalk.bold.green("Project is prepared, now run it normally!"));
}
shouldSkipFile(filename) {
const contents = fs.readFileSync(filename, 'utf8');
return contents.includes('tspath:skip-file');
}
/**
*
* @param sourceFilename
Expand All @@ -125,6 +128,10 @@ class ParserEngine {
var result = jsRequire.replace(alias, mapping);
utils_1.Utils.replaceDoubleSlashes(result);
var absoluteJsRequire = path.join(this.appRoot, result);
if (!fs.existsSync(`${absoluteJsRequire}.js`)) {
var newResult = jsRequire.replace(alias, '');
absoluteJsRequire = path.join(this.appRoot, newResult);
}
var sourceDir = path.dirname(sourceFilename);
let relativePath = path.relative(sourceDir, absoluteJsRequire);
/* If the path does not start with .. it´ not a sub directory
Expand Down Expand Up @@ -179,7 +186,9 @@ class ParserEngine {
node.arguments[0] = scope.processJsRequire(node.arguments[0], filename);
}
});
let option = { comment: true, format: { compact: true, quotes: '"' } };
let option = { comment: true };
if (tspath_1.TSPath.parseCommandLineParam("-c"))
option['format'] = { compact: true, quotes: '"' };
let finalSource = escodegen.generate(ast, option);
try {
this.saveFileContents(filename, finalSource);
Expand Down
2 changes: 1 addition & 1 deletion dist/src/tspath.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export declare class TSPath {
private engine;
constructor();
private processPath(projectPath);
parseCommandLineParam(): string;
static parseCommandLineParam(id: string): string;
}
16 changes: 10 additions & 6 deletions dist/src/tspath.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class TSPath {
constructor() {
this.engine = new parser_engine_1.ParserEngine();
log(chalk.yellow("TSPath " + pkg.version));
let args = process.argv.slice(2);
let param = args[0];
let param = TSPath.parseCommandLineParam("-f");
let projectPath = process.cwd();
let findResult = parent_file_finder_1.ParentFileFinder.findFile(projectPath, type_definitions_1.TS_CONFIG);
var scope = this;
if (param == "-f" && findResult.fileFound) {
if (param && findResult.fileFound) {
scope.processPath(findResult.path);
}
else if (findResult.fileFound) {
Expand All @@ -39,12 +38,17 @@ class TSPath {
this.engine.execute();
}
}
parseCommandLineParam() {
static parseCommandLineParam(id) {
let args = process.argv.slice(2);
var param = null;
if (args.length != 1) {
param = args[0];
const argsLen = args.length;
let counter = 0;
while (param === null && counter < argsLen) {
if (args[counter] === id)
param = args[counter];
counter++;
}
;
return param;
}
}
Expand Down
Loading