diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..d34eb4f --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +release.js \ No newline at end of file diff --git a/package.json b/package.json index 82be613..28ecac6 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,12 @@ "version": "0.0.1", "description": "", "repository": { - "url": "https://github.com/jamesatjaminit/" + "url": "https://github.com/jamesatjaminit/classcharts-api" }, - "main": "dist/index.js", + "main": "./index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "npx tsc && node dist/release.js" }, "author": "", "license": "ISC", diff --git a/src/release.ts b/src/release.ts new file mode 100644 index 0000000..803d76a --- /dev/null +++ b/src/release.ts @@ -0,0 +1,36 @@ +import fs from 'fs' + +// DO NOT DELETE THIS FILE +// This file is used by build system to build a clean npm package with the compiled js files in the root of the package. +// It will not be included in the npm package. + +function main() { + const source = fs + .readFileSync(__dirname + '/../package.json') + .toString('utf-8') + const sourceObj = JSON.parse(source) + sourceObj.scripts = {} + sourceObj.devDependencies = {} + if (sourceObj.main.startsWith('dist/')) { + sourceObj.main = sourceObj.main.slice(5) + } + fs.writeFileSync( + __dirname + '/package.json', + Buffer.from(JSON.stringify(sourceObj, null, 2), 'utf-8') + ) + fs.writeFileSync( + __dirname + '/version.txt', + Buffer.from(sourceObj.version, 'utf-8') + ) + try { + fs.mkdirSync(__dirname + '/types/') + } catch {} + + fs.copyFileSync( + __dirname + '/../types/index.d.ts', + __dirname + '/types/index.d.ts' + ) + fs.copyFileSync(__dirname + '/../.npmignore', __dirname + '/.npmignore') +} + +main()