Skip to content

Commit

Permalink
Merge pull request #14 from PolymerLabs/relative
Browse files Browse the repository at this point in the history
Interpret paths relative to config file, fix some tsc/npm issues, release v0.1.1
  • Loading branch information
aomarks authored May 5, 2020
2 parents ebdf0d4 + f97993d commit afbe5e1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 40 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- ## Unreleased -->

## 0.1.1

- Interpret paths as relative to the location of the config file, instead of
relative to the current working directory.

- Move `@types` packages from `dependencies` to `devDependencies` if they aren't
part of any API. In particular, this fixes an error where any package that depended
on `lit-localize` would need to add `DOM` to their TypeScript `lib` settings for
compatibility with `@types/xmldom`.

- Publish `.d.ts` files.

## 0.1.0

- Initial release of `lit-localize`.
51 changes: 28 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
"prepack": "npm run build"
},
"dependencies": {
"@types/jsonschema": "^1.1.1",
"@types/minimist": "^1.2.0",
"@types/node": "^13.13.4",
"@types/parse5": "^5.0.2",
"@types/xmldom": "^0.1.29",
"jsonschema": "^1.2.6",
"minimist": "^1.2.5",
"parse5": "^6.0.0",
Expand All @@ -40,6 +35,11 @@
"devDependencies": {
"@types/diff": "^4.0.2",
"@types/fs-extra": "^8.1.0",
"@types/jsonschema": "^1.1.1",
"@types/minimist": "^1.2.0",
"@types/node": "^13.13.4",
"@types/parse5": "^5.0.2",
"@types/xmldom": "^0.1.29",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"ava": "^3.8.1",
Expand Down
5 changes: 2 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {generateMsgModule, generateLocaleModule} from './module-generation';
import {generateXlb, parseXlb} from './xlb';
import {ProgramMessage} from './interfaces';
import {KnownError} from './error';
import {Config, readConfigFile, writeConfigSchemaIfMissing} from './config';
import {Config, readConfigFileAndWriteSchema} from './config';

require('source-map-support').install();

Expand Down Expand Up @@ -168,7 +168,6 @@ function configFromArgs(argv: string[]): Config {
throw new KnownError(usage);
}
const configPath = args['config'] || './lit-localize.json';
const config = readConfigFile(configPath);
writeConfigSchemaIfMissing(config, configPath);
const config = readConfigFileAndWriteSchema(configPath);
return config;
}
30 changes: 25 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import * as fs from 'fs';
import * as jsonSchema from 'jsonschema';
import * as pathLib from 'path';
import {Locale} from './locales';
import {KnownError} from './error';

Expand Down Expand Up @@ -81,10 +82,11 @@ export interface Patch {
}

/**
* Read a JSON config file from the given path, validate it, and return it.
* Throws if there was a problem reading, parsing, or validating.
* Read a JSON config file from the given path, validate it, and return it. Also
* adds a "$schema" property if missing. Throws if there was a problem reading,
* parsing, or validating.
*/
export function readConfigFile(configPath: string): Config {
export function readConfigFileAndWriteSchema(configPath: string): Config {
let str;
try {
str = fs.readFileSync(configPath, 'utf8');
Expand Down Expand Up @@ -113,7 +115,25 @@ export function readConfigFile(configPath: string): Config {
);
}

return parsed as Config;
const validated = parsed as Config;
writeConfigSchemaIfMissing(validated, configPath);

// Interpret paths as relative to the config file rather than the current
// working directory.
const configFileRelativePath = (path: string) =>
pathLib.relative(
process.cwd(),
pathLib.resolve(pathLib.dirname(configPath), path)
);

const config = {
...validated,
tsConfig: configFileRelativePath(validated.tsConfig),
xlbDir: configFileRelativePath(validated.xlbDir),
tsOut: configFileRelativePath(validated.tsOut),
};

return config;
}

/**
Expand All @@ -123,7 +143,7 @@ export function readConfigFile(configPath: string): Config {
* This $schema property allows editors like VSCode to provide validation and
* auto-completion for the config format.
*/
export function writeConfigSchemaIfMissing(config: Config, configPath: string) {
function writeConfigSchemaIfMissing(config: Config, configPath: string) {
if ('$schema' in config) {
return;
}
Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
"target": "es2018",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es2018", "DOM"],
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "src/",
"outDir": "lib/",
"declaration": true,
"sourceMap": true,
"incremental": true,
"tsBuildInfoFile": "lib/.tsbuildinfo"
},
"lib": [],
"include": ["src/**/*"],
"declaration": true,
"pretty": true
"include": ["src/**/*"]
}

0 comments on commit afbe5e1

Please sign in to comment.