Skip to content

Commit

Permalink
feat: strf-8589, drop JSPM support
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGenash committed Aug 18, 2020
1 parent 930922f commit c39c67b
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 714 deletions.
4 changes: 1 addition & 3 deletions bin/stencil-init
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ require('colors');
const StencilInit = require('../lib/stencil-init');
const pkg = require('../package.json');
const Program = require('commander');
const JspmAssembler = require('../lib/jspm-assembler');
const ThemeConfig = require('../lib/theme-config');
const dotStencilFilePath = './.stencil';
const versionCheck = require('../lib/version-check');

Expand All @@ -20,4 +18,4 @@ if (!versionCheck()) {
return;
}

StencilInit.run(JspmAssembler, ThemeConfig, dotStencilFilePath, Program.url, Program.token, Program.port);
StencilInit.run(dotStencilFilePath, Program.url, Program.token, Program.port);
18 changes: 1 addition & 17 deletions bin/stencil-start
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const Url = require('url');

const Cycles = require('../lib/cycles');
const templateAssembler = require('../lib/template-assembler');
const JspmAssembler = require('../lib/jspm-assembler');
const Pkg = require('../package.json');
const Program = require('commander');
const Server = require('../server');
Expand All @@ -29,7 +28,6 @@ Program
.version(Pkg.version)
.option('-o, --open', 'Automatically open default browser')
.option('-v, --variation [name]', 'Set which theme variation to use while developing')
.option('-t, --test', 'Enable QA mode which will bundle all javascript for speed to test locally')
.option('--tunnel [name]', 'Create a tunnel URL which points to your local server that anyone can use.')
.option('-n, --no-cache', 'Turns off caching for API resource data per storefront page. The cache lasts for 5 minutes before automatically refreshing.')
.parse(process.argv);
Expand Down Expand Up @@ -121,20 +119,7 @@ Wreck.get(
dotStencilFile.normalStoreUrl = payload.baseUrl;
dotStencilFile.stencilServerPort = stencilServerPort;

if (configuration.jspm && Program.test) {
bundleTask = JspmAssembler.assemble(
{
bootstrap: configuration.jspm.bootstrap,
},
themePath
);

bundleTask(function () {
return startServer();
});
} else {
return startServer();
}
return startServer();
}
}
);
Expand All @@ -159,7 +144,6 @@ async function startServer() {
let watchIgnored = [
'/assets/scss',
'/assets/css',
'/assets/jspm_packages',
];

// Display Set up information
Expand Down
36 changes: 0 additions & 36 deletions lib/bundle-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function BundleValidator(themePath, themeConfig, isPrivate) {
validateThemeConfiguration.bind(this),
validateThemeSchema.bind(this),
validateSchemaTranslations.bind(this),
validateJspmSettings.bind(this),
];

if (!this.isPrivate) {
Expand Down Expand Up @@ -186,28 +185,6 @@ function validateSchemaTranslations(callback) {
callback(null, true);
}

/**
* If a theme is using JSPM, make sure they
* @param callback
* @returns {*}
*/
function validateJspmSettings(callback) {
const configuration = this.themeConfig.getRawConfig();
let errorMessage;

if (configuration.jspm) {
if (!fileExists(Path.join(this.themePath, configuration.jspm.jspm_packages_path))) {
errorMessage = 'The path you specified for your "jspm_packages" folder does not exist.'.red;
errorMessage += 'Please check your '.red + 'jspm.jspm_packages_path'.cyan +
' setting in your theme\'s '.red + 'config.json'.cyan + ' file to make sure it\'s correct.'.red;

return callback(new Error(errorMessage));
}
}

callback(null, true);
}

/**
* Validates images for marketplace themes
* @param callback
Expand Down Expand Up @@ -277,19 +254,6 @@ function validateMetaImages(callback) {
});
}

/**
* Check if file exist synchronous
* @param {string} path
* @return {boolean}
*/
function fileExists(path) {
try {
return !!Fs.statSync(path);
} catch (e) {
return false;
}
}

/**
* Validates that require objects/properties exist in theme
* @param {array} assembledTemplates
Expand Down
2 changes: 1 addition & 1 deletion lib/json-lint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var jsonLint = require('jsonlint');
const jsonLint = require('jsonlint');

module.exports = {
parse: function (jsonString, file) {
Expand Down
50 changes: 0 additions & 50 deletions lib/jspm-assembler.js

This file was deleted.

49 changes: 2 additions & 47 deletions lib/stencil-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const PATHS_TO_ZIP = [
ignore: [
'assets/cdn/**',
'assets/**/*.js.map',
'assets/jspm_packages/**',
],
},
{ pattern: 'CHANGELOG.md' },
Expand All @@ -28,13 +27,11 @@ const PATHS_TO_ZIP = [
];

