Skip to content
Permalink
Browse files

chore(npm): update npm task for browser

  • Loading branch information...
suguru03 committed Aug 6, 2018
1 parent 8095ce3 commit 6b91a617ed5aa8b36ec1ccc4049a92181ed7a09a
Showing with 19 additions and 18 deletions.
  1. +18 −14 gulp/tasks/npm.js
  2. +0 −3 gulp/template
  3. +1 −1 index.js
@@ -12,42 +12,46 @@ const { exec } = require('../util');
gulp.task('npm:publish', publish);

async function publish() {
const rootpath = path.resolve(__dirname, '../..');
const buildpath = path.resolve(rootpath, 'build');
const rootpath = path.join(__dirname, '../..');
const buildpath = path.join(rootpath, 'build');

await exec(`rm -rf ${buildpath}`);

// make dir
!fs.existsSync(buildpath) && fs.mkdirSync(buildpath);

// copy lib
fs.copySync(path.resolve(rootpath, 'lib'), path.resolve(buildpath, 'lib'));
fs.copySync(path.join(rootpath, 'lib'), path.join(buildpath, 'lib'));
// copy a minified file
fs.copySync(path.resolve(rootpath, 'dist', 'aigle-es5.min.js'), path.resolve(buildpath, 'aigle-es5.min.js'));
fs.copySync(path.join(rootpath, 'dist', 'aigle-es5.min.js'), path.join(buildpath, 'aigle-es5.min.js'));

// copy package.json
const json = _.omit(require('../../package'), ['files', 'scripts', 'private']);
json.main = 'aigle.js';
json.main = 'lib/aigle';
json.browser = 'aigle-es5.min.js';
fs.writeFileSync(path.resolve(buildpath, 'package.json'), JSON.stringify(json, null, 2), 'utf8');
fs.writeFileSync(path.join(buildpath, 'package.json'), JSON.stringify(json, null, 2), 'utf8');

// copy README
fs.copySync(path.resolve(rootpath, 'README.md'), path.resolve(buildpath, 'README.md'));
fs.copySync(path.join(rootpath, 'README.md'), path.join(buildpath, 'README.md'));

// create all function files
const template = fs.readFileSync(path.resolve(__dirname, '../template'), 'utf8');
const template = `module.exports = require('./aigle')`;
_.forOwn(Aigle, (func, key) => {
if (!_.isFunction(func) || /Error$/.test(key)) {
if (!_.isFunction(func) || /Error$|^Aigle$/.test(key)) {
return;
}
const file = template.replace('<function>', key);
fs.writeFileSync(path.resolve(buildpath, `${_.camelCase(key)}.js`), file, 'utf8');
const file = `${template}.${key};`;
fs.writeFileSync(path.join(buildpath, `${_.camelCase(key)}.js`), file, 'utf8');
});
const aiglefile = template.replace(/require.*/, "require('./lib/aigle');");
fs.writeFileSync(path.resolve(buildpath, 'aigle.js'), aiglefile, 'utf8');

// craete aigle files
const aigledirpath = path.join(buildpath, 'aigle');
const pkg = { main: '../lib/aigle', browser: '../aigle-es5.min.js' };
fs.mkdirSync(aigledirpath);
fs.writeFileSync(path.join(aigledirpath, 'package.json'), JSON.stringify(pkg), 'utf8');

// copy type files
fs.copySync(path.resolve(rootpath, 'typings', 'aigle.d.ts'), path.resolve(buildpath, 'aigle.d.ts'));
fs.copySync(path.join(rootpath, 'typings', 'aigle.d.ts'), path.join(buildpath, 'aigle.d.ts'));

// TODO: fix publish task
// const tag = /alpha|beta/.test(json.version) ? '--tag next' : '';

This file was deleted.

@@ -1,4 +1,4 @@
'use strict';

// It is for browserify https://github.com/suguru03/aigle/issues/56
module.exports = require('./lib/aigle.js');
module.exports = require('./lib/aigle');

1 comment on commit 6b91a61

@suguru03

This comment has been minimized.

Copy link
Owner Author

commented on 6b91a61 Aug 7, 2018

#69

Please sign in to comment.
You can’t perform that action at this time.