Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: STRF-11903 Migrate to ESM #1230

Merged
merged 1 commit into from
Sep 24, 2024
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 .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
}
],
// Overwrites airbnb-base because woks badly with prettier making multyline strings ugly
"prefer-template": "off"
"prefer-template": "off",
"import/extensions": "off"
}
}
25 changes: 7 additions & 18 deletions bin/stencil-bundle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/env node

require('colors');

const program = require('../lib/commander');
const { THEME_PATH, PACKAGE_INFO } = require('../constants');
const ThemeConfig = require('../lib/theme-config');
const Bundle = require('../lib/stencil-bundle');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
const { prepareCommand } = require('../lib/cliCommon');
const BuildConfigManager = require('../lib/BuildConfigManager');
import 'colors';
import program from '../lib/commander.js';
import { THEME_PATH, PACKAGE_INFO } from '../constants.js';
import ThemeConfig from '../lib/theme-config.js';
import Bundle from '../lib/stencil-bundle.js';
import { printCliResultErrorAndExit, prepareCommand } from '../lib/cliCommon.js';
import BuildConfigManager from '../lib/BuildConfigManager.js';

program
.version(PACKAGE_INFO.version)
Expand All @@ -29,28 +26,23 @@ program
'Set a timeout for the bundle operation. Default is 20 secs',
'60',
);

const cliOptions = prepareCommand(program);
const themeConfig = ThemeConfig.getInstance(THEME_PATH);

async function run() {
try {
if (cliOptions.dest === true) {
throw new Error('You have to specify a value for -d or --dest'.red);
}

if (cliOptions.name === true) {
throw new Error('You have to specify a value for -n or --name'.red);
}

if (!themeConfig.configExists()) {
throw new Error(
`${
'You must have a '.red + 'config.json'.cyan
} file in your top level theme directory.`,
);
}

const rawConfig = await themeConfig.getRawConfig();
const timeout = cliOptions.timeout * 1000; // seconds
const buildConfigManager = new BuildConfigManager({ timeout });
Expand All @@ -61,13 +53,10 @@ async function run() {
cliOptions,
buildConfigManager,
);

const bundlePath = await bundle.initBundle();

console.log(`Bundled saved to: ${bundlePath.cyan}`);
} catch (err) {
printCliResultErrorAndExit(err);
}
}

run();
14 changes: 5 additions & 9 deletions bin/stencil-debug.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/usr/bin/env node

require('colors');
const program = require('../lib/commander');

