shonny-ua / gulp-rev-collector

Static asset revision data collector from manifests, with was generated from different streams and replace they's links in html template.
MIT License
149 stars 41 forks source link

why the file name can not contains "-" #32

Open dmwin72015 opened 7 years ago

dmwin72015 commented 7 years ago

If the name of the JS file contains “-”, it will be not work

shonny-ua commented 7 years ago

I wrote next test:

it('should generate correct collected manifest file, even if f the name of the JS file contains “-”', function (cb) {
    var stream = revCollector({
        // collectedManifest: 'collectedManifest.json'
    });
    var fileCount = 0;
    var revisionMap = {
        "assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js"
    };

    var htmlFileBody        = '<html><head><script src="/assets/js/com-mon.js"></head><body><img src="cdn/image.gif" /></body></html>';
    var htmlRevedFileBody   = '<html><head><script src="/assets/js/com-mon.js": "assets/js/common-2c0d21e40c.js"></head><body><img src="cdn/image.gif" /></body></html>';

    stream.write(new gutil.File({
        path: 'rev/css/rev-manifest.json',
        contents: new Buffer(JSON.stringify(revisionMap))
    }));

    stream.write(new gutil.File({
        path: 'index.html',
        contents: new Buffer(htmlFileBody)
    }));

    stream.on('data', function (file) {
        var fpath = file.path;
        var contents = file.contents.toString('utf8');
        var ext = path.extname(file.path);

        assert.equal(ext, '.html', 'Only html files should pass through the stream');

        assert(
            !/assets\/js\/com-mon\.js/.test(contents),
            'The JS file name should be replaced'
        );

        assert(
            /assets\/js\/com-mon-2c0d21e40c.js/.test(contents),
            'The JS file name should be correct replaced'
        );

        fileCount++;
    });

    stream.on('end', function() {
        assert.equal(fileCount, 1, 'Only one file should pass through the stream');
        cb();
    });

    stream.end();
});

The replacement "assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js" works correctly. Give my, please, more information about problem...

rainwen commented 7 years ago

gulp-rev-collector 1.2.2 Similar problems filename as a-c-12345678.css replace fail,modify filename as a.c.12345678.css replace success @shonny-ua

shonny-ua commented 6 years ago
// https://github.com/shonny-ua/gulp-rev-collector/issues/32
it('should generate correct collected manifest file, even if f the name of the JS or CSS file contains “-”', function (cb) {
    var stream = revCollector({
        // collectedManifest: 'collectedManifest.json'
    });
    var fileCount = 0;
    var revisionMap = {
        "assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js",
        "assets/css/a-c.css": "assets/css/a-c-12345678.css"
    };

    var htmlFileBody        = '<html><head><script src="/assets/js/com-mon.js"><link rel="stylesheet" href="/assets/css/a-c.css" /></head><body><img src="cdn/image.gif" /></body></html>';
    var htmlRevedFileBody   = '<html><head><script src="/assets/js/com-mon-2c0d21e40c.js"><link rel="stylesheet" href="/assets/css/a-c-12345678.css" /></head><body><img src="cdn/image.gif" /></body></html>';

    stream.write(new gutil.File({
        path: 'rev/css/rev-manifest.json',
        contents: new Buffer(JSON.stringify(revisionMap))
    }));

    stream.write(new gutil.File({
        path: 'index.html',
        contents: new Buffer(htmlFileBody)
    }));

    stream.on('data', function (file) {
        var fpath = file.path;
        var contents = file.contents.toString('utf8');
        var ext = path.extname(file.path);

        assert.equal(ext, '.html', 'Only html files should pass through the stream');

        assert(
            !/assets\/js\/com-mon\.js/.test(contents),
            'The JS file name should be replaced'
        );

        assert(
            !/assets\/css\/a-c\.css/.test(contents),
            'The CSS file name should be replaced'
        );

        assert(
            /assets\/js\/com-mon-2c0d21e40c\.js/.test(contents),
            'The JS file name should be correct replaced'
        );

        assert(
            /assets\/css\/a-c-12345678\.css/.test(contents),
            'The CSS file name should be correct replaced'
        );

        fileCount++;
    });

    stream.on('end', function() {
        assert.equal(fileCount, 1, 'Only one file should pass through the stream');
        cb();
    });

    stream.end();
});

works correctly.

Give my, please, more information about problem!!!

Write, Please, content of rev-manifest.json and html source files.