UNPKG

1.15 kBJavaScriptView Raw
1/**
2 * NPM install cgb-scripts.
3 *
4 * - Build package.json file.
5 * - NPM install the plugin block.
6 *
7 * @param {string} blockName The block name.
8 * @param {string} blockDir The block directory.
9 * @return {promise} promise resolved.
10 */
11
12'use strict';
13
14const path = require( 'path' );
15const fs = require( 'fs-extra' );
16const execa = require( 'execa' );
17const shell = require( 'shelljs' );
18
19module.exports = ( blockName, blockDir ) => {
20 shell.cd( blockDir );
21 shell.touch( 'package.json' );
22
23 // Build a package.json file since npm install needs it.
24 const appPackage = {
25 name: `${ blockName }-cgb-guten-block`,
26 version: '1.0.0',
27 private: true,
28 scripts: {
29 start: 'cgb-scripts start',
30 build: 'cgb-scripts build',
31 eject: 'cgb-scripts eject',
32 },
33 };
34
35 // Write the package.json file.
36 fs.writeFileSync(
37 path.join( process.cwd(), 'package.json' ),
38 JSON.stringify( appPackage, null, 2 ) + '\n'
39 );
40
41 // Install latest exact version of cgb-scripts.
42 return new Promise( async resolve => {
43 await execa( 'npm', [
44 'install',
45 'cgb-scripts',
46 '--save',
47 '--save-exact',
48 '--slient',
49 ] );
50 resolve( true );
51 } );
52};