-
Notifications
You must be signed in to change notification settings - Fork 472
Add tsfmt support for maven #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed9612b
0e429a5
bb72ebd
ae05010
588990a
e973a2e
2ebe163
6a71794
588aa43
528e708
811c661
90a1870
8783bc6
a82b418
7a897fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.maven.typescript; | ||
|
||
import java.io.File; | ||
import java.util.Map; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
import com.diffplug.spotless.npm.TsConfigFileType; | ||
import com.diffplug.spotless.npm.TsFmtFormatterStep; | ||
import com.diffplug.spotless.npm.TypedTsFmtConfigFile; | ||
|
||
public class Tsfmt implements FormatterStepFactory { | ||
|
||
@Parameter | ||
private String tslintFile; | ||
|
||
@Parameter | ||
private String tsconfigFile; | ||
|
||
@Parameter | ||
private String vscodeFile; | ||
|
||
@Parameter | ||
private String tsfmtFile; | ||
|
||
@Parameter | ||
private String typescriptFormatterVersion; | ||
|
||
@Parameter | ||
private String typescriptVersion; | ||
|
||
@Parameter | ||
private String tslintVersion; | ||
|
||
@Parameter | ||
private String npmExecutable; | ||
|
||
@Parameter | ||
private Map<String, Object> config; | ||
|
||
@Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true) | ||
private File buildDir; | ||
|
||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { | ||
|
||
Map<String, String> devDependencies = TsFmtFormatterStep.defaultDevDependencies(); | ||
if (typescriptFormatterVersion != null) { | ||
devDependencies.put("typescript-formatter", typescriptFormatterVersion); | ||
} | ||
if (typescriptVersion != null) { | ||
devDependencies.put("typescript", typescriptVersion); | ||
} | ||
if (tslintVersion != null) { | ||
devDependencies.put("tslint", tslintVersion); | ||
} | ||
|
||
File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; | ||
|
||
TypedTsFmtConfigFile configFile = null; | ||
|
||
// check that there is only 1 config file or inline config | ||
if (this.tsconfigFile != null | ||
^ this.tsfmtFile != null | ||
^ this.tslintFile != null | ||
^ this.vscodeFile != null) { | ||
if (this.tsconfigFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSCONFIG, stepConfig.getFileLocator().locateFile(tsconfigFile)); | ||
} else if (this.tsfmtFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSFMT, stepConfig.getFileLocator().locateFile(tsfmtFile)); | ||
} else if (this.tslintFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSLINT, stepConfig.getFileLocator().locateFile(tslintFile)); | ||
} else if (this.vscodeFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.VSCODE, stepConfig.getFileLocator().locateFile(vscodeFile)); | ||
} | ||
} else { | ||
if (config == null) { | ||
throw new IllegalArgumentException("must specify exactly one configFile or config"); | ||
} | ||
} | ||
|
||
if (buildDir == null) { | ||
buildDir = new File(stepConfig.getBaseDir(), "build-dir"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... because if it was, this wouldn't be necessary. I think part of what might be happening is that new File(".") is not resolving to where we suspect it to be. We could modify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I tried this below and it is still not working. |
||
return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), buildDir, npm, configFile, config); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.maven.typescript; | ||
|
||
import java.util.Set; | ||
|
||
import com.diffplug.common.collect.ImmutableSet; | ||
import com.diffplug.spotless.maven.FormatterFactory; | ||
|
||
/** | ||
* A {@link FormatterFactory} implementation that corresponds to {@code <typescript>...</typescript>} configuration element. | ||
* <p> | ||
* It defines a formatter for typescript source files. | ||
*/ | ||
public class Typescript extends FormatterFactory { | ||
|
||
private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/**/*.ts"); | ||
|
||
private static final String LICENSE_HEADER_DELIMITER = null; | ||
|
||
@Override | ||
public Set<String> defaultIncludes() { | ||
return DEFAULT_INCLUDES; | ||
} | ||
|
||
@Override | ||
public String licenseHeaderDelimiter() { | ||
return LICENSE_HEADER_DELIMITER; | ||
} | ||
|
||
public void addTsfmt(Tsfmt tsfmt) { | ||
addStepFactory(tsfmt); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default seems to not be effective...