Skip to content
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

Add more package goodies #75

Merged
merged 6 commits into from
Jun 19, 2020
Merged
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
5 changes: 5 additions & 0 deletions .changeset/loud-horses-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**template/package:** Drop module aliasing from `tsconfig.json`
5 changes: 5 additions & 0 deletions .changeset/stupid-apples-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': minor
---

**format, lint:** Enforce TSDoc syntax
3 changes: 3 additions & 0 deletions config/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
parserOptions: {
project: './tsconfig.json',
},
plugins: ['eslint-plugin-tsdoc'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-floating-promises': 'error',
Expand Down Expand Up @@ -69,6 +70,8 @@ module.exports = {
'jest/prefer-todo': 'error',
'jest/valid-title': 'error',

'tsdoc/syntax': 'error',

'no-use-before-define': 'off',
'sort-imports': [
'error',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"eslint": "^7.2.0",
"eslint-config-seek": "^7.0.1",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-tsdoc": "^0.2.5",
"execa": "^4.0.2",
"fs-extra": "^9.0.1",
"get-port": "^5.1.1",
Expand Down
7 changes: 4 additions & 3 deletions src/cli/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ export const init = async () => {
const processors = [createEjsRenderer(templateData)];

await copyFiles({
sourceRoot: destinationDir,
sourceRoot: BASE_TEMPLATE_DIR,
destinationRoot: destinationDir,
include,
// prefer template-specific files
overwrite: false,
processors,
});

// prefer skuba /template/base files
await copyFiles({
sourceRoot: BASE_TEMPLATE_DIR,
sourceRoot: destinationDir,
destinationRoot: destinationDir,
include,
processors,
Expand Down
17 changes: 14 additions & 3 deletions src/utils/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createInclusionFilter = async (gitIgnorePaths: string[]) => {
const copyFile = async (
sourcePath: string,
destinationPath: string,
processors: Array<TextProcessor>,
{ overwrite = true, processors }: CopyFilesOptions,
) => {
const oldContents = await fs.readFile(sourcePath, 'utf8');

Expand All @@ -47,14 +47,25 @@ const copyFile = async (
return;
}

await fs.writeFile(destinationPath, newContents);
try {
await fs.writeFile(destinationPath, newContents, {
flag: overwrite ? 'w' : 'wx',
});
} catch (err) {
if (isErrorWithCode(err, 'EEXIST')) {
return;
}

throw err;
}
};

interface CopyFilesOptions {
sourceRoot: string;
destinationRoot: string;

include: (pathname: string) => boolean;
overwrite?: boolean;
processors: Array<TextProcessor>;
}

Expand Down Expand Up @@ -95,7 +106,7 @@ export const copyFiles = async (
const destinationPath = toDestinationPath(filename);

try {
await copyFile(sourcePath, destinationPath, opts.processors);
await copyFile(sourcePath, destinationPath, opts);
} catch (err) {
if (isErrorWithCode(err, 'EISDIR')) {
await fs.ensureDir(destinationPath);
Expand Down
4 changes: 4 additions & 0 deletions template/oss-npm-package/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Writes "<%- moduleName %>" to stdout.
* Thrilling stuff.
*/
export const log = () =>
/* eslint-disable-next-line no-console */
console.log('<%- moduleName %>');
8 changes: 8 additions & 0 deletions template/oss-npm-package/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "lib",
"target": "ES2019"
},
"exclude": ["lib/**/*"],
"extends": "skuba/config/tsconfig.json"
}
4 changes: 4 additions & 0 deletions template/private-npm-package/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Writes "<%- moduleName %>" to stdout.
* Thrilling stuff.
*/
export const log = () =>
/* eslint-disable-next-line no-console */
console.log('<%- moduleName %>');
8 changes: 8 additions & 0 deletions template/private-npm-package/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "lib",
"target": "ES2019"
},
"exclude": ["lib/**/*"],
"extends": "skuba/config/tsconfig.json"
}
50 changes: 50 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,21 @@
globby "^11.0.0"
read-yaml-file "^1.1.0"

"@microsoft/[email protected]":
version "0.13.4"
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc-config/-/tsdoc-config-0.13.4.tgz#84ad92b88d3899683376224de91567b01d447d18"
integrity sha512-B3F3mndJTGUmcHTt8chqjN4EPvxJlkzZIkrZUHwJvKvbr74HEe6mB8Aa6Rlh8jj6mHq7mmtyiUn17+5zr4vbXw==
dependencies:
"@microsoft/tsdoc" "0.12.20"
ajv "~6.10.2"
jju "~1.4.0"
resolve "~1.12.0"

"@microsoft/[email protected]":
version "0.12.20"
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.20.tgz#4261285f666ee0c0378f810585dd4ec5bbfa8852"
integrity sha512-/b13m37QZYPV6nCOiqkFyvlQjlTNvAcQpgFZ6ZKIqtStJxNdqVo/frULubxMUMWi6p9Uo5f4BRlguv5ViFcL0A==

"@nodelib/[email protected]":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
Expand Down Expand Up @@ -1252,6 +1267,16 @@ ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@~6.10.2:
version "6.10.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.2.tgz#d3cea04d6b017b2894ad69040fec8b623eb4bd52"
integrity sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==
dependencies:
fast-deep-equal "^2.0.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ansi-align@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-2.0.0.tgz#c36aeccba563b89ceb556f3690f0b1d9e3547f7f"
Expand Down Expand Up @@ -2901,6 +2926,14 @@ eslint-plugin-react@^7.20.0:
string.prototype.matchall "^4.0.2"
xregexp "^4.3.0"

eslint-plugin-tsdoc@^0.2.5:
version "0.2.5"
resolved "https://registry.yarnpkg.com/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.5.tgz#ae8b1117c11b771d57797314da4bab620dfccc61"
integrity sha512-KXquQlf/3u2U7A3LebYdcmAMtMxmUW3HN4JtOluq+iRuRPbBNVeUlg4SOXrnqSuQCOpSITHlPhP418IwjExA+w==
dependencies:
"@microsoft/tsdoc" "0.12.20"
"@microsoft/tsdoc-config" "0.13.4"

eslint-scope@^5.0.0, eslint-scope@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5"
Expand Down Expand Up @@ -3140,6 +3173,11 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=

fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=

fast-deep-equal@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
Expand Down Expand Up @@ -4777,6 +4815,11 @@ jest@^26.0.1:
import-local "^3.0.2"
jest-cli "^26.0.1"

jju@~1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/jju/-/jju-1.4.0.tgz#a3abe2718af241a2b2904f84a625970f389ae32a"
integrity sha1-o6vicYryQaKykE+EpiWXDzia4yo=

"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down Expand Up @@ -7265,6 +7308,13 @@ resolve@^1.0.0, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15
dependencies:
path-parse "^1.0.6"

resolve@~1.12.0:
version "1.12.3"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.3.tgz#96d5253df8005ce19795c14338f2a013c38a8c15"
integrity sha512-hF6+hAPlxjqHWrw4p1rF3Wztbgxd4AjA5VlUzY5zcTb4J8D3JK4/1RjU48pHz2PJWzGVsLB1VWZkvJzhK2CCOA==
dependencies:
path-parse "^1.0.6"

responselike@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/responselike/-/responselike-1.0.2.tgz#918720ef3b631c5642be068f15ade5a46f4ba1e7"
Expand Down