-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: npm package structure update for future project refactor
Signed-off-by: Richard Lea <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,704 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as path from 'path'; | ||
import * as sh from 'shelljs'; | ||
|
||
const PKG_ROOT = path.resolve(__dirname, '../dist'); | ||
|
||
const a = sh.ls('-R', PKG_ROOT).forEach(f => { | ||
if (f.endsWith('.js.map')) { | ||
sh.rm(path.resolve(PKG_ROOT, f)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import chalk from 'chalk'; | ||
import * as fs from 'fs-extra'; | ||
import * as _ from 'lodash'; | ||
import * as mandocConsts from 'mandoc/paths.const'; | ||
import * as path from 'path'; | ||
import * as sh from 'shelljs'; | ||
const stringLength = require('string-length'); | ||
|
||
const OK = chalk.reset.inverse.bold.green(' DONE '); | ||
const pkg_json_path = path.resolve(__dirname, '../package.json'); | ||
|
||
const PKG_ROOT = path.resolve(__dirname, '../dist'); | ||
const BIN_PKG = path.join(PKG_ROOT, './bin'); | ||
|
||
if (!fs.existsSync(PKG_ROOT)) { | ||
process.stderr.write(chalk.red('Can\'t find dist directory.\n' | ||
+ 'Make sure typescript files building was done.\n')); | ||
process.exit(1); | ||
} | ||
|
||
if (!fs.existsSync(pkg_json_path)) { | ||
process.stderr.write(chalk.red('Can\'t find package json file to build package.\n')); | ||
process.exit(1); | ||
} | ||
|
||
/** | ||
* Learned from | ||
* https://github.com/facebook/jest/blob/36dcb7873e18e4fb059653cfef3bfb35359e6195/scripts/build.js#L54 | ||
* | ||
*/ | ||
function adjustToTerminalWidth(str: string) { | ||
const columns = process.stdout.columns || 80; | ||
const WIDTH = columns - stringLength(OK) + 1; | ||
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g')) as string[]; | ||
let lastString = strs[strs.length - 1]; | ||
if (lastString.length < WIDTH) { | ||
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.')); | ||
} | ||
|
||
return strs | ||
.slice(0, -1) | ||
.concat(lastString) | ||
.join('\n'); | ||
} | ||
|
||
(function main() { | ||
process.stdout.write(chalk.inverse(' Building package \n')); | ||
const package_config = require(pkg_json_path); | ||
// Learned from | ||
// https://github.com/ReactiveX/rxjs/blob/d5658fe68093861e0612be3c8c045f973168b87c/.make-packages.js#L45 | ||
delete package_config.devDependencies; | ||
delete package_config.scripts; | ||
fs.writeJsonSync(path.resolve(PKG_ROOT, './package.json'), | ||
_.assign({}, package_config, { | ||
name: 'mandoc', | ||
main: './index.js', | ||
typings: './index.d.ts', | ||
bin: { | ||
'mandoc': './bin/mandoc', | ||
'mandoc-gen': './bin/mandoc-gen', | ||
}, | ||
// Try in future commits, referring to the practice in rxjs repository. | ||
// module: './_esm5/index.js', | ||
// es2015: './_esm2015/index.js', | ||
}), { | ||
spaces: 2, | ||
}); | ||
sh.find(path.join(PKG_ROOT, './bin')) | ||
.filter(file => file.match(/\.js$/)) | ||
.forEach(file => sh.mv(file, file.slice(0, - 3))); | ||
})(); |
Oops, something went wrong.