How to use the @ui5/fs.resourceFactory function in @ui5/fs

To help you get started, we’ve selected a few @ui5/fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / ui5-builder / test / lib / tasks / replaceCopyright.js View on Github external
const test = require("ava");

const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const DuplexCollection = ui5Fs.DuplexCollection;

test("integration: replace copyright", (t) => {
	const reader = resourceFactory.createAdapter({
		virBasePath: "/"
	});
	const writer = resourceFactory.createAdapter({
		virBasePath: "/"
	});
	const workspace = new DuplexCollection({reader, writer});

	/* eslint-disable no-useless-escape */
	const content = `/*!
 * $\{copyright\}
 */
console.log('HelloWorld');`;
github SAP / ui5-builder / test / lib / tasks / jsdoc / generateJsdoc.js View on Github external
test.serial("writeResourcesToDir with byGlobSource", async (t) => {
	const writeStub = sinon.stub().resolves();
	const createAdapterStub = sinon.stub(require("@ui5/fs").resourceFactory, "createAdapter").returns({
		write: writeStub
	});

	await generateJsdoc._writeResourcesToDir({
		workspace: {
			// stub byGlobSource
			byGlobSource: (pattern) => {
				t.deepEqual(pattern, "some pattern", "Glob with correct pattern");
				return Promise.resolve(["resource A", "resource B"]);
			}
		},
		pattern: "some pattern",
		targetPath: path.join("/", "some", "target", "path")
	});

	t.deepEqual(createAdapterStub.getCall(0).args[0], {
github SAP / ui5-builder / lib / processors / versionInfoGenerator.js View on Github external
const resourceFactory = require("@ui5/fs").resourceFactory;

function pad(v) {
	return String(v).padStart(2, "0");
}
function getTimestamp() {
	const date = new Date();
	const year = date.getFullYear();
	const month = pad(date.getMonth() + 1);
	const day = pad(date.getDate());
	const hours = pad(date.getHours());
	const minutes = pad(date.getMinutes());
	// yyyyMMddHHmm
	return year + month + day + hours + minutes;
}

/**
github SAP / ui5-builder / lib / builder / builder.js View on Github external
const {promisify} = require("util");
const rimraf = promisify(require("rimraf"));
const log = require("@ui5/logger").getGroupLogger("builder:builder");
const resourceFactory = require("@ui5/fs").resourceFactory;
const MemAdapter = require("@ui5/fs").adapters.Memory;
const typeRepository = require("../types/typeRepository");
const taskRepository = require("../tasks/taskRepository");
const BuildContext = require("./BuildContext");

const definedTasks = taskRepository.getAllTasks();

// Set of tasks for development
const devTasks = [
	"replaceCopyright",
	"replaceVersion",
	"buildThemes"
];

/**
 * Calculates the elapsed build time and returns a prettified output
github SAP / ui5-builder / test / lib / tasks / replaceVersion.js View on Github external
const test = require("ava");

const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const DuplexCollection = ui5Fs.DuplexCollection;

test("integration: replace version", (t) => {
	const reader = resourceFactory.createAdapter({
		virBasePath: "/"
	});
	const writer = resourceFactory.createAdapter({
		virBasePath: "/"
	});

	const content = "console.log('${version}');";
	const expected = "console.log('1.337.0');";

	const resource = resourceFactory.createResource({
		path: "/test.js",
		string: content
github SAP / ui5-builder / test / lib / tasks / createDebugFiles.js View on Github external
const test = require("ava");

const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;

test("integration: test.js: dbg file creation", (t) => {
	const sourceAdapter = resourceFactory.createAdapter({
		virBasePath: "/"
	});
	const content = "console.log('Hello World');";

	const resource = resourceFactory.createResource({
		path: "/test.js",
		string: content
	});

	return sourceAdapter.write(resource).then(() => {
		return tasks.createDebugFiles({
			workspace: sourceAdapter,
			options: {
github SAP / ui5-builder / test / lib / tasks / buildThemes.integration.js View on Github external
const test = require("ava");

const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const DuplexCollection = ui5Fs.DuplexCollection;

test("integration: simple", (t) => {
	const reader = resourceFactory.createAdapter({
		virBasePath: "/"
	});
	const writer = resourceFactory.createAdapter({
		virBasePath: "/"
	});
	const duplexCollection = new DuplexCollection({reader, writer});
	const dependencies = resourceFactory.createAdapter({
		virBasePath: "/"
	});

	const content =
`@deepSea: #123456;
github SAP / ui5-builder / test / lib / processors / jsdoc / sdkTransformer.js View on Github external
test.serial("sdkTransformer", async (t) => {
	const transformerStub = sinon.stub().resolves("api.json content");
	mock("../../../../lib/processors/jsdoc/lib/transformApiJson", transformerStub);
	const createResourceStub = sinon.stub(require("@ui5/fs").resourceFactory, "createResource")
		.returns("result resource");

	const sdkTransformer = mock.reRequire("../../../../lib/processors/jsdoc/sdkTransformer");

	const res = await sdkTransformer({
		apiJsonPath: "/some/path/api.json",
		dotLibraryPath: "/some/path/.library",
		targetApiJsonPath: "/some/other/path/api.json",
		dependencyApiJsonPaths: [
			"/some/path/x/api.json",
			"/some/path/y/api.json"
		],
		fs: "custom fs"
	});

	t.deepEqual(res.length, 1, "Returned one resource");
github SAP / ui5-builder / lib / processors / bundlers / flexChangesBundler.js View on Github external
const log = require("@ui5/logger").getLogger("builder:processors:bundlers:flexChangesBundler");
const resourceFactory = require("@ui5/fs").resourceFactory;

/**
 * Bundles all supplied changes.
 *
 * @public
 * @alias module:@ui5/builder.processors.flexChangesBundler
 * @param {Object} parameters Parameters
 * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed
 * @param {Object} parameters.options Options
 * @param {string} parameters.options.pathPrefix Prefix for bundle path
 * @param {string} parameters.options.hasFlexBundleVersion true if minUI5Version >= 1.73 than create flexibility-bundle.json
 * @returns {Promise} Promise resolving with flex changes bundle resources
 */
module.exports = function({resources, options}) {
	let bundleName = "changes-bundle.json";
github SAP / ui5-builder / lib / processors / bundlers / manifestBundler.js View on Github external
const path = require("path");
const yazl = require("yazl");
const resourceFactory = require("@ui5/fs").resourceFactory;
const log = require("@ui5/logger").getLogger("builder:processors:bundlers:manifestBundler");

/**
 * Repository to handle i18n resource files
 *
 * @private
 */
class I18nResourceList {
	/**
	 * Constructor
	 */
	constructor() {
		this.propertyFiles = new Map();
	}

	/**