Skip to content

Commit

Permalink
Refactor: npm package structure update for future project refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Lea <[email protected]>
  • Loading branch information
chigix committed Sep 16, 2018
1 parent 5c55791 commit e97759b
Show file tree
Hide file tree
Showing 13 changed files with 1,704 additions and 575 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,20 @@ This project is inspired by
* [markdown-pdf](https://github.com/alanshaw/markdown-pdf)
* [pandoc](https://pandoc.org/)
* [DeckTape](https://github.com/astefanutti/decktape)
* [Hexo](https://hexo.io/)
* [Hexo](https://hexo.io/)

## To Try

* tsconfig file series practice
It seems that `esm5` and `esm2015` compiling result from typescript source
code could be directly used for the keys, [`module`](https://github.com/rollup/rollup/wiki/pkg.module)
and `es2015`, in `package.json` file.

This practice could also be totally referenced in `rxjs` official repository,
where different tsconfig files are prepared for compiling target as `es5` and
`es2015`.

This attempt sounds that a little time would be cost without any apparent technical
barrier that need to spend time for inspecting and learning.
* RXJS commit message guideline
https://github.com/ReactiveX/rxjs/blob/master/CONTRIBUTING.md#commit-message-guidelines
17 changes: 0 additions & 17 deletions bin/mandoc

This file was deleted.

20 changes: 0 additions & 20 deletions bin/mandoc-gen

This file was deleted.

10 changes: 10 additions & 0 deletions build/make-clean-source-map.ts
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));
}
});
71 changes: 71 additions & 0 deletions build/make-packages.ts
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)));
})();
Loading

0 comments on commit e97759b

Please sign in to comment.