Skip to content

Commit

Permalink
- Added 'clean-and-run-downlevel-dts' script for running 'clean', 'do…
Browse files Browse the repository at this point in the history
…wnlevel-dts', 'copy' steps for downlevel-dts output directory ('./ts3.5').

- Added generated 'downleveled dts' files (keeping this in the git cache
since we're already keeping the library's artifacts there - more
consistent).
  • Loading branch information
elycruz committed Jul 20, 2022
1 parent e67d9a5 commit 69c65e2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
45 changes: 45 additions & 0 deletions package-lock.json

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

12 changes: 11 additions & 1 deletion package.json
Expand Up @@ -4,9 +4,18 @@
"description": "Rollup Sass files.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"typesVersions": {
"<4.0": {
"*": [
"ts3.5/*"
]
}
},
"scripts": {
"prepare": "npm run build && npm test",
"build": "tsc --project tsconfig.json",
"build": "npm run build-downlevel-dts && tsc --project tsconfig.json",
"build-downlevel-dts": "node scripts/clean-and-run-downlevel-dts.js",
"downlevel-dts": "downlevel-dts . ts3.5 [--to=3.5]",
"test": "nyc --reporter=html --reporter=text ava ./test/*.test.ts -s && npm run test:rollup.config.spec.ts",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test:rollup.config.spec.ts": "tsc --project tsconfig.spec.json --noEmit"
Expand Down Expand Up @@ -59,6 +68,7 @@
"@types/sass": "^1.16.1",
"ava": "^4.3.1",
"coveralls": "^3.1.1",
"downlevel-dts": "^0.10.0",
"eslint": "^7.32.0",
"jsdom": "^17.0.0",
"nyc": "^15.1.0",
Expand Down
47 changes: 47 additions & 0 deletions scripts/clean-and-run-downlevel-dts.js
@@ -0,0 +1,47 @@
/**
* @script clean-and-run-downlevel-dts.js
* @description Removes '{repo-root}/ts3.5' directory, re-creates it, runs
* `npm run downlevel-dts` from repo-root, and copies the root tsconfig.json file into new directory.
*/
const fs = require('fs').promises,
path = require('path'),
{spawn} = require('child_process'),

{log, warn, error} = console,

rootDir = path.join(__dirname, '..'),
outputDir = path.resolve(path.join(__dirname, '../ts3.5')),

tsConfigFilePath = path.join(rootDir, 'tsconfig.json'),
tsConfigOutFilePath = path.join(outputDir, 'tsconfig.json');

(async () =>
fs.rmdir(outputDir, {recursive: true})

.then(() => fs.mkdir(outputDir))

.then(() => fs.copyFile(tsConfigFilePath, tsConfigOutFilePath))

// Run downlevel-dts
.then(() => new Promise((resolve, reject) => {

// Start downlevel-dts package script
const subProcess = spawn('npm', ['run', 'downlevel-dts'], {cwd: rootDir});

// Log child process buffer data as `string`
subProcess.stdout.on('data', data => log(data.toString().trim() + '\n'));

// Log stderr, child process, buffer data as a `string`
subProcess.stderr.on('data', data => warn(data.toString().trim() + '\n'));

// Handle process end
subProcess.on('close', (code) => code !== 0 ?
reject(`Child process existed with code ${code}.\n`) :
resolve('Process completed successfully.\n')
);

// Catch process start errors
subProcess.on('error', reject);
}))

)().then(log, error);

0 comments on commit 69c65e2

Please sign in to comment.