const StencilDebug = require('../lib/StencilDebug');
const { PACKAGE_INFO } = require('../constants');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
import 'colors';
import program from '../lib/commander.js';
import StencilDebug from '../lib/StencilDebug.js';
import { PACKAGE_INFO } from '../constants.js';
import { printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
.option('-o, --output [filename]', 'If provided will write to file')
.parse(process.argv);

const cliOptions = program.opts();

new StencilDebug().run(cliOptions).catch(printCliResultErrorAndExit);
26 changes: 7 additions & 19 deletions bin/stencil-download.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
#!/usr/bin/env node

require('colors');
const inquirer = require('inquirer');
const program = require('../lib/commander');

const { PACKAGE_INFO } = require('../constants');
const stencilDownload = require('../lib/stencil-download');
const { prepareCommand } = require('../lib/cliCommon');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
import 'colors';
import inquirer from 'inquirer';
import program from '../lib/commander.js';
import { PACKAGE_INFO } from '../constants.js';
import stencilDownload from '../lib/stencil-download.js';
import { prepareCommand, printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
.option('-f, --file [filename]', 'specify the filename to download only')
.option('-e, --exclude [exclude]', 'specify a directory to exclude from download')
.option('-c, --channel_id [channelId]', 'specify the channel ID of the storefront', parseInt)
.option('-o, --overwrite', 'overwrite local with remote files');

const cliOptions = prepareCommand(program);
const extraExclude = cliOptions.exclude ? [cliOptions.exclude] : [];
const options = {
exclude: ['parsed', 'manifest.json', ...extraExclude],
apiHost: cliOptions.host,
channelId: cliOptions.channel_id,
overwrite: cliOptions.overwrite,
applyTheme: true, // fix to be compatible with stencil-push.utils
applyTheme: true,
file: cliOptions.file,
};

async function run(opts) {
const overwriteType = opts.file ? opts.file : 'files';

const promptAnswers = await inquirer.prompt([
{
message: `${'Warning'.yellow} -- overwrite local with remote ${overwriteType}?`,
Expand All @@ -40,26 +34,20 @@ async function run(opts) {
},
},
]);

const answers = {
...opts,
...promptAnswers,
};

if (!answers.overwrite) {
console.log(`Request cancelled by user ${'No'.red}`);
return;
}

console.log(`${'ok'.green} -- ${overwriteType} will be overwritten by the changes`);

try {
await stencilDownload(opts);
} catch (err) {
printCliResultErrorAndExit(err);
}

console.log(`${'ok'.green} -- Theme file(s) updated from remote`);
}

run(options);
12 changes: 4 additions & 8 deletions bin/stencil-init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env node

const program = require('../lib/commander');

const StencilInit = require('../lib/stencil-init');
const { PACKAGE_INFO } = require('../constants');
const { prepareCommand, printCliResultErrorAndExit } = require('../lib/cliCommon');
import program from '../lib/commander.js';
import StencilInit from '../lib/stencil-init.js';
import { PACKAGE_INFO } from '../constants.js';
import { prepareCommand, printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
Expand All @@ -14,9 +12,7 @@ program
.option('-h, --apiHost [host]', 'API Host')
.option('-pm, --packageManager [pm]', 'Package manager')
.option('-skip, --skipInstall', 'Skip packages installation');

const cliOptions = prepareCommand(program);

new StencilInit()
.run({
normalStoreUrl: cliOptions.url,
Expand Down
16 changes: 5 additions & 11 deletions bin/stencil-pull.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/usr/bin/env node

require('colors');

const { PACKAGE_INFO } = require('../constants');
const program = require('../lib/commander');
const stencilPull = require('../lib/stencil-pull');
const { prepareCommand } = require('../lib/cliCommon');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
import 'colors';
import { PACKAGE_INFO } from '../constants.js';
import program from '../lib/commander.js';
import stencilPull from '../lib/stencil-pull.js';
import { prepareCommand, printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
Expand All @@ -21,17 +18,14 @@ program
'specify the channel ID of the storefront to pull configuration from',
parseInt,
);

const cliOptions = prepareCommand(program);

const options = {
apiHost: cliOptions.host,
saveConfigName: cliOptions.filename,
channelId: cliOptions.channel_id,
saved: cliOptions.saved || false,
applyTheme: true, // fix to be compatible with stencil-push.utils
};

stencilPull(options, (err) => {
if (err) {
printCliResultErrorAndExit(err);
Expand Down
13 changes: 5 additions & 8 deletions bin/stencil-push.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env node

require('colors');
const { PACKAGE_INFO } = require('../constants');
const program = require('../lib/commander');
const stencilPush = require('../lib/stencil-push');
const { prepareCommand } = require('../lib/cliCommon');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
import 'colors';
import { PACKAGE_INFO } from '../constants.js';
import program from '../lib/commander.js';
import stencilPush from '../lib/stencil-push.js';
import { prepareCommand, printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
Expand All @@ -18,7 +16,6 @@ program
'specify the channel IDs of the storefront to push the theme to',
)
.option('-allc, --all_channels', 'push a theme to all available channels');

const cliOptions = prepareCommand(program);
const options = {
apiHost: cliOptions.host,
Expand Down
15 changes: 5 additions & 10 deletions bin/stencil-release.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#!/usr/bin/env node

require('colors');
const StencilRelease = require('../lib/release/release');
const { PACKAGE_INFO } = require('../constants');
const program = require('../lib/commander');
const { checkNodeVersion } = require('../lib/cliCommon');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
import 'colors';
import StencilRelease from '../lib/release/release.js';
import { PACKAGE_INFO } from '../constants.js';
import program from '../lib/commander.js';
import { checkNodeVersion, printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
.option('-b, --branch [name]', 'specify the main branch name')
.parse(process.argv);

checkNodeVersion();

const cliOptions = program.opts();
const options = {
branch: cliOptions.branch || 'master',
};

new StencilRelease().run(options).catch(printCliResultErrorAndExit);
17 changes: 6 additions & 11 deletions bin/stencil-scss-autofix.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env node

require('colors');
const program = require('../lib/commander');

const ThemeConfig = require('../lib/theme-config');
const NodeSassAutoFixer = require('../lib/nodeSass/AutoFixer');
const { THEME_PATH, PACKAGE_INFO } = require('../constants');
const { printCliResultErrorAndExit } = require('../lib/cliCommon');
import 'colors';
import program from '../lib/commander.js';
import ThemeConfig from '../lib/theme-config.js';
import NodeSassAutoFixer from '../lib/nodeSass/AutoFixer.js';
import { THEME_PATH, PACKAGE_INFO } from '../constants.js';
import { printCliResultErrorAndExit } from '../lib/cliCommon.js';

program
.version(PACKAGE_INFO.version)
Expand All @@ -15,9 +13,6 @@ program
'will not write any changes to the file system, instead it will print the changes to the console',
)
.parse(process.argv);

const cliOptions = program.opts();

const themeConfig = ThemeConfig.getInstance(THEME_PATH);

new NodeSassAutoFixer(THEME_PATH, themeConfig, cliOptions).run().catch(printCliResultErrorAndExit);
15 changes: 6 additions & 9 deletions bin/stencil-start.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node

require('colors');
const { PACKAGE_INFO } = require('../constants');
const program = require('../lib/commander');
const StencilStart = require('../lib/stencil-start');
const { printCliResultErrorAndExit, prepareCommand } = require('../lib/cliCommon');
const BuildConfigManager = require('../lib/BuildConfigManager');
import 'colors';
import { PACKAGE_INFO } from '../constants.js';
import program from '../lib/commander.js';
import StencilStart from '../lib/stencil-start.js';
import { printCliResultErrorAndExit, prepareCommand } from '../lib/cliCommon.js';
import BuildConfigManager from '../lib/BuildConfigManager.js';

program
.version(PACKAGE_INFO.version)
Expand All @@ -21,7 +20,6 @@ program
'Turns off caching for API resource data per storefront page. The cache lasts for 5 minutes before automatically refreshing.',
)
.option('-t, --timeout', 'Set a timeout for the bundle operation. Default is 20 secs', '60');

const cliOptions = prepareCommand(program);
const options = {
open: cliOptions.open,
Expand All @@ -31,7 +29,6 @@ const options = {
tunnel: cliOptions.tunnel,
cache: cliOptions.cache,
};

const timeout = cliOptions.timeout * 1000; // seconds
const buildConfigManager = new BuildConfigManager({ timeout });
new StencilStart({ buildConfigManager }).run(options).catch(printCliResultErrorAndExit);
5 changes: 2 additions & 3 deletions bin/stencil.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

const program = require('../lib/commander');
const { PACKAGE_INFO } = require('../constants');
import program from '../lib/commander.js';
import { PACKAGE_INFO } from '../constants.js';

program
.version(PACKAGE_INFO.version)
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/// ////////////////////////////////////// Stencil CLI ///////////////////////////////////// ///

const PACKAGE_INFO = require('./package.json');

import { readFileSync } from 'fs';
/// //////////////////////////////////////// Themes /////////////////////////////////////// ///

const THEME_PATH = process.cwd();

const DEFAULT_CUSTOM_LAYOUTS_CONFIG = {
brand: {},
category: {},
page: {},
product: {},
};

/// ///////////////////////////////////////// Other //////////////////////////////////////// ///

const API_HOST = 'https://api.bigcommerce.com';

module.exports = {
const packageConfigUrl = new URL('./package.json', import.meta.url);
const PACKAGE_INFO = JSON.parse(readFileSync(packageConfigUrl));

export { PACKAGE_INFO };
export { THEME_PATH };
export { DEFAULT_CUSTOM_LAYOUTS_CONFIG };
export { API_HOST };
export default {
PACKAGE_INFO,
THEME_PATH,
DEFAULT_CUSTOM_LAYOUTS_CONFIG,
Expand Down
Loading