Skip to content

Commit

Permalink
✨ feat: Install script showcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
honzabubenik committed Oct 4, 2023
1 parent b678dcc commit 46aaeb0
Show file tree
Hide file tree
Showing 4 changed files with 1,408 additions and 377 deletions.
59 changes: 59 additions & 0 deletions install/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node

import path from 'node:path';
import { fileURLToPath } from 'url';
import fs from 'fs-extra';
import chalk from 'chalk';
import ora from 'ora';
import shell from 'shelljs';
import { createRequire } from 'module';

// To prevent node experimental features warning after `import(package.json)` require is used instead.
const require = createRequire(import.meta.url);
const pkg = require('../package.json');

// https://patorjk.com/software/taag/#p=display&h=1&v=1&f=Sub-Zero&t=Localazy
const banner = chalk.blue(`
__ ______ ______ ______ __ ______ ______ __ __
/\\ \\ /\\ __ \\ /\\ ___\\ /\\ __ \\ /\\ \\ /\\ __ \\ /\\___ \\ /\\ \\_\\ \\
\\ \\ \\____\\ \\ \\/\\ \\\\ \\ \\____\\ \\ __ \\\\ \\ \\____\\ \\ __ \\\\/_/ /__\\ \\____ \\
\\ \\_____\\\\ \\_____\\\\ \\_____\\\\ \\_\\ \\_\\\\ \\_____\\\\ \\_\\ \\_\\ /\\_____\\\\/\\_____\\
\\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \\/_____/ \\/_/\\/_/ \\/_____/ \\/_____/
`);
const name = `${chalk.bold.green(pkg.name)}`;
const version = `${chalk.grey(`@${pkg.version}`)}`;
const file = `${chalk.bold.green('webpack.config.example.js')}`;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const template = (await fs.readFile(path.join(__dirname, 'webpack.js'))).toString();
const installSpinner = ora();

const install = () => new Promise((resolve, reject) => {
try {
shell.exec(`npm install ${pkg.name}`, { silent: true }, () => {
resolve();
});
} catch (err) {
reject(err);
}
});

const updateConfig = () => new Promise((resolve, reject) => {
try {
shell.exec(`echo "${template}" > src/admin/webpack.config.example.js`, { silent: true }, () => {
resolve();
});
} catch (err) {
reject(err);
}
});

console.log(banner);

installSpinner.start(`Installing ${name}${version}`);
await install();
installSpinner.succeed();

installSpinner.start(`Updating ${file}`);
await updateConfig();
installSpinner.succeed();
33 changes: 33 additions & 0 deletions install/webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";

/* eslint-disable no-unused-vars */
module.exports = (config, webpack) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config

// return config;


return {
...config,
resolve: {
...config.resolve,
fallback: {
...config.resolve.fallback,
crypto: false,
http: false,
fs: false,
zlib: false,
https: false,
// os: false,
stream: false,
path: false,
timers: false,
tls: false,
net: false,
// util: false,
},
}
};
};
Loading

0 comments on commit 46aaeb0

Please sign in to comment.