const Upath = require('upath');
const Tmp = require('tmp');
const Readdir = require('recursive-readdir');
const Archiver = require('archiver');
const Async = require('async');
const Crypto = require('crypto');
const Fs = require('fs');
const Jspm = require('jspm');
const Path = require('path');
const buildConfig = require('../lib/build-config');
const BundleValidator = require('./bundle-validator');
Expand Down Expand Up @@ -79,11 +76,6 @@ function Bundle(themePath, themeConfig, rawConfig, options) {
}

this.tasks = tasks;

if (this.configuration.jspm) {
this.configuration.jspm.tmpBundleFile = Tmp.fileSync().name;
this.tasks.jspmBundle = this.getJspmBundleTask(this.configuration.jspm);
}
}

/**
Expand Down Expand Up @@ -216,35 +208,6 @@ Bundle.prototype.assembleLangTask = function (callback) {
});
};

Bundle.prototype.getJspmBundleTask = function (jspmConfig) {
return callback => {
const oldConsoleError = console.error;

console.log('JavaScript Bundling Started...');

// Need to suppress annoying errors from Babel.
// They will be gone in the next minor version of JSPM (0.16.0).
// Until then, this will stay in place
console.error = error => {
if (!/Deprecated option metadataUsedHelpers/.test(error)) {
oldConsoleError(error);
}
};

Jspm.setPackagePath(this.themePath);
Jspm.bundleSFX(jspmConfig.bootstrap, jspmConfig.tmpBundleFile, {
minify: true,
mangle: true,
}).then(() => {
console.log('ok'.green + ' -- JavaScript Bundling Finished');
console.error = oldConsoleError;
callback(null, true);
}).catch(err => {
callback(err);
});
};
};

Bundle.prototype.generateManifest = function (taskResults, callback) {
console.log('Generating Manifest Started...');

Expand Down Expand Up @@ -325,7 +288,7 @@ function bundleTaskRunner(callback) {

taskResults.manifest = manifest;
// zip theme files
bundleThemeFiles(archive, this.themePath, this.configuration);
bundleThemeFiles(archive, this.themePath);

// zip all generated files
const failedTemplates = bundleParsedFiles(archive, taskResults);
Expand Down Expand Up @@ -357,16 +320,8 @@ function bundleTaskRunner(callback) {
* Archive theme files
* @param {Archiver} archive
* @param {String} themePath
* @param {Object} configuration
*/
function bundleThemeFiles(archive, themePath, configuration) {
if (configuration.jspm) {
archive.append(
Fs.createReadStream(configuration.jspm.tmpBundleFile),
{ name: configuration.jspm.bundle_location },
);
}

function bundleThemeFiles(archive, themePath) {
PATHS_TO_ZIP.forEach(({ pattern, ignore }) =>
archive.glob(pattern, { ignore, cwd: themePath }),
);
Expand Down
34 changes: 0 additions & 34 deletions lib/stencil-bundle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const Sinon = require('sinon');
const Path = require('path');
const { promisify } = require('util');
const async = require('async');
const when = require('when');
const Lab = require('@hapi/lab');
const lab = exports.lab = Lab.script();
const describe = lab.describe;
Expand All @@ -15,7 +14,6 @@ const expect = Code.expect;
const it = lab.it;
const StencilBundle = require('./stencil-bundle');
const LangAssembler = require('./lang-assembler');
const jspm = require('jspm');
const themeSchema = Fs.readFileSync((Path.join(themePath, 'schema.json'))).toString();

describe('Stencil Bundle', () => {
Expand Down Expand Up @@ -123,29 +121,6 @@ describe('Stencil Bundle', () => {
expect(error).to.equal('our_error');
});

it('should bundle JSPM assets', async () => {
sandbox.stub(jspm, 'bundleSFX').returns(when());

const jspmBundleTask = Bundle.getJspmBundleTask(getThemeConfigStub().getRawConfig);
const result = await promisify(jspmBundleTask.bind(Bundle))();

expect(result).to.equal(true);
});

it('should fail to bundle JSPM assets', async () => {
sandbox.stub(jspm, 'bundleSFX').returns(when.reject('SFX Bundle input error'));

let error;
try {
const jspmBundleTask = Bundle.getJspmBundleTask(getThemeConfigStub().getRawConfig);
await promisify(jspmBundleTask.bind(Bundle))();
} catch (err) {
error = err;
}

expect(error).to.equal('SFX Bundle input error');
});

it('should generate a manifest of files.', async () => {
const templates = await promisify(Bundle.assembleTemplatesTask.bind(Bundle))();
const manifest = await promisify(Bundle.generateManifest.bind(Bundle))({ templates });
Expand All @@ -170,15 +145,6 @@ describe('Stencil Bundle', () => {

function getThemeConfigStub() {
const rawConfig = {
jspm: {
dev: {
dep_location: 'assets/js/dependency-bundle.js',
bootstrap: 'js/**/* - [js/**/*]',
},
bootstrap: 'js/app',
bundle_location: 'assets/js/bundle.js',
jspm_packages_path: 'assets/jspm_packages',
},
meta: {
"author_name": "Emilio Esteves",
"author_email": "Emilio@work.net",
Expand Down
27 changes: 3 additions & 24 deletions lib/stencil-init.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict';
const Fs = require('fs');
const { promisify } = require("util");
const Path = require('path');
const Inquirer = require('inquirer');

const jsonLint = require('./json-lint');
const themePath = process.cwd();

async function performAnswers(JspmAssembler, ThemeConfig, stencilConfig, dotStencilFilePath, answers) {
async function performAnswers(stencilConfig, dotStencilFilePath, answers) {
const performedStencilConfig = {
customLayouts: {
'brand': {},
Expand All @@ -20,27 +17,9 @@ async function performAnswers(JspmAssembler, ThemeConfig, stencilConfig, dotSten
};

Fs.writeFileSync(dotStencilFilePath, JSON.stringify(performedStencilConfig, null, 2));

// bundle dev dependencies
const themeConfig = ThemeConfig.getInstance(themePath).getConfig();
if (themeConfig.jspm) {
if (!Fs.existsSync(Path.join(themePath, themeConfig.jspm.jspm_packages_path))) {
console.log('Error: The path you specified for your "jspm_packages" folder does not exist.'.red);
return console.log(
'Please check your '.red +
'jspm.jspm_packages_path'.cyan +
' setting in your theme\'s '.red +
'config.json'.cyan +
' file to make sure it\'s correct.'.red,
);
}

const bundleTask = promisify(JspmAssembler.assemble.bind(JspmAssembler));
await bundleTask(themeConfig.jspm, themePath);
}
}

async function run(JspmAssembler, ThemeConfig, dotStencilFilePath, url, token, port) {
async function run(dotStencilFilePath, url, token, port) {
let stencilConfig = {};

if (Fs.existsSync(dotStencilFilePath)) {
Expand Down Expand Up @@ -97,7 +76,7 @@ async function run(JspmAssembler, ThemeConfig, dotStencilFilePath, url, token, p
];
const answers = await Inquirer.prompt(questions);

await performAnswers(JspmAssembler, ThemeConfig, stencilConfig, dotStencilFilePath, answers);
await performAnswers(stencilConfig, dotStencilFilePath, answers);

console.log('You are now ready to go! To start developing, run $ ' + 'stencil start'.cyan);
}
Expand Down
Loading

0 comments on commit c39c67b

Please sign in to comment.