Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/dev-scripts/bin/blockly-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const args = process.argv.slice(2);
const {spawnSync} = require('child_process');

const script = args[0];
if (['build', 'start', 'clean', 'lint', 'test'].includes(script)) {
if (['build', 'start', 'clean', 'lint', 'test', 'postinstall']
.includes(script)) {
const result = spawnSync('node',
[].concat(require.resolve('../scripts/' + script))
.concat(args.slice(1)), {stdio: 'inherit'}
Expand Down
14 changes: 13 additions & 1 deletion plugins/dev-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);

const packageJson = require(resolveApp('package.json'));

module.exports = (env) => {
const mode = env.mode;
const isDevelopment = mode === 'development';
Expand Down Expand Up @@ -55,6 +57,16 @@ module.exports = (env) => {
target = 'node';
}

// Add 'dist' to the end of the blockly module alias if we have acquired
// blockly from git instead of npm.
let blocklyAliasSuffix = '';
const blocklyDependency =
(packageJson.dependencies && packageJson.dependencies['blockly']) ||
(packageJson.devDependencies && packageJson.devDependencies['blockly']);
if (blocklyDependency && blocklyDependency.indexOf('git://') === 0) {
blocklyAliasSuffix = '/dist';
}

return {
target,
mode: isProduction ? 'production' : 'development',
Expand All @@ -69,7 +81,7 @@ module.exports = (env) => {
},
resolve: {
alias: {
'blockly': resolveApp('node_modules/blockly'),
'blockly': resolveApp(`node_modules/blockly${blocklyAliasSuffix}`),
},
extensions: ['.ts', '.js']
.filter((ext) => isTypescript || !ext.includes('ts')),
Expand Down
49 changes: 49 additions & 0 deletions plugins/dev-scripts/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview A 'postinstall' script for Blockly extension packages.
* This script:
* Completes post install tasks if necessary.
* @author samelh@google.com (Sam El-Husseini)
*/

'use strict';

const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;

const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);

const packageJson = require(resolveApp('package.json'));
const blocklyNodeModulesPath = resolveApp('node_modules/blockly');

// Check if we have installed blockly from git instead of npm.
const blocklyDependency =
(packageJson.dependencies && packageJson.dependencies['blockly']) ||
(packageJson.devDependencies && packageJson.devDependencies['blockly']);

if (!blocklyDependency) {
return;
}

if (blocklyDependency.indexOf('git://') !== 0) {
return;
}

// Blockly was installed from a Git repo. Install and build.
console.log(`Running postinstall steps for ${packageJson.name}`);

// Run npm install.
execSync(`npm install`, {cwd: blocklyNodeModulesPath, stdio: [0, 1, 2]});

// Build.
execSync(`npm run build`, {cwd: blocklyNodeModulesPath, stdio: [0, 1, 2]});

// Package.
execSync(`npm run package`, {cwd: blocklyNodeModulesPath, stdio: [0, 1, 2]});
Loading