Skip to content

Commit

Permalink
Dynamically create package file
Browse files Browse the repository at this point in the history
Create a package file with name provided by user and start installing the dependencies required for an extension
  • Loading branch information
dutiyesh committed Sep 14, 2019
1 parent 30cb815 commit 858dce3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 25 deletions.
47 changes: 42 additions & 5 deletions index.js
Expand Up @@ -5,6 +5,7 @@
const path = require('path');
const fs = require('fs-extra');
const chalk = require('chalk');
const spawn = require('cross-spawn');
const commander = require('commander');

const packageFile = require('./package.json');
Expand Down Expand Up @@ -57,11 +58,47 @@ function createExtension(name) {
private: true,
};

// Copy package file to project directory
// fs.writeFileSync(
// path.join(root, 'package.json'),
// JSON.stringify(appPackage, null, 2)
// );
appPackage.scripts = {
watch:
'webpack --mode=development --watch --config config/webpack.config.js',
build: 'webpack --mode=production --config config/webpack.config.js',
};

// Create package file in project directory
fs.writeFileSync(
path.join(root, 'package.json'),
JSON.stringify(appPackage, null, 2)
);

let command = 'npm';
let args = ['install', '--save-dev'];

// Add devDependencies
args.push(
'webpack',
'webpack-cli',
'webpack-merge',
'copy-webpack-plugin',
'size-plugin',
'mini-css-extract-plugin',
'css-loader',
'file-loader'
);

console.log('Installing packages. This might take a couple of minutes.');
console.log(
`Installing ${chalk.cyan('webpack')}, ${chalk.cyan(
'webpack-cli'
)} and few more...`
);
console.log();

// Install package dependencies
const proc = spawn.sync(command, args, { cwd: root, stdio: 'inherit' });
if (proc.status !== 0) {
console.error(`\`${command} ${args.join(' ')}\` failed`);
return;
}

// Copy template files to project directory
fs.copySync(path.resolve(__dirname, 'templates', 'popup'), root);
Expand Down
41 changes: 41 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"chalk": "^2.4.2",
"commander": "^3.0.1",
"cross-spawn": "^7.0.0",
"fs-extra": "^8.1.0",
"validate-npm-package-name": "^3.0.0"
},
Expand Down
20 changes: 0 additions & 20 deletions templates/popup/package.json

This file was deleted.

0 comments on commit 858dce3

Please sign in to comment.